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

cypress-lens

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypress-lens

Module for visual regression testing and reporting in Cypress

  • 1.10.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
859
increased by7.51%
Maintainers
1
Weekly downloads
 
Created
Source

Logo

Documentation | Changelog

The best module for visual testing for Cypress.

Cypress Conf Link

Join us, we're hiring.

version license semantic-version conventional

Cypress Lens

Based on Cypress Visual Regression

Module for visual regression testing and reporting for Cypress.

Visual Regression Demo

example

Reporter Demo

example

Getting Started

Install:

$ npm install cypress-lens

1. Setup visual regression

Add the following config to your cypress.config.js file:

const { defineConfig } = require("cypress");
const getCompareSnapshotsPlugin = require("cypress-lens/dist/plugin");

module.exports = defineConfig({
  screenshotsFolder: "./cypress/snapshots/actual",
  trashAssetsBeforeRuns: true,
  video: false,
  e2e: {
    setupNodeEvents(on, config) {
      getCompareSnapshotsPlugin(on, config);
    },
  },
});

Add the command to cypress/support/commands.js:

const compareSnapshotCommand = require("cypress-lens/dist/command");

compareSnapshotCommand();

Make sure you import commands.js in cypress/support/e2e.js:

import "./commands";

TypeScript

cypress/tsconfig.json

{
  "compilerOptions": {
    "types": ["cypress", "cypress-lens"]
  }
}

1. Setup reporter

Install cypress-multi-reporters: This plugin allows us to use more than one reporters since we want to keep the cypress default spec reports.

$ npm install cypress-multi-reporters

Create reporter-config.json and place the following code

{
  "reporterEnabled": "spec, cypress-lens"
}

Add the following config to your cypress.config.js file:

const { defineConfig } = require("cypress");
const getCompareSnapshotsPlugin = require("cypress-lens/dist/plugin");

module.exports = defineConfig({
  screenshotsFolder: "./cypress/snapshots/actual",
  trashAssetsBeforeRuns: true,
  video: false,
  e2e: {
    reporter: "cypress-multi-reporters",
    reporterOptions: {
      configFile: "reporter-config.json",
    },
    setupNodeEvents(on, config) {
      getCompareSnapshotsPlugin(on, config);
    },
  },
});

3. How to use

it("Should display the home page according to baseline snapshot", () => {
  cy.visit("www.dreamshot.bg");
  cy.compareSnapshot("home-page");
});

Options

failSilently is enabled by default. Add the following config to your cypress.config.js file to see the errors:

{
  env: {
    failSilently: false;
  }
}

You can also pass default arguments to compareSnapshotCommand():

const compareSnapshotCommand = require("cypress-visual-regression/dist/command");

compareSnapshotCommand({
  capture: "fullPage",
});

These will be used by default when no parameters are passed to the compareSnapshot command.

Take the base images:

$ ./node_modules/.bin/cypress run --env type=base"

Find regressions:

$ ./node_modules/.bin/cypress run --env type=actual

Keywords

FAQs

Package last updated on 16 Oct 2023

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