GithubHelp home page GithubHelp logo

isabella232 / jest-visual-snapshot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from getsentry/jest-visual-snapshot

0.0 0.0 0.0 1.37 MB

jest environment for taking image snapshots of React components

License: MIT License

JavaScript 22.32% TypeScript 77.68%

jest-visual-snapshot's Introduction

visual snapshot

Note: This is a work in progress and APIs may (will) change.

This library is meant as a replacement for jest's toMatchSnapshot() feature (currently, only supports React). Our snapshots tended to be large, hard to read, and frustrating to use when making changes. An example of this is when making a change to a styled component that was snapshotted - the snapshot diffs would only show that a class name has changed, which has limited value for the developer making the change, as well as code reviewers. For us, the main use-cases for snapshots where 1) to make sure that it renders ok and 2) we do not introduce regressions when making changes. Given this, we wanted to have snapshots produce an image of the component when rendered in the browser.

Getting Started

yarn add -D @visual-snapshot/jest

In your jest.config.js you must:

  • set the preset to @visual-snapshot/jest
  • add @visual-snapshot/jest to setupFilesAfterEnv - this will add a custom toSnapshot() matcher
  • set testEnvironmentOptions.output to the path where the images will be written
module.exports = {
  preset: '@visual-snapshot/jest',
  setupFilesAfterEnv: ['@visual-snapshot/jest'],
  testEnvironmentOptions: {
    output: path.resolve(__dirname, '.artifacts', 'visual-snapshots', 'jest'),
    includeCss: path.resolve(
      __dirname,
      'static',
      'global.css'
    ),
  },
};

Finally, you must run jest with the environment variable VISUAL_SNAPSHOT_ENABLE (or VISUAL_HTML_ENABLE for html output) set. e.g.

VISUAL_SNAPSHOT_ENABLE=1 yarn jest

Checking for Regressions

You'll notice that these snapshots do not get compared during jest runs - it only produces an output, and will not fail your builds. We moved that process into CI pipeline to avoid checking in snapshots into the repo, but also to streamline the process of checking for visual regressions. Check out the Visual Snapshot GitHub Action for more information.

Development

yarn install && yarn lerna bootstrap

yarn dev

jest-visual-snapshot's People

Contributors

billyvg avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.