Skip to content

Commit

Permalink
Report 'prerender' navigation type accurately (#75)
Browse files Browse the repository at this point in the history
* Add launchOption and update comments in playwright test file

* Expect 'prerender' navigationType in test assertions

* Output 'prerender' navigation type if activationStart is non-zero

---------

Co-authored-by: Andrew Hyndman <ahyndman@dropbox.com>
  • Loading branch information
ajhyndman and Andrew Hyndman authored Jun 7, 2023
1 parent 237266c commit 79615ce
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
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');
});
});

0 comments on commit 79615ce

Please sign in to comment.