npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nfelger/cypress-har-generator

v0.0.0

Published

Generate [HTTP Archive (HAR)](http://www.softwareishard.com/blog/har-12-spec/) while running tests

Downloads

120

Readme

cypress-har-generator

Generate HTTP Archive (HAR) while running tests

Install

Run npm i --save-dev @neuralegion/cypress-har-generator to install the plugin.

✴ For details about changes between versions, and information about updates on previous releases, see the Releases tab on GitHub: https://github.com/NeuraLegion/cypress-har-generator/releases

Quick Start

First, install cypress-har-generator as development dependency:

npm i --save-dev @neuralegion/cypress-har-generator

Next, go to the cypress's directory and put this code is in your cypress/plugins/index.js file:

const { install, ensureBrowserFlags } = require('@neuralegion/cypress-har-generator');

module.exports = (on, config) => {
  install(on, config);
  
  on('before:browser:launch', (browser = {}, launchOptions) => {
    ensureBrowserFlags(browser, launchOptions);
    return launchOptions;
  });
};

After then, you should register commands that perform the manipulation with the HAR file. For that add this module to your support file cypress/support/index.js:

require('@neuralegion/cypress-har-generator/commands');

Once the configuration is completed, add the following code into each test:

// cypress/integration/users.spec.js

describe('my tests', () => {
  before(() => {
    // start recording
    cy.recordHar();
  });

  after(() => {
    // HAR will be saved as users.spec.har 
    // at the root of the project 
    cy.saveHar();
  });
});

After then, you can start the tests with:

cypress run --browser chrome

✴ Now only Chrome family browsers are supported.

When the cypress finished executing tests, the plugin will save a new archive at the root of the project. By default, a HAR is saved to a file with a name including the current spec’s name: {specName}.har

Commands

recordHar

Starts recording network logs. The plugin records all network requests so long as the browser session is open.

cy.recordHar();

You can set content flag to false to skip loading content fields in the HAR.

cy.recordHar({ content: false });

To include only requests on specific hosts, you can specify a list of hosts using includeHosts.

cy.recordHar({ includeHosts: [ '.*.execute-api.eu-west-1.amazonaws.com'] });

To exclude some requests, you can specify a list of paths to be excluded using excludePaths.

cy.recordHar({ excludePaths: ['^/login', 'logout$'] });

saveHar

Stops recording and save all requests that have occurred since you run recording to the HAR file.

cy.saveHar();

Pass a filename to change the default naming behavior.

cy.saveHar({ fileName: 'example.com.har' });

Pass an output directory to change the destination folder manually. It allows overriding the value, that is specified in the cypress.json

cy.saveHar({ outDir: './hars' });

Generate HAR file only for chrome, if it is not interactive run, and if test failed.

beforeEach(() => {
  const isInteractive = Cypress.config('isInteractive');
  const isChrome = Cypress.browser.name === 'chrome';
  if (!isInteractive && isChrome) {
    cy.recordHar();
  }
});

afterEach(() => {
  const { state } = this.currentTest;
  const isInteractive = Cypress.config('isInteractive');
  const isChrome = Cypress.browser.name === 'chrome';
  if (!isInteractive && isChrome && state !== 'passed') {
    cy.saveHar();
  }
});

If you want to change the path to the files, you can specify it by setting the hars_folder environment variable.

cypress run --browser chrome --env hars_folders=cypress/hars

License

Copyright © 2021 NeuraLegion.

This project is licensed under the MIT License - see the LICENSE file for details.