Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upUse puppeteer for @vx/text tests #216
Comments
|
I could contribute with this, You mean run all tests over Puppeteer instead of JSDom? |
|
@montogeek that would be awesome! We need to use puppeteer for @vx/text tests so it can returned the measured width which is unavailable in JSDom (since there isn't a true DOM). @hshoff I've been using react-testing-library over enzyme nowaways in my libraries (example), initially due to it not supporting React 16 APIs, but also has a simpler / easier to understand API (felt less magic-y to me). Should we move to it as well? |
|
I'm using puppeteer + jest + jest-image-snapshot for a project of mine. Here is what the code looks like: const puppeteer = require("puppeteer");
const HOST = "http://localhost:3000";
const EXPECTED_IMAGES = "src/__tests__/expected_images";
const directNavigationOptions = {
waitUntil: "networkidle2",
};
describe("Visual regressions)", () => {
// use the same browser instance for all visual regression tests to save time
let browser = null;
beforeAll(async () => {
// WebGL context is available in headless mode too!
browser = await puppeteer.launch({ headless: true });
});
afterAll(async () => {
browser.close();
});
it("matches the expected snapshot of /", async () => {
const page = await browser.newPage();
const url = `${HOST}/`;
await page.goto(url, directNavigationOptions);
const options = {
path: `${EXPECTED_IMAGES}/home.png`,
};
const image = await page.screenshot(options);
expect(image).toMatchImageSnapshot();
});As you can see it's very similar to the one described in this article (Navalia is no longer maintained). |


Now that jest has support for puppeteer, we need to use it for @vx/text tests as it requires a DOM to perform the text measurements (something that jsdom does not support which jest uses by default).
Here is a full working example: https://github.com/xfumihiro/jest-puppeteer-example