commit-and-tag-version 12.7.3 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/.github/workflows/ci.yaml +7 -14
  2. package/.github/workflows/release-please.yml +1 -1
  3. package/CHANGELOG.md +22 -0
  4. package/MIGRATION.md +51 -0
  5. package/README.md +22 -21
  6. package/bin/cli.js +2 -2
  7. package/command.js +9 -4
  8. package/defaults.js +5 -3
  9. package/eslint.config.mjs +52 -42
  10. package/index.js +12 -12
  11. package/lib/checkpoint.js +5 -5
  12. package/lib/configuration.js +9 -6
  13. package/lib/detect-package-manager.js +4 -8
  14. package/lib/format-commit-message.js +2 -2
  15. package/lib/latest-semver-tag.js +30 -30
  16. package/lib/lifecycles/bump.js +97 -65
  17. package/lib/lifecycles/changelog.js +48 -60
  18. package/lib/lifecycles/commit.js +8 -8
  19. package/lib/lifecycles/tag.js +10 -10
  20. package/lib/preset-loader.js +73 -9
  21. package/lib/print-error.js +3 -3
  22. package/lib/run-exec.js +6 -5
  23. package/lib/run-execFile.js +6 -5
  24. package/lib/run-lifecycle-script.js +6 -6
  25. package/lib/stringify-package.js +1 -5
  26. package/lib/updaters/index.js +25 -12
  27. package/lib/updaters/types/csproj.js +4 -4
  28. package/lib/updaters/types/gradle.js +4 -4
  29. package/lib/updaters/types/json.js +9 -9
  30. package/lib/updaters/types/maven.js +10 -6
  31. package/lib/updaters/types/openapi.js +6 -6
  32. package/lib/updaters/types/plain-text.js +4 -4
  33. package/lib/updaters/types/python.js +4 -4
  34. package/lib/updaters/types/yaml.js +6 -6
  35. package/lib/write-file.js +3 -3
  36. package/package.json +18 -13
  37. package/test/commit-message-config.integration-test.js +23 -10
  38. package/test/config-files.integration-test.js +25 -10
  39. package/test/config-keys.integration-test.js +20 -7
  40. package/test/core.spec.js +69 -37
  41. package/test/git.integration-test.js +23 -15
  42. package/test/invalid-config.integration-test.js +19 -9
  43. package/test/mocks/pom-6.3.1-attrs-lf.xml +1 -0
  44. package/test/mocks/pom-6.4.0-attrs-lf.xml +1 -0
  45. package/test/mocks/vitest-mocks.js +260 -0
  46. package/test/package.json +3 -0
  47. package/test/pre-commit-hook.integration-test.js +22 -14
  48. package/test/preset.integration-test.js +7 -5
  49. package/test/setup-coverage.js +47 -0
  50. package/test/stringify-package.spec.js +1 -3
  51. package/test/utils.spec.js +3 -4
  52. package/vitest.config.js +26 -0
  53. package/jest.config.js +0 -28
  54. package/test/mocks/jest-mocks.js +0 -66
