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

Improve test flakiness #507

Merged
merged 28 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c23b0f6
Remove firefox workarounds for test flakiness
tunetheweb Aug 1, 2024
c57c1a6
Add extra wait to hidden test
tunetheweb Aug 1, 2024
360db97
Skip prerender tests if unsupported
tunetheweb Aug 1, 2024
8b7fa8b
Oops, forgot to include the new file
tunetheweb Aug 1, 2024
df3ab5e
Urgh I should just test this first
tunetheweb Aug 1, 2024
6e15ba8
Refactor
tunetheweb Aug 1, 2024
4a81735
Skip prerender on all metrics if not supported
tunetheweb Aug 1, 2024
71916de
Alternative LCP hidden flakiness fix
tunetheweb Aug 1, 2024
ee0eb2f
Another anti-flaky test
tunetheweb Aug 1, 2024
1741c04
Check
tunetheweb Aug 1, 2024
267e303
Update to complete
tunetheweb Aug 1, 2024
b115980
Fix for Safari
tunetheweb Aug 1, 2024
4494dca
Add comment
tunetheweb Aug 1, 2024
22a2068
Another Safari fix
tunetheweb Aug 1, 2024
1d5aa87
Try Phil's fix
tunetheweb Aug 2, 2024
94792fe
Revert fix
tunetheweb Aug 2, 2024
526fee6
Remove 100ms delay
tunetheweb Aug 2, 2024
9b2d7f7
Add Safari to navigateTo workaround
tunetheweb Aug 2, 2024
1bd2263
Remove debugging logging
tunetheweb Aug 2, 2024
639134d
Revert Safari change
tunetheweb Aug 2, 2024
46c8e91
Try another fix
tunetheweb Aug 2, 2024
4604f46
Check both
tunetheweb Aug 2, 2024
ad022dd
Fix it
tunetheweb Aug 2, 2024
1b000b8
Restrict to Safari and Firefox
tunetheweb Aug 2, 2024
feed6ab
Remove debugging logging
tunetheweb Aug 2, 2024
aeb6e91
Wait for interactive for flakey INP test
tunetheweb Aug 2, 2024
d162c14
Temporarily disable prerender support check
philipwalton Aug 2, 2024
b474f82
Remove the prerender skips in tests
philipwalton Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions test/e2e/onFCP-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,6 @@ import {navigateTo} from '../utils/navigateTo.js';
import {stubForwardBack} from '../utils/stubForwardBack.js';
import {stubVisibilityChange} from '../utils/stubVisibilityChange.js';

// Temp fix to address Firefox flakiness.
// See https://github.com/GoogleChrome/web-vitals/issues/472
const originalStrictEqual = assert.strictEqual;
assert.strictEqual = function (actual, expected, message) {
if (
process.env.GITHUB_ACTIONS &&
browser.capabilities.browserName === 'firefox' &&
(expected === 'good' || expected === 'needs-improvement') &&
actual !== expected
) {
console.error(
`Override assert for Firefox (actual: ${actual}, expected: ${expected})`,
);
return true;
}
return originalStrictEqual(actual, expected, message);
};

