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

Reduce number of network reqs in visual regression #294

Merged
merged 1 commit into from
Aug 26, 2020

Conversation

Rigellute
Copy link
Collaborator

On my machine, this cuts down the test run time from ~5 mins to ~3 mins!

Closes #249

Copy link
Contributor

@wgolledge wgolledge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small comment but looks great!

describe("landscape viewport", () => {
beforeEach(async () => {
describe("Go to page, test landscape and portrait viewport", () => {
it("matches landscape and portrait snapshot", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be nice still having these split into separate landscape and portrait tests with a beforeAll or something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the same, however I kept running into an issue using beforeAll where the page would close after the first run - then all the remaining tests would fail.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the error I get when using beforeAll

    Protocol error (Page.navigate): Session closed. Most likely the page has been closed.

      72 |   describe("Go to page, test landscape and portrait viewport", () => {
      73 |     beforeAll(async () => {
    > 74 |       await page.goto(rendererUrl, { waitUntil: "load" });
         |                  ^
      75 |       await page.mouse.move(0, 0);
      76 |       await delay(500);
      77 |     });

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - that's happening because of the execution order, https://jestjs.io/docs/en/setup-teardown.html. beforeAll getting triggered before the beforeEach page.close()

Copy link
Contributor

@wgolledge wgolledge Aug 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A (crude) fix would be to force the navigation to run after the page.close()

      let pageRendered = false;

      beforeEach(async () => {
        if (pageRendered) {
          return;
        }
        pageRendered = true;
        await page.goto(rendererUrl, { waitUntil: "load" });
  
        await page.mouse.move(0, 0);
      })

  
      it("matches landscape", async () => {
        await page.setViewport({ width: 1200, height: 600 });
        await delay(500);
        await matchSnapshot({ viewport: "landscape" });
      });
      it("matches portrait", async () => {
        await page.setViewport({ width: 600, height: 1200 });
        await delay(500);
        await matchSnapshot({ viewport: "portrait" });
      });
    })

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running with if (page.url() != rendererUrl) was surprisingly ~30% slower than the above (or by just rendering the render in the landscape test)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay cool. I'll go with your suggestion. Shame that the more idiomatic beforeAll fails due the somewhat obscure execution order.

Although I now see the afterEach in setupTests.ts that closes the page - so now it makes sense.

Copy link
Collaborator Author

@Rigellute Rigellute Aug 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On reflection - it looks like the page is setup and torn down in setupTests but then the page is only ever used in the visual regression test?

Perhaps we should move page setup and teardown to visual-regression?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should move page setup and teardown to visual-regression?

We did have that in the past but from what I remember, using jest-puppeteer was solving some determinism issues we were having during tests.

Totally open to having the setup configured in this test alone if we get a performance benefit! Going to ask some Formidafolks today about getting something like Percy setup

On my machine, this cuts down the test run time from ~5 mins to ~3 mins!

Closes #249
@Rigellute Rigellute force-pushed the reduce-number-of-network-requests-vis-regression branch from 310eb32 to 3cefdcb Compare August 20, 2020 12:56
@Rigellute Rigellute merged commit 5acda0d into master Aug 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reduce number of network requests during visual regression
3 participants