@@ -1,6 +1,6 @@
1
1
  const versionRegex = /^version\s*=\s*['"]([\d.]+.*)['"]/m;
2
2
 
3
- module.exports.readVersion = function (contents) {
3
+ export function readVersion(contents) {
4
4
  const matches = versionRegex.exec(contents);
5
5
  if (matches === null) {
6
6
  throw new Error(
@@ -9,10 +9,10 @@ module.exports.readVersion = function (contents) {
9
9
  }
10
10
 
11
11
  return matches[1];
12
- };
12
+ }
13
13
 
14
- module.exports.writeVersion = function (contents, version) {
14
+ export function writeVersion(contents, version) {
15
15
  return contents.replace(versionRegex, () => {
16
16
  return `version = "${version}"`;
17
17
  });
18
- };
18
+ }
@@ -1,12 +1,12 @@
1
- const stringifyPackage = require('../../stringify-package');
2
- const detectIndent = require('detect-indent');
3
- const detectNewline = require('detect-newline');
1
+ import detectIndent from 'detect-indent';
2
+ import detectNewline from 'detect-newline';
3
+ import stringifyPackage from '../../stringify-package.js';
4
4
 
5
- module.exports.readVersion = function (contents) {
5
+ export function readVersion(contents) {
6
6
  return JSON.parse(contents).version;
7
- };
7
+ }
8
8
 
9
- module.exports.writeVersion = function (contents, version) {
9
+ export function writeVersion(contents, version) {
10
10
  const json = JSON.parse(contents);
11
11
  const indent = detectIndent(contents).indent;
12
12
  const newline = detectNewline(contents);
@@ -18,8 +18,8 @@ module.exports.writeVersion = function (contents, version) {
18
18
  }
19
19
 
20
20
  return stringifyPackage(json, indent, newline);
21
- };
21
+ }
22
22
 
23
- module.exports.isPrivate = function (contents) {
23
+ export function isPrivate(contents) {
24
24
  return JSON.parse(contents).private;
25
- };
25
+ }
@@ -1,5 +1,5 @@
1
- const detectNewline = require('detect-newline');
2
- const { XMLParser, XMLBuilder } = require('fast-xml-parser');
1
+ import detectNewline from 'detect-newline';
2
+ import { XMLParser, XMLBuilder } from 'fast-xml-parser';
3
3
 
4
4
  const CRLF = '\r\n';
5
5
  const LF = '\n';
@@ -12,6 +12,8 @@ function pomDocument(contents) {
12
12
  parseTagValue: false,
13
13
  // Don't coerce attribute values to numbers/booleans (e.g. keep port="8080" as a string)
14
14
  parseAttributeValue: false,
15
+ // Preserve comments
16
+ commentPropName: '#comment',
15
17
  });
16
18
  return parser.parse(contents);
17
19
  }
@@ -28,12 +30,12 @@ function pomVersion(document) {
28
30
  return version;
29
31
  }
30
32
 
31
- module.exports.readVersion = function (contents) {
33
+ export function readVersion(contents) {
32
34
  const document = pomDocument(contents);
33
35
  return pomVersion(document);
34
- };
36
+ }
35
37
 
36
- module.exports.writeVersion = function (contents, version) {
38
+ export function writeVersion(contents, version) {
37
39
  const newline = detectNewline(contents);
38
40
  const document = pomDocument(contents);
39
41
 
@@ -45,6 +47,8 @@ module.exports.writeVersion = function (contents, version) {
45
47
  // Write fork="true" instead of shorthand fork (which is invalid in XML)
46
48
  suppressBooleanAttributes: false,
47
49
  format: true,
50
+ // Preserve comments
51
+ commentPropName: '#comment',
48
52
  });
49
53
  const xml = builder.build(document);
50
54
 
@@ -53,4 +57,4 @@ module.exports.writeVersion = function (contents, version) {
53
57
  }
54
58
 
55
59
  return xml + LF;
56
- };
60
+ }
@@ -1,15 +1,15 @@
1
- const yaml = require('yaml');
2
- const detectNewline = require('detect-newline');
1
+ import yaml from 'yaml';
2
+ import detectNewline from 'detect-newline';
3
3
 
4
- module.exports.readVersion = function (contents) {
4
+ export function readVersion(contents) {
5
5
  return yaml.parse(contents).info.version;
6
- };
6
+ }
7
7
 
8
- module.exports.writeVersion = function (contents, version) {
8
+ export function writeVersion(contents, version) {
9
9
  const newline = detectNewline(contents);
10
10
  const document = yaml.parseDocument(contents);
11
11
 
12
12
  document.get('info').set('version', version);
13
13
 
14
14
  return document.toString().replace(/\r?\n/g, newline);
15
- };
15
+ }
@@ -1,7 +1,7 @@
1
- module.exports.readVersion = function (contents) {
1
+ export function readVersion(contents) {
2
2
  return contents;
3
- };
3
+ }
4
4
 
