Skip to content

Commit

Permalink
test: Better service worker e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmilton committed Dec 14, 2024
1 parent c1eef94 commit 28b1419
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions test/e2e/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export const test = baseTest.extend<{
await context.close();
},
async extensionId({ context }, use) {
let [background] = context.serviceWorkers();
let [sw] = context.serviceWorkers();
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
background ??= await context.waitForEvent('serviceworker');
sw ??= await context.waitForEvent('serviceworker', { timeout: 200 });

const extensionId = background.url().split('/')[2];
const extensionId = sw.url().split('/')[2];
await use(extensionId);
},
});
Expand Down
14 changes: 6 additions & 8 deletions test/e2e/sw.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { expect, test } from './fixtures';

test('background service worker', async ({ context }) => {
let [background] = context.serviceWorkers();
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
background ??= await context.waitForEvent('serviceworker');

// FIXME: Better assertions

expect(background).toBeTruthy();
test('has a single background service worker (sw.js)', async ({ context, extensionId }) => {
const workers = context.serviceWorkers();
expect(workers).toHaveLength(1);
expect(workers[0]?.url()).toBe(`chrome-extension://${extensionId}/sw.js`);
});

// TODO: Check there are no console messages or unhandled errors in the worker.

0 comments on commit 28b1419

Please sign in to comment.