Skip to content

test: migrate simple-git from jest to vitest#1171

Open
steveukx wants to merge 2 commits into
canary/v4from
v4/vitest
Open

test: migrate simple-git from jest to vitest#1171
steveukx wants to merge 2 commits into
canary/v4from
v4/vitest

Conversation

@steveukx

Copy link
Copy Markdown
Owner

Stacked on #1170 (pnpm). Replaces jest + babel-jest with vitest for the simple-git package (plan PR 2). Targets v4/pnpm-migration so it reviews as a clean diff on top of the pnpm work; both land on canary/v4.

Test infrastructure

  • vitest.config.mts with two projects:
    • unit — mocks child_process (+ debug, @kwsites/file-exists) via a setup file.
    • integrationno child_process mock, real git, longer timeouts.
      This mirrors the old jest split where only unit specs imported the manual child_process mock; a single global mock would have hung the real-git integration tests.
  • The three jest.mock() calls move into test/unit/__fixtures__/setup.ts as vi.mock(), with the debug factory inlined to satisfy vi.mock hoisting (the exact trap called out in the plan).
  • mock-child-process.ts + fixtures: jest.*vi.*; jest.Mock type → Mock from vitest across all specs.
  • Aliases for simple-git / simple-git/promise / typings to source; @simple-git/test-utils inlined so its import '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 .ts files extensionlessly — Node's CJS resolver runs those requires and can't find .ts. So:

  • src/index.jssrc/index.ts (keeps export = for the callable require('simple-git') CJS shape).
  • src/git.jssrc/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).
  • Dev mainsrc/index.ts (publishConfig still overrides to dist for publishing).

Package

  • testvitest run --coverage; test:winvitest run win32.
  • Drop jest, @types/jest, ts-node, @simple-git/babel-config; delete jest.config.js / babel.config.js; add vitest + @vitest/coverage-v8.
  • test-typescript-consumer still 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 === self via require('../..')) now asserts the equivalent source-level guarantees (typeof default === 'function', simpleGit === default). The built-CJS __esModule shape 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

@changeset-bot

changeset-bot Bot commented May 30, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: de26659

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@steveukx steveukx changed the base branch from v4/pnpm-migration to canary/v4 May 31, 2026 20:28
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.
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