test: adopt @cloudflare/vitest-pool-workers, delete SQL-parser mock#9
Merged
Merged
Conversation
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>
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 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>
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>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@cloudflare/vitest-pool-workers. Pure-lib tests + archtests stay on happy-dom (6 files, 99 tests).src/lib/test/db-mock.ts(~390 lines of brittle SQL parser). Net diff: +2,480 / −5,412.vitest4.0.18→4.1.x(pool-workers peer dep).ALTER TABLE ADD COLUMN ... UNIQUEtoADD COLUMN+CREATE UNIQUE INDEX. Safe for prod (already applied), unblocks local D1.approveendpoint (mock couldn't handle datetime expressions before).COALESCE).process.envshim insetup.ts(aligns with the existingno-process-envarchtest rule).Test plan
npm run test:happy-dom→ 99 / 99 (6 files)npm run test:workers→ 181 / 181 (14 files)npm run validate→ lint clean, 0 svelte-check errors, both suites green, build OKcheckjob still passes against the bumped vitestNotes for reviewer
vitest.workers.config.tsruns the pool-workers suite separately; both configs are wired intonpm test, plus targeted scriptstest:happy-domandtest:workers.src/lib/test/{call,seed,apply-migrations}.ts—call(handler, opts)replaces ~30 lines ofRequestEventboilerplate per test;seed(db, rows)is a typed inserter;applyD1Migrationsruns in-memory before each suite.vitest.workers.config.ts. Tests seed their own fixtures.