Commit 77166b5
test: adopt @cloudflare/vitest-pool-workers, delete SQL-parser mock (#9)
* test: introduce vitest-pool-workers for D1-backed integration tests
Migrates 4 server tests from the SQL-parsing mock DB to real D1 running
inside the Workers runtime via @cloudflare/vitest-pool-workers. Existing
tests on happy-dom remain untouched.
Changes:
- Adds vitest.workers.config.ts (cloudflareTest plugin + cloudflarePool)
scoped to the 4 migrated tests; filters out data-only migrations
- Adds src/lib/test/{apply-migrations,seed,call}.ts as the new test
infrastructure (real-D1 seeding, FK-aware reset, minimal RequestEvent
builder)
- Migrates health, db/configs, api/configs, and api/auth/cli/poll tests
- Bumps vitest 4.0.18 -> 4.1.x (pool-workers peer dep)
- Fixes migration 0002 to use ADD COLUMN + CREATE UNIQUE INDEX instead
of ALTER TABLE ADD COLUMN ... UNIQUE (SQLite-illegal; hosted D1 had
tolerated it). Safe for prod, already applied
- Fixes 3 hidden test bugs where fixtures duplicated UNIQUE alias
values; the SQL-parser mock didn't enforce the constraint
After: 48 tests on pool-workers (4 files), 232 on happy-dom (16 files),
all green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test: complete vitest-pool-workers migration, delete SQL-parser mock
Migrates the remaining 9 server tests to vitest-pool-workers and removes
the fragile SQL-parsing mock DB. Pure-library tests (rate-limit,
install-script, validation) and archtests stay on happy-dom — they don't
need D1 or the Workers runtime.
Migrated to pool-workers in this commit:
- src/lib/server/auth.test.ts (JWT + DB-backed getCurrentUser)
- src/routes/api/auth/cli/start/server.test.ts
- src/routes/api/auth/cli/approve/server.test.ts
- src/routes/api/configs/[slug]/server.test.ts
- src/routes/api/configs/[slug]/revisions/server.test.ts
- src/routes/[username]/[slug]/install/server.test.ts
- src/routes/[username]/[slug]/config/server.test.ts
- src/smoke-tests/{cli-auth-flow,config-crud,critical-paths}.test.ts
The CLI auth-flow smoke test now exercises the real approve endpoint
end-to-end (previously had to fake it because the mock couldn't handle
datetime expressions). The config-crud smoke test now verifies UPDATE
side effects in the DB (previously couldn't — mock didn't honor
COALESCE).
Infrastructure:
- Adds src/lib/test/call.ts helper to cut RequestEvent boilerplate
- Extends call() with params/clientAddress for routes that need them
- Deletes src/lib/test/db-mock.ts (~390 lines of SQL-parsing mock)
- Deletes src/lib/test/setup.ts (process.env shims no longer needed)
- Deletes src/lib/test/helpers.ts (unused after migration)
- Trims src/lib/test/fixtures.ts to data-only exports
- Adds @cloudflare/vitest-pool-workers/types to tsconfig.json
- Wires npm test / test:run / test:coverage to run both configs;
adds test:happy-dom and test:workers for targeted runs
Final test layout: 181 tests on pool-workers (14 files, real D1 +
Workers runtime), 99 tests on happy-dom (6 files, pure libs +
archtests). Both green; full npm run validate clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* ci: bump Node to 22 and silence knip on cloudflare:test virtual module
CI Node 20 → 22 because @cloudflare/vitest-pool-workers transitively
pulls @cloudflare/kv-asset-handler@0.5.0 which requires Node ≥22.
knip drift sensor was flagging every `cloudflare:test` import as an
unlisted dependency (it doesn't grok the virtual-module convention).
Added `cloudflare` to knip.json's ignoreDependencies so the sensor stops
opening tracking issues for this. The package itself is provided by
@cloudflare/vitest-pool-workers and not a real dependency entry.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(test): skip v8 coverage on pool-workers suite
workerd has no node:inspector/promises module, which @vitest/coverage-v8
requires. Coverage now runs only on the happy-dom suite; the
pool-workers suite still runs (verifying behavior) but does not
contribute to the coverage report. Trade-off: covered % drops because
many tests moved to pool-workers. Acceptable — tests still execute,
and switching the coverage backend (e.g. istanbul) is a separate
decision.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent b6a3cf9 commit 77166b5
31 files changed
Lines changed: 2485 additions & 5417 deletions
File tree
- .github/workflows
- migrations
- src
- lib
- server
- db
- test
- routes
- [username]/[slug]
- config
- install
- api
- auth/cli
- approve
- poll
- start
- configs
- [slug]
- revisions
- health
- smoke-tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
5 | 13 | | |
6 | | - | |
7 | | - | |
| 14 | + | |
8 | 15 | | |
9 | | - | |
10 | | - | |
| 16 | + | |
0 commit comments