Skip to content

chore(test): migrate from jest to vitest - #141

Open
catomean wants to merge 2 commits into
masterfrom
chore/vitest-migration
Open

chore(test): migrate from jest to vitest#141
catomean wants to merge 2 commits into
masterfrom
chore/vitest-migration

Conversation

@catomean

@catomean catomean commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

198/198 test files were green when this branch was cut. Merging master afterward pulled in commit #138 ("track whether the AI chain is actually up"), which adds src/lib/ai/health.ts calling createHealthTracker from ai-kit — an export that does not exist in the installed ai-kit@0.4.0. health.ts calls it at module load time, so every file that transitively imports it (health.test.ts directly, provider.test.ts via provider.ts) now crashes on import: 2 files / 11 tests.

This is unrelated to the jest→vitest migration and would fail under any runner that actually imports the module chain — it's not something this PR introduced or can fix (ai-kit is a shared package). Current state: 197/199 files, 3487/3495 non-skipped tests green, all 11 failures traced to this one missing export. See the top commit for the framework-migration details.

Also: #139 (generation lift) bumps jest to v30 on a separate branch. That and this PR are mutually exclusive — keep jest v30, or remove jest for vitest.

All 198 test files pass, 3492 tests green, 8 intentionally skipped.

jest.* -> vi.* is mostly mechanical, but several differences are not:
  - jest ran CJS with moduleNameMapper; require() inside a test body ignored
    the @/ alias under vitest's ESM runtime. Converted to await import().
  - jest.requireActual is synchronous; vitest only has the async
    vi.importActual, so 8 factories became async.
  - jest tolerated a vi.mock-style factory closing over an outer const; vitest
    hoists vi.mock above the temporal dead zone. vi.hoisted() wraps every
    declaration a factory (including another vi.hoisted block) reads.
  - jest's module interop accepted a factory returning a bare function as the
    default export; vitest requires an explicit { default: Fn }.
  - jest let a mock factory return a subset of a module's real exports; vitest
    validates the mock's shape against every import site and refuses to run
    the file if something used elsewhere is missing. Spread the real module via
    vi.importActual and override only the property the test controls.
  - jest.setTimeout(n) has no vi.setTimeout; the vitest equivalent is
    vi.setConfig({ testTimeout: n }).

Config: two vitest projects (server/node, components/jsdom) replacing jest's
own projects array; transformIgnorePatterns is gone rather than translated,
since vitest loads ESM natively and that workaround existed only for jest's
CJS transform.

NOTE: PR #139 (generation lift) bumps jest to v30 on a separate branch. That
and this PR are mutually exclusive — keep jest v30, or remove jest for vitest.
Whoever reviews first should close the other.
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.

1 participant