mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-09-14 17:42:17 +00:00
4af33709a3
Several assertions could not fail: - "the catch update remains saved" was `caught.isChecked() || notes.includes(...)` shared by two scenarios, so either half satisfied both. Split into two steps that each assert the outcome their own scenario is about. - The token-refresh check read a global counter with `> 0` and asserted an upload had happened `some(...)`, both already satisfied by the preceding scenario. It now asserts exactly one refresh, ordered before the upload. - The box step ignored its box argument and asserted on the first N entries on the page; it now scopes to that box and checks its full contents. - The filter step asserted on whichever entry was first after filtering; it now records the caught entry beforehand and names it, and checks the filter did not exclude everything. - The empty-state precondition asserted emptiness instead of establishing it, which a fresh user satisfies for free. - Offline coverage was `caches.keys().length > 0`. It now checks the precache contract: one workbox cache holding the shell and a revisioned web manifest, with _app/immutable assets cached without a revision query. The scenario that claimed to test a trailing slash did not; it is replaced with real offline client-side navigation. The mock provider kept recorded requests, its refresh counter and the fail-uploads switch in one process-wide object that only one step reset, so scenario order was load-bearing and the failing-upload scenario poisoned everything after it. An auto fixture now resets it per scenario, and the mock no longer records its own control-plane calls. That reset is why the suite stays on a single worker, which is now documented. Coverage was gated at 90% per file over an allowlist of exactly the five files that had tests, so new code was invisible to it permanently. It now measures all of src/lib with global thresholds at the measured baseline, and no longer runs the unit tests twice. Also: a global teardown removes the users each run creates, the Supabase wrapper distinguishes a stopped stack from a broken CLI call and detects an unseeded database, the sign-in rate limit is raised above what one serial run needs, and the integration suite no longer falls back to a hard-coded anon key that would mask a misconfigured run. The password-reset scenarios are renamed to what they actually cover: following a real recovery link bounces to /signin, because the browser client persists no cookies and so cannot keep the session it parses out of the URL. The helper for the real flow is left in place and the gap is documented.
108 lines
3.9 KiB
TypeScript
108 lines
3.9 KiB
TypeScript
import { createBdd } from 'playwright-bdd';
|
|
import type { Page } from '@playwright/test';
|
|
import { test, expect } from '../fixtures';
|
|
|
|
const { Given, When, Then } = createBdd(test);
|
|
|
|
async function waitForServiceWorker(page: Page) {
|
|
return page.evaluate(async () => {
|
|
if (!('serviceWorker' in navigator)) throw new Error('Service workers are not supported');
|
|
const registration = await Promise.race([
|
|
navigator.serviceWorker.ready,
|
|
new Promise<never>((_, reject) =>
|
|
setTimeout(() => reject(new Error('Service worker registration timed out')), 15_000)
|
|
)
|
|
]);
|
|
return registration.active?.scriptURL ?? null;
|
|
});
|
|
}
|
|
|
|
async function cacheContents(page: Page) {
|
|
return page.evaluate(async () => {
|
|
const contents: Record<string, string[]> = {};
|
|
for (const name of await caches.keys()) {
|
|
const cache = await caches.open(name);
|
|
contents[name] = (await cache.keys()).map((request) => request.url);
|
|
}
|
|
return contents;
|
|
});
|
|
}
|
|
|
|
When('I open the built application', async ({ page }) => {
|
|
await page.goto('/');
|
|
await waitForServiceWorker(page);
|
|
});
|
|
|
|
Given('I have opened the built application online', async ({ page }) => {
|
|
await page.context().setOffline(false);
|
|
await page.goto('/');
|
|
await waitForServiceWorker(page);
|
|
await page.reload();
|
|
});
|
|
|
|
When('I go offline and reload the home page', async ({ page }) => {
|
|
await page.context().setOffline(true);
|
|
await page.reload({ waitUntil: 'domcontentloaded' });
|
|
});
|
|
|
|
When('I go offline and navigate to the sign-in page', async ({ page }) => {
|
|
await page.context().setOffline(true);
|
|
// Client-side navigation, which only works if the route's chunks were precached.
|
|
await page.getByRole('link', { name: 'Sign In' }).click();
|
|
await expect(page).toHaveURL(/\/signin$/);
|
|
});
|
|
|
|
When('I go offline and then return online', async ({ page }) => {
|
|
await page.context().setOffline(true);
|
|
await page.reload({ waitUntil: 'domcontentloaded' });
|
|
await page.context().setOffline(false);
|
|
await page.reload({ waitUntil: 'domcontentloaded' });
|
|
});
|
|
|
|
Then('a service worker controls the page', async ({ page }) => {
|
|
expect(await waitForServiceWorker(page)).toMatch(/\/(?:sw|prompt-sw)\.js$/);
|
|
});
|
|
|
|
/**
|
|
* Replaces the deleted client-test/sw.spec.ts assertions. The precise entries differ by build
|
|
* strategy, so this checks the contract that matters: one workbox precache, the app shell and
|
|
* web manifest are in it, and `_app/immutable` assets are cached WITHOUT a revision query -
|
|
* that last one is the `dontCacheBustURLsMatching` behaviour, and it silently regresses.
|
|
*/
|
|
Then('the application shell is precached', async ({ page }) => {
|
|
const contents = await cacheContents(page);
|
|
const names = Object.keys(contents).filter((name) => name.startsWith('workbox-precache'));
|
|
expect(names).toHaveLength(1);
|
|
|
|
const origin = new URL(page.url()).origin;
|
|
const urls = contents[names[0]].map((url) => url.slice(`${origin}/`.length));
|
|
|
|
expect(urls, 'app shell is not precached').toContain('');
|
|
expect(
|
|
urls.some((url) => url.startsWith('manifest.webmanifest?__WB_REVISION__=')),
|
|
'revisioned manifest.webmanifest is not precached'
|
|
).toBe(true);
|
|
expect(
|
|
urls.some((url) => url.startsWith('_app/version.json?__WB_REVISION__=')),
|
|
'revisioned _app/version.json is not precached'
|
|
).toBe(true);
|
|
|
|
const immutable = urls.filter((url) => url.startsWith('_app/immutable/'));
|
|
expect(immutable.some((url) => url.endsWith('.css'))).toBe(true);
|
|
expect(immutable.some((url) => url.endsWith('.js'))).toBe(true);
|
|
expect(
|
|
immutable.filter((url) => url.includes('__WB_REVISION__')),
|
|
'immutable assets must not be cache-busted'
|
|
).toEqual([]);
|
|
});
|
|
|
|
Then('the application remains available', async ({ page }) => {
|
|
await expect(page.getByRole('heading', { name: /Start Your Pokédex Journey/ })).toBeVisible();
|
|
});
|
|
|
|
Then('the sign-in form is available offline', async ({ page }) => {
|
|
await expect(page.getByLabel('Email')).toBeVisible();
|
|
await expect(page.getByLabel('Password')).toBeVisible();
|
|
await expect(page.getByRole('button', { name: 'Sign In' })).toBeVisible();
|
|
});
|