
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
jsdom-screenshot-playwright
Advanced tools
📸 Take screenshots of jsdom with playwright
Inspired by jsdom-screenshot
yarn add -D jsdom-screenshot-playwright
It is recommended to use this package with jest-image-snapshot and react-testing-library. Use it as together like this:
import { generateImage } from "jsdom-screenshot-playwright";
import { render } from "react-testing-library";
import { SomeComponent } from "<your-code>";
it("should have no visual regressions", async () => {
render(<SomeComponent />);
expect(await generateImage()).toMatchImageSnapshot();
});
Example of setupFilesAfterEnv
in jest config:
// react-testing-library setup
import '@testing-library/jest-dom'
// playwright polyfills
import 'core-js'
// jest-image-snapshot setup
import { configureToMatchImageSnapshot } from 'jest-image-snapshot'
// jsdom-screenshot-playwright setup
import { close, start } from 'jsdom-screenshot-playwright'
// jest-image-snapshot setup
const toMatchImageSnapshot = configureToMatchImageSnapshot({
diffDirection: 'vertical',
// useful on CI (no need to retrieve the diff image, copy/paste image content from logs)
dumpDiffToConsole: true,
// use SSIM to limit false positive
// https://github.com/americanexpress/jest-image-snapshot#recommendations-when-using-ssim-comparison
comparisonMethod: 'ssim',
customDiffConfig: {
ssim: 'fast',
},
failureThreshold: 0.01,
failureThresholdType: 'percent',
})
expect.extend({ toMatchImageSnapshot })
// jsdom-screenshot-playwright setup
beforeAll(async () => {
// start jsdom-screenshot-playwright before all tests (to avoid starting it for each test and improve performance)
await start(
{
defaultSelector: 'div', // first div element in rendered html
},
{
// playwright context options
viewport: {
width: 800,
height: 600,
},
}
)
})
afterAll(async () => {
// close jsdom-screenshot-playwright after all tests (close playwright instance)
await close()
})
generateImage(options?: ScreenshotParams): Promise<Buffer>
Takes a screenshot of the current jsdom document and returns a Buffer
containing the image data.
options
options.selector
(optional) - A selector to use for the screenshot.options.screenshotOptions
(optional) - Options to pass to playwright's screenshot method.options.contextOptions
(optional) - Options to pass to playwright's launch context method.start(options?: BrowserOptions, contextOptions?: BrowserContextOptions): Promise<void>
Starts a new playwright instance. This is useful if you want to use the same instance for multiple screenshots.
options
options.device
(optional) - A device to emulate. Defaults to Desktop Firefox HiDPI
.options.launchOptions
(optional) - Options to pass to playwright's launch options method.options.defaultSelector
(optional) - A selector to use for the screenshot. Defaults to body
.options.maxOpenPages
(optional) - Maximum number of pages to open. Defaults to 10
. (to increase performance)options.debug
(optional) - Enable debug mode (logs for internal actions). Defaults to false
.contextOptions
contextOptions
(optional) - Options to pass to playwright's launch context method.close(): Promise<void>
Closes the current playwright instance.
This package is based on jsdom-screenshot by dferber90.
FAQs
Generate screenshots of jsdom using Playwright
The npm package jsdom-screenshot-playwright receives a total of 2 weekly downloads. As such, jsdom-screenshot-playwright popularity was classified as not popular.
We found that jsdom-screenshot-playwright demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.