Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
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.
FAQs
Run your tests using Jest & Puppeteer.
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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.