describe('onFCP()', async function () {
// Retry all tests in this suite up to 2 times.
this.retries(2);
Expand Down Expand Up @@ -134,7 +116,7 @@ describe('onFCP()', async function () {
it('does not report if the document was hidden at page load time', async function () {
if (!browserSupportsFCP) this.skip();

await navigateTo('/test/fcp?hidden=1', {readyState: 'interactive'});
await navigateTo('/test/fcp?hidden=1', {readyState: 'complete'});

await stubVisibilityChange('visible');

Expand Down
6 changes: 5 additions & 1 deletion test/e2e/onINP-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,12 +699,16 @@ describe('onINP()', async function () {
it('includes LoAF entries if the browser supports it', async function () {
if (!browserSupportsLoAF) this.skip();

await navigateTo('/test/inp?attribution=1&pointerdown=100');
await navigateTo('/test/inp?attribution=1&pointerdown=100', {
readyState: 'interactive',
});

// Click on the <textarea>.
const textarea = await $('#textarea');
await textarea.click();

await nextFrame();

await stubVisibilityChange('hidden');
await beaconCountIs(1);

Expand Down
36 changes: 4 additions & 32 deletions test/e2e/onLCP-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,6 @@ import {navigateTo} from '../utils/navigateTo.js';
import {stubForwardBack} from '../utils/stubForwardBack.js';
import {stubVisibilityChange} from '../utils/stubVisibilityChange.js';

// Temp fix to address Firefox flakiness.
// See https://github.com/GoogleChrome/web-vitals/issues/472
const originalStrictEqual = assert.strictEqual;
assert.strictEqual = function (actual, expected, message) {
if (
process.env.GITHUB_ACTIONS &&
browser.capabilities.browserName === 'firefox' &&
(expected === 'good' || expected === 'needs-improvement') &&
actual !== expected
) {
console.error(
`Override assert for Firefox (actual: ${actual}, expected: ${expected})`,
);
return true;
}
return originalStrictEqual(actual, expected, message);
};

describe('onLCP()', async function () {
// Retry all tests in this suite up to 2 times.
this.retries(2);
Expand Down Expand Up @@ -277,7 +259,9 @@ describe('onLCP()', async function () {
it('stops reporting after the document changes to hidden (reportAllChanges === false)', async function () {
if (!browserSupportsLCP) this.skip();

await navigateTo('/test/lcp?imgDelay=0&imgHidden=1');
await navigateTo('/test/lcp?imgDelay=0&imgHidden=1', {
readyState: 'interactive',
});

// Wait for a frame to be painted.
await browser.executeAsync((done) => requestAnimationFrame(done));
Expand Down Expand Up @@ -716,19 +700,7 @@ const assertStandardReportsAreCorrect = (beacons) => {
const assertFullReportsAreCorrect = (beacons) => {
const [lcp1, lcp2] = beacons;

// Temp fix to address Firefox flakiness.
// See https://github.com/GoogleChrome/web-vitals/issues/472
if (
process.env.GITHUB_ACTIONS &&
browser.capabilities.browserName === 'firefox' &&
lcp1.value >= 500
) {
console.log(
`Override assert for Firefox (actual: ${lcp1.value}, expected: < 500)`,
);
} else {
assert(lcp1.value < 500); // Less than the image load delay.
}
assert(lcp1.value < 500); // Less than the image load delay.
assert(lcp1.id.match(/^v4-\d+-\d+$/));
assert.strictEqual(lcp1.name, 'LCP');
assert.strictEqual(lcp1.value, lcp1.delta);
Expand Down
19 changes: 13 additions & 6 deletions test/utils/navigateTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,22 @@ import {domReadyState} from './domReadyState.js';
export async function navigateTo(urlPath, opts) {
await browser.url(urlPath);

// In Firefox, if the global PageLoadStrategy is set to "none", then
// it's possible that `browser.url()` will return before the navigation
// In Firefox and Safari, if the global PageLoadStrategy is set to "none",
// then it's possible that `browser.url()` will return before the navigation
// has started and the old page will still be around, so we have to
// manually wait until the URL matches the passed URL. Note that this can
// still fail if the prior test navigated to a page with the same URL.
if (browser.capabilities.browserName === 'firefox') {
await browser.waitUntil(async () => {
return (await browser.getUrl()).endsWith(urlPath);
});
if (browser.capabilities.browserName !== 'chrome') {
await browser.waitUntil(
async () => {
// Get the URL from the browser and webdriver to ensure the page has
// actually started to load.
const url = await browser.execute(() => location.href);

return url.endsWith(urlPath);
},
{interval: 50},
);
}

if (opts?.readyState) {
Expand Down
2 changes: 2 additions & 0 deletions wdio.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ module.exports.config = {
if (browserName === 'chrome') {
capability['goog:chromeOptions'] = {
excludeSwitches: ['enable-automation'],
// Can remove next line after puppeteer 21.2.1 lands
args: ['disable-search-engine-choice-screen'],
philipwalton marked this conversation as resolved.
Show resolved Hide resolved
// Uncomment to test on Chrome Canary.
// binary: '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'
};
Expand Down