5
- module.exports.writeVersion = function (_contents, version) {
5
+ export function writeVersion(_contents, version) {
6
6
  return version;
7
- };
7
+ }
@@ -14,17 +14,17 @@ const getVersionIndex = function (lines) {
14
14
  return { version, lineNumber };
15
15
  };
16
16
 
17
- module.exports.readVersion = function (contents) {
17
+ export function readVersion(contents) {
18
18
  const lines = contents.split('\n');
19
19
  const versionIndex = getVersionIndex(lines);
20
20
  return versionIndex.version;
21
- };
21
+ }
22
22
 
23
- module.exports.writeVersion = function (contents, version) {
23
+ export function writeVersion(contents, version) {
24
24
  const lines = contents.split('\n');
25
25
  const versionIndex = getVersionIndex(lines);
26
26
  const versionLine = lines[versionIndex.lineNumber];
27
27
  const newVersionLine = versionLine.replace(versionIndex.version, version);
28
28
  lines[versionIndex.lineNumber] = newVersionLine;
29
29
  return lines.join('\n');
30
- };
30
+ }
@@ -1,15 +1,15 @@
1
- const yaml = require('yaml');
2
- const detectNewline = require('detect-newline');
1
+ import yaml from 'yaml';
2
+ import detectNewline from 'detect-newline';
3
3
 
4
- module.exports.readVersion = function (contents) {
4
+ export function readVersion(contents) {
5
5
  return yaml.parse(contents).version;
6
- };
6
+ }
7
7
 
8
- module.exports.writeVersion = function (contents, version) {
8
+ export function writeVersion(contents, version) {
9
9
  const newline = detectNewline(contents);
10
10
  const document = yaml.parseDocument(contents);
11
11
 
12
12
  document.set('version', version);
13
13
 
14
14
  return document.toString().replace(/\r?\n/g, newline);
15
- };
15
+ }
package/lib/write-file.js CHANGED
@@ -1,6 +1,6 @@
1
- const fs = require('fs');
1
+ import fs from 'fs';
2
2
 
3
- module.exports = function (args, filePath, content) {
3
+ export default function (args, filePath, content) {
4
4
  if (args.dryRun) return;
5
5
  fs.writeFileSync(filePath, content, 'utf8');
6
- };
6
+ }
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "commit-and-tag-version",
3
- "version": "12.7.3",
3
+ "version": "13.0.0",
4
4
  "description": "replacement for `npm version` with automatic CHANGELOG generation",
5
+ "type": "module",
6
+ "main": "index.js",
5
7
  "bin": {
6
8
  "commit-and-tag-version": "bin/cli.js"
7
9
  },
@@ -12,9 +14,9 @@
12
14
  "format:base": "prettier \"./**/*.{ts,js}\"",
13
15
  "format:fix": "npm run format:base -- --write",
14
16
  "format:check": "npm run format:base -- --check",
15
- "test": "jest",
16
- "test:unit": "jest --testPathIgnorePatterns test/git.integration-test.js",
17
- "test:git-integration": "jest --testPathPattern test/git.integration-test.js",
17
+ "test": "vitest run --coverage",
18
+ "test:unit": "vitest run --exclude 'test/*.integration-test.js'",
19
+ "test:git-integration": "vitest run test/git.integration-test.js",
18
20
  "release": "bin/cli.js"
19
21
  },
20
22
  "repository": {
@@ -22,7 +24,7 @@
22
24
  "url": "git+https://github.com/absolute-version/commit-and-tag-version.git"
23
25
  },
24
26
  "engines": {
25
- "node": ">=18"
27
+ "node": ">=22"
26
28
  },
27
29
  "keywords": [
28
30
  "conventional-changelog",
@@ -44,34 +46,37 @@
44
46
  },
