All Projects → fwouts → React Screenshot Test

fwouts / React Screenshot Test

Licence: mit
A dead simple library to screenshot test React components

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Screenshot Test

puppeteer-screenshot-tester
Small library that allows us to compare screenshots generated by puppeteer in our tests.
Stars: ✭ 50 (-90.37%)
Mutual labels:  screenshot, jest
Deviceframe
📱 Put device frames around your mobile/web/progressive app screenshots.
Stars: ✭ 507 (-2.31%)
Mutual labels:  screenshot
Shotlooter
a recon tool that finds sensitive data inside the screenshots uploaded to prnt.sc
Stars: ✭ 451 (-13.1%)
Mutual labels:  screenshot
Artplayer
🎨 ArtPlayer.js is a modern and full featured HTML5 video player
Stars: ✭ 484 (-6.74%)
Mutual labels:  screenshot
Opensource
Delivering delightful digital solutions. Open Source packages with combined ~85M/month downloads, semantically versioned following @conventional-commits. Fully powered by Jest, @Babel TypeScript, @Airbnb @ESLint + @Prettier, @YarnPKG + @Lerna independent versioning, GH @Actions & automated dep updates with @RenovateBot.
Stars: ✭ 459 (-11.56%)
Mutual labels:  jest
Snapshot Diff
Diffing snapshot utility for Jest
Stars: ✭ 490 (-5.59%)
Mutual labels:  jest
Surfboard
Surfboard is a delightful onboarding framework for iOS.
Stars: ✭ 434 (-16.38%)
Mutual labels:  screenshot
Pepperoni App Kit
Pepperoni - React Native App Starter Kit for Android and iOS
Stars: ✭ 4,657 (+797.3%)
Mutual labels:  jest
Snowflake
❄️ A React-Native Android iOS Starter App/ BoilerPlate / Example with Redux, RN Router, & Jest with the Snowflake Hapi Server running locally or on RedHat OpenShift for the backend, or a Parse Server running locally or remotely on Heroku
Stars: ✭ 4,576 (+781.7%)
Mutual labels:  jest
Ts Jest
A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.
Stars: ✭ 5,380 (+936.61%)
Mutual labels:  jest
Chromda
λ 🖼️ Chromda is an AWS Lambda function for capturing screenshots of websites.
Stars: ✭ 481 (-7.32%)
Mutual labels:  screenshot
Ts Monorepo
Template for setting up a TypeScript monorepo
Stars: ✭ 459 (-11.56%)
Mutual labels:  jest
Url2img
HTTP server with API for capturing screenshots of websites
Stars: ✭ 495 (-4.62%)
Mutual labels:  screenshot
Storycap
A Storybook Addon, Save the screenshot image of your stories 📷 via puppeteer.
Stars: ✭ 451 (-13.1%)
Mutual labels:  screenshot
Ashot
WebDriver Screenshot utility. Take screenshots, crop, prettify, compare
Stars: ✭ 507 (-2.31%)
Mutual labels:  screenshot
Gatsby Starter Ecommerce
Gatsby starter for creating an eCommerce site using the Moltin eCommerce Api
Stars: ✭ 448 (-13.68%)
Mutual labels:  jest
Ffcast
Run command on rectangular screen regions
Stars: ✭ 478 (-7.9%)
Mutual labels:  screenshot
Injectablegenericcamerasystem
This is a generic camera system to be used as the base for cameras for taking screenshots within games. The main purpose of the system is to hijack the in-game 3D camera by overwriting values in its camera structure with our own values so we can control where the camera is located, it's pitch/yaw/roll values, its FoV and the camera's look vector.
Stars: ✭ 492 (-5.2%)
Mutual labels:  screenshot
Jest Clean Console Reporter
A Jest Reporter to group, hide and prettify spammy console warnings
Stars: ✭ 520 (+0.19%)
Mutual labels:  jest
React Typescript Web Extension Starter
🖥 A Web Extension starter kit built with React, TypeScript, SCSS, Storybook, Jest, EsLint, Prettier, Webpack and Bootstrap. Supports Google Chrome + Mozilla Firefox + Brave Browser 🔥
Stars: ✭ 510 (-1.73%)
Mutual labels:  jest

