Skip to content

Commit c98ad65

Browse files
committed
test(html): cover pages navigated away from before they arrive
Navigating elsewhere before a page arrives aborts the navigation to it, and the handler drops the page when it does arrive, so only the last page navigated to shows, however late the earlier ones answer. Without the `event.signal.aborted` check, this test fails: the late page is swapped in over the last one. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 81cedcf commit c98ad65

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

‎e2e/client-side-navigation.spec.js‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,38 @@ test.describe('Client-side navigation', () => {
149149
expect(await page.evaluate(() => window.__document)).toBeUndefined();
150150
});
151151

152+
test('shows only the last of the pages navigated to at once', async ({
153+
page,
154+
}) => {
155+
// The page navigated to first answers last
156+
await page.route(/\/all(\.html)?$/, async route => {
157+
await new Promise(resolve => setTimeout(resolve, 500));
158+
await route.fallback();
159+
});
160+
161+
const answered = page.waitForEvent('requestfinished', request =>
162+
/\/all$/.test(request.url())
163+
);
164+
165+
await page.evaluate(() => {
166+
window.__swaps = 0;
167+
168+
new MutationObserver(records => {
169+
window.__swaps += records.length;
170+
}).observe(document.documentElement, { childList: true });
171+
172+
navigation.navigate('all.html');
173+
});
174+
175+
await navigate(page, '404.html');
176+
await answered;
177+
// Gives the first navigation the chance to show its page, if it would
178+
await page.evaluate(() => new Promise(requestAnimationFrame));
179+
180+
await expect(page).toHaveTitle(/^Page Not Found \|/);
181+
expect(await page.evaluate(() => window.__swaps)).toBe(1);
182+
});
183+
152184
test('leaves the URL to scripts that rewrite it', async ({ page }) => {
153185
// As a script dropping tracking parameters does
154186
const swapped = await page.evaluate(async () => {

0 commit comments

Comments
 (0)