The Wayback Machine - https://web.archive.org/web/20200701145747/https://github.com/hshoff/vx/issues/216
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use puppeteer for @vx/text tests #216

Open
techniq opened this issue Dec 18, 2017 · 3 comments
Open

Use puppeteer for @vx/text tests #216

techniq opened this issue Dec 18, 2017 · 3 comments
Labels

Comments

@techniq
Copy link
Collaborator

@techniq techniq commented Dec 18, 2017

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

@hshoff hshoff added the 🏠internal label Feb 20, 2018
@montogeek
Copy link

@montogeek montogeek commented Sep 1, 2018

I could contribute with this, You mean run all tests over Puppeteer instead of JSDom?

@techniq
Copy link
Collaborator Author

@techniq techniq commented Sep 1, 2018

@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?

@jackdbd
Copy link

@jackdbd jackdbd commented Jan 2, 2019

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.