All Projects → wix-incubator → match-screenshot

wix-incubator / match-screenshot

Licence: MIT License
A simple Jest or Chai matcher to compare screenshots, using Applitools Eyes

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to match-screenshot

Mostly
They mostly come at night; mostly.
Stars: ✭ 78 (+457.14%)
Mutual labels:  jest, puppeteer
Redux Actions Assertions
Simplify testing of redux action and async action creators
Stars: ✭ 177 (+1164.29%)
Mutual labels:  jest, chai
Jest Extended
Additional Jest matchers 🃏💪
Stars: ✭ 1,763 (+12492.86%)
Mutual labels:  jest, matchers
Marvelheroes
Marvel Heroes
Stars: ✭ 54 (+285.71%)
Mutual labels:  jest, puppeteer
patent-free-react-ecosystem-migration-plan
Patent Free React Ecosystem Migration Plan
Stars: ✭ 15 (+7.14%)
Mutual labels:  jest, chai
Nuxt Jest Puppeteer
🚀 Nuxt.js zero configuration tests, run with Jest and Puppetter
Stars: ✭ 57 (+307.14%)
Mutual labels:  jest, puppeteer
Earl
☕ Ergonomic, modern and type-safe assertion library for TypeScript
Stars: ✭ 153 (+992.86%)
Mutual labels:  jest, chai
Enzyme
JavaScript Testing utilities for React
Stars: ✭ 19,781 (+141192.86%)
Mutual labels:  jest, chai
qa-automation-base
There are basic projects for automation frameworks based on Kotlin/Java and TypeScript for the backend, frontend, and mobile.
Stars: ✭ 45 (+221.43%)
Mutual labels:  jest, chai
Puppeteer Examples
Puppeteer example scripts for running Headless Chrome from Node.
Stars: ✭ 2,781 (+19764.29%)
Mutual labels:  jest, puppeteer
Aws Testing Library
Chai (https://chaijs.com) and Jest (https://jestjs.io/) assertions for testing services built with aws
Stars: ✭ 52 (+271.43%)
Mutual labels:  jest, chai
energy-use-case-trading-client
Energy Use Case Web UI for Lition Trading Platform
Stars: ✭ 23 (+64.29%)
Mutual labels:  jest, puppeteer
Jest Codemods
Codemods for migrating to Jest https://github.com/facebook/jest 👾
Stars: ✭ 731 (+5121.43%)
Mutual labels:  jest, chai
Openapivalidators
Use Jest or Chai to assert that HTTP responses satisfy an OpenAPI spec
Stars: ✭ 77 (+450%)
Mutual labels:  jest, chai
Differencify
Differencify is a library for visual regression testing
Stars: ✭ 572 (+3985.71%)
Mutual labels:  jest, puppeteer
Javascript Testing Best Practices
📗🌐 🚢 Comprehensive and exhaustive JavaScript & Node.js testing best practices (August 2021)
Stars: ✭ 13,976 (+99728.57%)
Mutual labels:  jest, chai
puppeteer-screenshot-tester
Small library that allows us to compare screenshots generated by puppeteer in our tests.
Stars: ✭ 50 (+257.14%)
Mutual labels:  jest, puppeteer
Jest Puppeteer
Run your tests using Jest & Puppeteer 🎪✨
Stars: ✭ 3,267 (+23235.71%)
Mutual labels:  jest, puppeteer
Root Cause
🔍 Root Cause is a tool for troubleshooting Puppeteer and Playwright tests. 🔎
Stars: ✭ 205 (+1364.29%)
Mutual labels:  jest, puppeteer
xstate-marionettist
Model based testing with Jest, XState and Puppeteer or Playwright made easy
Stars: ✭ 23 (+64.29%)
Mutual labels:  jest, puppeteer

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",
 ]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].