Logo

CircleCI npm downloads license



Here is a screenshot test written with react-screenshot-test:

Code example

All you need is to install react-screenshot-test and configure Jest:

// jest.screenshot.config.js

module.exports = {
  testEnvironment: "node",
  globalSetup: "react-screenshot-test/global-setup",
  globalTeardown: "react-screenshot-test/global-teardown",
  testMatch: ["**/?(*.)+(screenshot).[jt]s?(x)"],
  transform: {
    "^.+\\.[t|j]sx?$": "babel-jest", // or ts-jest
    "^.+\\.module\\.css$": "react-screenshot-test/css-modules-transform",
    "^.+\\.css$": "react-screenshot-test/css-transform",
    "^.+\\.scss$": "react-screenshot-test/sass-transform",
    "^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
      "react-screenshot-test/asset-transform"
  },
  transformIgnorePatterns: ["node_modules/.+\\.js"]
};

You can then generate screenshots with jest -c jest.screenshot.config.js -u, just like you would with Jest snapshots.

What does it look like?

Here's a real example of a pull request where a component was changed: Example PR

How does it work?

Under the hood, we start a local server which renders components server-side. Each component is given its own dedicated page (e.g. /render/my-component). Then we use Puppeteer to take a screenshot of that page.

Curious to learn more? Check out the internal documentation!

Cross-platform consistency

If you work on a team where developers use a different OS (e.g. Mac OS and Linux), or if you develop on Mac OS but use Linux for continuous integration, you would quickly run into issues where screenshots are inconsistent across platforms. This is, for better or worse, expected behaviour.

In order to work around this issue, react-screenshot-test will default to running Puppeteer (i.e. Chrome) inside Docker to take screenshots of your components. This ensures that generated screenshots are consistent regardless of which platform you run your tests on.

You can override this behaviour by setting the SCREENSHOT_MODE environment variable to local, which will always use a local browser instead of Docker.

Note: On Linux, react-screenshot-test will run Docker using host network mode on port 3001

CSS support

CSS-in-JS libraries such as Emotion and Styled Components are supported.

CSS technique Supported
<div style={...}
CSS stylesheets
import "./style.css"
Sass stylesheets
import "./style.scss"
CSS Modules
import css from "./style.css"
Emotion
Styled Components

Usage with create-react-app

If you'd like to set up react-screenshot-test with a create-react-app, here is everything you need.

Storing image snapshots

We recommend using Git LFS to store image snapshots. This will help prevent your Git repository from becoming bloated over time.

If you're unfamiliar with Git LFS, you can learn about it with this short video (2 min) and/or going through the official tutorial.

To set up Git LFS, install the Git extension and add the following to .gitattributes in your repository (source):

**/__screenshots__/*.* binary
**/__screenshots__/*.* filter=lfs diff=lfs merge=lfs -text

You may also need to set up Git LFS for continuous integration. See our config for an example with CircleCI.

Usage with Percy

If you prefer to keep image snapshots out of your repository, you can use a third-party service such as Percy:

  • Install @percy/puppeteer
  • Ensure that PERCY_TOKEN is set in your enviroment
  • Set up a script to invoke Jest through Percy:
{
  "screenshot-test-percy": "SCREENSHOT_MODE=percy percy exec -- jest -c jest.screenshot.config.js"
}

TypeScript support

This library is written in TypeScript. All declarations are included.

Browser support

At the moment, screenshots are only generated with Chrome. However, the design can be extended to any headless browser. File an issue if you'd like to help make this happen.

Comparison

Tool Visual Open Source Price for 100,000 snapshots/month Jest integration Review process
react-screenshot-test Free Pull request
Jest snapshots Free Pull request
Percy $469 Separate UI
storycap Free Implicit approval with reg-suit

Reporting issues

If something doesn't work, or if the documentation is unclear, please do not hesitate to raise an issue!

If it doesn't work for you, it probably doesn't work for others either 🙃

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].