Migrate Jest to Vitest and add backend route test utilities#11
Merged
Conversation
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
c452997 to
23d9106
Compare
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.
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