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

match-screenshot

v3.0.168

Published

[![Build Status](https://travis-ci.org/wix-incubator/match-screenshot.svg?branch=master)](https://travis-ci.org/wix-incubator/match-screenshot) [![npm](https://img.shields.io/npm/v/match-screenshot.svg)](https://www.npmjs.com/package/match-screenshot)

Downloads

1,091

Readme

match-screenshot

Build Status npm

A simple Jest or Chai matcher to compare screenshots, using Applitools Eyes (other platforms will be supported as well, TBD)

Install & Configure

Install Package

npm install --save-dev match-screenshot

Setup eyes env variable

Add EYES_API_KEY environment variable, with your eyes key

CI

Travis

go to your build's options -> settings -> Environment Variables and add EYES_API_KEY + your key

locally

add an .env file, with:

EYES_API_KEY=<your key here>
  • this step is not mandatory - you should use it if you want to use eyes when running locally.
  • ⚠️ you should put your .env file in git ignore!!!

Set the matcher

Jest
"jest": {
  "setupTestFrameworkScriptFile": "match-screenshot/jest"
}

In case you have several custom matchers in your project / you need setupTestFrameworkScriptFile for other configurations, just use:

"jest": {
  "setupTestFrameworkScriptFile": "<rootDir>/setupTestFrameworkScriptFile.js"
}

Inside setupTestFrameworkScriptFile.js you can then:

require('match-screenshot/jest');
Chai
const {Assertion} = require('chai');
const toMatchScreenshot = require('match-screenshot/chai');
Assertion.addMethod('toMatchScreenshot', toMatchScreenshot);

Usage

Basic

Puppeteer example:

it('my test', async () {
  await page.goto('http://www.wix.com');
  const screenshot = await page.screenshot();
  await expect(screenshot).toMatchScreenshot({key: 'my test'});
});

Creating a new baseline

When you change production code implementation, Eyes will break, and you will have to go to its management Dashboard and approve the change. In order to avoid that, you can assign a new version and create a new baseline:

  it('my test', async () {
    await page.goto('http://www.wix.com');
    const screenshot = await page.screenshot();
    await expect(screenshot).toMatchScreenshot({key: 'my test', version: 'v1.0.1'});
  });

API

toMatchScreenshot([options])

  • options

    key <[string]> A unique key for your screenshot. This key will be used in Applittols Eyes.

    version <[string]> (optional) Used to create a new baseline. See Creating a new baseline for more details. Default value: 'v1.0.0'.

    viewport <[string]> (optional) Explicitly pass viewport argument to Applitools api. This will prevent Applitools from creating a new baseline in case of a change in the screenshot actual viewport. Instead, it will fail the test.

    matchLevel <[enum]> (optional) Explicitly set match level

    autoSaveNewTest <[boolean]> (optional) If you set it to false, every time that eyes will detect a new test(different viewport size, first run) it will fail the test and the baseline will need to be approved in Eyes. Default value: true.

    const MatchLevel = require('match-screenshot/matchLevel')
    ...
    await expect(screenshot).toMatchScreenshot({key: 'my test', matchLevel: MatchLevel.Explicit});

jestWithConfig([options])

Configure your matcher with global options.

Set the matcher:

"jest": {
  "setupTestFrameworkScriptFile": "<rootDir>/setupTestFrameworkScriptFile.js"
},

Inside setupTestFrameworkScriptFile.js you can then:

require('match-screenshot/jestWithConfig')(options);
  • options

    appName <[string]> Application name. Will be used inside Applitools as part of test title

How does it work

Everytime you use toMatchScreenshot matcher, a screenshot will be sent to Applitools Eyes, which will compare the new screenshot with the baseline. The test will fail if they are not equal.

Typescript defintions

If you are using typescript and are missing type defintions for toMatchScreenshot, you can add the following line to your tsconfig:

 "files": [
   "./node_modules/match-screenshot/index.d.ts",
 ]