From fb02175e8ac07783fb46a9ae7e891f6db651e3e9 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 30 May 2026 23:14:49 +0000 Subject: [PATCH 1/2] 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. --- packages/test-utils/package.json | 1 + pnpm-lock.yaml | 307 ++++++++++++++++-- simple-git/babel.config.js | 1 - simple-git/jest.config.js | 14 - simple-git/package.json | 14 +- simple-git/scripts/build.js | 2 +- simple-git/src/{git.js => git.ts} | 58 ++-- simple-git/src/index.js | 6 - simple-git/src/index.ts | 6 + simple-git/src/lib/git-factory.ts | 2 +- simple-git/test/integration/add.spec.ts | 1 + .../test/integration/bad-initial-path.spec.ts | 3 +- .../integration/branches-show-current.spec.ts | 1 + simple-git/test/integration/branches.spec.ts | 1 + .../test/integration/broken-chains.spec.ts | 3 +- .../test/integration/change-directory.spec.ts | 3 +- .../integration/check-ignore.win32.spec.ts | 1 + .../test/integration/check-is-repo.spec.ts | 3 +- simple-git/test/integration/checkout.spec.ts | 1 + simple-git/test/integration/clean.spec.ts | 1 + simple-git/test/integration/commit.spec.ts | 1 + .../integration/concurrent-commands.spec.ts | 1 + simple-git/test/integration/config.spec.ts | 3 +- simple-git/test/integration/diff.spec.ts | 1 + simple-git/test/integration/exec.spec.ts | 1 + simple-git/test/integration/fetch.spec.ts | 1 + simple-git/test/integration/grep.spec.ts | 3 +- .../test/integration/log-name-status.spec.ts | 3 +- .../test/integration/log-numstat.spec.ts | 1 + simple-git/test/integration/log.spec.ts | 1 + .../integration/merge-integration.spec.ts | 1 + .../test/integration/output-handler.spec.ts | 1 + .../test/integration/plugin.abort.spec.ts | 3 +- .../integration/plugin.completion.spec.ts | 1 + .../test/integration/plugin.progress.spec.ts | 5 +- .../test/integration/plugin.timeout.spec.ts | 3 +- .../test/integration/plugin.unsafe.spec.ts | 3 +- .../integration/promise-from-root.spec.ts | 11 +- simple-git/test/integration/promise.spec.ts | 7 +- .../test/integration/pull-fails-ff.spec.ts | 1 + simple-git/test/integration/remote.spec.ts | 1 + simple-git/test/integration/reset.spec.ts | 1 + simple-git/test/integration/rev-parse.spec.ts | 1 + simple-git/test/integration/status.spec.ts | 1 + simple-git/test/integration/tag.spec.ts | 1 + simple-git/test/integration/version.spec.ts | 1 + .../test/unit/__fixtures__/child-processes.ts | 1 + simple-git/test/unit/__fixtures__/debug.ts | 42 +-- .../test/unit/__fixtures__/file-exists.ts | 9 +- simple-git/test/unit/__fixtures__/setup.ts | 54 +++ .../test/unit/__mocks__/mock-child-process.ts | 20 +- simple-git/test/unit/add.spec.ts | 3 +- simple-git/test/unit/apply-patch.spec.ts | 7 +- simple-git/test/unit/args.log-format.spec.ts | 1 + simple-git/test/unit/branch.spec.ts | 5 +- simple-git/test/unit/catfile.spec.ts | 7 +- simple-git/test/unit/check-ignore.spec.ts | 5 +- simple-git/test/unit/check-is-repo.spec.ts | 5 +- simple-git/test/unit/checkout.spec.ts | 5 +- simple-git/test/unit/child-process.spec.ts | 5 +- simple-git/test/unit/clean.spec.ts | 3 +- simple-git/test/unit/clone.spec.ts | 3 +- simple-git/test/unit/commit.spec.ts | 7 +- simple-git/test/unit/config.spec.ts | 5 +- simple-git/test/unit/count-objects.spec.ts | 1 + simple-git/test/unit/cwd.spec.ts | 5 +- simple-git/test/unit/diff.spec.ts | 13 +- simple-git/test/unit/fetch.spec.ts | 5 +- simple-git/test/unit/first-commit.spec.ts | 3 +- simple-git/test/unit/git-executor.spec.ts | 5 +- simple-git/test/unit/git.spec.ts | 15 +- simple-git/test/unit/grep.spec.ts | 5 +- simple-git/test/unit/hash-object.spec.ts | 1 + simple-git/test/unit/init.spec.ts | 9 +- simple-git/test/unit/log.spec.ts | 5 +- simple-git/test/unit/logging.spec.ts | 1 + simple-git/test/unit/merge.spec.ts | 13 +- simple-git/test/unit/mv.spec.ts | 5 +- simple-git/test/unit/output-handler.spec.ts | 5 +- .../test/unit/plugins/plugin.abort.spec.ts | 3 +- .../test/unit/plugins/plugin.binary.spec.ts | 1 + .../plugin.completion-detection.spec.ts | 1 + .../test/unit/plugins/plugin.error.spec.ts | 9 +- .../test/unit/plugins/plugin.pathspec.spec.ts | 1 + .../test/unit/plugins/plugin.unsafe.spec.ts | 1 + simple-git/test/unit/plugins/plugins.spec.ts | 11 +- simple-git/test/unit/promises.spec.ts | 11 +- simple-git/test/unit/pull.spec.ts | 3 +- simple-git/test/unit/push.spec.ts | 1 + simple-git/test/unit/raw.spec.ts | 5 +- simple-git/test/unit/rebase.spec.ts | 5 +- simple-git/test/unit/remote-messages.spec.ts | 1 + simple-git/test/unit/remote.spec.ts | 7 +- simple-git/test/unit/reset.spec.ts | 5 +- simple-git/test/unit/rev-parse.spec.ts | 5 +- simple-git/test/unit/revert.spec.ts | 7 +- simple-git/test/unit/rm.spec.ts | 5 +- simple-git/test/unit/scheduler.spec.ts | 21 +- simple-git/test/unit/show.spec.ts | 5 +- simple-git/test/unit/stash-list.spec.ts | 5 +- simple-git/test/unit/stash.spec.ts | 5 +- simple-git/test/unit/status.spec.ts | 5 +- simple-git/test/unit/sub-module.spec.ts | 5 +- simple-git/test/unit/tags.spec.ts | 5 +- simple-git/test/unit/task-options.spec.ts | 1 + .../test/unit/update-server-info.spec.ts | 1 + simple-git/test/unit/utils.spec.ts | 1 + simple-git/test/unit/version.spec.ts | 1 + simple-git/vitest.config.mts | 64 ++++ 109 files changed, 693 insertions(+), 273 deletions(-) delete mode 100644 simple-git/babel.config.js delete mode 100644 simple-git/jest.config.js rename simple-git/src/{git.js => git.ts} (91%) delete mode 100644 simple-git/src/index.js create mode 100644 simple-git/src/index.ts create mode 100644 simple-git/test/unit/__fixtures__/setup.ts create mode 100644 simple-git/vitest.config.mts diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index db49d760..a4ef8c16 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -2,6 +2,7 @@ "name": "@simple-git/test-utils", "version": "4.0.0", "private": true, + "main": "index.ts", "peerDependencies": { "simple-git": "*" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1c030bae..3fa4e384 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -146,36 +146,34 @@ importers: '@kwsites/promise-result': specifier: ^1.1.0 version: 1.2.0 - '@simple-git/babel-config': - specifier: workspace:^ - version: link:../packages/babel-config '@types/debug': specifier: ^4.1.12 version: 4.1.13 - '@types/jest': - specifier: ^29.2.2 - version: 29.5.14 '@types/node': specifier: ^22.15.30 version: 22.19.19 + '@vitest/coverage-v8': + specifier: ^3.0.0 + version: 3.2.4(vitest@3.2.4(@types/debug@4.1.13)(@types/node@22.19.19)(tsx@4.22.3)) esbuild: specifier: ^0.25.0 version: 0.25.12 esbuild-node-externals: specifier: ^1.18.0 version: 1.22.0(esbuild@0.25.12) - jest: - specifier: 29.7.0 - version: 29.7.0(@types/node@22.19.19)(ts-node@10.9.2(@types/node@22.19.19)(typescript@5.9.3)) - ts-node: - specifier: ^10.9.2 - version: 10.9.2(@types/node@22.19.19)(typescript@5.9.3) typescript: specifier: ^5.7.3 version: 5.9.3 + vitest: + specifier: ^3.0.0 + version: 3.2.4(@types/debug@4.1.13)(@types/node@22.19.19)(tsx@4.22.3) packages: + '@ampproject/remapping@2.3.0': + resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==} + engines: {node: '>=6.0.0'} + '@babel/code-frame@7.29.7': resolution: {integrity: sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==} engines: {node: '>=6.9.0'} @@ -777,6 +775,10 @@ packages: '@bcoe/v8-coverage@0.2.3': resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} + '@bcoe/v8-coverage@1.0.2': + resolution: {integrity: sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==} + engines: {node: '>=18'} + '@biomejs/biome@2.4.16': resolution: {integrity: sha512-x9ajFh1zChVybCiM3TN6OD4phAqLgtPZjFrZF+aTMYCPjwBO+k529TX7PPsAqtGNLeV4UgzwQnowEgS7bGmzcA==} engines: {node: '>=14.21.3'} @@ -1372,6 +1374,10 @@ packages: '@types/node': optional: true + '@isaacs/cliui@8.0.2': + resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} + engines: {node: '>=12'} + '@istanbuljs/load-nyc-config@1.1.0': resolution: {integrity: sha512-VjeHSlIzpv/NyD3N0YuHfXOPDIixcA1q2ZV98wsMqcYlPmv2n3Yb2lYP9XMElnaFVXg5A7YLTeLu6V84uQDjmQ==} engines: {node: '>=8'} @@ -1503,6 +1509,10 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} + '@pkgjs/parseargs@0.11.0': + resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} + engines: {node: '>=14'} + '@rollup/rollup-android-arm-eabi@4.60.4': resolution: {integrity: sha512-F5QXMSiFebS9hKZj02XhWLLnRpJ3B3AROP0tWbFBSj+6kCbg5m9j5JoHKd4mmSVy5mS/IMQloYgYxCuJC0fxEQ==} cpu: [arm] @@ -1712,6 +1722,15 @@ packages: '@types/yargs@17.0.35': resolution: {integrity: sha512-qUHkeCyQFxMXg79wQfTtfndEC+N9ZZg76HJftDJp+qH2tV7Gj4OJi7l+PiWwJ+pWtW8GwSmqsDj/oymhrTWXjg==} + '@vitest/coverage-v8@3.2.4': + resolution: {integrity: sha512-EyF9SXU6kS5Ku/U82E259WSnvg6c8KTjppUncuNdm5QHpe17mwREHnjDzozC8x9MZ0xfBUFSaLkRv4TMA75ALQ==} + peerDependencies: + '@vitest/browser': 3.2.4 + vitest: 3.2.4 + peerDependenciesMeta: + '@vitest/browser': + optional: true + '@vitest/expect@3.2.4': resolution: {integrity: sha512-Io0yyORnB6sikFlt8QW5K7slY4OjqNX9jmJQ02QDda8lyM6B5oNgVWoSoKPac8/kgnCUzuHQKrSLtu/uOqqrig==} @@ -1762,6 +1781,10 @@ packages: resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} engines: {node: '>=8'} + ansi-regex@6.2.2: + resolution: {integrity: sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg==} + engines: {node: '>=12'} + ansi-styles@4.3.0: resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} engines: {node: '>=8'} @@ -1770,6 +1793,10 @@ packages: resolution: {integrity: sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==} engines: {node: '>=10'} + ansi-styles@6.2.3: + resolution: {integrity: sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==} + engines: {node: '>=12'} + anymatch@3.1.3: resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==} engines: {node: '>= 8'} @@ -1791,6 +1818,9 @@ packages: resolution: {integrity: sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==} engines: {node: '>=12'} + ast-v8-to-istanbul@0.3.12: + resolution: {integrity: sha512-BRRC8VRZY2R4Z4lFIL35MwNXmwVqBityvOIwETtsCSwvjl0IdgFsy9NhdaA6j74nUdtJJlIypeRhpDam19Wq3g==} + babel-jest@27.5.1: resolution: {integrity: sha512-cdQ5dXjGRd0IBRATiQ4mZGlGlRE8kJpjPOixdNRdT+m3UcNqmYWN6rK6nvtXYfY3D76cb8s/O1Ss8ea24PIwcg==} engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} @@ -1854,6 +1884,10 @@ packages: balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} + balanced-match@4.0.4: + resolution: {integrity: sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==} + engines: {node: 18 || 20 || >=22} + baseline-browser-mapping@2.10.33: resolution: {integrity: sha512-bA6+tcSLpz2tIEdDXZPpPTIuxBcC4+w6SieaYyfigIa4h8GlFxbA17v22Vx3JUtuZQj9SgOsnbK+aTBzyDyEuw==} engines: {node: '>=6.0.0'} @@ -1866,6 +1900,13 @@ packages: brace-expansion@1.1.15: resolution: {integrity: sha512-EwOCDEex4quD37XhqM3omwtMoJjr//isUZz1JopUNWms+4Z2ViyM/k1YIRePpoVNnQhENnxtFjLaxNHrT7xIUg==} + brace-expansion@2.1.1: + resolution: {integrity: sha512-WR1cURNjuvBLMZBMbqM0UoE+WAfdUcEV1ccD8PVBVOI+Z3ND4+SZbN8RsfT2bMuG1qwz5RFvPukSZm5fF2D5eA==} + + brace-expansion@5.0.6: + resolution: {integrity: sha512-kLpxurY4Z4r9sgMsyG0Z9uzsBlgiU/EFKhj/h91/8yHu0edo7XuixOIH3VcJ8kkxs6/jPzoI6U9Vj3WqbMQ94g==} + engines: {node: 18 || 20 || >=22} + braces@3.0.3: resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} engines: {node: '>=8'} @@ -2020,6 +2061,9 @@ packages: resolution: {integrity: sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==} engines: {node: '>=10'} + eastasianwidth@0.2.0: + resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} + electron-to-chromium@1.5.364: resolution: {integrity: sha512-G/dYE3+AYhyHwzTwg8UbnXf7zqMERYh7l2jJ3QujhFsH8agSYwtnGAR2aZ7f0AakIKJXd5En/Hre4igIUrdlYw==} @@ -2030,6 +2074,9 @@ packages: emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} + emoji-regex@9.2.2: + resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} + empathic@2.0.1: resolution: {integrity: sha512-YGRs8knHhKHVShLkFET/rWAU8kmHbOV5LwN938RHI0pljAJ1Gf6SzXsSmRaEzcXTtOOmVqJ5+WtQPL5uigY50Q==} engines: {node: '>=14'} @@ -2146,6 +2193,10 @@ packages: resolution: {integrity: sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==} engines: {node: '>=8'} + foreground-child@3.3.1: + resolution: {integrity: sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==} + engines: {node: '>=14'} + fs-extra@7.0.1: resolution: {integrity: sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==} engines: {node: '>=6 <7 || >=8'} @@ -2185,6 +2236,11 @@ packages: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} + glob@10.5.0: + resolution: {integrity: sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg==} + deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me + hasBin: true + glob@7.2.3: resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==} deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me @@ -2304,10 +2360,17 @@ packages: resolution: {integrity: sha512-n3s8EwkdFIJCG3BPKBYvskgXGoy88ARzvegkitk60NxRdwltLOTaH7CUiMRXvwYorl0Q712iEjcWB+fK/MrWVw==} engines: {node: '>=10'} + istanbul-lib-source-maps@5.0.6: + resolution: {integrity: sha512-yg2d+Em4KizZC5niWhQaIomgf5WlL4vOOjZ5xGCmF8SnPE/mDWWXgvRExdcpCgh9lLRRa1/fSYp2ymmbJ1pI+A==} + engines: {node: '>=10'} + istanbul-reports@3.2.0: resolution: {integrity: sha512-HGYWWS/ehqTV3xN10i23tkPkpH46MLCIMFNCaaKNavAXTF1RkqxawEPtnjnGZ6XKSInBKkiOA5BKS+aZiY3AvA==} engines: {node: '>=8'} + jackspeak@3.4.3: + resolution: {integrity: sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==} + jest-changed-files@29.7.0: resolution: {integrity: sha512-fEArFiwf1BpQ+4bXSprcDc3/x4HSzL4al2tozwVpDFpsxALjLYdyiIK4e5Vz66GQJIbXJ82+35PtysofptNX2w==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -2457,6 +2520,9 @@ packages: node-notifier: optional: true + js-tokens@10.0.0: + resolution: {integrity: sha512-lM/UBzQmfJRo9ABXbPWemivdCW8V2G8FHaHdypQaIy523snUjog0W71ayWXTjiR+ixeMyVHN2XcpnTd/liPg/Q==} + js-tokens@4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} @@ -2519,12 +2585,18 @@ packages: loupe@3.2.1: resolution: {integrity: sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ==} + lru-cache@10.4.3: + resolution: {integrity: sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==} + lru-cache@5.1.1: resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==} magic-string@0.30.21: resolution: {integrity: sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==} + magicast@0.3.5: + resolution: {integrity: sha512-L0WhttDl+2BOsybvEOLK7fW3UA0OQ0IQ2d6Zl2x/a6vVRs3bAY0ECOSHHeL5jD+SbOpOCUEi0y1DgHEn9Qn1AQ==} + make-dir@4.0.0: resolution: {integrity: sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==} engines: {node: '>=10'} @@ -2550,12 +2622,24 @@ packages: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} engines: {node: '>=6'} + minimatch@10.2.5: + resolution: {integrity: sha512-MULkVLfKGYDFYejP07QOurDLLQpcjk7Fw+7jXS2R2czRQzR56yHRveU5NDJEOviH+hETZKSkIk5c+T23GjFUMg==} + engines: {node: 18 || 20 || >=22} + minimatch@3.1.5: resolution: {integrity: sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==} + minimatch@9.0.9: + resolution: {integrity: sha512-OBwBN9AL4dqmETlpS2zasx+vTeWclWzkblfZk7KTA5j3jeOONz/tRCnZomUyvNg83wL5Zv9Ss6HMJXAgL8R2Yg==} + engines: {node: '>=16 || 14 >=14.17'} + minimist@1.2.8: resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} + minipass@7.1.3: + resolution: {integrity: sha512-tEBHqDnIoM/1rXME1zgka9g6Q2lcoCkxHLuc7ODJ5BxbP5d4c2Z5cGgtXAku59200Cx7diuHTOYfSBD8n6mm8A==} + engines: {node: '>=16 || 14 >=14.17'} + mri@1.2.0: resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} engines: {node: '>=4'} @@ -2633,6 +2717,9 @@ packages: resolution: {integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==} engines: {node: '>=6'} + package-json-from-dist@1.0.1: + resolution: {integrity: sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==} + package-manager-detector@0.2.11: resolution: {integrity: sha512-BEnLolu+yuz22S56CU1SUKq3XC3PkwD5wv4ikR4MfGvnRVcmzXR9DwSlW2fEamyTPyXHomBJRzgapeuBvRNzJQ==} @@ -2659,6 +2746,10 @@ packages: path-parse@1.0.7: resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} + path-scurry@1.11.1: + resolution: {integrity: sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==} + engines: {node: '>=16 || 14 >=14.18'} + path-type@4.0.0: resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} engines: {node: '>=8'} @@ -2856,10 +2947,18 @@ packages: resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} engines: {node: '>=8'} + string-width@5.1.2: + resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==} + engines: {node: '>=12'} + strip-ansi@6.0.1: resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} engines: {node: '>=8'} + strip-ansi@7.2.0: + resolution: {integrity: sha512-yDPMNjp4WyfYBkHnjIRLfca1i6KMyGCtsVgoKe/z1+6vukgaENdgGBZt+ZmKPc4gavvEZ5OgHfHdrazhgNyG7w==} + engines: {node: '>=12'} + strip-bom@3.0.0: resolution: {integrity: sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==} engines: {node: '>=4'} @@ -2899,6 +2998,10 @@ packages: resolution: {integrity: sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==} engines: {node: '>=8'} + test-exclude@7.0.2: + resolution: {integrity: sha512-u9E6A+ZDYdp7a4WnarkXPZOx8Ilz46+kby6p1yZ8zsGTz9gYa6FIS7lj2oezzNKmtdyyJNNmmXDppga5GB7kSw==} + engines: {node: '>=18'} + tinybench@2.9.0: resolution: {integrity: sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==} @@ -3098,6 +3201,10 @@ packages: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'} + wrap-ansi@8.1.0: + resolution: {integrity: sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==} + engines: {node: '>=12'} + wrappy@1.0.2: resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} @@ -3133,6 +3240,11 @@ packages: snapshots: + '@ampproject/remapping@2.3.0': + dependencies: + '@jridgewell/gen-mapping': 0.3.13 + '@jridgewell/trace-mapping': 0.3.31 + '@babel/code-frame@7.29.7': dependencies: '@babel/helper-validator-identifier': 7.29.7 @@ -3900,6 +4012,8 @@ snapshots: '@bcoe/v8-coverage@0.2.3': {} + '@bcoe/v8-coverage@1.0.2': {} + '@biomejs/biome@2.4.16': optionalDependencies: '@biomejs/cli-darwin-arm64': 2.4.16 @@ -4096,6 +4210,7 @@ snapshots: '@cspotcode/source-map-support@0.8.1': dependencies: '@jridgewell/trace-mapping': 0.3.9 + optional: true '@esbuild/aix-ppc64@0.25.12': optional: true @@ -4338,6 +4453,15 @@ snapshots: optionalDependencies: '@types/node': 22.19.19 + '@isaacs/cliui@8.0.2': + dependencies: + string-width: 5.1.2 + string-width-cjs: string-width@4.2.3 + strip-ansi: 7.2.0 + strip-ansi-cjs: strip-ansi@6.0.1 + wrap-ansi: 8.1.0 + wrap-ansi-cjs: wrap-ansi@7.0.0 + '@istanbuljs/load-nyc-config@1.1.0': dependencies: camelcase: 5.3.1 @@ -4561,6 +4685,7 @@ snapshots: dependencies: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.5 + optional: true '@kwsites/exec-p@0.4.0': {} @@ -4602,6 +4727,9 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.20.1 + '@pkgjs/parseargs@0.11.0': + optional: true + '@rollup/rollup-android-arm-eabi@4.60.4': optional: true @@ -4687,13 +4815,17 @@ snapshots: dependencies: '@sinonjs/commons': 3.0.1 - '@tsconfig/node10@1.0.12': {} + '@tsconfig/node10@1.0.12': + optional: true - '@tsconfig/node12@1.0.11': {} + '@tsconfig/node12@1.0.11': + optional: true - '@tsconfig/node14@1.0.3': {} + '@tsconfig/node14@1.0.3': + optional: true - '@tsconfig/node16@1.0.4': {} + '@tsconfig/node16@1.0.4': + optional: true '@types/babel__core@7.20.5': dependencies: @@ -4770,6 +4902,25 @@ snapshots: dependencies: '@types/yargs-parser': 21.0.3 + '@vitest/coverage-v8@3.2.4(vitest@3.2.4(@types/debug@4.1.13)(@types/node@22.19.19)(tsx@4.22.3))': + dependencies: + '@ampproject/remapping': 2.3.0 + '@bcoe/v8-coverage': 1.0.2 + ast-v8-to-istanbul: 0.3.12 + debug: 4.4.3 + istanbul-lib-coverage: 3.2.2 + istanbul-lib-report: 3.0.1 + istanbul-lib-source-maps: 5.0.6 + istanbul-reports: 3.2.0 + magic-string: 0.30.21 + magicast: 0.3.5 + std-env: 3.10.0 + test-exclude: 7.0.2 + tinyrainbow: 2.0.0 + vitest: 3.2.4(@types/debug@4.1.13)(@types/node@22.19.19)(tsx@4.22.3) + transitivePeerDependencies: + - supports-color + '@vitest/expect@3.2.4': dependencies: '@types/chai': 5.2.3 @@ -4815,8 +4966,10 @@ snapshots: acorn-walk@8.3.5: dependencies: acorn: 8.16.0 + optional: true - acorn@8.16.0: {} + acorn@8.16.0: + optional: true ansi-colors@4.1.3: {} @@ -4826,18 +4979,23 @@ snapshots: ansi-regex@5.0.1: {} + ansi-regex@6.2.2: {} + ansi-styles@4.3.0: dependencies: color-convert: 2.0.1 ansi-styles@5.2.0: {} + ansi-styles@6.2.3: {} + anymatch@3.1.3: dependencies: normalize-path: 3.0.0 picomatch: 2.3.2 - arg@4.1.3: {} + arg@4.1.3: + optional: true argparse@1.0.10: dependencies: @@ -4849,6 +5007,12 @@ snapshots: assertion-error@2.0.1: {} + ast-v8-to-istanbul@0.3.12: + dependencies: + '@jridgewell/trace-mapping': 0.3.31 + estree-walker: 3.0.3 + js-tokens: 10.0.0 + babel-jest@27.5.1(@babel/core@7.29.7): dependencies: '@babel/core': 7.29.7 @@ -4965,6 +5129,8 @@ snapshots: balanced-match@1.0.2: {} + balanced-match@4.0.4: {} + baseline-browser-mapping@2.10.33: {} better-path-resolve@1.0.0: @@ -4976,6 +5142,14 @@ snapshots: balanced-match: 1.0.2 concat-map: 0.0.1 + brace-expansion@2.1.1: + dependencies: + balanced-match: 1.0.2 + + brace-expansion@5.0.6: + dependencies: + balanced-match: 4.0.4 + braces@3.0.3: dependencies: fill-range: 7.1.1 @@ -5068,7 +5242,8 @@ snapshots: - supports-color - ts-node - create-require@1.1.1: {} + create-require@1.1.1: + optional: true cross-spawn@7.0.6: dependencies: @@ -5094,7 +5269,8 @@ snapshots: diff-sequences@29.6.3: {} - diff@4.0.4: {} + diff@4.0.4: + optional: true dir-glob@3.0.1: dependencies: @@ -5102,12 +5278,16 @@ snapshots: dotenv@8.6.0: {} + eastasianwidth@0.2.0: {} + electron-to-chromium@1.5.364: {} emittery@0.13.1: {} emoji-regex@8.0.0: {} + emoji-regex@9.2.2: {} + empathic@2.0.1: {} enquirer@2.4.1: @@ -5293,6 +5473,11 @@ snapshots: locate-path: 5.0.0 path-exists: 4.0.0 + foreground-child@3.3.1: + dependencies: + cross-spawn: 7.0.6 + signal-exit: 4.1.0 + fs-extra@7.0.1: dependencies: graceful-fs: 4.2.11 @@ -5324,6 +5509,15 @@ snapshots: dependencies: is-glob: 4.0.3 + glob@10.5.0: + dependencies: + foreground-child: 3.3.1 + jackspeak: 3.4.3 + minimatch: 9.0.9 + minipass: 7.1.3 + package-json-from-dist: 1.0.1 + path-scurry: 1.11.1 + glob@7.2.3: dependencies: fs.realpath: 1.0.0 @@ -5442,11 +5636,25 @@ snapshots: transitivePeerDependencies: - supports-color + istanbul-lib-source-maps@5.0.6: + dependencies: + '@jridgewell/trace-mapping': 0.3.31 + debug: 4.4.3 + istanbul-lib-coverage: 3.2.2 + transitivePeerDependencies: + - supports-color + istanbul-reports@3.2.0: dependencies: html-escaper: 2.0.2 istanbul-lib-report: 3.0.1 + jackspeak@3.4.3: + dependencies: + '@isaacs/cliui': 8.0.2 + optionalDependencies: + '@pkgjs/parseargs': 0.11.0 + jest-changed-files@29.7.0: dependencies: execa: 5.1.1 @@ -5795,6 +6003,8 @@ snapshots: - supports-color - ts-node + js-tokens@10.0.0: {} + js-tokens@4.0.0: {} js-tokens@9.0.1: {} @@ -5843,6 +6053,8 @@ snapshots: loupe@3.2.1: {} + lru-cache@10.4.3: {} + lru-cache@5.1.1: dependencies: yallist: 3.1.1 @@ -5851,11 +6063,18 @@ snapshots: dependencies: '@jridgewell/sourcemap-codec': 1.5.5 + magicast@0.3.5: + dependencies: + '@babel/parser': 7.29.7 + '@babel/types': 7.29.7 + source-map-js: 1.2.1 + make-dir@4.0.0: dependencies: semver: 7.8.1 - make-error@1.3.6: {} + make-error@1.3.6: + optional: true makeerror@1.0.12: dependencies: @@ -5872,12 +6091,22 @@ snapshots: mimic-fn@2.1.0: {} + minimatch@10.2.5: + dependencies: + brace-expansion: 5.0.6 + minimatch@3.1.5: dependencies: brace-expansion: 1.1.15 + minimatch@9.0.9: + dependencies: + brace-expansion: 2.1.1 + minimist@1.2.8: {} + minipass@7.1.3: {} + mri@1.2.0: {} ms@2.1.3: {} @@ -5934,6 +6163,8 @@ snapshots: p-try@2.2.0: {} + package-json-from-dist@1.0.1: {} + package-manager-detector@0.2.11: dependencies: quansync: 0.2.11 @@ -5955,6 +6186,11 @@ snapshots: path-parse@1.0.7: {} + path-scurry@1.11.1: + dependencies: + lru-cache: 10.4.3 + minipass: 7.1.3 + path-type@4.0.0: {} pathe@2.0.3: {} @@ -6147,10 +6383,20 @@ snapshots: is-fullwidth-code-point: 3.0.0 strip-ansi: 6.0.1 + string-width@5.1.2: + dependencies: + eastasianwidth: 0.2.0 + emoji-regex: 9.2.2 + strip-ansi: 7.2.0 + strip-ansi@6.0.1: dependencies: ansi-regex: 5.0.1 + strip-ansi@7.2.0: + dependencies: + ansi-regex: 6.2.2 + strip-bom@3.0.0: {} strip-bom@4.0.0: {} @@ -6181,6 +6427,12 @@ snapshots: glob: 7.2.3 minimatch: 3.1.5 + test-exclude@7.0.2: + dependencies: + '@istanbuljs/schema': 0.1.6 + glob: 10.5.0 + minimatch: 10.2.5 + tinybench@2.9.0: {} tinyexec@0.3.2: {} @@ -6221,6 +6473,7 @@ snapshots: typescript: 5.9.3 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 + optional: true tsx@4.22.3: dependencies: @@ -6259,7 +6512,8 @@ snapshots: escalade: 3.2.0 picocolors: 1.1.1 - v8-compile-cache-lib@3.0.1: {} + v8-compile-cache-lib@3.0.1: + optional: true v8-to-istanbul@9.3.0: dependencies: @@ -6369,6 +6623,12 @@ snapshots: string-width: 4.2.3 strip-ansi: 6.0.1 + wrap-ansi@8.1.0: + dependencies: + ansi-styles: 6.2.3 + string-width: 5.1.2 + strip-ansi: 7.2.0 + wrappy@1.0.2: {} write-file-atomic@3.0.3: @@ -6399,6 +6659,7 @@ snapshots: y18n: 5.0.8 yargs-parser: 21.1.1 - yn@3.1.1: {} + yn@3.1.1: + optional: true yocto-queue@0.1.0: {} diff --git a/simple-git/babel.config.js b/simple-git/babel.config.js deleted file mode 100644 index b0d20644..00000000 --- a/simple-git/babel.config.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('@simple-git/babel-config')(); diff --git a/simple-git/jest.config.js b/simple-git/jest.config.js deleted file mode 100644 index f77cd57c..00000000 --- a/simple-git/jest.config.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - roots: ['/src/', '/test/', '/typings/'], - coverageThreshold: { - global: { - branches: 80, - functions: 80, - lines: 80, - statements: 80, - }, - }, - coveragePathIgnorePatterns: ['/test/'], - coverageReporters: ['json', 'lcov', 'text', 'clover'], - testMatch: ['**/test/**/test-*.js', '**/test/**/*.spec.*'], -}; diff --git a/simple-git/package.json b/simple-git/package.json index 546b90f8..c044130c 100644 --- a/simple-git/package.json +++ b/simple-git/package.json @@ -22,15 +22,13 @@ }, "devDependencies": { "@kwsites/promise-result": "^1.1.0", - "@simple-git/babel-config": "workspace:^", "@types/debug": "^4.1.12", - "@types/jest": "^29.2.2", "@types/node": "^22.15.30", + "@vitest/coverage-v8": "^3.0.0", "esbuild": "^0.25.0", "esbuild-node-externals": "^1.18.0", - "jest": "^29.7.0", - "ts-node": "^10.9.2", - "typescript": "^5" + "typescript": "^5", + "vitest": "^3.0.0" }, "keywords": [ "git", @@ -43,7 +41,7 @@ "url": "https://github.com/steveukx/git-js.git", "directory": "simple-git" }, - "main": "src/index.js", + "main": "src/index.ts", "module": "dist/esm/index.js", "exports": { ".": { @@ -65,8 +63,8 @@ "build:defs": "tsc -p tsconfig.release.json --outDir dist && cp -r typings dist", "build:pkg": "tsx ../devtools/package-json ./simple-git/package.json", "prepublishOnly": "pnpm run build:pkg", - "test": "jest --coverage", - "test:win": "jest .win32.spec.ts$" + "test": "vitest run --coverage", + "test:win": "vitest run win32" }, "publish": { "main": "dist/cjs/index.js", diff --git a/simple-git/scripts/build.js b/simple-git/scripts/build.js index 62bc8297..1e1b832b 100644 --- a/simple-git/scripts/build.js +++ b/simple-git/scripts/build.js @@ -41,7 +41,7 @@ async function cjs() { const outfile = resolve(outDir, 'cjs', 'index.js'); await esbuild.build({ - entryPoints: ['src/index.js'], + entryPoints: ['src/index.ts'], bundle: true, platform: 'node', format: 'cjs', diff --git a/simple-git/src/git.js b/simple-git/src/git.ts similarity index 91% rename from simple-git/src/git.js rename to simple-git/src/git.ts index 97ce3c18..9aaf2b5d 100644 --- a/simple-git/src/git.js +++ b/simple-git/src/git.ts @@ -1,9 +1,10 @@ -const { GitExecutor } = require('./lib/runners/git-executor'); -const { SimpleGitApi } = require('./lib/simple-git-api'); +// @ts-nocheck — legacy prototype-style implementation, retyped in the task-refactor PR. +import { GitExecutor } from './lib/runners/git-executor'; +import { SimpleGitApi } from './lib/simple-git-api'; -const { Scheduler } = require('./lib/runners/scheduler'); -const { adhocExecTask, configurationErrorTask } = require('./lib/tasks/task'); -const { +import { Scheduler } from './lib/runners/scheduler'; +import { adhocExecTask, configurationErrorTask } from './lib/tasks/task'; +import { asArray, filterArray, filterPrimitives, @@ -13,39 +14,39 @@ const { getTrailingOptions, trailingFunctionArgument, trailingOptionsArgument, -} = require('./lib/utils'); -const { applyPatchTask } = require('./lib/tasks/apply-patch'); -const { +} from './lib/utils'; +import { applyPatchTask } from './lib/tasks/apply-patch'; +import { branchTask, branchLocalTask, deleteBranchesTask, deleteBranchTask, -} = require('./lib/tasks/branch'); -const { checkIgnoreTask } = require('./lib/tasks/check-ignore'); -const { checkIsRepoTask } = require('./lib/tasks/check-is-repo'); -const { cleanWithOptionsTask, isCleanOptionsArray } = require('./lib/tasks/clean'); -const { diffSummaryTask } = require('./lib/tasks/diff'); -const { fetchTask } = require('./lib/tasks/fetch'); -const { moveTask } = require('./lib/tasks/move'); -const { pullTask } = require('./lib/tasks/pull'); -const { pushTagsTask } = require('./lib/tasks/push'); -const { +} from './lib/tasks/branch'; +import { checkIgnoreTask } from './lib/tasks/check-ignore'; +import { checkIsRepoTask } from './lib/tasks/check-is-repo'; +import { cleanWithOptionsTask, isCleanOptionsArray } from './lib/tasks/clean'; +import { diffSummaryTask } from './lib/tasks/diff'; +import { fetchTask } from './lib/tasks/fetch'; +import { moveTask } from './lib/tasks/move'; +import { pullTask } from './lib/tasks/pull'; +import { pushTagsTask } from './lib/tasks/push'; +import { addRemoteTask, getRemotesTask, listRemotesTask, remoteTask, removeRemoteTask, -} = require('./lib/tasks/remote'); -const { getResetMode, resetTask } = require('./lib/tasks/reset'); -const { stashListTask } = require('./lib/tasks/stash-list'); -const { +} from './lib/tasks/remote'; +import { getResetMode, resetTask } from './lib/tasks/reset'; +import { stashListTask } from './lib/tasks/stash-list'; +import { addSubModuleTask, initSubModuleTask, subModuleTask, updateSubModuleTask, -} = require('./lib/tasks/sub-module'); -const { addAnnotatedTagTask, addTagTask, tagListTask } = require('./lib/tasks/tag'); -const { straightThroughBufferTask, straightThroughStringTask } = require('./lib/tasks/task'); +} from './lib/tasks/sub-module'; +import { addAnnotatedTagTask, addTagTask, tagListTask } from './lib/tasks/tag'; +import { straightThroughBufferTask, straightThroughStringTask } from './lib/tasks/task'; function Git(options, plugins) { this._plugins = plugins; @@ -596,4 +597,9 @@ Git.prototype.checkIsRepo = function (checkType, then) { ); }; -module.exports = Git; +const GitConstructor = Git as unknown as new ( + options: SimpleGitOptions, + plugins: PluginStore +) => SimpleGit; + +export default GitConstructor; diff --git a/simple-git/src/index.js b/simple-git/src/index.js deleted file mode 100644 index 02dc5e66..00000000 --- a/simple-git/src/index.js +++ /dev/null @@ -1,6 +0,0 @@ -const { gitP } = require('./lib/runners/promise-wrapped'); -const { esModuleFactory, gitInstanceFactory, gitExportFactory } = require('./lib/git-factory'); - -const simpleGit = esModuleFactory(gitExportFactory(gitInstanceFactory)); - -module.exports = Object.assign(simpleGit, { gitP, simpleGit }); diff --git a/simple-git/src/index.ts b/simple-git/src/index.ts new file mode 100644 index 00000000..8842e40a --- /dev/null +++ b/simple-git/src/index.ts @@ -0,0 +1,6 @@ +import { esModuleFactory, gitExportFactory, gitInstanceFactory } from './lib/git-factory'; +import { gitP } from './lib/runners/promise-wrapped'; + +const simpleGit = esModuleFactory(gitExportFactory(gitInstanceFactory)); + +export = Object.assign(simpleGit, { gitP, simpleGit }); diff --git a/simple-git/src/lib/git-factory.ts b/simple-git/src/lib/git-factory.ts index 2bf16f0e..f5ef374f 100644 --- a/simple-git/src/lib/git-factory.ts +++ b/simple-git/src/lib/git-factory.ts @@ -18,7 +18,7 @@ import { suffixPathsPlugin } from './plugins/suffix-paths.plugin'; import { createInstanceConfig, folderExists } from './utils'; import { SimpleGitOptions } from './types'; -const Git = require('../git'); +import Git from '../git'; /** * Adds the necessary properties to the supplied object to enable it for use as diff --git a/simple-git/test/integration/add.spec.ts b/simple-git/test/integration/add.spec.ts index aaaf0417..04b0ce1a 100644 --- a/simple-git/test/integration/add.spec.ts +++ b/simple-git/test/integration/add.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, like, diff --git a/simple-git/test/integration/bad-initial-path.spec.ts b/simple-git/test/integration/bad-initial-path.spec.ts index 155612ee..3ff99d19 100644 --- a/simple-git/test/integration/bad-initial-path.spec.ts +++ b/simple-git/test/integration/bad-initial-path.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { assertGitError, createTestContext, @@ -6,7 +7,7 @@ import { SimpleGitTestContext, } from '@simple-git/test-utils'; -import { GitConstructError } from '../..'; +import { GitConstructError } from 'simple-git'; describe('bad initial path', () => { let context: SimpleGitTestContext; diff --git a/simple-git/test/integration/branches-show-current.spec.ts b/simple-git/test/integration/branches-show-current.spec.ts index 958288c8..73190f13 100644 --- a/simple-git/test/integration/branches-show-current.spec.ts +++ b/simple-git/test/integration/branches-show-current.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, like, setUpFilesAdded, setUpInit, SimpleGitTestContext } from '@simple-git/test-utils'; describe('branch-show-current', () => { diff --git a/simple-git/test/integration/branches.spec.ts b/simple-git/test/integration/branches.spec.ts index 6f05c2bc..e02c1eee 100644 --- a/simple-git/test/integration/branches.spec.ts +++ b/simple-git/test/integration/branches.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { promiseResult } from '@kwsites/promise-result'; import { assertGitError, diff --git a/simple-git/test/integration/broken-chains.spec.ts b/simple-git/test/integration/broken-chains.spec.ts index 8a9faaef..fcebc051 100644 --- a/simple-git/test/integration/broken-chains.spec.ts +++ b/simple-git/test/integration/broken-chains.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { isPromiseFailure, promiseError, promiseResult } from '@kwsites/promise-result'; import { assertGitError, @@ -89,7 +90,7 @@ describe('broken-chains', () => { async function testPromiseChains(git: SimpleGit) { const successes: string[] = []; const errors: string[] = []; - const catcher = jest.fn(() => { + const catcher = vi.fn(() => { expect(successes).toEqual(['A']); expect(errors).toEqual([]); }); diff --git a/simple-git/test/integration/change-directory.spec.ts b/simple-git/test/integration/change-directory.spec.ts index 136202aa..fab34005 100644 --- a/simple-git/test/integration/change-directory.spec.ts +++ b/simple-git/test/integration/change-directory.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { promiseError, promiseResult } from '@kwsites/promise-result'; import { assertGitError, @@ -67,7 +68,7 @@ describe('change-directory', () => { }); it('switches into new directory - chained with callbacks', async () => { - const spies = [jest.fn(), jest.fn(), jest.fn()]; + const spies = [vi.fn(), vi.fn(), vi.fn()]; newSimpleGit(context.root) .cwd(goodDir, spies[0]) diff --git a/simple-git/test/integration/check-ignore.win32.spec.ts b/simple-git/test/integration/check-ignore.win32.spec.ts index 5499443a..eefd83c0 100644 --- a/simple-git/test/integration/check-ignore.win32.spec.ts +++ b/simple-git/test/integration/check-ignore.win32.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, setUpIgnored, setUpInit, SimpleGitTestContext } from '@simple-git/test-utils'; import { join } from 'node:path'; diff --git a/simple-git/test/integration/check-is-repo.spec.ts b/simple-git/test/integration/check-is-repo.spec.ts index 4bf5fbee..0e60f554 100644 --- a/simple-git/test/integration/check-is-repo.spec.ts +++ b/simple-git/test/integration/check-is-repo.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { assertGitError, createTestContext, @@ -26,7 +27,7 @@ describe('check-is-repo', () => { it('throws errors other than in-repo detection errors', async () => { const git = newSimpleGit(roots.realRoot).customBinary('nonsense'); - const catcher = jest.fn((err) => { + const catcher = vi.fn((err) => { assertGitError(err, 'nonsense'); }); diff --git a/simple-git/test/integration/checkout.spec.ts b/simple-git/test/integration/checkout.spec.ts index 8812e339..bf623baf 100644 --- a/simple-git/test/integration/checkout.spec.ts +++ b/simple-git/test/integration/checkout.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, newSimpleGit, diff --git a/simple-git/test/integration/clean.spec.ts b/simple-git/test/integration/clean.spec.ts index 79e9ff35..d2aa6125 100644 --- a/simple-git/test/integration/clean.spec.ts +++ b/simple-git/test/integration/clean.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertGitError, diff --git a/simple-git/test/integration/commit.spec.ts b/simple-git/test/integration/commit.spec.ts index 6f0f2838..3ae8de0d 100644 --- a/simple-git/test/integration/commit.spec.ts +++ b/simple-git/test/integration/commit.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, newSimpleGit, diff --git a/simple-git/test/integration/concurrent-commands.spec.ts b/simple-git/test/integration/concurrent-commands.spec.ts index a2cce2df..2d739e3c 100644 --- a/simple-git/test/integration/concurrent-commands.spec.ts +++ b/simple-git/test/integration/concurrent-commands.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, newSimpleGit, diff --git a/simple-git/test/integration/config.spec.ts b/simple-git/test/integration/config.spec.ts index d0468033..a3017ea2 100644 --- a/simple-git/test/integration/config.spec.ts +++ b/simple-git/test/integration/config.spec.ts @@ -1,10 +1,11 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, newSimpleGit, setUpInit, SimpleGitTestContext, } from '@simple-git/test-utils'; -import { GitConfigScope } from '../..'; +import { GitConfigScope } from 'simple-git'; import { SimpleGit } from '../../typings'; describe('config', () => { diff --git a/simple-git/test/integration/diff.spec.ts b/simple-git/test/integration/diff.spec.ts index 6aee0ada..e1d0bd18 100644 --- a/simple-git/test/integration/diff.spec.ts +++ b/simple-git/test/integration/diff.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, like, diff --git a/simple-git/test/integration/exec.spec.ts b/simple-git/test/integration/exec.spec.ts index 6c7b0f6f..6beeedbf 100644 --- a/simple-git/test/integration/exec.spec.ts +++ b/simple-git/test/integration/exec.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, newSimpleGit, SimpleGitTestContext } from '@simple-git/test-utils'; describe('exec', () => { diff --git a/simple-git/test/integration/fetch.spec.ts b/simple-git/test/integration/fetch.spec.ts index 964ae06d..5b0ef6f1 100644 --- a/simple-git/test/integration/fetch.spec.ts +++ b/simple-git/test/integration/fetch.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, newSimpleGit, diff --git a/simple-git/test/integration/grep.spec.ts b/simple-git/test/integration/grep.spec.ts index 041d7d18..04a6f623 100644 --- a/simple-git/test/integration/grep.spec.ts +++ b/simple-git/test/integration/grep.spec.ts @@ -1,5 +1,6 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, newSimpleGit, SimpleGitTestContext } from '@simple-git/test-utils'; -import { grepQueryBuilder } from '../..'; +import { grepQueryBuilder } from 'simple-git'; import { pathspec } from '@simple-git/args-pathspec'; describe('grep', () => { diff --git a/simple-git/test/integration/log-name-status.spec.ts b/simple-git/test/integration/log-name-status.spec.ts index 0e9be3d5..77e3a0d7 100644 --- a/simple-git/test/integration/log-name-status.spec.ts +++ b/simple-git/test/integration/log-name-status.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, like, @@ -7,7 +8,7 @@ import { SimpleGitTestContext, } from '@simple-git/test-utils'; -import { DiffNameStatus, DiffResultTextFile } from '../..'; +import { DiffNameStatus, DiffResultTextFile } from 'simple-git'; describe('log-name-status', function () { let context: SimpleGitTestContext; diff --git a/simple-git/test/integration/log-numstat.spec.ts b/simple-git/test/integration/log-numstat.spec.ts index 983b3cfb..428276ae 100644 --- a/simple-git/test/integration/log-numstat.spec.ts +++ b/simple-git/test/integration/log-numstat.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { newSimpleGit } from '@simple-git/test-utils'; diff --git a/simple-git/test/integration/log.spec.ts b/simple-git/test/integration/log.spec.ts index 2a57ae7e..a46e8d54 100644 --- a/simple-git/test/integration/log.spec.ts +++ b/simple-git/test/integration/log.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { promiseResult } from '@kwsites/promise-result'; import { createTestContext, diff --git a/simple-git/test/integration/merge-integration.spec.ts b/simple-git/test/integration/merge-integration.spec.ts index e7560108..3f810bca 100644 --- a/simple-git/test/integration/merge-integration.spec.ts +++ b/simple-git/test/integration/merge-integration.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { GitResponseError, MergeResult, SimpleGit } from '../../typings'; import { promiseError } from '@kwsites/promise-result'; import { diff --git a/simple-git/test/integration/output-handler.spec.ts b/simple-git/test/integration/output-handler.spec.ts index 67b66a67..eddeb0f2 100644 --- a/simple-git/test/integration/output-handler.spec.ts +++ b/simple-git/test/integration/output-handler.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, setUpInit, SimpleGitTestContext, wait } from '@simple-git/test-utils'; describe('outputHandler', function () { diff --git a/simple-git/test/integration/plugin.abort.spec.ts b/simple-git/test/integration/plugin.abort.spec.ts index e2a7e898..771e77d8 100644 --- a/simple-git/test/integration/plugin.abort.spec.ts +++ b/simple-git/test/integration/plugin.abort.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertGitError, @@ -8,7 +9,7 @@ import { wait, } from '@simple-git/test-utils'; -import { GitPluginError } from '../..'; +import { GitPluginError } from 'simple-git'; describe('timeout', () => { let context: SimpleGitTestContext; diff --git a/simple-git/test/integration/plugin.completion.spec.ts b/simple-git/test/integration/plugin.completion.spec.ts index f0fb1bb0..11aa363d 100644 --- a/simple-git/test/integration/plugin.completion.spec.ts +++ b/simple-git/test/integration/plugin.completion.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { createTestContext, newSimpleGit, SimpleGitTestContext } from '@simple-git/test-utils'; diff --git a/simple-git/test/integration/plugin.progress.spec.ts b/simple-git/test/integration/plugin.progress.spec.ts index 7430ad44..7b81a051 100644 --- a/simple-git/test/integration/plugin.progress.spec.ts +++ b/simple-git/test/integration/plugin.progress.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { createTestContext, newSimpleGit, SimpleGitTestContext } from '@simple-git/test-utils'; import { SimpleGitOptions } from '../../src/lib/types'; @@ -9,7 +10,7 @@ describe('progress-monitor', () => { beforeEach(async () => (context = await createTestContext())); it('emits progress events', async () => { - const progress = jest.fn(); + const progress = vi.fn(); const opt: Partial = { baseDir: context.root, progress, @@ -36,6 +37,6 @@ describe('progress-monitor', () => { }); }); -function progressEventsAtStage(mock: jest.Mock, stage: string) { +function progressEventsAtStage(mock: Mock, stage: string) { return mock.mock.calls.filter((c) => c[0].stage === stage).map((c) => c[0]); } diff --git a/simple-git/test/integration/plugin.timeout.spec.ts b/simple-git/test/integration/plugin.timeout.spec.ts index 17442747..aa095a01 100644 --- a/simple-git/test/integration/plugin.timeout.spec.ts +++ b/simple-git/test/integration/plugin.timeout.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, it } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertGitError, @@ -6,7 +7,7 @@ import { SimpleGitTestContext, } from '@simple-git/test-utils'; -import { GitPluginError } from '../..'; +import { GitPluginError } from 'simple-git'; describe('timeout', () => { let context: SimpleGitTestContext; diff --git a/simple-git/test/integration/plugin.unsafe.spec.ts b/simple-git/test/integration/plugin.unsafe.spec.ts index 15886ff0..ffdba81b 100644 --- a/simple-git/test/integration/plugin.unsafe.spec.ts +++ b/simple-git/test/integration/plugin.unsafe.spec.ts @@ -1,9 +1,10 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import {join} from 'node:path'; import {exists} from '@kwsites/file-exists'; import {promiseError, promiseResult} from '@kwsites/promise-result'; import {assertGitError, createTestContext, newSimpleGit, SimpleGitTestContext} from '@simple-git/test-utils'; -import {GitPluginError} from '../..'; +import {GitPluginError} from 'simple-git'; describe('plugin.unsafe', () => { let context: SimpleGitTestContext; diff --git a/simple-git/test/integration/promise-from-root.spec.ts b/simple-git/test/integration/promise-from-root.spec.ts index 314727c3..8c89b60d 100644 --- a/simple-git/test/integration/promise-from-root.spec.ts +++ b/simple-git/test/integration/promise-from-root.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { createTestContext, newSimpleGit, SimpleGitTestContext } from '@simple-git/test-utils'; describe('promises-from-root', () => { @@ -6,9 +7,9 @@ describe('promises-from-root', () => { beforeEach(async () => (context = await createTestContext())); it('chains through the default export', async () => { - const onInit = jest.fn(); - const onShowTopLevel = jest.fn(); - const onError = jest.fn(); + const onInit = vi.fn(); + const onShowTopLevel = vi.fn(); + const onError = vi.fn(); const git = newSimpleGit(context.root); const queue = git @@ -25,8 +26,8 @@ describe('promises-from-root', () => { }); it('calls provided callbacks when chained through root export', async () => { - const onInit = jest.fn(); - const onShowTopLevel = jest.fn(); + const onInit = vi.fn(); + const onShowTopLevel = vi.fn(); const queue = newSimpleGit(context.root) .init(onInit) diff --git a/simple-git/test/integration/promise.spec.ts b/simple-git/test/integration/promise.spec.ts index bfd4a618..7a4ce79f 100644 --- a/simple-git/test/integration/promise.spec.ts +++ b/simple-git/test/integration/promise.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { createTestContext, newSimpleGit, @@ -59,9 +60,9 @@ describe('promise', () => { let init, status, callbacks = { - init: jest.fn(), - initNested: jest.fn(), - status: jest.fn(), + init: vi.fn(), + initNested: vi.fn(), + status: vi.fn(), }; const git = newSimpleGit(context.root); diff --git a/simple-git/test/integration/pull-fails-ff.spec.ts b/simple-git/test/integration/pull-fails-ff.spec.ts index 0ba22a9e..26704637 100644 --- a/simple-git/test/integration/pull-fails-ff.spec.ts +++ b/simple-git/test/integration/pull-fails-ff.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { GitResponseError, PullFailedResult } from '../../typings'; import { diff --git a/simple-git/test/integration/remote.spec.ts b/simple-git/test/integration/remote.spec.ts index 0e61c829..070d438d 100644 --- a/simple-git/test/integration/remote.spec.ts +++ b/simple-git/test/integration/remote.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, newSimpleGit, diff --git a/simple-git/test/integration/reset.spec.ts b/simple-git/test/integration/reset.spec.ts index 5649978d..1b56b370 100644 --- a/simple-git/test/integration/reset.spec.ts +++ b/simple-git/test/integration/reset.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertGitError, diff --git a/simple-git/test/integration/rev-parse.spec.ts b/simple-git/test/integration/rev-parse.spec.ts index 9197ba28..4b388ec5 100644 --- a/simple-git/test/integration/rev-parse.spec.ts +++ b/simple-git/test/integration/rev-parse.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, newSimpleGit, diff --git a/simple-git/test/integration/status.spec.ts b/simple-git/test/integration/status.spec.ts index 74e12051..7e9a6cda 100644 --- a/simple-git/test/integration/status.spec.ts +++ b/simple-git/test/integration/status.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, like, diff --git a/simple-git/test/integration/tag.spec.ts b/simple-git/test/integration/tag.spec.ts index f0e7f345..364ee4f6 100644 --- a/simple-git/test/integration/tag.spec.ts +++ b/simple-git/test/integration/tag.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, like, diff --git a/simple-git/test/integration/version.spec.ts b/simple-git/test/integration/version.spec.ts index 1e51a8fd..ec3fb148 100644 --- a/simple-git/test/integration/version.spec.ts +++ b/simple-git/test/integration/version.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { createTestContext, newSimpleGit, SimpleGitTestContext } from '@simple-git/test-utils'; describe('version', () => { diff --git a/simple-git/test/unit/__fixtures__/child-processes.ts b/simple-git/test/unit/__fixtures__/child-processes.ts index 70e7c7fd..135a066c 100644 --- a/simple-git/test/unit/__fixtures__/child-processes.ts +++ b/simple-git/test/unit/__fixtures__/child-processes.ts @@ -1,3 +1,4 @@ +import type { Mock } from 'vitest'; import { MockChildProcess, mockChildProcessModule } from '../__mocks__/mock-child-process'; import { wait } from '@simple-git/test-utils'; diff --git a/simple-git/test/unit/__fixtures__/debug.ts b/simple-git/test/unit/__fixtures__/debug.ts index 22b66d62..29e857a9 100644 --- a/simple-git/test/unit/__fixtures__/debug.ts +++ b/simple-git/test/unit/__fixtures__/debug.ts @@ -1,44 +1,8 @@ -jest.mock('debug', () => { - function logger(name: string, logs: any) { - logs[name] = logs[name] || []; - - return Object.assign( - (_: string, ...messages: Array) => { - logs[name].push( - messages.filter((m) => typeof m === 'string' || Buffer.isBuffer(m)).join(' ') - ); - }, - { - extend(suffix: string) { - return debug(`${name}:${suffix}`); - }, - get logs() { - return logs; - }, - } - ); - } - - const debug: any = Object.assign( - jest.fn((name) => { - if (debug.mock.results[0].type === 'return') { - return logger(name, debug.mock.results[0].value.logs); - } - - return logger(name, {}); - }), - { - formatters: { - H: 'hello-world', - }, - } - ); - - return debug; -}); +import { type Mock, expect } from 'vitest'; +import debugModule from 'debug'; function logs(): Record { - return (require('debug') as jest.Mock).mock.results[0].value.logs; + return (debugModule as unknown as Mock).mock.results[0].value.logs; } export function $logNames(...matching: RegExp[]) { diff --git a/simple-git/test/unit/__fixtures__/file-exists.ts b/simple-git/test/unit/__fixtures__/file-exists.ts index 16bff21f..8c2c4291 100644 --- a/simple-git/test/unit/__fixtures__/file-exists.ts +++ b/simple-git/test/unit/__fixtures__/file-exists.ts @@ -1,13 +1,10 @@ +import type { Mock } from 'vitest'; import { exists } from '@kwsites/file-exists'; -jest.mock('@kwsites/file-exists', () => ({ - exists: jest.fn().mockReturnValue(true), -})); - export function isInvalidDirectory() { - (exists as jest.Mock).mockReturnValue(false); + (exists as Mock).mockReturnValue(false); } export function isValidDirectory() { - (exists as jest.Mock).mockReturnValue(true); + (exists as Mock).mockReturnValue(true); } diff --git a/simple-git/test/unit/__fixtures__/setup.ts b/simple-git/test/unit/__fixtures__/setup.ts new file mode 100644 index 00000000..34af76db --- /dev/null +++ b/simple-git/test/unit/__fixtures__/setup.ts @@ -0,0 +1,54 @@ +import { afterEach, vi } from 'vitest'; +import { mockChildProcessModule } from '../__mocks__/mock-child-process'; + +vi.mock('child_process', () => mockChildProcessModule); +vi.mock('node:child_process', () => mockChildProcessModule); + +vi.mock('debug', () => { + function logger(name: string, logs: any) { + logs[name] = logs[name] || []; + + return Object.assign( + (_: string, ...messages: Array) => { + logs[name].push( + messages.filter((m) => typeof m === 'string' || Buffer.isBuffer(m)).join(' ') + ); + }, + { + extend(suffix: string) { + return debug(`${name}:${suffix}`); + }, + get logs() { + return logs; + }, + } + ); + } + + const debug: any = Object.assign( + vi.fn((name) => { + if (debug.mock.results[0]?.type === 'return') { + return logger(name, debug.mock.results[0].value.logs); + } + + return logger(name, {}); + }), + { + enable() {}, + formatters: { + H: 'hello-world', + }, + } + ); + + return { default: debug }; +}); + +vi.mock('@kwsites/file-exists', async (importOriginal) => ({ + ...(await importOriginal()), + exists: vi.fn().mockReturnValue(true), +})); + +afterEach(() => { + mockChildProcessModule.$reset(); +}); diff --git a/simple-git/test/unit/__mocks__/mock-child-process.ts b/simple-git/test/unit/__mocks__/mock-child-process.ts index 26459ab9..19a8ea20 100644 --- a/simple-git/test/unit/__mocks__/mock-child-process.ts +++ b/simple-git/test/unit/__mocks__/mock-child-process.ts @@ -1,8 +1,10 @@ +import { type Mock, vi } from 'vitest'; + export type MockEventTarget = { $emit(event: string, data: any): void; $emitted(event: string): boolean; - on: jest.Mock; - off: jest.Mock; + on: Mock; + off: Mock; }; export type MockChildProcess = MockEventTarget & { @@ -32,7 +34,7 @@ class MockEventTargetImpl implements MockEventTarget { this.getHandlers(event).forEach((handler) => handler(data)); }; - public kill = jest.fn((_signal = 'SIGINT') => { + public kill = vi.fn((_signal = 'SIGINT') => { if (this.$emitted('exit')) { throw new Error('MockEventTarget:kill called on process after exit'); } @@ -41,11 +43,11 @@ class MockEventTargetImpl implements MockEventTarget { this.$emit('close', 1); }); - public off = jest.fn((event: string, handler: Function) => { + public off = vi.fn((event: string, handler: Function) => { this.delHandler(event, handler); }); - public on = jest.fn((event: string, handler: Function) => { + public on = vi.fn((event: string, handler: Function) => { this.addHandler(event, handler); }); @@ -106,7 +108,7 @@ export const mockChildProcessModule = (function mockChildProcessModule() { const children: MockChildProcess[] = []; return { - spawn: jest.fn((...args: ChildProcessConstructor) => + spawn: vi.fn((...args: ChildProcessConstructor) => addChild(new MockChildProcessImpl(args)) ), @@ -147,9 +149,3 @@ export const mockChildProcessModule = (function mockChildProcessModule() { return (children[children.length] = child); } })(); - -jest.mock('child_process', () => mockChildProcessModule); - -afterEach(() => { - mockChildProcessModule.$reset(); -}); diff --git a/simple-git/test/unit/add.spec.ts b/simple-git/test/unit/add.spec.ts index 5421cb10..ba8b2ad8 100644 --- a/simple-git/test/unit/add.spec.ts +++ b/simple-git/test/unit/add.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { SimpleGit } from '../../typings'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; @@ -23,7 +24,7 @@ describe('add', () => { }); it('adds files with trailing callback', async () => { - const callback = jest.fn(); + const callback = vi.fn(); const queue = git.add(['file.one', 'file.two'], callback); await closeWithSuccess('raw response'); diff --git a/simple-git/test/unit/apply-patch.spec.ts b/simple-git/test/unit/apply-patch.spec.ts index 5c33e090..72774706 100644 --- a/simple-git/test/unit/apply-patch.spec.ts +++ b/simple-git/test/unit/apply-patch.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { SimpleGit, TaskOptions } from 'typings'; import { assertExecutedCommands, @@ -38,7 +39,7 @@ describe('applyPatch', () => { it.each(applyPatchTests)( 'callbacks - %s %s', async (api, name, applyPatchArgs, executedCommands) => { - const callback = jest.fn(); + const callback = vi.fn(); const queue = (git[api] as any)(...applyPatchArgs, callback); await closeWithSuccess(name); @@ -61,7 +62,7 @@ describe('applyPatch', () => { }); describe('usage', () => { - let callback: jest.Mock; + let callback: Mock; const tests: Array<[string, RegExp | null, 'Y' | 'N', (git: SimpleGit) => Promise]> = [ @@ -141,7 +142,7 @@ describe('applyPatch', () => { ], ]; - beforeEach(() => (callback = jest.fn())); + beforeEach(() => (callback = vi.fn())); it.each(tests)(`git.applyPatch %s`, async (name, error, withCallback, task) => { const result = task(newSimpleGit()); diff --git a/simple-git/test/unit/args.log-format.spec.ts b/simple-git/test/unit/args.log-format.spec.ts index d8d9db99..e4122850 100644 --- a/simple-git/test/unit/args.log-format.spec.ts +++ b/simple-git/test/unit/args.log-format.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from 'vitest'; import { LogFormat, logFormatFromCommand } from '../../src/lib/args/log-format'; describe('log-format', function () { diff --git a/simple-git/test/unit/branch.spec.ts b/simple-git/test/unit/branch.spec.ts index fbf8a793..2cc10993 100644 --- a/simple-git/test/unit/branch.spec.ts +++ b/simple-git/test/unit/branch.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { BranchSingleDeleteResult, BranchSummary, SimpleGit } from 'typings'; import { assertExecutedCommands, @@ -12,7 +13,7 @@ import { parseBranchSummary } from '../../src/lib/parsers/parse-branch'; import { BranchSummaryResult } from '../../src/lib/responses/BranchSummary'; describe('branch', () => { - let callback: jest.Mock; + let callback: Mock; let git: SimpleGit; let promise: Promise; @@ -35,7 +36,7 @@ describe('branch', () => { beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); it('handles verbosity being set by the user', async () => { diff --git a/simple-git/test/unit/catfile.spec.ts b/simple-git/test/unit/catfile.spec.ts index 2a3a8583..0cb6cecb 100644 --- a/simple-git/test/unit/catfile.spec.ts +++ b/simple-git/test/unit/catfile.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertExecutedCommands, @@ -29,7 +30,7 @@ describe('catFile', () => { }); it('displays tree for initial commit hash', async () => { - const later = jest.fn(); + const later = vi.fn(); const queue = git.catFile(['-p', '366e4409'], later); await closeWithSuccess(stdOut); @@ -39,7 +40,7 @@ describe('catFile', () => { it('displays valid usage when no arguments passed', async () => { const message = 'Please pass in a valid (tree/commit/object) hash'; - const later = jest.fn(); + const later = vi.fn(); const queue = git.catFile(later); closeWithSuccess(message); @@ -49,7 +50,7 @@ describe('catFile', () => { }); it('optionally returns a buffer of raw data', async () => { - const later = jest.fn(); + const later = vi.fn(); const queue = git.binaryCatFile(['-p', 'HEAD:some-image.gif'], later); closeWithSuccess('foo'); diff --git a/simple-git/test/unit/check-ignore.spec.ts b/simple-git/test/unit/check-ignore.spec.ts index 0a7054b2..9456c2bc 100644 --- a/simple-git/test/unit/check-ignore.spec.ts +++ b/simple-git/test/unit/check-ignore.spec.ts @@ -1,13 +1,14 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; import { SimpleGit } from '../../typings'; describe('checkIgnore', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); it('with single excluded file specified', async () => { diff --git a/simple-git/test/unit/check-is-repo.spec.ts b/simple-git/test/unit/check-is-repo.spec.ts index 9ff1b55e..d9b24de8 100644 --- a/simple-git/test/unit/check-is-repo.spec.ts +++ b/simple-git/test/unit/check-is-repo.spec.ts @@ -1,3 +1,4 @@ +import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { SimpleGit } from 'typings'; import { @@ -15,12 +16,12 @@ describe('checkIsRepo', () => { const EXIT_ERROR = 1; let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; let error: Error | null | undefined; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn((_error) => { + callback = vi.fn((_error) => { error = _error; }); }); diff --git a/simple-git/test/unit/checkout.spec.ts b/simple-git/test/unit/checkout.spec.ts index 0563e6f2..cab05621 100644 --- a/simple-git/test/unit/checkout.spec.ts +++ b/simple-git/test/unit/checkout.spec.ts @@ -1,13 +1,14 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { SimpleGit } from 'typings'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit, wait } from './__fixtures__'; describe('checkout', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); it('checkout with trailing options array', async () => { diff --git a/simple-git/test/unit/child-process.spec.ts b/simple-git/test/unit/child-process.spec.ts index 71d0fef0..f409ddd0 100644 --- a/simple-git/test/unit/child-process.spec.ts +++ b/simple-git/test/unit/child-process.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertChildProcessEnvironmentVariables, @@ -10,11 +11,11 @@ import { SimpleGit } from '../../typings'; describe('child-process', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); it('handles child process errors', async () => { diff --git a/simple-git/test/unit/clean.spec.ts b/simple-git/test/unit/clean.spec.ts index 2656a92e..9be7ddbd 100644 --- a/simple-git/test/unit/clean.spec.ts +++ b/simple-git/test/unit/clean.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, test } from 'vitest'; import { SimpleGit } from 'typings'; import { assertExecutedCommands, @@ -8,7 +9,7 @@ import { wait, } from './__fixtures__'; -import { TaskConfigurationError } from '../..'; +import { TaskConfigurationError } from 'simple-git'; import { CleanResponse, cleanSummaryParser } from '../../src/lib/responses/CleanSummary'; import { CleanOptions, diff --git a/simple-git/test/unit/clone.spec.ts b/simple-git/test/unit/clone.spec.ts index ca6cc964..07f89da2 100644 --- a/simple-git/test/unit/clone.spec.ts +++ b/simple-git/test/unit/clone.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; import {promiseError} from '@kwsites/promise-result'; import {SimpleGit, TaskOptions} from 'typings'; import {assertExecutedCommands, assertGitError, closeWithSuccess, newSimpleGit,} from './__fixtures__'; @@ -68,7 +69,7 @@ describe('clone', () => { beforeEach(() => (git = newSimpleGit())); it.each(cloneTests)('callbacks - %s %s', async (api, name, cloneArgs, executedCommands) => { - const callback = jest.fn(); + const callback = vi.fn(); const queue = (git[api] as any)(...cloneArgs, callback); await closeWithSuccess(name); diff --git a/simple-git/test/unit/commit.spec.ts b/simple-git/test/unit/commit.spec.ts index 7823a5c5..ecbc65b3 100644 --- a/simple-git/test/unit/commit.spec.ts +++ b/simple-git/test/unit/commit.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertExecutedCommands, @@ -10,16 +11,16 @@ import { like, newSimpleGit, } from './__fixtures__'; -import { SimpleGit, TaskConfigurationError } from '../..'; +import { SimpleGit, TaskConfigurationError } from 'simple-git'; import { parseCommitResult } from '../../src/lib/parsers/parse-commit'; describe('commit', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); describe('usage', () => { diff --git a/simple-git/test/unit/config.spec.ts b/simple-git/test/unit/config.spec.ts index 8085b54a..ec175b9d 100644 --- a/simple-git/test/unit/config.spec.ts +++ b/simple-git/test/unit/config.spec.ts @@ -1,6 +1,7 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { SimpleGit } from 'typings'; import { assertExecutedCommands, closeWithSuccess, like, newSimpleGit } from './__fixtures__'; -import { GitConfigScope } from '../..'; +import { GitConfigScope } from 'simple-git'; import { configListParser } from '../../src/lib/responses/ConfigList'; describe('config list parser', () => { @@ -208,7 +209,7 @@ final@mydev.co\0`); }); it('allows callbacks when getting a single item', async () => { - const callback = jest.fn(); + const callback = vi.fn(); git.getConfig('foo', GitConfigScope.system, callback); await closeWithSuccess(`file:/Users/me/.gitconfig\0foo\nbar\0\n\n`); diff --git a/simple-git/test/unit/count-objects.spec.ts b/simple-git/test/unit/count-objects.spec.ts index 07eb6fef..2f1c5b88 100644 --- a/simple-git/test/unit/count-objects.spec.ts +++ b/simple-git/test/unit/count-objects.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from 'vitest'; import { closeWithSuccess, like, newSimpleGit } from './__fixtures__'; import { CountObjectsResult } from '../../typings'; diff --git a/simple-git/test/unit/cwd.spec.ts b/simple-git/test/unit/cwd.spec.ts index e89fe55b..277ee331 100644 --- a/simple-git/test/unit/cwd.spec.ts +++ b/simple-git/test/unit/cwd.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { SimpleGit } from 'typings'; import { assertNoExecutedTasks, @@ -17,7 +18,7 @@ describe('cwd', () => { it('to a known directory', async () => { isValidDirectory(); - const callback = jest.fn(); + const callback = vi.fn(); git.cwd('./', callback); await wait(); @@ -28,7 +29,7 @@ describe('cwd', () => { it('to an invalid directory', async () => { isInvalidDirectory(); - const callback = jest.fn((err) => expect(err.message).toMatch('invalid_path')); + const callback = vi.fn((err) => expect(err.message).toMatch('invalid_path')); git.cwd('./invalid_path', callback); await wait(); diff --git a/simple-git/test/unit/diff.spec.ts b/simple-git/test/unit/diff.spec.ts index eaab3687..559a833a 100644 --- a/simple-git/test/unit/diff.spec.ts +++ b/simple-git/test/unit/diff.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertExecutedCommands, @@ -9,7 +10,7 @@ import { newSimpleGit, wait, } from './__fixtures__'; -import { SimpleGit, TaskConfigurationError } from '../..'; +import { SimpleGit, TaskConfigurationError } from 'simple-git'; import { LogFormat } from '../../src/lib/args/log-format'; import { getDiffParser } from '../../src/lib/parsers/parse-diff-summary'; @@ -177,7 +178,7 @@ describe('diff', () => { }); it('diff - options with callback', async () => { - const later = jest.fn(); + const later = vi.fn(); git.diff({ a: null }, later); closeWithSuccess('~~ data ~~'); await wait(); @@ -186,7 +187,7 @@ describe('diff', () => { }); it('trailing function handler receives result', async () => { - const later = jest.fn(); + const later = vi.fn(); const queue = git.diffSummary(later); await closeWithSuccess(diffSummarySingleFile().stdOut); @@ -217,19 +218,19 @@ describe('diff', () => { }); it('diffSummary - with options', async () => { - git.diffSummary(['opt-a', 'opt-b'], jest.fn()); + git.diffSummary(['opt-a', 'opt-b'], vi.fn()); await closeWithSuccess(); assertExecutedCommands('diff', '--stat=4096', 'opt-a', 'opt-b'); }); it('diffSummary - with options object', async () => { - git.diffSummary({ HEAD: null, FETCH_HEAD: null }, jest.fn()); + git.diffSummary({ HEAD: null, FETCH_HEAD: null }, vi.fn()); await closeWithSuccess(); assertExecutedCommands('diff', '--stat=4096', 'HEAD', 'FETCH_HEAD'); }); it('diffSummary - single option', async () => { - git.diffSummary('opt-a' as any, jest.fn()); + git.diffSummary('opt-a' as any, vi.fn()); await closeWithSuccess(diffSummarySingleFile().stdOut); assertExecutedCommands('diff', '--stat=4096', 'opt-a'); }); diff --git a/simple-git/test/unit/fetch.spec.ts b/simple-git/test/unit/fetch.spec.ts index 497e7447..00e6820d 100644 --- a/simple-git/test/unit/fetch.spec.ts +++ b/simple-git/test/unit/fetch.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertExecutedCommands, @@ -11,11 +12,11 @@ import { parseFetchResult } from '../../src/lib/parsers/parse-fetch'; describe('fetch', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); it('runs escaped fetch', async () => { diff --git a/simple-git/test/unit/first-commit.spec.ts b/simple-git/test/unit/first-commit.spec.ts index 360e7190..c0d4716f 100644 --- a/simple-git/test/unit/first-commit.spec.ts +++ b/simple-git/test/unit/first-commit.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, vi } from 'vitest'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; describe('firstCommit', () => { @@ -10,7 +11,7 @@ describe('firstCommit', () => { }); it('gets the first commit in a repo callback', async () => { - const callback = jest.fn(); + const callback = vi.fn(); const task = newSimpleGit().firstCommit(callback); await closeWithSuccess('a-commit-hash\n'); diff --git a/simple-git/test/unit/git-executor.spec.ts b/simple-git/test/unit/git-executor.spec.ts index 96e8e458..cdb0312f 100644 --- a/simple-git/test/unit/git-executor.spec.ts +++ b/simple-git/test/unit/git-executor.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { newSimpleGit, wait } from './__fixtures__'; import { SimpleGit } from 'typings'; import { mockChildProcessModule } from './__mocks__/mock-child-process'; @@ -26,12 +27,12 @@ const aWhile = () => wait(50); describe('git-executor', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; let task: Promise; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); async function thenTheTaskHasCompleted() { diff --git a/simple-git/test/unit/git.spec.ts b/simple-git/test/unit/git.spec.ts index 242044c8..b05a6d04 100644 --- a/simple-git/test/unit/git.spec.ts +++ b/simple-git/test/unit/git.spec.ts @@ -1,3 +1,4 @@ +import { afterEach, describe, expect, it, vi } from 'vitest'; import { SimpleGit } from 'typings'; import { autoMergeConflict, @@ -9,13 +10,13 @@ import { wait, } from './__fixtures__'; -import { GitResponseError } from '../..'; +import simpleGitDefault, { GitResponseError, simpleGit as simpleGitNamed } from 'simple-git'; import { createInstanceConfig } from '../../src/lib/utils'; describe('git', () => { let git: SimpleGit; - afterEach(() => jest.clearAllMocks()); + afterEach(() => vi.clearAllMocks()); describe('deprecations', () => { it('direct access to properties of custom error on GitResponseError', async () => { @@ -35,7 +36,7 @@ describe('git', () => { expect(callbackErr).toBeInstanceOf(GitResponseError); expect(callbackErr).not.toBe(promiseErr); - const warning = jest.spyOn(console, 'warn'); + const warning = vi.spyOn(console, 'warn'); // accessing properties on the callback error shows a warning const conflicts = (callbackErr as any).conflicts; @@ -91,13 +92,13 @@ describe('git', () => { }); describe('simpleGit', () => { - const simpleGit = require('../..'); + const simpleGit = simpleGitDefault; it('can be created using the default export', () => { - expect(simpleGit.__esModule).toBe(true); - expect(simpleGit.default).toEqual(simpleGit); + expect(typeof simpleGitDefault).toBe('function'); + expect(simpleGitNamed).toBe(simpleGitDefault); - expect(() => simpleGit.default()).not.toThrow(); + expect(() => simpleGitDefault()).not.toThrow(); }); it('throws when created with a non-existent directory', () => { diff --git a/simple-git/test/unit/grep.spec.ts b/simple-git/test/unit/grep.spec.ts index e7f636fe..5c92aa45 100644 --- a/simple-git/test/unit/grep.spec.ts +++ b/simple-git/test/unit/grep.spec.ts @@ -1,3 +1,4 @@ +import { afterEach, describe, expect, it, vi } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { @@ -7,7 +8,7 @@ import { newSimpleGit, } from './__fixtures__'; -import { grepQueryBuilder, TaskConfigurationError } from '../..'; +import { grepQueryBuilder, TaskConfigurationError } from 'simple-git'; import { NULL } from '../../src/lib/utils'; import { pathspec } from '@simple-git/args-pathspec'; @@ -40,7 +41,7 @@ describe('grep', () => { }); describe('usage', () => { - const callback = jest.fn(); + const callback = vi.fn(); afterEach(() => callback.mockReset()); diff --git a/simple-git/test/unit/hash-object.spec.ts b/simple-git/test/unit/hash-object.spec.ts index 6cb2b6d1..dae242d8 100644 --- a/simple-git/test/unit/hash-object.spec.ts +++ b/simple-git/test/unit/hash-object.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { SimpleGit } from 'typings'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; diff --git a/simple-git/test/unit/init.spec.ts b/simple-git/test/unit/init.spec.ts index 173aa180..34d59e22 100644 --- a/simple-git/test/unit/init.spec.ts +++ b/simple-git/test/unit/init.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { InitResult, SimpleGit } from 'typings'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit, wait } from './__fixtures__'; import { InitSummary } from '../../src/lib/responses/InitSummary'; @@ -91,8 +92,8 @@ describe('init', () => { }); describe('callbacks', () => { - let callback: jest.Mock; - beforeEach(() => (callback = jest.fn())); + let callback: Mock; + beforeEach(() => (callback = vi.fn())); it('no arguments', async () => { git.init(mockSuccessCallback({ bare: false, existing: false }, ['init'])); @@ -156,8 +157,8 @@ describe('init', () => { expect(callback).toHaveBeenCalled(); }); - function mockSuccessCallback(expected: Partial, commands: string[]): jest.Mock { - return (callback = jest.fn((_err, init) => { + function mockSuccessCallback(expected: Partial, commands: string[]): Mock { + return (callback = vi.fn((_err, init) => { assertSuccess(init, expected, commands); })); } diff --git a/simple-git/test/unit/log.spec.ts b/simple-git/test/unit/log.spec.ts index 43298660..f341ce5d 100644 --- a/simple-git/test/unit/log.spec.ts +++ b/simple-git/test/unit/log.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import type { LogResult, SimpleGit } from 'typings'; import { @@ -9,7 +10,7 @@ import { like, newSimpleGit, } from './__fixtures__'; -import { TaskConfigurationError } from '../..'; +import { TaskConfigurationError } from 'simple-git'; import {pathspec} from "@simple-git/args-pathspec"; import { COMMIT_BOUNDARY, @@ -609,7 +610,7 @@ ${START_BOUNDARY}207601debebc170830f2921acf2b6b27034c3b1f::2016-01-03 15:50:58 + describe('usage:', () => { it('passes result to callback', async () => { - const then = jest.fn(); + const then = vi.fn(); const task = git.log(['--some-option'], then); await closeWithSuccess(); expect(then).toHaveBeenCalledWith(null, await task); diff --git a/simple-git/test/unit/logging.spec.ts b/simple-git/test/unit/logging.spec.ts index f53334bf..a0cda7c8 100644 --- a/simple-git/test/unit/logging.spec.ts +++ b/simple-git/test/unit/logging.spec.ts @@ -1,3 +1,4 @@ +import { afterEach, describe, expect, it } from 'vitest'; import { $logMessagesFor, $logNames, diff --git a/simple-git/test/unit/merge.spec.ts b/simple-git/test/unit/merge.spec.ts index 7c3f85d5..80d8b345 100644 --- a/simple-git/test/unit/merge.spec.ts +++ b/simple-git/test/unit/merge.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertExecutedCommands, @@ -14,7 +15,7 @@ import { MergeResult, SimpleGit, SimpleGitTaskCallback } from 'typings'; import { MergeSummaryDetail } from '../../src/lib/responses/MergeSummary'; import { parseMergeResult } from '../../src/lib/parsers/parse-merge'; -import { TaskConfigurationError } from '../..'; +import { TaskConfigurationError } from 'simple-git'; describe('merge', () => { describe('api', () => { @@ -30,7 +31,7 @@ describe('merge', () => { }); it('mergeFromTo', async () => { - git.mergeFromTo('aaa', 'bbb', jest.fn()); + git.mergeFromTo('aaa', 'bbb', vi.fn()); await closeWithSuccess(); assertExecutedCommands('merge', 'aaa', 'bbb'); @@ -45,14 +46,14 @@ describe('merge', () => { }); it('mergeFromToWithOptions', async () => { - git.mergeFromTo('aaa', 'bbb', ['x', 'y'], jest.fn()); + git.mergeFromTo('aaa', 'bbb', ['x', 'y'], vi.fn()); await closeWithSuccess(); assertExecutedCommands('merge', 'aaa', 'bbb', 'x', 'y'); }); it('mergeFromToWithBadOptions', async () => { - (git as any).mergeFromTo('aaa', 'bbb', 'x', jest.fn()); + (git as any).mergeFromTo('aaa', 'bbb', 'x', vi.fn()); await closeWithSuccess(); assertExecutedCommands('merge', 'aaa', 'bbb'); @@ -60,7 +61,7 @@ describe('merge', () => { it('merge with fatal error', async () => { const message = 'Some fatal error'; - const later = jest.fn(); + const later = vi.fn(); git.mergeFromTo('aaa', 'bbb', 'x' as any, later); await closeWithError(message, 128); @@ -81,7 +82,7 @@ Automatic merge failed; fix conflicts and then commit the result. }); it('responds with a MergeResult', async () => { - const mock: SimpleGitTaskCallback = jest.fn(); + const mock: SimpleGitTaskCallback = vi.fn(); const queue = git.mergeFromTo('alpha', 'beta', mock); await closeWithSuccess(mergeMadeByStrategy('recursive')); diff --git a/simple-git/test/unit/mv.spec.ts b/simple-git/test/unit/mv.spec.ts index 7f32cd69..0c27a819 100644 --- a/simple-git/test/unit/mv.spec.ts +++ b/simple-git/test/unit/mv.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; import { SimpleGit } from '../../typings'; import { parseMoveResult } from '../../src/lib/parsers/parse-move'; @@ -6,11 +7,11 @@ const renaming = (from: string, to: string) => `Renaming ${from} to ${to}`; describe('mv', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); describe('parsing', () => { diff --git a/simple-git/test/unit/output-handler.spec.ts b/simple-git/test/unit/output-handler.spec.ts index 47316946..84eeb4d3 100644 --- a/simple-git/test/unit/output-handler.spec.ts +++ b/simple-git/test/unit/output-handler.spec.ts @@ -1,13 +1,14 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { closeWithSuccess, newSimpleGit } from './__fixtures__'; import { SimpleGit } from '../../typings'; describe('outputHandler', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); it('passes name of command to callback', async () => { diff --git a/simple-git/test/unit/plugins/plugin.abort.spec.ts b/simple-git/test/unit/plugins/plugin.abort.spec.ts index c7bceb56..1ab4e2b0 100644 --- a/simple-git/test/unit/plugins/plugin.abort.spec.ts +++ b/simple-git/test/unit/plugins/plugin.abort.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertExecutedTasksCount, @@ -6,7 +7,7 @@ import { newSimpleGit, wait, } from '../__fixtures__'; -import { GitPluginError } from '../../..'; +import { GitPluginError } from 'simple-git'; describe('plugin.abort', function () { it('aborts an active child process', async () => { diff --git a/simple-git/test/unit/plugins/plugin.binary.spec.ts b/simple-git/test/unit/plugins/plugin.binary.spec.ts index d1969a15..d4684dc5 100644 --- a/simple-git/test/unit/plugins/plugin.binary.spec.ts +++ b/simple-git/test/unit/plugins/plugin.binary.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertGitError, closeWithSuccess, newSimpleGit } from '../__fixtures__'; import { mockChildProcessModule } from '../__mocks__/mock-child-process'; diff --git a/simple-git/test/unit/plugins/plugin.completion-detection.spec.ts b/simple-git/test/unit/plugins/plugin.completion-detection.spec.ts index 5c5e23d9..458589b2 100644 --- a/simple-git/test/unit/plugins/plugin.completion-detection.spec.ts +++ b/simple-git/test/unit/plugins/plugin.completion-detection.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from 'vitest'; import { newSimpleGit, theChildProcessMatching, wait } from '../__fixtures__'; import { MockChildProcess } from '../__mocks__/mock-child-process'; diff --git a/simple-git/test/unit/plugins/plugin.error.spec.ts b/simple-git/test/unit/plugins/plugin.error.spec.ts index dbbcc6b4..8b7cd13d 100644 --- a/simple-git/test/unit/plugins/plugin.error.spec.ts +++ b/simple-git/test/unit/plugins/plugin.error.spec.ts @@ -1,11 +1,12 @@ +import { describe, expect, it, vi } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertGitError, closeWithError, closeWithSuccess, newSimpleGit } from '../__fixtures__'; -import { GitError } from '../../..'; +import { GitError } from 'simple-git'; describe('errorDetectionPlugin', () => { it('can throw with custom content', async () => { - const errors = jest.fn().mockReturnValue(Buffer.from('foo')); + const errors = vi.fn().mockReturnValue(Buffer.from('foo')); const git = newSimpleGit({ errors }).init(); await closeWithError('err'); @@ -13,7 +14,7 @@ describe('errorDetectionPlugin', () => { }); it('can throw error when otherwise deemed ok', async () => { - const errors = jest.fn().mockReturnValue(new Error('FAIL')); + const errors = vi.fn().mockReturnValue(new Error('FAIL')); const git = newSimpleGit({ errors }).init(); await closeWithSuccess('OK'); @@ -26,7 +27,7 @@ describe('errorDetectionPlugin', () => { }); it('can ignore errors that would otherwise throw', async () => { - const errors = jest.fn(); + const errors = vi.fn(); const git = newSimpleGit({ errors }).raw('foo'); await closeWithError('OUT', 100); diff --git a/simple-git/test/unit/plugins/plugin.pathspec.spec.ts b/simple-git/test/unit/plugins/plugin.pathspec.spec.ts index 129d2fa1..9e19290f 100644 --- a/simple-git/test/unit/plugins/plugin.pathspec.spec.ts +++ b/simple-git/test/unit/plugins/plugin.pathspec.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, it } from 'vitest'; import { SimpleGit } from '../../../typings'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from '../__fixtures__'; import { pathspec } from '@simple-git/args-pathspec'; diff --git a/simple-git/test/unit/plugins/plugin.unsafe.spec.ts b/simple-git/test/unit/plugins/plugin.unsafe.spec.ts index 43a74160..1b7989bd 100644 --- a/simple-git/test/unit/plugins/plugin.unsafe.spec.ts +++ b/simple-git/test/unit/plugins/plugin.unsafe.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from 'vitest'; import {promiseError, promiseResult} from '@kwsites/promise-result'; import {assertExecutedCommands, assertGitError, closeWithSuccess, newSimpleGit,} from '../__fixtures__'; diff --git a/simple-git/test/unit/plugins/plugins.spec.ts b/simple-git/test/unit/plugins/plugins.spec.ts index e9b05b69..9c21cfd6 100644 --- a/simple-git/test/unit/plugins/plugins.spec.ts +++ b/simple-git/test/unit/plugins/plugins.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { SimpleGit } from '../../../typings'; import { assertChildProcessSpawnOptions, @@ -12,9 +13,9 @@ import { describe('plugins', () => { let git: SimpleGit; - let fn: jest.Mock; + let fn: Mock; - beforeEach(() => (fn = jest.fn())); + beforeEach(() => (fn = vi.fn())); it('allows configuration prefixing', async () => { git = newSimpleGit({ config: ['a', 'bcd'] }); @@ -151,7 +152,7 @@ describe('plugins', () => { }); describe('timeout', () => { - beforeEach(() => jest.useFakeTimers()); + beforeEach(() => vi.useFakeTimers()); it('waits for some time after a block on stdout', async () => { git = newSimpleGit({ timeout: { block: 2000 } }); @@ -160,12 +161,12 @@ describe('plugins', () => { await Promise.resolve(); const stdOut = Promise.all([writeToStdOut('first'), writeToStdOut('second')]); - jest.advanceTimersByTime(1000); + vi.advanceTimersByTime(1000); await stdOut; expect(theChildProcess().kill).not.toHaveBeenCalled(); - jest.advanceTimersByTime(2000); + vi.advanceTimersByTime(2000); expect(theChildProcess().kill).toHaveBeenCalled(); }); }); diff --git a/simple-git/test/unit/promises.spec.ts b/simple-git/test/unit/promises.spec.ts index a4c32c92..03442914 100644 --- a/simple-git/test/unit/promises.spec.ts +++ b/simple-git/test/unit/promises.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { closeWithError, closeWithSuccess, newSimpleGit } from './__fixtures__'; import { SimpleGit } from '../../typings'; import { BranchDeletionBatch } from '../../src/lib/responses/BranchDeleteSummary'; @@ -79,11 +80,11 @@ describe('promises', () => { expect(callbacks.named.branch).toHaveBeenCalledWith(expect.any(BranchDeletionBatch)); }); - function callbackArray(callbacks: jest.Mock[] = []) { - const resolveMock = (c: jest.Mock) => c; - const resolveMockCallCount = (c: jest.Mock) => c.mock.calls.length; + function callbackArray(callbacks: Mock[] = []) { + const resolveMock = (c: Mock) => c; + const resolveMockCallCount = (c: Mock) => c.mock.calls.length; - function byName(resolver: (c: jest.Mock) => T) { + function byName(resolver: (c: Mock) => T) { return callbacks.reduce( (all, callback) => { all[callback.getMockName()] = resolver(callback); @@ -95,7 +96,7 @@ describe('promises', () => { return { create(name: string, fn = () => name) { - return (callbacks[callbacks.length] = jest.fn(fn || (() => name)).mockName(name)); + return (callbacks[callbacks.length] = vi.fn(fn || (() => name)).mockName(name)); }, slice(from: number, to = callbacks.length) { return callbackArray(callbacks.slice(from, to)); diff --git a/simple-git/test/unit/pull.spec.ts b/simple-git/test/unit/pull.spec.ts index 9c159517..ae5193eb 100644 --- a/simple-git/test/unit/pull.spec.ts +++ b/simple-git/test/unit/pull.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { SimpleGit } from 'typings'; import { assertExecutedCommands, closeWithSuccess, like, newSimpleGit } from './__fixtures__'; import { parsePullResult } from '../../src/lib/parsers/parse-pull'; @@ -5,7 +6,7 @@ import { PullSummary } from '../../src/lib/responses/PullSummary'; describe('pull', () => { let git: SimpleGit; - const callback = jest.fn(); + const callback = vi.fn(); beforeEach(() => (git = newSimpleGit())); diff --git a/simple-git/test/unit/push.spec.ts b/simple-git/test/unit/push.spec.ts index 4a82a38e..0ee9e358 100644 --- a/simple-git/test/unit/push.spec.ts +++ b/simple-git/test/unit/push.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { PushResult, SimpleGit } from '../../typings'; import { assertExecutedCommands, closeWithSuccess, like, newSimpleGit } from './__fixtures__'; import { diff --git a/simple-git/test/unit/raw.spec.ts b/simple-git/test/unit/raw.spec.ts index 5ad492b5..9427924b 100644 --- a/simple-git/test/unit/raw.spec.ts +++ b/simple-git/test/unit/raw.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertExecutedCommands, @@ -11,12 +12,12 @@ import { SimpleGit } from '../../typings'; describe('raw', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; const response = 'passed through raw response'; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); it('does not trim by default', async () => { diff --git a/simple-git/test/unit/rebase.spec.ts b/simple-git/test/unit/rebase.spec.ts index 246f5664..fe518441 100644 --- a/simple-git/test/unit/rebase.spec.ts +++ b/simple-git/test/unit/rebase.spec.ts @@ -1,13 +1,14 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; import { SimpleGit } from '../../typings'; describe('rebase', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); it('rebases', async () => { diff --git a/simple-git/test/unit/remote-messages.spec.ts b/simple-git/test/unit/remote-messages.spec.ts index 682fce17..1d0c2cb0 100644 --- a/simple-git/test/unit/remote-messages.spec.ts +++ b/simple-git/test/unit/remote-messages.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from 'vitest'; import { gitHubAlertsUrl, gitHubPullRequest, diff --git a/simple-git/test/unit/remote.spec.ts b/simple-git/test/unit/remote.spec.ts index b683b8a0..7187a4de 100644 --- a/simple-git/test/unit/remote.spec.ts +++ b/simple-git/test/unit/remote.spec.ts @@ -1,17 +1,18 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; import { SimpleGit } from '../../typings'; import { getRemotesTask } from '../../src/lib/tasks/remote'; describe('remotes', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); - async function assertResolved(expected: T, task: Promise, cb?: jest.Mock) { + async function assertResolved(expected: T, task: Promise, cb?: Mock) { const actual = await task; expect(actual).toEqual(expected); if (cb) { diff --git a/simple-git/test/unit/reset.spec.ts b/simple-git/test/unit/reset.spec.ts index f7c2b306..76b7f5a5 100644 --- a/simple-git/test/unit/reset.spec.ts +++ b/simple-git/test/unit/reset.spec.ts @@ -1,14 +1,15 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; import { SimpleGit } from '../../typings'; import { ResetMode } from '../../src/lib/tasks/reset'; describe('reset', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); it.each<[ResetMode, string]>( diff --git a/simple-git/test/unit/rev-parse.spec.ts b/simple-git/test/unit/rev-parse.spec.ts index 034ec740..6ac78cf4 100644 --- a/simple-git/test/unit/rev-parse.spec.ts +++ b/simple-git/test/unit/rev-parse.spec.ts @@ -1,12 +1,13 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; import { SimpleGit } from '../../typings'; describe('revParse', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { - callback = jest.fn(); + callback = vi.fn(); }); describe('simple-git', () => { diff --git a/simple-git/test/unit/revert.spec.ts b/simple-git/test/unit/revert.spec.ts index 1c1ee88e..e7bef46f 100644 --- a/simple-git/test/unit/revert.spec.ts +++ b/simple-git/test/unit/revert.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, it, vi, type Mock } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertExecutedCommands, @@ -8,15 +9,15 @@ import { } from './__fixtures__'; import { SimpleGit } from '../../typings'; -import { TaskConfigurationError } from '../..'; +import { TaskConfigurationError } from 'simple-git'; describe('revert', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); it('reverts', async () => { diff --git a/simple-git/test/unit/rm.spec.ts b/simple-git/test/unit/rm.spec.ts index 91884df7..9d03acbe 100644 --- a/simple-git/test/unit/rm.spec.ts +++ b/simple-git/test/unit/rm.spec.ts @@ -1,13 +1,14 @@ +import { beforeEach, describe, it, vi, type Mock } from 'vitest'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; import { SimpleGit } from '../../typings'; describe('rm', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); it('remove single file', async () => { diff --git a/simple-git/test/unit/scheduler.spec.ts b/simple-git/test/unit/scheduler.spec.ts index 30a405ed..54d92b4d 100644 --- a/simple-git/test/unit/scheduler.spec.ts +++ b/simple-git/test/unit/scheduler.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { assertAllExecutedCommands, newSimpleGit, @@ -9,18 +10,18 @@ import { Scheduler } from '../../src/lib/runners/scheduler'; describe('scheduler', () => { describe('in isolation', () => { - let mocks: Map; - let first: jest.Mock; - let second: jest.Mock; - let third: jest.Mock; - let fourth: jest.Mock; + let mocks: Map; + let first: Mock; + let second: Mock; + let third: Mock; + let fourth: Mock; beforeEach(() => { mocks = new Map([ - ['first', (first = jest.fn().mockName('first'))], - ['second', (second = jest.fn().mockName('second'))], - ['third', (third = jest.fn().mockName('third'))], - ['fourth', (fourth = jest.fn().mockName('fourth'))], + ['first', (first = vi.fn().mockName('first'))], + ['second', (second = vi.fn().mockName('second'))], + ['third', (third = vi.fn().mockName('third'))], + ['fourth', (fourth = vi.fn().mockName('fourth'))], ]); }); @@ -92,7 +93,7 @@ describe('scheduler', () => { }); }); - function assertCallsTo(...srcMocks: jest.Mock[]) { + function assertCallsTo(...srcMocks: Mock[]) { return { are(...counts: number[]) { expect(srcMocks.length).toBe(counts.length); diff --git a/simple-git/test/unit/show.spec.ts b/simple-git/test/unit/show.spec.ts index e3268b57..9669fdbe 100644 --- a/simple-git/test/unit/show.spec.ts +++ b/simple-git/test/unit/show.spec.ts @@ -1,14 +1,15 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; import { SimpleGit } from '../../typings'; import { showAbbrevCommitSingleFile } from './__fixtures__/responses/show'; describe('show', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); it('permits binary responses', async () => { diff --git a/simple-git/test/unit/stash-list.spec.ts b/simple-git/test/unit/stash-list.spec.ts index 8ed2b069..3702fc23 100644 --- a/simple-git/test/unit/stash-list.spec.ts +++ b/simple-git/test/unit/stash-list.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { SimpleGit } from '../../typings'; import { assertExecutedCommands, closeWithSuccess, like, newSimpleGit } from './__fixtures__'; import { @@ -8,11 +9,11 @@ import { describe('stashList', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); it('with no stash', async () => { diff --git a/simple-git/test/unit/stash.spec.ts b/simple-git/test/unit/stash.spec.ts index b7baf26d..c535a744 100644 --- a/simple-git/test/unit/stash.spec.ts +++ b/simple-git/test/unit/stash.spec.ts @@ -1,13 +1,14 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; import { SimpleGit } from '../../typings'; describe('stash', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); it('supports selecting all files with a star', async () => { diff --git a/simple-git/test/unit/status.spec.ts b/simple-git/test/unit/status.spec.ts index b80f3593..ae2161b2 100644 --- a/simple-git/test/unit/status.spec.ts +++ b/simple-git/test/unit/status.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it, test, vi, type Mock } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertExecutedCommands, @@ -21,7 +22,7 @@ import { NULL } from '../../src/lib/utils'; describe('status', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; let statusCommands = (...extras: string[]) => [ 'status', '--porcelain', @@ -31,7 +32,7 @@ describe('status', () => { ...extras, ]; - beforeEach(() => (callback = jest.fn())); + beforeEach(() => (callback = vi.fn())); describe('usage', () => { beforeEach(() => (git = newSimpleGit())); diff --git a/simple-git/test/unit/sub-module.spec.ts b/simple-git/test/unit/sub-module.spec.ts index 5bbb63b7..3cc90d22 100644 --- a/simple-git/test/unit/sub-module.spec.ts +++ b/simple-git/test/unit/sub-module.spec.ts @@ -1,13 +1,14 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; import { SimpleGit } from '../../typings'; describe('submodule', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; beforeEach(() => { git = newSimpleGit(); - callback = jest.fn(); + callback = vi.fn(); }); describe('add', () => { diff --git a/simple-git/test/unit/tags.spec.ts b/simple-git/test/unit/tags.spec.ts index 5ce6304c..62629f1b 100644 --- a/simple-git/test/unit/tags.spec.ts +++ b/simple-git/test/unit/tags.spec.ts @@ -1,12 +1,13 @@ +import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; import { SimpleGit } from '../../typings'; import { parseTagList } from '../../src/lib/responses/TagList'; describe('tags', () => { let git: SimpleGit; - let callback: jest.Mock; + let callback: Mock; - beforeEach(() => (callback = jest.fn())); + beforeEach(() => (callback = vi.fn())); describe('simple-git', () => { beforeEach(() => (git = newSimpleGit())); diff --git a/simple-git/test/unit/task-options.spec.ts b/simple-git/test/unit/task-options.spec.ts index 5ebad07a..aa118025 100644 --- a/simple-git/test/unit/task-options.spec.ts +++ b/simple-git/test/unit/task-options.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, test } from 'vitest'; import { getTrailingOptions } from '../../src/lib/utils'; type OptionsTest = [string, { expected: string[]; args: [any] | [any, number] }]; diff --git a/simple-git/test/unit/update-server-info.spec.ts b/simple-git/test/unit/update-server-info.spec.ts index 65b7aa59..416c47cc 100644 --- a/simple-git/test/unit/update-server-info.spec.ts +++ b/simple-git/test/unit/update-server-info.spec.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, it } from 'vitest'; import { promiseError } from '@kwsites/promise-result'; import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; import { SimpleGit } from '../../typings'; diff --git a/simple-git/test/unit/utils.spec.ts b/simple-git/test/unit/utils.spec.ts index 98fbf799..5ec6317a 100644 --- a/simple-git/test/unit/utils.spec.ts +++ b/simple-git/test/unit/utils.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it, test } from 'vitest'; import { append, asCamelCase, diff --git a/simple-git/test/unit/version.spec.ts b/simple-git/test/unit/version.spec.ts index 223a56c2..0a425ea1 100644 --- a/simple-git/test/unit/version.spec.ts +++ b/simple-git/test/unit/version.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from 'vitest'; import { closeWithError, closeWithSuccess, newSimpleGit } from './__fixtures__'; describe('version', () => { diff --git a/simple-git/vitest.config.mts b/simple-git/vitest.config.mts new file mode 100644 index 00000000..a375e38a --- /dev/null +++ b/simple-git/vitest.config.mts @@ -0,0 +1,64 @@ +import { resolve } from 'node:path'; +import { defineConfig } from 'vitest/config'; + +const root = __dirname; + +const sharedResolve = { + alias: [ + { find: /^simple-git\/promise$/, replacement: resolve(root, 'promise') }, + { find: /^simple-git$/, replacement: resolve(root, 'src/index.ts') }, + { find: /^typings$/, replacement: resolve(root, 'typings') }, + ], +}; + +export default defineConfig({ + resolve: sharedResolve, + test: { + globals: false, + environment: 'node', + // @simple-git/test-utils is a workspace dep that imports the package + // source; inline it so vite transforms it (and the aliased TS source it + // pulls in) rather than letting Node externalise it. + server: { deps: { inline: [/@simple-git\/test-utils/] } }, + coverage: { + provider: 'v8', + reporter: ['json', 'lcov', 'text', 'clover'], + include: ['src/**'], + thresholds: { + branches: 80, + functions: 80, + lines: 80, + statements: 80, + }, + }, + projects: [ + { + resolve: sharedResolve, + test: { + name: 'unit', + globals: false, + environment: 'node', + include: ['test/unit/**/*.spec.ts', 'test/unit/**/test-*.js'], + // Unit tests run against a mocked child_process; the setup file + // registers the module mocks globally for this project only. + setupFiles: ['./test/unit/__fixtures__/setup.ts'], + server: { deps: { inline: [/@simple-git\/test-utils/] } }, + }, + }, + { + resolve: sharedResolve, + test: { + name: 'integration', + globals: false, + environment: 'node', + include: ['test/integration/**/*.spec.ts'], + // Integration tests spawn real git, so no child_process mock and + // a longer timeout for the real processes. + testTimeout: 30000, + hookTimeout: 30000, + server: { deps: { inline: [/@simple-git\/test-utils/] } }, + }, + }, + ], + }, +}); From de26659e2a8e1894620778d098c5d20783066247 Mon Sep 17 00:00:00 2001 From: Steve King Date: Sun, 31 May 2026 21:55:46 +0100 Subject: [PATCH 2/2] Update biome settings, fix imports --- biome.json | 2 +- simple-git/test/unit/__fixtures__/child-processes.ts | 5 ++--- simple-git/test/unit/__fixtures__/expectations.ts | 3 ++- simple-git/test/unit/clean.spec.ts | 7 +++---- simple-git/test/unit/status.spec.ts | 10 +++++----- simple-git/test/unit/task-options.spec.ts | 4 ++-- simple-git/test/unit/utils.spec.ts | 2 +- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/biome.json b/biome.json index 64b102d7..b19b60a1 100644 --- a/biome.json +++ b/biome.json @@ -76,7 +76,7 @@ } }, { - "includes": ["simple-git/src/git.js", "simple-git/scripts/*"], + "includes": ["simple-git/src/git.ts", "simple-git/scripts/*"], "linter": { "rules": { "complexity": { diff --git a/simple-git/test/unit/__fixtures__/child-processes.ts b/simple-git/test/unit/__fixtures__/child-processes.ts index 135a066c..b4d8e03f 100644 --- a/simple-git/test/unit/__fixtures__/child-processes.ts +++ b/simple-git/test/unit/__fixtures__/child-processes.ts @@ -1,6 +1,5 @@ -import type { Mock } from 'vitest'; -import { MockChildProcess, mockChildProcessModule } from '../__mocks__/mock-child-process'; -import { wait } from '@simple-git/test-utils'; +import {MockChildProcess, mockChildProcessModule} from '../__mocks__/mock-child-process'; +import {wait} from '@simple-git/test-utils'; const EXIT_CODE_SUCCESS = 0; const EXIT_CODE_ERROR = 1; diff --git a/simple-git/test/unit/__fixtures__/expectations.ts b/simple-git/test/unit/__fixtures__/expectations.ts index 370451d6..6d6e795a 100644 --- a/simple-git/test/unit/__fixtures__/expectations.ts +++ b/simple-git/test/unit/__fixtures__/expectations.ts @@ -1,4 +1,5 @@ -import { mockChildProcessModule } from '../__mocks__/mock-child-process'; +import {expect} from 'vitest'; +import {mockChildProcessModule} from '../__mocks__/mock-child-process'; export function assertTheBuffer(actual: Buffer | unknown, content?: string) { expect(Buffer.isBuffer(actual)).toBe(true); diff --git a/simple-git/test/unit/clean.spec.ts b/simple-git/test/unit/clean.spec.ts index 9be7ddbd..72a14495 100644 --- a/simple-git/test/unit/clean.spec.ts +++ b/simple-git/test/unit/clean.spec.ts @@ -1,5 +1,5 @@ -import { beforeEach, describe, expect, it, test } from 'vitest'; -import { SimpleGit } from 'typings'; +import {beforeEach, describe, expect, it} from 'vitest'; +import {SimpleGit, TaskConfigurationError} from 'typings'; import { assertExecutedCommands, assertGitError, @@ -9,8 +9,7 @@ import { wait, } from './__fixtures__'; -import { TaskConfigurationError } from 'simple-git'; -import { CleanResponse, cleanSummaryParser } from '../../src/lib/responses/CleanSummary'; +import {CleanResponse, cleanSummaryParser} from '../../src/lib/responses/CleanSummary'; import { CleanOptions, CONFIG_ERROR_INTERACTIVE_MODE, diff --git a/simple-git/test/unit/status.spec.ts b/simple-git/test/unit/status.spec.ts index ae2161b2..5fd9c979 100644 --- a/simple-git/test/unit/status.spec.ts +++ b/simple-git/test/unit/status.spec.ts @@ -1,5 +1,5 @@ -import { beforeEach, describe, expect, it, test, vi, type Mock } from 'vitest'; -import { promiseError } from '@kwsites/promise-result'; +import {beforeEach, describe, expect, it, type Mock, vi} from 'vitest'; +import {promiseError} from '@kwsites/promise-result'; import { assertExecutedCommands, assertGitError, @@ -16,9 +16,9 @@ import { statusResponse, unStagedDeleted, } from './__fixtures__'; -import { SimpleGit, StatusResult } from '../../typings'; -import { parseStatusSummary, StatusSummary } from '../../src/lib/responses/StatusSummary'; -import { NULL } from '../../src/lib/utils'; +import {SimpleGit, StatusResult} from '../../typings'; +import {parseStatusSummary, StatusSummary} from '../../src/lib/responses/StatusSummary'; +import {NULL} from '../../src/lib/utils'; describe('status', () => { let git: SimpleGit; diff --git a/simple-git/test/unit/task-options.spec.ts b/simple-git/test/unit/task-options.spec.ts index aa118025..bfa6b071 100644 --- a/simple-git/test/unit/task-options.spec.ts +++ b/simple-git/test/unit/task-options.spec.ts @@ -1,5 +1,5 @@ -import { describe, expect, it, test } from 'vitest'; -import { getTrailingOptions } from '../../src/lib/utils'; +import {describe, expect, it} from 'vitest'; +import {getTrailingOptions} from '../../src/lib/utils'; type OptionsTest = [string, { expected: string[]; args: [any] | [any, number] }]; diff --git a/simple-git/test/unit/utils.spec.ts b/simple-git/test/unit/utils.spec.ts index 5ec6317a..6001180c 100644 --- a/simple-git/test/unit/utils.spec.ts +++ b/simple-git/test/unit/utils.spec.ts @@ -1,4 +1,4 @@ -import { describe, expect, it, test } from 'vitest'; +import {describe, expect, it} from 'vitest'; import { append, asCamelCase,