question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using Jest with Puppeteer and create-react-app

See original GitHub issue

Using Jest with Puppeteer can be great, for example I like to take screenshot from the headless browser to test regression of the user interface.

The result is just right here

screen shot 2018-02-13 at 20 38 29

The problem

Everything is working perfectly, the problem is that for each test file including puppeteer a new instance of Chrome is loaded, and of course it’s the slowest part of the process.

Jest documentation links us to this repo with a perfect example of integration with Puppeteer. It is initialised inside globalSetup and killed in globalTeardown. But they are not available in create-react-app.

The available src/setupTests.js is not enough to do this properly.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:15
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
vuhminhcommented, Apr 12, 2018

u can create a separate test runner for tests with puppeteer

// package.json
"scripts": {
    "test:e2e": "jest -c jest-e2e.config.js",
}
... rest
// jest-e2e.config.js

// Configarion for running jest for end-to-end tests
module.exports = {
  preset: 'jest-puppeteer-preset',
  ...other jest config
};

// jest-puppeteer.config.js
module.exports = {
  launch: {
    headless: true,
  }
};

2reactions
christopher-franciscocommented, May 8, 2018

How is this working for you guys? CRA uses Jest 20 and it’s not recognizing globalSetup nor globalTeardown options. I’ve also tried to update react-scripts but mine is on 1.1.4 which seems to be the latest version, so I don’t see how would I even have Jest 22. What am I missing?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React end-to-end testing with Jest and Puppeteer
In React, E2E testing with Jest and Puppeteer helps to ensure that the code you wrote is functional and your app works as...
Read more >
Adding Puppeteer to create-react-app generated projects
This post looks at adding Puppeteer to a create-react-app generated app, and shows how easy it is to get Puppeteer up and running....
Read more >
How not to despair while setting up Puppeteer and Jest on a ...
Here's today's tale of woe: setting up my create-react-app for end-to-end testing. Background. We have a number of React clients in our ...
Read more >
Testing your React App with Puppeteer and Jest | by Rajat S
How to use Puppeteer and Jest to perform End-to-End Testing on your React App ... Go to src/App and create a new file...
Read more >
Testing React App With Jest & Puppeteer - DEV Community ‍ ‍
This application is created using create-react-app. The application folder will be structured as shown below. ├── e2e │ ├── custom- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found