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 🙏

© 2025 – Pkg Stats / Ryan Hefner

cypress-match-screenshot

v1.1.0

Published

Utility to take screenshots during a cypress test and match them against previous runs

Readme

cypress-match-screenshot

npm version

Utility to take screenshots during a cypress test and match them against previous runs.

Disclaimer

Cypress is actively working on a feature like this, see https://github.com/cypress-io/cypress/issues/495. With that in mind this package should only be seen as temporary solution until Cypress publishes their official solution … but if you're like me and want to do some screenshot matching rather sooner than later, feel free to give it a shot 😄

Usage

yarn add cypress-match-screenshot --dev

Then register the custom command in your cypress/support/commands.js file:

import { register } from 'cypress-match-screenshot';
register();

That's it, now you can use the feature like this:

describe('Example', function () {
  it('Should match screenshot', function () {
    cy.visit('https://google.com');
    cy.matchScreenshot('Google Screenshot');
  });
});

On the first run the assertion will always pass and the tool will just store the screenshot. On subsequent runs it will take a screenshot and compare it to the previous one. Only if the difference is below the threshold the assertion will pass and the old screenshot will be replaced by the new one.

You can find all diffs as images in cypress/screenshots/diff to see what excactly changed 😊

CI

NOTE: I haven't played around with screenshot matching in CI, so treat everything in here careful and please feel free to add / edit anything if you find missing or wrong information 😊

Keep screenshots around to be matched

By default Cypress deletes all the screenshots before running tests in CI mode. To disable that (to keep the screenshots around so they can be matched in subsequent runs) just add the following to your cypress.json config:

{
  "trashAssetsBeforeHeadlessRuns": false
}

API

register

name (optional)

You can optionally define the name you want the functionality to be registered on. By default its matchScreenshot.

import { register } from 'cypress-match-screenshot'
register('myCustomName');

// then in the test
cy.myCustomName('Example');

Match screenshot method

cy.matchScreenshot(name, {
  threshold,
  thresholdType
});

name

If you have multiple screenshots within the same test case, you need to give them unique names so that the matcher can identify which image it should match to. It also makes it easier for you to find the image in the screenshots folder.

The general rule for screenshot naming is: [Test Suit Name] -- [Test Name] -- [Screenshot Name].png

options

  • threshold: Threshold for the screenshot matching, default: 0.005
  • thresholdType: unit for the threshold,pixel or percent, default: percent

Update screenshots

If you want to update the base screenshots with the new generated set, put the updateScreenshots parameter to your Cypress config. This will allow your tests to pass and the base screenshots being replaced by the new ones.

Todos

  • [x] ~~Crop screenshots to only contain relevant viewport (see https://github.com/cypress-io/cypress/issues/1810)~~
  • [x] ~~See if we can add more meaningful assertion messages~~
  • [ ] Somehow show the diff image whenever the check fails
  • [ ] Test and verify CI behaviour of this plugin