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

Report 'prerender' navigation type accurately #75

Merged
merged 3 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion src/visuallyCompleteCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ class VisuallyCompleteCalculator {

const navigationType = isBfCacheRestore
? 'back_forward'
: start !== 0
: activationStart > 0
? 'prerender'
: start > 0
? 'script'
: getNavigationType();

Expand Down
59 changes: 37 additions & 22 deletions test/e2e/prerender1/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import {test, expect} from '@playwright/test';

import {FUDGE} from '../../util/constants';
import {getEntries} from '../../util/entries';
import {entryCountIs, getEntries} from '../../util/entries';

test.use({
// If you run this test headless, you must run with --headless=new to enable prerender2.
launchOptions: {
args: ['--headless=new'],
},
});

test.describe('TTVC', () => {
//we had to skip this test since chromium does not support prerendering yet, hopefully in the future we can enforce it. Meanwhile you can test this changes manually by waiting a set amount before the prerender and then navigating, ttvc should be somewhere less than the delay all the way up to zero depending on how long you wait.
test.skip('a prerendered navigation', async ({page}) => {
// NOTE: At time of writing, there is a bug in chromium which prevents
// playwright from accessing the correct frame to run assertions after a
// prerendered page has been activated.
// These tests should be re-enabled once this issue is resolved.
// https://github.com/microsoft/playwright/issues/22733
test.skip('navigation to a partially prerendered route', async ({browserName, page}) => {
// neither safari nor firefox do not support page prerendering
test.fail(['safari', 'firefox'].includes(browserName));

await page.goto(`/test/prerender1`, {
waitUntil: 'networkidle',
});
Expand All @@ -14,35 +28,36 @@ test.describe('TTVC', () => {

await page.click('a');

await page.waitForTimeout(2000);

await entryCountIs(page, 1);
const entries = await getEntries(page);

console.log(entries);

expect(entries.length).toBe(1);
expect(entries[0].duration).toBeGreaterThanOrEqual(1000);
expect(entries[0].duration).toBeLessThanOrEqual(1000 + FUDGE);
expect(entries[0].detail.navigationType).toBe('prerender');
});

test.describe('TTVC', () => {
//we had to skip this test since chromium does not support prerendering yet, hopefully in the future we can enforce it. Meanwhile you can test this changes manually by waiting a set amount before the prerender and then navigating, ttvc should be somewhere less than the delay all the way up to zero depending on how long you wait.
test.skip('a prerendered navigation', async ({page}) => {
await page.goto(`/test/prerender1`, {
waitUntil: 'networkidle',
});
// NOTE: At time of writing, there is a bug in chromium which prevents
// playwright from accessing the correct frame to run assertions after a
// prerendered page has been activated.
// These tests should be re-enabled once this issue is resolved.
// https://github.com/microsoft/playwright/issues/22733
test.skip('navigation to a fully prerendered route', async ({browserName, page}) => {
// neither safari nor firefox do not support page prerendering
test.fail(['safari', 'firefox'].includes(browserName));

await page.waitForTimeout(2000);
await page.goto(`/test/prerender1`, {
waitUntil: 'networkidle',
});

await page.click('a');
await page.waitForTimeout(5000);

await page.waitForTimeout(2000);
await page.click('a');

const entries = await getEntries(page);
await entryCountIs(page, 1);
const entries = await getEntries(page);

expect(entries.length).toBe(1);
expect(entries[0].duration).toBeGreaterThanOrEqual(0);
expect(entries[0].duration).toBeLessThanOrEqual(0 + FUDGE);
});
expect(entries[0].duration).toBeGreaterThanOrEqual(0);
expect(entries[0].duration).toBeLessThanOrEqual(0 + FUDGE);
expect(entries[0].detail.navigationType).toBe('prerender');
});
});