test: migrate unit test runner from jest to vitest#656
Merged
Conversation
Swaps the unit suite's runner from jest to vitest, removing jest's finicky ESM workarounds now that the wizard's source is ESM-native. - Add vitest.config.ts: resolve.alias mirrors the old jest moduleNameMapper (manual mocks + tsconfig path aliases), a small pre-resolve plugin maps NodeNext `.js` import specifiers back to their `.ts` source, globals + node environment, and v8 coverage. - Codemod every test/mock file: jest.fn/mock/spyOn/timers → vi.*, and the jest.Mock/Mocked/... ambient types → vitest equivalents (bridged globally in types/vitest-global-types.d.ts so call sites stay bare). - Port the APIs without a 1:1 vitest mapping: requireMock → mocked imports, isolateModules → resetModules + dynamic import, hoisted-factory vars → vi.hoisted, and partial module mocks that omit an accessed export → importOriginal (vitest throws where jest returned undefined). - Stabilise the CLI re-import tests: the dispatch fires detached async work that used to run synchronously under jest's babel-commonjs imports; settle() now anchors on the decisive sink before asserting, and env-var setup mutates process.env in place (reassigning it defeats yargs' .env() reader once the module graph is reset). - Keep jest for the standalone e2e-tests package (own jest.config + ts-jest): give it a self-contained tsconfig and drop it from the root tsconfig/eslint scope. jest and its babel deps stay installed for that suite. 737/737 unit tests pass; `pnpm build`, `pnpm typecheck`, and `pnpm lint` are clean; the postbuild smoke-test still runs via `pnpm test`. Generated-By: PostHog Code Task-Id: 4ced191a-7fea-49ed-a854-ab6330f1c83d
🧙 Wizard CIRun the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands: Test all apps:
Test all apps in a directory:
Test an individual app:
Show more apps
Results will be posted here when complete. |
sarahxsanders
approved these changes
Jun 15, 2026
sarahxsanders
left a comment
Collaborator
There was a problem hiding this comment.
I ran all the tests locally a bunch of times to ensure no flakiness, looks like we are good. nothing jumping out to me as a blocker
sarahxsanders
added a commit
that referenced
this pull request
Jun 16, 2026
Resolve conflicts from main's progress against this branch's jest->vitest migration (#656). Keep vitest mechanics, fold in main's newer test content: - package.json: keep `test:watch: vitest`, add main's `screens:check` script - analytics.test.ts: keep vi.fn() mocks, add main's `identify` mock - health-checks.test.ts: keep `as Mock`, take main's renamed no-connection tests - claude-web.test.ts: adopt main's openTrackedLink mock in vitest syntax Also convert jest-style test files main added after the migration so they run under vitest (vi.fn/vi.mock, vi.hoisted for backup mocks) and fix `as jest.Mock` type casts to `as Mock` so typecheck passes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
Closes #519
The wizard's source is ESM (
"type": "module"), but the unit suite still ran on jest, whose ESM support is opt-in and finicky. That friction is visible in the warlock work this stacks on: the__mocks__/@posthog/warlock.tsdrift guard,babel-jestfor nanostores, and the.js→.tsmoduleNameMapper all exist to work around jest. Sibling repos (warlock, context-mill) already use vitest.Stacked on #597 (
yara-improvements) — this is that PR "made vite". Review/merge #597 first.Changes
vitest.config.ts—resolve.aliasmirrors the old jestmoduleNameMapper(manual mocks for@anthropic-ai/claude-agent-sdk,@posthog/warlock,ink+ the tsconfig path aliases); a small pre-resolve plugin maps NodeNext.jsimport specifiers to their.tssource;globals: true, node env, v8 coverage.jest.fn/mock/spyOn/useFakeTimers/...→vi.*, and thejest.Mock/Mocked/MockedFunction/...ambient types → vitest equivalents (bridged as globals intypes/vitest-global-types.d.tsso call sites stay bare).requireMock→ mocked imports,isolateModules→resetModules+ dynamic import, hoisted-factory vars →vi.hoisted, and partial mocks that omit an accessed export →importOriginal(vitest throws where jest silently returnedundefined, e.g.RunPhase/WizardError).settle()now anchors on the decisive sink before asserting, and env setup mutatesprocess.envin place (reassigning it defeats yargs'.env()reader once the module graph is reset).e2e-testspackage (ownjest.config.ts+ ts-jest) keeps jest; it now has a self-contained tsconfig and is dropped from the root tsconfig/eslint scope. jest + its babel deps stay installed for that suite (the pnpm trust policy blocks pruning them cleanly), so the dependency diff is additive:+vitest,+@vitest/coverage-v8.The warlock manual mock stays (per #519's note): the real package loads a YARA-X WASM binary at runtime that the unit runner still can't execute —
resolve.aliasreplaces jest'smoduleNameMapperto wire it, and its compile-time drift guard is unchanged.Test plan
pnpm test— 737/737 pass (build → postbuild smoke-test →vitest run), verified stable across repeated full-suite runs.pnpm typecheckandpnpm lint— clean (0 errors).Created with PostHog Code from a Slack thread