Files
LivingDexTracker/tests/build/build.test.ts
T
Josh Creek de39dc78ea test: replace ad-hoc tests with a layered suite and CI workflow
Splits testing into five layers so a failure points at the responsible one:

- tests/unit    isolated utility, repository and service tests
- tests/data    validates the tracked Pokémon, game, region and dex files
- tests/integration  schema, views, constraints, RLS and repositories
- tests/bdd     executable Gherkin for user-visible behaviour
- tests/build   service worker and manifest artifacts per build variant

Replaces the two Playwright specs in client-test/ and the two Vitest files in
test/. Adds a GitHub Actions workflow running the layers as separate jobs, a
mock OAuth provider server so the Drive and Dropbox scenarios never touch real
accounts, and a wrapper that reads the local Supabase keys from
`supabase status` rather than hard-coding them.

Extracts the pure formatting helpers out of PokedexExportService so they can be
unit tested, and makes the provider endpoints configurable so the mock server
can stand in for Google and Dropbox.
2026-09-13 17:38:41 +01:00

43 lines
1.8 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { existsSync, readFileSync } from 'node:fs';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { generateSW } from '../../pwa.mjs';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { nodeAdapter } from '../../adapter.mjs';
describe(`test-build: ${nodeAdapter ? 'node' : 'static'} adapter`, () => {
it(`service worker is generated: ${generateSW ? 'sw.js' : 'prompt-sw.js'}`, () => {
const swName = `./build/${nodeAdapter ? 'client/' : ''}${generateSW ? 'sw.js' : 'prompt-sw.js'}`;
expect(existsSync(swName), `${swName} doesn't exist`).toBeTruthy();
const webManifest = `./build/${nodeAdapter ? 'client/' : ''}manifest.webmanifest`;
expect(existsSync(webManifest), `${webManifest} doesn't exist`).toBeTruthy();
const swContent = readFileSync(swName, 'utf-8');
let match: RegExpMatchArray | null;
if (generateSW) {
match = swContent.match(/define\(\['\.\/(workbox-\w+)'/);
expect(
match && match.length === 2,
`workbox-***.js entry not found in ${swName}`
).toBeTruthy();
const workboxName = `./build/${nodeAdapter ? 'client/' : ''}${match?.[1]}.js`;
expect(existsSync(workboxName), `${workboxName} doesn't exist`).toBeTruthy();
}
match = swContent.match(/"url":\s*"manifest\.webmanifest"/);
expect(
match && match.length === 1,
'missing manifest.webmanifest in sw precache manifest'
).toBeTruthy();
match = swContent.match(/"url":\s*"(?:\/|index\.html)"/);
expect(
match && match.length === 1,
'missing offline entry point in sw precache manifest'
).toBeTruthy();
if (nodeAdapter) {
match = swContent.match(/"url":\s*"server\//);
expect(match === null, 'found server/ entries in sw precache manifest').toBeTruthy();
}
});
});