Skip to content

Commit ef61804

Browse files
committed
tests/e2e: adjust failure threshold of snapshot tests
We had increased the failure threshold to prevent test flake but it is too high to capture diffs on very large snapshot images. This change decreases the failure threshold and page sizes to ensure we catch diffs. Test flake is avoided by waiting for style transitions on the unit page and waiting for network requests to finish before proceeding with snapshots. Change-Id: I517027caf31064e4f70dcf121853e34457849d87 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/336710 Trust: Jamal Carvalho <[email protected]> Run-TryBot: Jamal Carvalho <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]>
1 parent aae8096 commit ef61804

File tree

73 files changed

+31
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+31
-11
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

tests/e2e/golang-x-tools.desktop.test.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Page } from 'puppeteer';
99

1010
import './global-types';
1111
import * as pg from './helpers/page';
12-
import * as golangxtools from './helpers/golang-x-tools.page.ts';
12+
import * as golangxtools from './helpers/golang-x-tools.page';
1313

1414
let page: Page;
1515

@@ -25,6 +25,8 @@ afterAll(async () => {
2525

2626
test('fixed header appears after scrolling', async () => {
2727
await page.evaluate(() => window.scrollTo({ top: 250 }));
28+
// Wait for header transition
29+
await page.evaluate(() => new Promise(r => setTimeout(r, 250)));
2830
const image = await page.screenshot();
2931
expect(image).toMatchImageSnapshot();
3032
await page.evaluate(() => window.scrollTo({ top: 0 }));
@@ -33,14 +35,14 @@ test('fixed header appears after scrolling', async () => {
3335
describe('readme', () => {
3436
test('expands', async () => {
3537
await page.click(pg.select('readme-expand'));
36-
await page.evaluate(() => window.scrollTo({ top: 0 }));
38+
await scrollTop(page);
3739
const expanded = await page.screenshot({ fullPage: true });
3840
expect(expanded).toMatchImageSnapshot();
3941
});
4042

4143
test('collapses', async () => {
4244
await page.click(pg.select('readme-collapse'));
43-
await page.evaluate(() => window.scrollTo({ top: 0 }));
45+
await scrollTop(page);
4446
const collapsed = await page.screenshot({ fullPage: true });
4547
expect(collapsed).toMatchImageSnapshot();
4648
});
@@ -49,14 +51,14 @@ describe('readme', () => {
4951
describe('directories', () => {
5052
test('expand', async () => {
5153
await page.click(pg.select('directories-toggle'));
52-
await page.evaluate(() => window.scrollTo({ top: 0 }));
54+
await scrollTop(page);
5355
const expanded = await page.screenshot({ fullPage: true });
5456
expect(expanded).toMatchImageSnapshot();
5557
});
5658

5759
test('collapse', async () => {
5860
await page.click(pg.select('directories-toggle'));
59-
await page.evaluate(() => window.scrollTo({ top: 0 }));
61+
await scrollTop(page);
6062
const collapsed = await page.screenshot({ fullPage: true });
6163
expect(collapsed).toMatchImageSnapshot();
6264
});
@@ -65,14 +67,14 @@ describe('directories', () => {
6567
describe('jump to modal', () => {
6668
test('opens', async () => {
6769
await page.click(pg.select('jump-to-button'));
68-
await page.evaluate(() => window.scrollTo({ top: 0 }));
70+
await scrollTop(page);
6971
const expanded = await page.screenshot();
7072
expect(expanded).toMatchImageSnapshot();
7173
});
7274

7375
test('closes', async () => {
7476
await page.click(pg.select('close-dialog'));
75-
await page.evaluate(() => window.scrollTo({ top: 0 }));
77+
await scrollTop(page);
7678
const collapsed = await page.screenshot();
7779
expect(collapsed).toMatchImageSnapshot();
7880
});
@@ -81,3 +83,15 @@ describe('jump to modal', () => {
8183
test('no page errors', () => {
8284
expect(pageErrors).toHaveLength(0);
8385
});
86+
87+
/**
88+
* scrollTop scrolls to the top of a given page and waits
89+
* a short amount of time for any style transitions to
90+
* complete. Used to make sure the documentation page
91+
* header has completed transitioning.
92+
* @param page the page to scroll.
93+
*/
94+
async function scrollTop(page: Page): Promise<void> {
95+
await page.evaluate(() => window.scrollTo({ top: 0 }));
96+
await page.evaluate(() => new Promise(r => setTimeout(r, 250)));
97+
}

tests/e2e/golang-x-tools.mobile.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ afterAll(async () => {
2626

2727
test('fixed header appears after scrolling', async () => {
2828
await page.evaluate(() => window.scrollTo({ top: 250 }));
29+
// Wait for header transition
30+
await page.evaluate(() => new Promise(r => setTimeout(r, 250)));
2931
const image = await page.screenshot();
3032
expect(image).toMatchImageSnapshot();
3133
});

tests/e2e/helpers/page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export async function newPage(): Promise<Page> {
4444
});
4545
const go = page.goto;
4646
page.goto = (path: string, opts?: DirectNavigationOptions) =>
47-
go.call(page, GO_DISCOVERY_E2E_BASE_URL + path, opts);
47+
go.call(page, GO_DISCOVERY_E2E_BASE_URL + path, { waitUntil: 'networkidle0', ...opts });
4848
return page;
4949
}
5050

tests/e2e/seed.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ github.com/tendermint/[email protected]
1414
1515
golang.org/x/[email protected]
1616
golang.org/x/[email protected]
17+
golang.org/x/[email protected]
1718
1819
mvdan.cc/sh/[email protected]
1920
mvdan.cc/[email protected]+incompatible
2021
golang.org/x/tools/[email protected]
2122
github.com/jackc/[email protected]+incompatible
23+
24+
2225
26+
2327

2428
# This module is expected to return a 404, so that the path will redirect
2529
# to github.com/jackc/pgx/v4/pgxpool.

tests/e2e/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { configureToMatchImageSnapshot } from 'jest-image-snapshot';
99

1010
// Extends jest to compare image snapshots.
1111
const toMatchImageSnapshot = configureToMatchImageSnapshot({
12-
failureThreshold: 0.1,
12+
failureThreshold: 0.001,
1313
failureThresholdType: 'percent',
1414
customSnapshotIdentifier: ({ defaultIdentifier, counter }) => {
1515
return defaultIdentifier.replace('test-ts', '').replace(`-${counter}`, '');

tests/e2e/unit.desktop.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let page: Page;
1616

1717
beforeAll(async () => {
1818
page = await pg.newPage();
19-
await page.setViewport({ height: 2732, width: 1366 });
19+
await page.setViewport({ height: 1366, width: 1366 });
2020
});
2121

2222
afterAll(async () => {

tests/e2e/unit.mobile.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let page: Page;
1616

1717
beforeAll(async () => {
1818
page = await pg.newPage();
19-
await page.setViewport({ height: 2732, width: 500 });
19+
await page.setViewport({ height: 1000, width: 500 });
2020
});
2121

2222
afterAll(async () => {

0 commit comments

Comments
 (0)