Generating code coverage for test files using Puppeteer is currently not possible if your test uses
page.evaluateas the passed function is executed outside of Jest's scope. Check out issue #7962 on GitHub for a workaround.
Jest Puppeteer provides all required configuration to run your tests using Puppeteer.
- First, install
- Specify preset in your Jest configuration:
- Write your test
There's no need to load any dependencies. Puppeteer's
browser classes will automatically be exposed
You can also hook up puppeteer from scratch. The basic idea is to:
- launch & file the websocket endpoint of puppeteer with Global Setup
- connect to puppeteer from each Test Environment
- close puppeteer with Global Teardown
Here's an example of the GlobalSetup script
Then we need a custom Test Environment for puppeteer
Finally, we can close the puppeteer instance and clean-up the file
With all the things set up, we can now write our tests like this:
jest.config.js to read from these files. (The
jest-puppeteer preset does something like this under the hood.)
Here's the code of full working example.