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

Merge branch next into master #2207

Merged
merged 15 commits into from
Dec 14, 2024
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@eslint/js": "9.17.0",
"@maxmilton/eslint-config": "0.0.8",
"@maxmilton/stylelint-config": "0.1.2",
"@maxmilton/test-utils": "0.0.6",
"@maxmilton/test-utils": "0.0.7",
"@playwright/test": "1.49.1",
"@types/bun": "1.1.14",
"@types/chrome": "0.0.287",
Expand Down
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.
14 changes: 12 additions & 2 deletions test/unit/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, test } from 'bun:test';
import { readdir } from 'node:fs/promises';
import { validate } from '@maxmilton/test-utils/html';

describe('dist files', () => {
// FIXME: The bun file type is just inferred from the file extension, not the
Expand Down Expand Up @@ -34,7 +35,7 @@ describe('dist files', () => {
expect(file.type).toBe(type); // TODO: Keep this? Type seems to be resolved from the file extension, not the file data.
});

if (minBytes != null && maxBytes != null) {
if (minBytes !== undefined && maxBytes !== undefined) {
test('is within expected file size limits', () => {
expect.assertions(2);
expect(file.size).toBeGreaterThan(minBytes);
Expand All @@ -49,8 +50,17 @@ describe('dist files', () => {
const distDir = await readdir('dist');
expect(distDir).toHaveLength(distFiles.length);
});

test.each(distFiles.filter(([filename]) => filename.endsWith('.html')))(
'%s contains valid HTML',
async (filename) => {
const file = Bun.file(`dist/${filename}`);
const html = await file.text();
const result = validate(html);
expect(result.valid).toBeTrue();
},
);
});

// TODO: HTML files should be valid HTML
// TODO: HTML files have correct title
// TODO: HTML files have correct JS and CSS file references
Loading