45
47
  "homepage": "https://github.com/absolute-version/commit-and-tag-version#readme",
46
48
  "dependencies": {
49
+ "@conventional-changelog/git-client": "3.1.0",
47
50
  "chalk": "^2.4.2",
48
- "conventional-changelog": "4.0.0",
51
+ "conventional-changelog": "8.1.0",
49
52
  "conventional-changelog-config-spec": "2.1.0",
50
- "conventional-changelog-conventionalcommits": "6.1.0",
51
- "conventional-recommended-bump": "7.0.1",
53
+ "conventional-changelog-conventionalcommits": "10.2.1",
54
+ "conventional-recommended-bump": "12.1.0",
52
55
  "detect-indent": "^6.1.0",
53
56
  "detect-newline": "^3.1.0",
54
57
  "dotgitignore": "^2.1.0",
55
58
  "fast-xml-parser": "^5.5.6",
56
59
  "figures": "^3.2.0",
57
60
  "find-up": "^5.0.0",
58
- "git-semver-tags": "^5.0.1",
59
61
  "semver": "^7.7.2",
60
62
  "yaml": "^2.6.0",
61
63
  "yargs": "^17.7.2"
62
64
  },
63
65
  "devDependencies": {
64
66
  "@eslint/js": "^9.36.0",
67
+ "@vitest/coverage-istanbul": "^4.1.0",
68
+ "@vitest/eslint-plugin": "^1.6.23",
69
+ "conventional-changelog-angular": "^9.2.1",
65
70
  "eslint": "^9.13.0",
66
71
  "eslint-config-prettier": "^10.1.8",
67
72
  "eslint-plugin-import": "^2.31.0",
68
- "eslint-plugin-jest": "^28.8.3",
69
73
  "eslint-plugin-n": "^17.21.3",
70
74
  "eslint-plugin-promise": "^7.2.1",
71
- "jest": "^29.7.0",
72
- "jest-serial-runner": "^1.2.1",
75
+ "istanbul-lib-instrument": "^6.0.3",
76
+ "pirates": "^4.0.7",
73
77
  "prettier": "^3.3.3",
74
78
  "shelljs": "^0.10.0",
75
- "strip-ansi": "^6.0.1"
79
+ "strip-ansi": "^6.0.1",
80
+ "vitest": "^4.1.0"
76
81
  }
77
82
  }
