How to use the @tracerbench/core.harTrace function in @tracerbench/core

To help you get started, we’ve selected a few @tracerbench/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TracerBench / tracerbench / packages / cli / src / commands / create-archive.ts View on Github external
public async run() {
    const { flags } = this.parse(CreateArchive);
    const { browserArgs, url, tbResultsFolder } = flags;
    const archiveOutput = path.join(tbResultsFolder, 'trace.har');
    const cookiesJSON = path.join(tbResultsFolder, 'cookies.json');
    let cookies;
    let harArchive;

    if (!fs.existsSync(tbResultsFolder)) {
      fs.mkdirSync(tbResultsFolder);
    }

    [cookies, harArchive] = await harTrace(url, browserArgs);
    fs.writeFileSync(cookiesJSON, JSON.stringify(cookies));
    fs.writeFileSync(archiveOutput, JSON.stringify(harArchive));

    this.log(
      `Captured ${harArchive.log.entries.length} request responses in har file.`
    );
    return this.log(
      `HAR & cookies.json successfully generated from ${url} and available here: ${archiveOutput} and ${cookiesJSON}`
    );
  }
}