test(e2e): block the service worker except where the test is about it

The caching worker controls every page once it registers, and Playwright's
page.route() does not see the fetches a worker makes — so the failed-load test,
which forces a 500 to check the error path, got the real 200 through the worker
and read as a broken feature. Block the worker by default and turn it back on only
for the offline test, which is the one that needs a real one.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
kristianwind
2026-09-04 08:12:15 +02:00
co-authored by Claude Opus 4.8
parent 57689ddfbb
commit 6db61b0cc7
2 changed files with 13 additions and 1 deletions
+7 -1
View File
@@ -320,7 +320,12 @@ test('manifestet og service workeren findes, og ikonerne findes også', async ({
* back to the app rather than to a dead tab. The retry in api.js covers the write
* side of the same drop; this covers the read side.
*/
test('appen overlever et netværksudfald og åbner fra cachen', async ({ page, context }) => {
test.describe('med service worker', () => {
// The rest of the suite blocks the worker (see playwright.config.js); this one
// test is about the worker, so it turns it back on for its own context.
test.use({ serviceWorkers: 'allow' });
test('appen overlever et netværksudfald og åbner fra cachen', async ({ page, context }) => {
// First load, online: the worker installs, and once it controls the page the
// shell and the reads it serves are in the cache.
await page.goto('/');
@@ -351,6 +356,7 @@ test('appen overlever et netværksudfald og åbner fra cachen', async ({ page, c
// Never leave the shared context offline for whatever test runs next.
await context.setOffline(false);
}
});
});
/**
+6
View File
@@ -51,6 +51,12 @@ export default defineConfig({
use: {
baseURL,
// Off by default. The app now ships a caching service worker, and once it
// controls a page Playwright's page.route() no longer sees the fetches it
// makes — so a test that forces a 500 to check the error path gets the real
// 200 through the worker instead, and reads as a broken feature. The one test
// that needs the real worker turns it back on for its own context.
serviceWorkers: 'block',
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
// Pinned, because the app reads both. The sign-up form sends