Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
jest-puppeteer
Advanced tools
jest-puppeteer is a Jest preset that allows you to use Puppeteer, a headless Chrome Node API, for end-to-end testing. It simplifies the setup and configuration needed to use Puppeteer with Jest, enabling you to write tests that interact with web pages in a browser-like environment.
Setup and Teardown
jest-puppeteer provides a simple way to configure global setup and teardown scripts, as well as a custom test environment for running Puppeteer tests.
module.exports = {
globalSetup: './setup.js',
globalTeardown: './teardown.js',
testEnvironment: './puppeteer_environment.js'
};
Writing Tests
You can write tests using Jest's syntax, and use Puppeteer's API to interact with the web page. In this example, the test navigates to Google's homepage and checks if the text 'google' is present.
describe('Google', () => {
beforeAll(async () => {
await page.goto('https://google.com');
});
it('should display "google" text on page', async () => {
await expect(page).toMatch('google');
});
});
Custom Matchers
jest-puppeteer allows you to extend Jest with custom matchers that can be used to assert conditions specific to Puppeteer. This example shows how to create a custom matcher to check if an element's text includes a specific string.
expect.extend({
async toMatchText(received, argument) {
const text = await received.evaluate(el => el.textContent);
if (text.includes(argument)) {
return {
message: () => `expected ${text} to include ${argument}`,
pass: true
};
} else {
return {
message: () => `expected ${text} to include ${argument}`,
pass: false
};
}
}
});
Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. While jest-puppeteer is a preset that integrates Puppeteer with Jest, Puppeteer itself is more low-level and requires more setup to use with a testing framework.
Cypress is an end-to-end testing framework that provides a rich, interactive environment for writing and running tests. Unlike jest-puppeteer, which uses Puppeteer to control a headless browser, Cypress runs in the browser and provides a more integrated and user-friendly experience.
TestCafe is a Node.js tool to automate end-to-end web testing. It does not require browser plugins and works with all modern browsers. Compared to jest-puppeteer, TestCafe provides a more streamlined API and built-in support for parallel test execution.
Jest preset containing all required configuration for writing integration tests using Puppeteer.
npm install jest-puppeteer puppeteer
// jest.config.js
module.exports = {
preset: 'jest-puppeteer',
}
MIT
FAQs
Run your tests using Jest & Puppeteer.
The npm package jest-puppeteer receives a total of 119,115 weekly downloads. As such, jest-puppeteer popularity was classified as popular.
We found that jest-puppeteer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.