Skip to content

Migrate Jest to Vitest and add backend route test utilities#11

Merged
AlexKempen merged 10 commits into
certfrom
claude/laughing-brahmagupta-nlyzws
Jun 20, 2026
Merged

Migrate Jest to Vitest and add backend route test utilities#11
AlexKempen merged 10 commits into
certfrom
claude/laughing-brahmagupta-nlyzws

Conversation

@AlexKempen

@AlexKempen AlexKempen commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Switch the test runner from Jest (ts-jest/jsdom) to Vitest 4, using
@cloudflare/vitest-pool-workers for backend tests (real, per-test isolated
D1/R2/KV bindings) and a Node project for pure frontend tests. Move tests
out of tests folders into colocated *.test.ts files.

Refactor Hono interactions with the Onshape API to use shared dependency inject functions from createClient and add tests around most endpoints in the app.

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01UVxXhTLH1UeLRUgdQs3yp5

claude and others added 10 commits June 17, 2026 04:20
Switch the test runner from Jest (ts-jest/jsdom) to Vitest 4, using
@cloudflare/vitest-pool-workers for backend tests (real, per-test isolated
D1/R2/KV bindings) and a Node project for pure frontend tests. Move tests
out of __tests__ folders into colocated *.test.ts files.

Refactor auth into composable Hono middleware (onshapeApiMiddleware,
userIdMiddleware) that inject onshapeApi/userId into the context, and add a
src/__test_utils__ folder with reusable helpers for testing Hono routes:
a MockOnshapeApi (backs userId via users/sessioninfo and stubs other calls),
a request harness that injects the mock and real bindings, D1 seed helpers,
and D1 migration application. Admin access is driven by ACCESS_LEVEL_OVERRIDE.

Add full unit tests for the favorites routes and migrate the existing parse
and frontend tests to Vitest.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UVxXhTLH1UeLRUgdQs3yp5
Introduce a createApp(servicesFactory) composition root that injects the
Onshape API, userId, and access-level getters flattened onto the request
context (c.var.getOnshapeApi/getUserId/getAccessLevel). This removes the
ad-hoc onshapeApi/userId middlewares and lets access-level-utils just check
the level. All route files now resolve identity/access through the injected
getters; production wiring lives in services.ts and the Worker entry is
createApp(productionServices).

Tests now build the real app via createTestApp (returns a plain Hono app)
with mock services — no vi.mock, no ACCESS_LEVEL_OVERRIDE juggling. Add
resetDb() for per-test D1 isolation (pool-workers isolates storage per file,
not per test, and reset() only clears Durable Objects), and a jsonRequest
helper.

Swap the VSCode Jest extension/settings for Vitest, and add a GitHub Actions
workflow running tsc, lint, and tests on PRs and pushes to the default branch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UVxXhTLH1UeLRUgdQs3yp5
MockOnshapeApi now extends OAuthApi and intercepts requests by overriding the
protected _request method, so it is a real OAuthApi instance. This removes the
asOAuthApi() cast (and the per-method overrides) without widening any Onshape
API signatures away from OAuthApi.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UVxXhTLH1UeLRUgdQs3yp5
Replace the verbose per-helper option interfaces (which enumerated version
info, document/microversion/instance ids, names, etc.) with
`Partial<table.$inferInsert>` overrides layered over fixed defaults. Tests now
only pass the fields they actually vary (ids, userId, libraryId, sortOrder);
everything else uses shared constants. Drops ~60 lines and the bespoke
SeedXxxOptions interfaces.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UVxXhTLH1UeLRUgdQs3yp5
Add smoke tests (1-2 per endpoint) for user, library, configurations, group
admin updaters, the insert flow (add-to-part-studio / add-to-assembly, with the
Onshape API mocked), and R2 thumbnail serving. Rewrite the seed layer into a
fixed canonical dataset (library, user, group, a part studio, an assembly, two
favorites) with no override args — seeders default everything and expose
testInstancePath / testPartStudioPath / testAssemblyPath for API mocking.

Fix two un-pathed `.use(requireAdminMiddleware)` calls that leaked admin gating
onto unrelated routes: in insertables.ts (gated the insert routes) and in
thumbnails.ts (the reload-thumbnail guard leaked across sub-apps onto every
route mounted after thumbnails — groups, insertables, configurations). Both now
apply requireAdminMiddleware per-route, so inserts and configuration reads work
for normal users while the toggle/reload routes stay admin-only.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UVxXhTLH1UeLRUgdQs3yp5
@AlexKempen AlexKempen force-pushed the claude/laughing-brahmagupta-nlyzws branch from c452997 to 23d9106 Compare June 18, 2026 03:38
@AlexKempen AlexKempen merged commit add30b3 into cert Jun 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants