Gathering detailed insights and metrics for jest-environment-puppeteer-jsdom
Gathering detailed insights and metrics for jest-environment-puppeteer-jsdom
Gathering detailed insights and metrics for jest-environment-puppeteer-jsdom
Gathering detailed insights and metrics for jest-environment-puppeteer-jsdom
npm install jest-environment-puppeteer-jsdom
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
3 Stars
2 Commits
1 Forks
2 Watching
15 Branches
1 Contributors
Updated on 15 Feb 2022
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-16%
21
Compared to previous day
Last week
33%
121
Compared to previous week
Last month
-48.6%
481
Compared to previous month
Last year
-65.6%
11,244
Compared to previous year
The version of jest-environment-puppeteer-jsdom based on js-dom to support server side rendering and visual tests.
Run your tests using Jest & Puppeteer 🎪✨
npm install jest-environment-puppeteer-jsdom puppeteer
Update your Jest configuration:
1{ 2 "globalSetup": "jest-environment-puppeteer-jsdom/setup", 3 "globalTeardown": "jest-environment-puppeteer-jsdom/teardown", 4 "testEnvironment": "jest-environment-puppeteer-jsdom" 5}
Use Puppeteer in your tests:
1describe('Google', () => { 2 beforeAll(async () => { 3 await page.goto('https://google.com') 4 }) 5 6 it('should display "google" text on page', async () => { 7 const text = await page.evaluate(() => document.body.textContent) 8 expect(text).toContain('google') 9 }) 10})
global.browser
Give access to the Puppeteer Browser.
1it('should open a new page', async () => { 2 const page = await browser.newPage() 3 await page.goto('https://google.com') 4})
global.page
Give access to a Puppeteer Page opened at start (you will use it most of time).
1it('should fill an input', async () => { 2 await page.type('#myinput', 'Hello') 3})
global.context
Give access to a browser context that is instantiated when the browser is launched. You can control whether each test has its own isolated browser context using the browserContext
option in your jest-puppeteer.config.js
.
global.jestPuppeteer.debug()
Put test in debug mode.
debugger
instruction to Chromium, if Puppeteer has been launched with { devtools: true }
it will stop1it('should put test in debug mode', async () => { 2 await jestPuppeteer.debug() 3})
global.jestPuppeteer.resetPage()
Reset global.page
1beforeEach(async () => { 2 await jestPuppeteer.resetPage() 3})
global.jestPuppeteer.resetBrowser()
Reset global.browser, global.context, and global.page
1beforeEach(async () => { 2 await jestPuppeteer.resetBrowser() 3})
jest-puppeteer.config.js
You can specify a jest-puppeteer.config.js
at the root of the project or define a custom path using JEST_PUPPETEER_CONFIG
environment variable. It should export a config object or a Promise for a config object.
launch
<[object]> All Puppeteer launch options can be specified in config. Since it is JavaScript, you can use all stuff you need, including environment.connect
<[object]> All Puppeteer connect options can be specified in config. This is an alternative to launch
config, allowing you to connect to an already running instance of Chrome.browser
<[string]>. Define a browser to run tests into.
chromium
Each test uses puppeteer and runs Chromiumfirefox
Each test uses puppeteer-firefox and runs Firefox. This option requires puppeteer-firefox
as a peer dependency.browserContext
<[string]>. By default, the browser context (cookies, localStorage, etc) is shared between all tests. The following options are available for browserContext
:
default
Each test starts a tab, so all tests share the same context.incognito
Each tests starts an incognito window, so all tests have a separate, isolated context. Useful when running tests that could interfere with one another. (Example: testing multiple users on the same app at once with login, transactions, etc.)exitOnPageError
<[boolean]> Exits page on any global error message thrown. Defaults to true
.server
<[Object]> Server options allowed by jest-dev-server1// jest-puppeteer.config.js 2module.exports = { 3 launch: { 4 dumpio: true, 5 headless: process.env.HEADLESS !== 'false', 6 }, 7 server: { 8 command: 'node server.js', 9 port: 4444, 10 launchTimeout: 10000, 11 debug: true, 12 }, 13}
This example uses an already running instance of Chrome by passing the active web socket endpoint to connect
. This is useful, for example, when you want to connect to Chrome running in the cloud.
1// jest-puppeteer.config.js 2const fetch = require('node-fetch') 3const dockerHost = 'http://localhost:9222' 4 5async function getConfig() { 6 const response = await fetch(`${dockerHost}/json/version`) 7 const browserWSEndpoint = (await response.json()).webSocketDebuggerUrl 8 return { 9 connect: { 10 browserWSEndpoint, 11 }, 12 server: { 13 command: 'node server.js', 14 port: 3000, 15 launchTimeout: 10000, 16 debug: true, 17 }, 18 } 19} 20 21module.exports = getConfig()
Thanks to Fumihiro Xue for his great Jest example.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/2 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
40 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More