Skip to content

Commit 378d1c5

Browse files
committed
test: migrate simple-git from jest to vitest
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.
1 parent 0670611 commit 378d1c5

73 files changed

Lines changed: 630 additions & 273 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/test-utils/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@simple-git/test-utils",
33
"version": "4.0.0",
44
"private": true,
5+
"main": "index.ts",
56
"peerDependencies": {
67
"simple-git": "*"
78
}

pnpm-lock.yaml

Lines changed: 284 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

simple-git/babel.config.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

simple-git/jest.config.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

simple-git/package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@
2222
},
2323
"devDependencies": {
2424
"@kwsites/promise-result": "^1.1.0",
25-
"@simple-git/babel-config": "workspace:^",
2625
"@types/debug": "^4.1.12",
27-
"@types/jest": "^29.2.2",
2826
"@types/node": "^22.15.30",
27+
"@vitest/coverage-v8": "^3.0.0",
2928
"esbuild": "^0.25.0",
3029
"esbuild-node-externals": "^1.18.0",
31-
"jest": "^29.7.0",
32-
"ts-node": "^10.9.2",
33-
"typescript": "^5"
30+
"typescript": "^5",
31+
"vitest": "^3.0.0"
3432
},
3533
"keywords": [
3634
"git",
@@ -43,7 +41,7 @@
4341
"url": "https://github.com/steveukx/git-js.git",
4442
"directory": "simple-git"
4543
},
46-
"main": "src/index.js",
44+
"main": "src/index.ts",
4745
"module": "dist/esm/index.js",
4846
"exports": {
4947
".": {
@@ -65,8 +63,8 @@
6563
"build:defs": "tsc -p tsconfig.release.json --outDir dist && cp -r typings dist",
6664
"build:pkg": "tsx ../devtools/package-json ./simple-git/package.json",
6765
"prepublishOnly": "pnpm run build:pkg",
68-
"test": "jest --coverage",
69-
"test:win": "jest '\\.win32.spec.ts$'"
66+
"test": "vitest run --coverage",
67+
"test:win": "vitest run win32"
7068
},
7169
"publish": {
7270
"main": "dist/cjs/index.js",

simple-git/scripts/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function cjs() {
4141
const outfile = resolve(outDir, 'cjs', 'index.js');
4242

4343
await esbuild.build({
44-
entryPoints: ['src/index.js'],
44+
entryPoints: ['src/index.ts'],
4545
bundle: true,
4646
platform: 'node',
4747
format: 'cjs',
Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
const { GitExecutor } = require('./lib/runners/git-executor');
2-
const { SimpleGitApi } = require('./lib/simple-git-api');
1+
// @ts-nocheck — legacy prototype-style implementation, retyped in the task-refactor PR.
2+
import { GitExecutor } from './lib/runners/git-executor';
3+
import { SimpleGitApi } from './lib/simple-git-api';
34

4-
const { Scheduler } = require('./lib/runners/scheduler');
5-
const { adhocExecTask, configurationErrorTask } = require('./lib/tasks/task');
6-
const {
5+
import { Scheduler } from './lib/runners/scheduler';
6+
import { adhocExecTask, configurationErrorTask } from './lib/tasks/task';
7+
import {
78
asArray,
89
filterArray,
910
filterPrimitives,
@@ -13,39 +14,39 @@ const {
1314
getTrailingOptions,
1415
trailingFunctionArgument,
1516
trailingOptionsArgument,
16-
} = require('./lib/utils');
17-
const { applyPatchTask } = require('./lib/tasks/apply-patch');
18-
const {
17+
} from './lib/utils';
18+
import { applyPatchTask } from './lib/tasks/apply-patch';
19+
import {
1920
branchTask,
2021
branchLocalTask,
2122
deleteBranchesTask,
2223
deleteBranchTask,
23-
} = require('./lib/tasks/branch');
24-
const { checkIgnoreTask } = require('./lib/tasks/check-ignore');
25-
const { checkIsRepoTask } = require('./lib/tasks/check-is-repo');
26-
const { cleanWithOptionsTask, isCleanOptionsArray } = require('./lib/tasks/clean');
27-
const { diffSummaryTask } = require('./lib/tasks/diff');
28-
const { fetchTask } = require('./lib/tasks/fetch');
29-
const { moveTask } = require('./lib/tasks/move');
30-
const { pullTask } = require('./lib/tasks/pull');
31-
const { pushTagsTask } = require('./lib/tasks/push');
32-
const {
24+
} from './lib/tasks/branch';
25+
import { checkIgnoreTask } from './lib/tasks/check-ignore';
26+
import { checkIsRepoTask } from './lib/tasks/check-is-repo';
27+
import { cleanWithOptionsTask, isCleanOptionsArray } from './lib/tasks/clean';
28+
import { diffSummaryTask } from './lib/tasks/diff';
29+
import { fetchTask } from './lib/tasks/fetch';
30+
import { moveTask } from './lib/tasks/move';
31+
import { pullTask } from './lib/tasks/pull';
32+
import { pushTagsTask } from './lib/tasks/push';
33+
import {
3334
addRemoteTask,
3435
getRemotesTask,
3536
listRemotesTask,
3637
remoteTask,
3738
removeRemoteTask,
38-
} = require('./lib/tasks/remote');
39-
const { getResetMode, resetTask } = require('./lib/tasks/reset');
40-
const { stashListTask } = require('./lib/tasks/stash-list');
41-
const {
39+
} from './lib/tasks/remote';
40+
import { getResetMode, resetTask } from './lib/tasks/reset';
41+
import { stashListTask } from './lib/tasks/stash-list';
42+
import {
4243
addSubModuleTask,
4344
initSubModuleTask,
4445
subModuleTask,
4546
updateSubModuleTask,
46-
} = require('./lib/tasks/sub-module');
47-
const { addAnnotatedTagTask, addTagTask, tagListTask } = require('./lib/tasks/tag');
48-
const { straightThroughBufferTask, straightThroughStringTask } = require('./lib/tasks/task');
47+
} from './lib/tasks/sub-module';
48+
import { addAnnotatedTagTask, addTagTask, tagListTask } from './lib/tasks/tag';
49+
import { straightThroughBufferTask, straightThroughStringTask } from './lib/tasks/task';
4950

5051
function Git(options, plugins) {
5152
this._plugins = plugins;
@@ -596,4 +597,9 @@ Git.prototype.checkIsRepo = function (checkType, then) {
596597
);
597598
};
598599

599-
module.exports = Git;
600+
const GitConstructor = Git as unknown as new (
601+
options: SimpleGitOptions,
602+
plugins: PluginStore
603+
) => SimpleGit;
604+
605+
export default GitConstructor;

simple-git/src/index.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

simple-git/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { esModuleFactory, gitExportFactory, gitInstanceFactory } from './lib/git-factory';
2+
import { gitP } from './lib/runners/promise-wrapped';
3+
4+
const simpleGit = esModuleFactory(gitExportFactory(gitInstanceFactory));
5+
6+
export = Object.assign(simpleGit, { gitP, simpleGit });

simple-git/src/lib/git-factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { suffixPathsPlugin } from './plugins/suffix-paths.plugin';
1818
import { createInstanceConfig, folderExists } from './utils';
1919
import { SimpleGitOptions } from './types';
2020

21-
const Git = require('../git');
21+
import Git from '../git';
2222

2323
/**
2424
* Adds the necessary properties to the supplied object to enable it for use as

0 commit comments

Comments
 (0)