
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
jest-playwright-preset
Advanced tools
The jest-playwright-preset package allows you to use Playwright with Jest for end-to-end testing. It provides a Jest preset configuration that simplifies the setup and usage of Playwright within Jest, enabling you to write tests that can interact with web pages in a headless browser environment.
Setup and Configuration
This feature allows you to easily set up Jest to use Playwright by adding the jest-playwright-preset to your Jest configuration file. This simplifies the initial setup process.
module.exports = { preset: 'jest-playwright-preset' };
Writing Tests
This feature allows you to write tests that interact with web pages. In this example, the test navigates to a URL and checks if the page title is as expected.
test('should display the correct title', async () => { await page.goto('https://example.com'); const title = await page.title(); expect(title).toBe('Example Domain'); });
Custom Browser Contexts
This feature allows you to customize the browser context for your tests. In this example, the viewport size is set before all tests run.
beforeAll(async () => { await jestPlaywright.resetContext({ viewport: { width: 1280, height: 720 } }); });
The jest-puppeteer package provides similar functionality but uses Puppeteer instead of Playwright. It allows you to run end-to-end tests with Jest and Puppeteer, offering a similar API and setup process. However, Playwright supports multiple browsers (Chromium, Firefox, and WebKit), whereas Puppeteer is primarily focused on Chromium.
The playwright-test package is a test runner built specifically for Playwright. It offers a more integrated experience with Playwright's features and capabilities, including parallel test execution and advanced test isolation. While jest-playwright-preset integrates Playwright with Jest, playwright-test is a standalone solution designed to leverage Playwright's full potential.
Running your tests using Jest & Playwright
npm install jest-playwright-preset playwright
Also you can use jest-playwright-preset
with specific playwright packages:
playwright-webkit
, playwright-chromium
and playwright-firefox
npm install jest-playwright-preset playwright-firefox
Update your Jest configuration:
package.json
:"jest": {
"preset": "jest-playwright-preset"
}
jest.config.js
:module.exports = {
preset: "jest-playwright-preset",
...
}
NOTE: Be sure to remove any existing testEnvironment
option from your Jest configuration. The jest-playwright-preset
preset needs to manage that option itself.
You can specify a jest-playwright.config.js
at the root of the project or define a custom path using JEST_PLAYWRIGHT_CONFIG
environment variable. It should export a config object.
launchBrowserApp
<[object]> All Playwright launch options can be specified in config. Since it is JavaScript, you can use all stuff you need, including environment.context
<[object]> All Playwright context options can be specified in config.browser
<[string]>. Define a browser to run tests into.
chromium
Each test runs Chromium.firefox
Each test runs Firefox.webkit
Each test runs Webkit.device
<[string]>. Define a device to run tests into. Actual list of devices can be found hereexitOnPageError
<[boolean]> Exits page on any global error message thrown. Defaults to true
.You can specify browser in multiple ways: Note: You should do it only if you are using whole playwright package
BROWSER
environment variablejest-playwright.config.js
If you don't pass any value it will be use chromium
as default
Use Playwright in your tests:
"test": "jest"
describe('Google', () => {
beforeAll(async () => {
await page.goto('https://whatismybrowser.com/')
})
it('should display "google" text on page', async () => {
const browser = await page.$eval('.string-major a', el => el.text)
expect(browser).toContain('Chrome')
})
})
Debugging tests can be hard sometimes and it is very useful to be able to pause tests in order to inspect the browser. Jest Playwright exposes a method jestPlaywright.debug()
that suspends test execution and gives you opportunity to see what's going on in the browser.
await jestPlaywright.debug()
Thanks to Smooth Code for great jest-puppeteer.
MIT
FAQs
Running tests using Jest & Playwright.
The npm package jest-playwright-preset receives a total of 1,006,958 weekly downloads. As such, jest-playwright-preset popularity was classified as popular.
We found that jest-playwright-preset demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.