@@ -1,16 +1,29 @@
1
- 'use strict';
2
-
3
- const shell = require('shelljs');
4
- const fs = require('fs');
5
-
6
- const mockers = require('./mocks/jest-mocks');
7
-
8
- function exec(opt = '') {
1
+ import shell from 'shelljs';
2
+ import fs from 'fs';
3
+
4
+ const mockers = vi.hoisted(() => require('./mocks/vitest-mocks').setup());
5
+ vi.mock('conventional-changelog', () => mockers.conventionalChangelogModule());
6
+ vi.mock('conventional-recommended-bump', async (importOriginal) =>
7
+ mockers.conventionalRecommendedBumpModule(
8
+ await importOriginal(),
9
+ await import('@conventional-changelog/git-client'),
10
+ ),
11
+ );
12
+ vi.mock('@conventional-changelog/git-client', async (importOriginal) =>
13
+ mockers.gitClientModule(await importOriginal()),
14
+ );
15
+
16
+ vi.spyOn(console, 'info').mockImplementation(() => {});
17
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
18
+
19
+ async function exec(opt = '') {
20
+ vi.resetModules();
21
+ const { default: cli } = await import('../command');
9
22
  if (typeof opt === 'string') {
10
- const cli = require('../command');
11
23
  opt = cli.parse(`commit-and-tag-version ${opt}`);
12
24
  }
13
- return require('../index')(opt);
25
+ const { default: standardVersion } = await import('../index');
26
+ return standardVersion(opt);
14
27
  }
15
28
 
16
29
  /**
@@ -1,15 +1,30 @@
1
- 'use strict';
2
-
3
- const shell = require('shelljs');
4
- const fs = require('fs');
5
-
6
- const mockers = require('./mocks/jest-mocks');
7
-
8
- function exec() {
9
- const cli = require('../command');
1
+ import shell from 'shelljs';
2
+ import fs from 'fs';
3
+
4
+ const mockers = vi.hoisted(() => require('./mocks/vitest-mocks').setup());
5
+ vi.mock('conventional-changelog', () => mockers.conventionalChangelogModule());
6
+ vi.mock('conventional-recommended-bump', async (importOriginal) =>
7
+ mockers.conventionalRecommendedBumpModule(
8
+ await importOriginal(),
9
+ await import('@conventional-changelog/git-client'),
10
+ ),
11
+ );
12
+ vi.mock('@conventional-changelog/git-client', async (importOriginal) =>
13
+ mockers.gitClientModule(await importOriginal()),
14
+ );
15
+
16
+ vi.spyOn(console, 'info').mockImplementation(() => {});
17
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
18
+
19
+ // command.js must be loaded AFTER shell.cd() changes CWD, because yargs.config()
20
+ // reads .versionrc at module load time. Use dynamic import with vi.resetModules().
21
+ async function exec() {
22
+ vi.resetModules();
23
+ const { default: cli } = await import('../command');
10
24
  const opt = cli.parse('commit-and-tag-version');
11
25
  opt.skip = { commit: true, tag: true };
12
- return require('../index')(opt);
26
+ const { default: standardVersion } = await import('../index');
27
+ return standardVersion(opt);
13
28
  }
14
29
 
15
30
  /**
@@ -1,15 +1,28 @@
1
- 'use strict';
1
+ import shell from 'shelljs';
2
+ import fs from 'fs';
2
3
 
3
- const shell = require('shelljs');
4
- const fs = require('fs');
4
+ const mockers = vi.hoisted(() => require('./mocks/vitest-mocks').setup());
5
+ vi.mock('conventional-changelog', () => mockers.conventionalChangelogModule());
6
+ vi.mock('conventional-recommended-bump', async (importOriginal) =>
7
+ mockers.conventionalRecommendedBumpModule(
8
+ await importOriginal(),
9
+ await import('@conventional-changelog/git-client'),
10
+ ),
11
+ );
12
+ vi.mock('@conventional-changelog/git-client', async (importOriginal) =>
13
+ mockers.gitClientModule(await importOriginal()),
14
+ );
5
15
 
6
- const mockers = require('./mocks/jest-mocks');
16
+ vi.spyOn(console, 'info').mockImplementation(() => {});
17
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
7
18
 
8
- function exec() {
9
- const cli = require('../command');
19
+ async function exec() {
20
+ vi.resetModules();
21
+ const { default: cli } = await import('../command');
10
22
  const opt = cli.parse('commit-and-tag-version');
11
23
  opt.skip = { commit: true, tag: true };
12
- return require('../index')(opt);
24
+ const { default: standardVersion } = await import('../index');
25
+ return standardVersion(opt);
13
26
  }
14
27
 
15
28
  /**
package/test/core.spec.js CHANGED
@@ -1,29 +1,64 @@
1
- 'use strict';
2
-
3
- const shell = require('shelljs');
4
- const stripAnsi = require('strip-ansi');
5
- const fs = require('fs');
6
-
7
- const mockers = require('./mocks/jest-mocks');
1
+ import shell from 'shelljs';
2
+ import stripAnsi from 'strip-ansi';
3
+
4
+ // Set up CJS require() hook + create mock fns (must be before any source imports)
5
+ const mockers = vi.hoisted(() =>
6
+ require('./mocks/vitest-mocks').setup({ mockRunExecFile: true }),
7
+ );
8
+
9
+ // Register vi.mock for ESM imports in this test file
10
+ vi.mock('conventional-changelog', () => mockers.conventionalChangelogModule());
11
+ vi.mock('conventional-recommended-bump', async (importOriginal) =>
12
+ mockers.conventionalRecommendedBumpModule(
13
+ await importOriginal(),
14
+ await import('@conventional-changelog/git-client'),
15
+ ),
16
+ );
17
+ vi.mock('@conventional-changelog/git-client', async (importOriginal) =>
18
+ mockers.gitClientModule(await importOriginal()),
19
+ );
20
+ vi.mock('../lib/run-execFile', () => ({ default: mockers.runExecFile }));
21
+ // Now that the source is ESM, this mock applies to the source's import of
22
+ // dotgitignore too (under CJS it only affected this file's import), so it
23
+ // needs a working default implementation rather than a bare automock.
24
+ vi.mock('dotgitignore', () => ({
25
+ default: vi.fn(() => ({ ignore: () => false })),
26
+ }));
27
+
28
+ // Mock fs at the Vitest ESM level so spies work for both test and source code.
29
+ vi.mock('fs', async (importOriginal) => {
30
+ const actual = await importOriginal();
31
+ const proxy = mockers.fsProxy;
32
+ return {
33
+ ...actual,
34
+ default: proxy,
35
+ readFileSync: (...args) => proxy.readFileSync(...args),
36
+ writeFileSync: (...args) => proxy.writeFileSync(...args),
37
+ lstatSync: (...args) => proxy.lstatSync(...args),
38
+ chmodSync: (...args) => proxy.chmodSync(...args),
39
+ promises: actual.promises,
40
+ };
41
+ });
8
42
 
9
- const runExecFile = require('../lib/run-execFile');
43
+ const runExecFile = mockers.runExecFile;
10
44
 
11
- const cli = require('../command');
12
- const formatCommitMessage = require('../lib/format-commit-message');
45
+ import cli from '../command';
46
+ import formatCommitMessage from '../lib/format-commit-message';
47
+ import standardVersion from '../index';
48
+ import { header as defaultHeader } from '../defaults';
49
+ import DotGitIgnore from 'dotgitignore';
50
+ import fs from 'fs';
13
51
 
14
52
  // set by mock()
15
- let standardVersion;
16
53
  let readFileSyncSpy;
17
54
  let lstatSyncSpy;
55
+ let writeFileSyncSpy = vi
56
+ .spyOn(fs, 'writeFileSync')
57
+ .mockImplementation(() => {});
18
58
 
19
- // Rather than trying to re-read something written out during tests, we can spy on writeFileSync
20
- // we can trust fs is capable of writing the file
21
- let writeFileSyncSpy;
22
-
23
- const consoleErrorSpy = jest.spyOn(console, 'warn').mockImplementation();
24
- const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
25
-
26
- jest.mock('../lib/run-execFile');
59
+ const consoleErrorSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
60
+ const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
61
+ vi.spyOn(console, 'error').mockImplementation(() => {});
27
62
 
28
63
  const { readFileSync: readFileSyncActual, lstatSync: lstatSyncActual } = fs;
29
64
 
@@ -54,7 +89,7 @@ const mockReadFilesFromDisk = ({
54
89
  testFiles,
55
90
  realTestFiles,
56
91
  }) =>
57
- jest.spyOn(fs, 'readFileSync').mockImplementation((path, opts) => {
92
+ vi.spyOn(fs, 'readFileSync').mockImplementation((path, opts) => {
58
93
  if (path === 'CHANGELOG.md') {
59
94
  if (existingChangelog) {
60
95
  return existingChangelog;
@@ -113,7 +148,7 @@ const mockReadFilesFromDisk = ({
113
148
  * @return Jest spy on lstatSync
114
149
  */
115
150
  const mockFsLStat = ({ fs, lstatSyncActual, testFiles, realTestFiles }) =>
116
- jest.spyOn(fs, 'lstatSync').mockImplementation((path) => {
151
+ vi.spyOn(fs, 'lstatSync').mockImplementation((path) => {
117
152
  if (testFiles) {
118
153
  const file = testFiles.find((otherFile) => {
119
154
  return path.includes(otherFile.path);
@@ -179,9 +214,6 @@ function mock({
179
214
  commits,
180
215
  });
181
216
 
182
- // needs to be set after mockery, but before mock-fs
183
- standardVersion = require('../index');
184
-
185
217
  // For fake and injected test files pretend they exist at root level when Fs queries lstat
186
218
  // Package.json works without this as it'll check the one in this actual repo...
187
219
  lstatSyncSpy = mockFsLStat({
@@ -200,7 +232,7 @@ function mock({
200
232
  });
201
233
 
202
234
  // Spies on writeFileSync to capture calls and ensure we don't actually try write anything to disc
203
- writeFileSyncSpy = jest.spyOn(fs, 'writeFileSync').mockImplementation();
235
+ writeFileSyncSpy = vi.spyOn(fs, 'writeFileSync').mockImplementation(() => {});
204
236
  }
205
237
 
206
238
  function clearCapturedSpyCalls() {
@@ -212,14 +244,17 @@ function restoreMocksToRealImplementation() {
212
244
  readFileSyncSpy.mockRestore();
213
245
  writeFileSyncSpy.mockRestore();
214
246
  lstatSyncSpy.mockRestore();
247
+ // Immediately re-protect against writes after restoring
248
+ writeFileSyncSpy = vi.spyOn(fs, 'writeFileSync').mockImplementation(() => {});
215
249
  }
216
250
 
217
251
  function unmock() {
218
252
  clearCapturedSpyCalls();
219
253
 
220
- restoreMocksToRealImplementation();
254
+ // Reset runExecFile mock between tests to prevent state leakage
255
+ runExecFile.mockReset();
221
256
 
222
- standardVersion = null;
257
+ restoreMocksToRealImplementation();
223
258
  }
224
259
 
225
260
  describe('format-commit-message', function () {
@@ -314,7 +349,7 @@ describe('cli', function () {
314
349
  });
315
350
 
316
351
  it('appends the new release above the last release, replacing the old header (standard-version format) with header (new format), and retains any front matter', async function () {
317
- const { header } = require('../defaults');
352
+ const header = defaultHeader;
318
353
 
319
354
  const standardVersionHeader =
320
355
  '# Changelog\n\nAll notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.';
@@ -346,7 +381,7 @@ describe('cli', function () {
346
381
  });
347
382
 
348
383
  it('appends the new release above the last release, removing the old header (new format), and retains any front matter', async function () {
349
- const { header } = require('../defaults');
384
+ const header = defaultHeader;
350
385
  const frontMatter = '---\nstatus: new\n---\n';
351
386
 
352
387
  const changelog101 =
@@ -374,7 +409,7 @@ describe('cli', function () {
374
409
  });
375
410
 
376
411
  it('appends the new release above the last release, removing the old header (new format)', async function () {
377
- const { header } = require('../defaults');
412
+ const header = defaultHeader;
378
413
  const changelog1 =
379
414
  '### [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n';
380
415
  mock({ bump: 'patch', changelog: changelog1, tags: ['v1.0.0'] });
@@ -921,7 +956,7 @@ describe('cli', function () {
921
956
 
922
957
  it('bumps using actual recommendedBump when there are no semver relevant changes and --noBumpWhenEmptyChanges flag is not set', async function () {
923
958
  mock({
924
- bump: jest.requireActual('conventional-recommended-bump'),
959
+ bump: mockers.actualConventionalRecommendedBump,
925
960
  changelog: ['chore release\n'],
926
961
  tags: ['v1.0.0'],
927
962
  commits: ['chore: update deps\n\n-hash-\nabc123\n'],
@@ -934,7 +969,7 @@ describe('cli', function () {
934
969
 
935
970
  it('bumps using actual recommendedBump when there are semver relevant changes and --noBumpWhenEmptyChanges flag is not set', async function () {
936
971
  mock({
937
- bump: jest.requireActual('conventional-recommended-bump'),
972
+ bump: mockers.actualConventionalRecommendedBump,
938
973
  changelog: ['feat release\n'],
939
974
  tags: ['v1.0.0'],
940
975
  commits: ['feat: shiny new stuff\n\n-hash-\nabc123\n'],
@@ -947,7 +982,7 @@ describe('cli', function () {
947
982
 
948
983
  it('does not bump when there are no semver relevant changes and --noBumpWhenEmptyChanges flag is set', async function () {
949
984
  mock({
950
- bump: jest.requireActual('conventional-recommended-bump'),
985
+ bump: mockers.actualConventionalRecommendedBump,
951
986
  changelog: ['chore release\n'],
952
987
  tags: ['v1.0.0'],
953
988
  commits: ['chore: update deps\n\n-hash-\nabc123\n'],
@@ -960,7 +995,7 @@ describe('cli', function () {
960
995
 
961
996
  it('bumps when there are semver relevant changes and --noBumpWhenEmptyChanges flag is set', async function () {
962
997
  mock({
963
- bump: jest.requireActual('conventional-recommended-bump'),
998
+ bump: mockers.actualConventionalRecommendedBump,
964
999
  changelog: ['feat release\n'],
965
1000
  tags: ['v1.0.0'],
966
1001
  commits: ['feat: shiny new stuff\n\n-hash-\nabc123\n'],
@@ -1686,9 +1721,6 @@ describe('cli', function () {
1686
1721
  });
1687
1722
 
1688
1723
  it('does not update files present in .gitignore', async function () {
1689
- const DotGitIgnore = require('dotgitignore');
1690
- jest.mock('dotgitignore');
1691
-
1692
1724
  DotGitIgnore.mockImplementation(() => {
1693
1725
  return {
1694
1726
  ignore: (filename) => {
@@ -1,21 +1,29 @@
1
- 'use strict';
2
-
3
- const shell = require('shelljs');
4
- const fs = require('fs');
5
-
6
- const mockers = require('./mocks/jest-mocks');
7
-
8
- // Jest swallows most standard console logs not explicitly defined into a custom logger
9
- // see: https://stackoverflow.com/questions/51555568/remove-logging-the-origin-line-in-jest
10
- const consoleWarnSpy = jest.spyOn(global.console, 'warn').mockImplementation();
11
- const consoleInfoSpy = jest.spyOn(global.console, 'info').mockImplementation();
12
-
13
- function exec(opt = '') {
1
+ import shell from 'shelljs';
2
+ import fs from 'fs';
3
+
4
+ const mockers = vi.hoisted(() => require('./mocks/vitest-mocks').setup());
5
+ vi.mock('conventional-changelog', () => mockers.conventionalChangelogModule());
6
+ vi.mock('conventional-recommended-bump', async (importOriginal) =>
7
+ mockers.conventionalRecommendedBumpModule(
8
+ await importOriginal(),
9
+ await import('@conventional-changelog/git-client'),
10
+ ),
11
+ );
12
+ vi.mock('@conventional-changelog/git-client', async (importOriginal) =>
13
+ mockers.gitClientModule(await importOriginal()),
14
+ );
15
+
16
+ const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
17
+ const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
18
+
19
+ async function exec(opt = '') {
20
+ vi.resetModules();
21
+ const { default: cli } = await import('../command');
14
22
  if (typeof opt === 'string') {
15
- const cli = require('../command');
16
23
  opt = cli.parse(`commit-and-tag-version ${opt}`);
17
24
  }
18
- return require('../index')(opt);
25
+ const { default: standardVersion } = await import('../index');
26
+ return standardVersion(opt);
19
27
  }
20
28
 
21
29
  function writePackageJson(version, option) {