Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cypress-audit

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypress-audit

:zap: Run Lighthouse audit directly in your E2E test suites.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
50K
decreased by-0.09%
Maintainers
1
Weekly downloads
 
Created
Source

:zap: Run Lighthouse audit directly in your E2E test suites.

cypress audit

Why?

My opinion is that we're using Lighthouse in the browser or in CI only to verify that the homepage has good scores. However, a user could open a website from another page than the home one.

With this module, I wanted to facilitate the automation control of Lighthouse in my E2E test suite using a simple command called cy.audit()

Usage

Installation

In your favorite terminal:

$ yarn add -D cypress-audit

In your cypress/plugins/index.js, add:

const { audit, prepareAudit } = require("cypress-audit");

module.exports = (on, config) => {
  on("before:browser:launch", (browser = {}, launchOptions) => {
    prepareAudit(launchOptions);
  });

  on("task", {
    audit
  });
};

In your cypress/support/commands.js, add:

import "cypress-audit/commands";

In your code

You can now use the cy.audit() command in your tests:

it("should verify the lighthouse scores", function() {
  cy.audit({
    performance: 85,
    accessibility: 100,
    "best-practices": 85,
    seo: 85,
    pwa: 100
  });
});

NB: none of the keys are required, you can put the keys you want and the module will make the assertions based on them.

You can also define the default thresholds in your cypress.json file. However, it will be replaced by the cy.audit argument if provided:

// cypress.json
{
  "lighthouse": {
    "performance": 85,
    "accessibility": 50,
    "best-practices": 85,
    "seo": 85,
    "pwa": 50
  }
}

Example

The example folder of the projects owns a create-react-app application with an associated cypress test running lighthouse. You can run it by:

  • Cloning this repo ($ git clone https://github.com/mfrachet/cypress-audit)
  • Start the application ($ yarn start)
  • Run the E2E test suite ($ yarn e2e for UI and $ yarn e2e:headless for headless)

FAQs

Package last updated on 19 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc