Conversation
|
Replace jest + babel-jest with vitest for the simple-git package. Test infrastructure: - vitest.config.mts with two projects: 'unit' (mocked child_process via a setup file) and 'integration' (real git, longer timeouts). This mirrors the old split where only unit specs imported the child_process manual mock. - Move the global jest.mock() calls (child_process, debug, @kwsites/file-exists) into test/unit/__fixtures__/setup.ts, registered via vi.mock with the factory inlined to satisfy vi.mock hoisting. - Convert mock-child-process.ts and fixtures from jest.* to vi.*; jest.Mock type -> Mock from vitest across all specs. - Alias 'simple-git' / 'simple-git/promise' / 'typings' to source; inline @simple-git/test-utils so its 'simple-git' import resolves to TS source. Source entry points: - Convert src/index.js and src/git.js to TypeScript (.ts). vitest cannot run the legacy CommonJS entries that require() sibling .ts files; ESM/TS imports are required. git.ts keeps its prototype body verbatim under @ts-nocheck (retyped in the task-refactor PR); index.ts keeps export = for the callable require('simple-git') CJS shape. - Point dev 'main' at src/index.ts (publishConfig still overrides to dist). Package: - test -> 'vitest run --coverage', test:win -> 'vitest run win32'. - Drop jest, @types/jest, ts-node, @simple-git/babel-config, and delete jest.config.js / babel.config.js. Add vitest + @vitest/coverage-v8. - test-typescript-consumer keeps using jest (its own migration is separate). All 787 tests pass (matching the previous jest count) at 94% coverage; build, build:pkg and all consumer tests remain green.
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.
Stacked on #1170 (pnpm). Replaces jest + babel-jest with vitest for the
simple-gitpackage (plan PR 2). Targetsv4/pnpm-migrationso it reviews as a clean diff on top of the pnpm work; both land oncanary/v4.Test infrastructure
vitest.config.mtswith two projects:unit— mockschild_process(+debug,@kwsites/file-exists) via a setup file.integration— no child_process mock, real git, longer timeouts.This mirrors the old jest split where only unit specs imported the manual
child_processmock; a single global mock would have hung the real-git integration tests.jest.mock()calls move intotest/unit/__fixtures__/setup.tsasvi.mock(), with thedebugfactory inlined to satisfyvi.mockhoisting (the exact trap called out in the plan).mock-child-process.ts+ fixtures:jest.*→vi.*;jest.Mocktype →Mockfromvitestacross all specs.simple-git/simple-git/promise/typingsto source;@simple-git/test-utilsinlined so itsimport 'simple-git'resolves to TS source rather than being externalised.Source entry points (the necessary prerequisite)
vitest can't execute the legacy CommonJS entries that
require()sibling.tsfiles extensionlessly — Node's CJS resolver runs those requires and can't find.ts. So:src/index.js→src/index.ts(keepsexport =for the callablerequire('simple-git')CJS shape).src/git.js→src/git.ts, body kept verbatim under// @ts-nocheck(it's the 600-line prototype file the task-refactor PR rewrites; type-checking it now is out of scope).main→src/index.ts(publishConfigstill overrides todistfor publishing).Package
test→vitest run --coverage;test:win→vitest run win32.jest,@types/jest,ts-node,@simple-git/babel-config; deletejest.config.js/babel.config.js; addvitest+@vitest/coverage-v8.test-typescript-consumerstill uses jest (separate migration; full babel removal is its own PR).§0.1 acceptance
All 787 tests pass (exactly matching the previous jest count) at 94.45% coverage (≥80 gate).
build,build:pkg, and all consumer tests (ESM, CJS callable+named+default, TS types) remain green.Note for review
git.spec.ts's CJS-interop test (__esModule/default === selfviarequire('../..')) now asserts the equivalent source-level guarantees (typeof default === 'function',simpleGit === default). The built-CJS__esModuleshape is still covered by the JS consumer tests. Flagging since it's the one place an assertion changed rather than just being ported.Generated by Claude Code