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.
- package/.github/workflows/ci.yaml +7 -14
- package/.github/workflows/release-please.yml +1 -1
- package/CHANGELOG.md +22 -0
- package/MIGRATION.md +51 -0
- package/README.md +22 -21
- package/bin/cli.js +2 -2
- package/command.js +9 -4
- package/defaults.js +5 -3
- package/eslint.config.mjs +52 -42
- package/index.js +12 -12
- package/lib/checkpoint.js +5 -5
- package/lib/configuration.js +9 -6
- package/lib/detect-package-manager.js +4 -8
- package/lib/format-commit-message.js +2 -2
- package/lib/latest-semver-tag.js +30 -30
- package/lib/lifecycles/bump.js +97 -65
- package/lib/lifecycles/changelog.js +48 -60
- package/lib/lifecycles/commit.js +8 -8
- package/lib/lifecycles/tag.js +10 -10
- package/lib/preset-loader.js +73 -9
- package/lib/print-error.js +3 -3
- package/lib/run-exec.js +6 -5
- package/lib/run-execFile.js +6 -5
- package/lib/run-lifecycle-script.js +6 -6
- package/lib/stringify-package.js +1 -5
- package/lib/updaters/index.js +25 -12
- package/lib/updaters/types/csproj.js +4 -4
- package/lib/updaters/types/gradle.js +4 -4
- package/lib/updaters/types/json.js +9 -9
- package/lib/updaters/types/maven.js +10 -6
- package/lib/updaters/types/openapi.js +6 -6
- package/lib/updaters/types/plain-text.js +4 -4
- package/lib/updaters/types/python.js +4 -4
- package/lib/updaters/types/yaml.js +6 -6
- package/lib/write-file.js +3 -3
- package/package.json +18 -13
- package/test/commit-message-config.integration-test.js +23 -10
- package/test/config-files.integration-test.js +25 -10
- package/test/config-keys.integration-test.js +20 -7
- package/test/core.spec.js +69 -37
- package/test/git.integration-test.js +23 -15
- package/test/invalid-config.integration-test.js +19 -9
- package/test/mocks/pom-6.3.1-attrs-lf.xml +1 -0
- package/test/mocks/pom-6.4.0-attrs-lf.xml +1 -0
- package/test/mocks/vitest-mocks.js +260 -0
- package/test/package.json +3 -0
- package/test/pre-commit-hook.integration-test.js +22 -14
- package/test/preset.integration-test.js +7 -5
- package/test/setup-coverage.js +47 -0
- package/test/stringify-package.spec.js +1 -3
- package/test/utils.spec.js +3 -4
- package/vitest.config.js +26 -0
- package/jest.config.js +0 -28
- package/test/mocks/jest-mocks.js +0 -66
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
import shell from 'shelljs';
|
|
2
|
+
import fs from 'fs';
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const cli = require('../command');
|
|
16
|
+
async function exec() {
|
|
17
|
+
vi.resetModules();
|
|
18
|
+
const { default: cli } = await import('../command');
|
|
10
19
|
const opt = cli.parse('commit-and-tag-version');
|
|
11
20
|
opt.skip = { commit: true, tag: true };
|
|
12
|
-
|
|
21
|
+
const { default: standardVersion } = await import('../index');
|
|
22
|
+
return standardVersion(opt);
|
|
13
23
|
}
|
|
14
24
|
|
|
15
25
|
/**
|
|
@@ -68,6 +78,6 @@ describe('invalid .versionrc', function () {
|
|
|
68
78
|
mock({ bump: 'minor' });
|
|
69
79
|
fs.writeFileSync('.versionrc.js', 'module.exports = 3', 'utf-8');
|
|
70
80
|
|
|
71
|
-
expect(exec).toThrow(/Invalid configuration/);
|
|
81
|
+
await expect(exec()).rejects.toThrow(/Invalid configuration/);
|
|
72
82
|
});
|
|
73
83
|
});
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create mock state and module factories for the conventional-changelog
|
|
5
|
+
* ecosystem packages.
|
|
6
|
+
*
|
|
7
|
+
* Usage in test files:
|
|
8
|
+
*
|
|
9
|
+
* const mockers = vi.hoisted(() => require('./mocks/vitest-mocks').setup());
|
|
10
|
+
*
|
|
11
|
+
* vi.mock('conventional-changelog', () =>
|
|
12
|
+
* mockers.conventionalChangelogModule(),
|
|
13
|
+
* );
|
|
14
|
+
* vi.mock('conventional-recommended-bump', async (importOriginal) =>
|
|
15
|
+
* mockers.conventionalRecommendedBumpModule(
|
|
16
|
+
* await importOriginal(),
|
|
17
|
+
* await import('@conventional-changelog/git-client'),
|
|
18
|
+
* ),
|
|
19
|
+
* );
|
|
20
|
+
* vi.mock('@conventional-changelog/git-client', async (importOriginal) =>
|
|
21
|
+
* mockers.gitClientModule(await importOriginal()),
|
|
22
|
+
* );
|
|
23
|
+
*/
|
|
24
|
+
function setup({ mockRunExecFile = false } = {}) {
|
|
25
|
+
const runExecFile = vi.fn();
|
|
26
|
+
|
|
27
|
+
// Use the actual fs module object directly for spying
|
|
28
|
+
const fsProxy = require('fs');
|
|
29
|
+
|
|
30
|
+
// Sentinel passed as `bump` by tests that want the real Bumper
|
|
31
|
+
// implementation to run (against the mocked git client).
|
|
32
|
+
const actualConventionalRecommendedBump = Symbol(
|
|
33
|
+
'actual-conventional-recommended-bump',
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// Shared mock data, updated by the mock* helpers below.
|
|
37
|
+
const state = {
|
|
38
|
+
tags: [], // string[] | Error - git tags yielded by the git client
|
|
39
|
+
commits: [], // string[] - raw commit bodies yielded by the git client
|
|
40
|
+
changelog: [], // Array<string | Error | fn | undefined> - changelog chunks
|
|
41
|
+
bump: undefined, // releaseType | Error | fn | actualConventionalRecommendedBump
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Module factory for '@conventional-changelog/git-client': the real
|
|
46
|
+
* ConventionalGitClient with the raw git interactions (log for commits and
|
|
47
|
+
* tags) replaced by the mock state. Parsing and semver filtering still use
|
|
48
|
+
* the real implementation.
|
|
49
|
+
*/
|
|
50
|
+
const gitClientModule = (actual) => {
|
|
51
|
+
class MockConventionalGitClient extends actual.ConventionalGitClient {
|
|
52
|
+
async *getRawCommits() {
|
|
53
|
+
for (const commit of state.commits || []) {
|
|
54
|
+
yield commit;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async *getTags() {
|
|
59
|
+
if (state.tags instanceof Error) throw state.tags;
|
|
60
|
+
for (const tag of state.tags || []) {
|
|
61
|
+
yield tag;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return { ...actual, ConventionalGitClient: MockConventionalGitClient };
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Module factory for 'conventional-changelog': a chainable stub whose
|
|
71
|
+
* write() generator yields the queued changelog chunks.
|
|
72
|
+
*/
|
|
73
|
+
const conventionalChangelogModule = () => {
|
|
74
|
+
class MockConventionalChangelog {
|
|
75
|
+
readPackage() {
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
package() {
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
loadPreset(preset) {
|
|
84
|
+
this.presetParams = preset;
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
config(config) {
|
|
89
|
+
this.configParams = config;
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
tags(params) {
|
|
94
|
+
this.tagsParams = params;
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
options(options) {
|
|
99
|
+
this.optionsParams = options;
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
context(context) {
|
|
104
|
+
this.contextParams = context;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
commits(params, parserOptions) {
|
|
109
|
+
this.commitsParams = params;
|
|
110
|
+
this.parserOptions = parserOptions;
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
writer(options) {
|
|
115
|
+
this.writerOptions = options;
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async *write() {
|
|
120
|
+
// Mirrors the behaviour of the old stream mock: consume queued
|
|
121
|
+
// entries until an empty entry ends the stream; an Error entry
|
|
122
|
+
// fails it; a function entry is called with the params captured
|
|
123
|
+
// from the chained setup calls.
|
|
124
|
+
for (;;) {
|
|
125
|
+
const next = state.changelog.shift();
|
|
126
|
+
if (next instanceof Error) throw next;
|
|
127
|
+
const chunk =
|
|
128
|
+
typeof next === 'function'
|
|
129
|
+
? next({
|
|
130
|
+
preset: this.presetParams,
|
|
131
|
+
tags: this.tagsParams,
|
|
132
|
+
options: this.optionsParams,
|
|
133
|
+
context: this.contextParams,
|
|
134
|
+
commits: this.commitsParams,
|
|
135
|
+
parser: this.parserOptions,
|
|
136
|
+
writer: this.writerOptions,
|
|
137
|
+
})
|
|
138
|
+
: next;
|
|
139
|
+
if (!chunk) return;
|
|
140
|
+
yield chunk;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return { ConventionalChangelog: MockConventionalChangelog };
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Module factory for 'conventional-recommended-bump': a chainable Bumper
|
|
150
|
+
* stub driven by the `bump` mock state. When `bump` is the
|
|
151
|
+
* `actualConventionalRecommendedBump` sentinel, the real Bumper runs with
|
|
152
|
+
* the mocked git client, so real presets, parsing and whatBump logic are
|
|
153
|
+
* exercised against the mock commits/tags.
|
|
154
|
+
*/
|
|
155
|
+
const conventionalRecommendedBumpModule = (actual, gitClientMod) => {
|
|
156
|
+
class MockBumper {
|
|
157
|
+
loadPreset(preset) {
|
|
158
|
+
this.presetParams = preset;
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
config(config) {
|
|
163
|
+
this.configParams = config;
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
options(options) {
|
|
168
|
+
this.optionsParams = options;
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
tag(params) {
|
|
173
|
+
this.tagParams = params;
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
commits(params, parserOptions) {
|
|
178
|
+
this.commitsParams = params;
|
|
179
|
+
this.parserOptions = parserOptions;
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async bump(whatBump) {
|
|
184
|
+
const bump = state.bump;
|
|
185
|
+
|
|
186
|
+
if (bump === actualConventionalRecommendedBump) {
|
|
187
|
+
const bumper = new actual.Bumper(
|
|
188
|
+
new gitClientMod.ConventionalGitClient(process.cwd()),
|
|
189
|
+
);
|
|
190
|
+
if (this.presetParams) bumper.loadPreset(this.presetParams);
|
|
191
|
+
if (this.tagParams) bumper.tag(this.tagParams);
|
|
192
|
+
if (this.commitsParams || this.parserOptions) {
|
|
193
|
+
bumper.commits(this.commitsParams || {}, this.parserOptions);
|
|
194
|
+
}
|
|
195
|
+
if (this.optionsParams) bumper.options(this.optionsParams);
|
|
196
|
+
return bumper.bump(whatBump);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (bump instanceof Error) throw bump;
|
|
200
|
+
|
|
201
|
+
if (typeof bump === 'function') {
|
|
202
|
+
// Legacy callback-style test hook: (opt, parserOpts, cb)
|
|
203
|
+
return new Promise((resolve, reject) => {
|
|
204
|
+
bump(
|
|
205
|
+
{
|
|
206
|
+
preset: this.presetParams,
|
|
207
|
+
tag: this.tagParams,
|
|
208
|
+
commits: this.commitsParams,
|
|
209
|
+
},
|
|
210
|
+
this.parserOptions,
|
|
211
|
+
(err, release) => {
|
|
212
|
+
if (err) reject(err);
|
|
213
|
+
else resolve({ commits: [], ...release });
|
|
214
|
+
},
|
|
215
|
+
);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (bump) {
|
|
220
|
+
return { releaseType: bump, commits: [] };
|
|
221
|
+
}
|
|
222
|
+
return { commits: [] };
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return { ...actual, Bumper: MockBumper };
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const mockGitSemverTags = ({ tags = [] }) => {
|
|
230
|
+
state.tags = tags;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const mockGitRawCommits = ({ commits = [] }) => {
|
|
234
|
+
state.commits = commits;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const mockConventionalChangelog = ({ changelog }) => {
|
|
238
|
+
state.changelog = Array.isArray(changelog) ? changelog : [changelog];
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const mockRecommendedBump = ({ bump }) => {
|
|
242
|
+
state.bump = bump;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
return {
|
|
246
|
+
fsProxy,
|
|
247
|
+
runExecFile,
|
|
248
|
+
mockRunExecFile,
|
|
249
|
+
actualConventionalRecommendedBump,
|
|
250
|
+
gitClientModule,
|
|
251
|
+
conventionalChangelogModule,
|
|
252
|
+
conventionalRecommendedBumpModule,
|
|
253
|
+
mockGitSemverTags,
|
|
254
|
+
mockGitRawCommits,
|
|
255
|
+
mockConventionalChangelog,
|
|
256
|
+
mockRecommendedBump,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
module.exports = { setup };
|
|
@@ -1,26 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
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
|
+
);
|
|
7
15
|
|
|
8
16
|
// Jest swallows most standard console logs not explicitly defined into a custom logger
|
|
9
17
|
// see: https://stackoverflow.com/questions/51555568/remove-logging-the-origin-line-in-jest
|
|
10
|
-
const consoleWarnSpy =
|
|
18
|
+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
11
19
|
|
|
12
|
-
const consoleInfoSpy =
|
|
20
|
+
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
|
|
13
21
|
|
|
14
|
-
const consoleErrorSpy =
|
|
15
|
-
.spyOn(global.console, 'error')
|
|
16
|
-
.mockImplementation();
|
|
22
|
+
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
17
23
|
|
|
18
|
-
function exec(opt = '') {
|
|
24
|
+
async function exec(opt = '') {
|
|
25
|
+
vi.resetModules();
|
|
26
|
+
const { default: cli } = await import('../command');
|
|
19
27
|
if (typeof opt === 'string') {
|
|
20
|
-
const cli = require('../command');
|
|
21
28
|
opt = cli.parse(`commit-and-tag-version ${opt}`);
|
|
22
29
|
}
|
|
23
|
-
|
|
30
|
+
const { default: standardVersion } = await import('../index');
|
|
31
|
+
return standardVersion(opt);
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
function writePackageJson(version, option) {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import shell from 'shelljs';
|
|
2
|
+
import fs from 'fs';
|
|
3
3
|
|
|
4
|
-
function exec(opt) {
|
|
5
|
-
|
|
4
|
+
async function exec(opt) {
|
|
5
|
+
vi.resetModules();
|
|
6
|
+
const { default: cli } = await import('../command');
|
|
6
7
|
opt = cli.parse(`commit-and-tag-version ${opt} --silent`);
|
|
7
8
|
opt.skip = { commit: true, tag: true };
|
|
8
|
-
|
|
9
|
+
const { default: standardVersion } = await import('../index');
|
|
10
|
+
return standardVersion(opt);
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
function setupTempGitRepo() {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js require hook that applies Istanbul instrumentation to source files
|
|
3
|
+
* loaded via CJS require() chains.
|
|
4
|
+
*
|
|
5
|
+
* In Vitest with pool:'forks', files directly imported by tests go through
|
|
6
|
+
* Vite's transform pipeline (where @vitest/coverage-istanbul instruments them).
|
|
7
|
+
* But files loaded via CJS require() inside source code bypass Vite entirely
|
|
8
|
+
* and go through Node's native Module._load. This hook uses pirates to
|
|
9
|
+
* intercept those loads and apply Istanbul instrumentation, writing to the
|
|
10
|
+
* same __VITEST_COVERAGE__ global that the coverage provider reads.
|
|
11
|
+
*
|
|
12
|
+
* Preloaded via execArgv: ['--require', ...] in vitest.config.js.
|
|
13
|
+
*/
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
const path = require('path');
|
|
17
|
+
const { createInstrumenter } = require('istanbul-lib-instrument');
|
|
18
|
+
const { addHook } = require('pirates');
|
|
19
|
+
|
|
20
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
21
|
+
|
|
22
|
+
const instrumenter = createInstrumenter({
|
|
23
|
+
esModules: false,
|
|
24
|
+
compact: false,
|
|
25
|
+
produceSourceMap: false,
|
|
26
|
+
coverageVariable: '__VITEST_COVERAGE__',
|
|
27
|
+
coverageGlobalScope: 'globalThis',
|
|
28
|
+
coverageGlobalScopeFunc: false,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
addHook(
|
|
32
|
+
(code, filename) => {
|
|
33
|
+
return instrumenter.instrumentSync(code, filename);
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
exts: ['.js'],
|
|
37
|
+
matcher: (filename) => {
|
|
38
|
+
// Only instrument project source files, not node_modules or test files
|
|
39
|
+
return (
|
|
40
|
+
filename.startsWith(ROOT) &&
|
|
41
|
+
!filename.includes('node_modules') &&
|
|
42
|
+
!filename.includes(path.sep + 'test' + path.sep) &&
|
|
43
|
+
!filename.includes(path.sep + 'bin' + path.sep)
|
|
44
|
+
);
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
);
|
package/test/utils.spec.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { promises as fsp } from 'fs';
|
|
2
|
+
import { detectPMByLockFile } from '../lib/detect-package-manager';
|
|
2
3
|
|
|
3
4
|
let mockFs;
|
|
4
5
|
|
|
@@ -6,7 +7,7 @@ const setLockFile = (lockFile) => {
|
|
|
6
7
|
if (mockFs) {
|
|
7
8
|
mockFs.mockRestore();
|
|
8
9
|
}
|
|
9
|
-
mockFs =
|
|
10
|
+
mockFs = vi.spyOn(fsp, 'access').mockImplementation(async (path) => {
|
|
10
11
|
if (lockFile && path.endsWith(lockFile)) {
|
|
11
12
|
return Promise.resolve();
|
|
12
13
|
}
|
|
@@ -16,8 +17,6 @@ const setLockFile = (lockFile) => {
|
|
|
16
17
|
|
|
17
18
|
describe('utils', function () {
|
|
18
19
|
it('detectPMByLockFile should work', async function () {
|
|
19
|
-
const { detectPMByLockFile } = require('../lib/detect-package-manager');
|
|
20
|
-
|
|
21
20
|
let pm = await detectPMByLockFile();
|
|
22
21
|
expect(pm).toEqual('npm');
|
|
23
22
|
|
package/vitest.config.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
globals: true,
|
|
6
|
+
testTimeout: 30000,
|
|
7
|
+
include: ['test/**/*.spec.js', 'test/**/*.integration-test.js'],
|
|
8
|
+
coverage: {
|
|
9
|
+
provider: 'istanbul',
|
|
10
|
+
include: ['**/*.{js,jsx,ts}'],
|
|
11
|
+
exclude: [
|
|
12
|
+
'node_modules/**',
|
|
13
|
+
'tmp/**',
|
|
14
|
+
'test/**',
|
|
15
|
+
'coverage/**',
|
|
16
|
+
'bin/**',
|
|
17
|
+
],
|
|
18
|
+
reporter: ['lcov', 'text'],
|
|
19
|
+
},
|
|
20
|
+
pool: 'forks',
|
|
21
|
+
execArgv: ['--require', './test/setup-coverage.js'],
|
|
22
|
+
sequence: {
|
|
23
|
+
concurrent: false,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
});
|
package/jest.config.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const config = {
|
|
2
|
-
collectCoverage: true,
|
|
3
|
-
collectCoverageFrom: [
|
|
4
|
-
'**/*.{js,jsx,ts}',
|
|
5
|
-
'!**/node_modules/**',
|
|
6
|
-
'!**/tmp/**',
|
|
7
|
-
'!**/test/**',
|
|
8
|
-
'!**/coverage/**',
|
|
9
|
-
'!**/bin/**',
|
|
10
|
-
],
|
|
11
|
-
coverageReporters: ['lcov', 'text'],
|
|
12
|
-
projects: [
|
|
13
|
-
{
|
|
14
|
-
displayName: 'Unit Test',
|
|
15
|
-
testMatch: ['**/test/*.spec.js'],
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
displayName: 'Integration Test',
|
|
19
|
-
runner: 'jest-serial-runner',
|
|
20
|
-
testMatch: ['**/test/*.integration-test.js'],
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
silent: true, // Suppresses runtime console logs during test runs
|
|
24
|
-
testTimeout: 30000,
|
|
25
|
-
verbose: true, // Prints test describe/it names into console during test runs
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
module.exports = config;
|
package/test/mocks/jest-mocks.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const gitSemverTags = require('git-semver-tags');
|
|
2
|
-
const conventionalChangelog = require('conventional-changelog');
|
|
3
|
-
const conventionalRecommendedBump = require('conventional-recommended-bump');
|
|
4
|
-
const gitRawCommits = require('git-raw-commits');
|
|
5
|
-
|
|
6
|
-
const { Readable } = require('stream');
|
|
7
|
-
|
|
8
|
-
jest.mock('conventional-changelog');
|
|
9
|
-
jest.mock('conventional-recommended-bump');
|
|
10
|
-
jest.mock('git-semver-tags');
|
|
11
|
-
jest.mock('git-raw-commits');
|
|
12
|
-
|
|
13
|
-
const mockGitSemverTags = ({ tags = [] }) => {
|
|
14
|
-
gitSemverTags.mockImplementation((opts, cb) => {
|
|
15
|
-
if (tags instanceof Error) cb(tags);
|
|
16
|
-
else cb(null, tags);
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @param { { commits: string[] } }
|
|
22
|
-
* a commit should look like `<rawBody>\n\n-hash-\n<hash>\n`
|
|
23
|
-
*/
|
|
24
|
-
const mockGitRawCommits = ({ commits = [] }) => {
|
|
25
|
-
gitRawCommits.mockImplementation(() => {
|
|
26
|
-
return new Readable({
|
|
27
|
-
read() {
|
|
28
|
-
commits.forEach((c) => this.push(c));
|
|
29
|
-
this.push(null);
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const mockConventionalChangelog = ({ changelog }) => {
|
|
36
|
-
conventionalChangelog.mockImplementation(
|
|
37
|
-
(opt) =>
|
|
38
|
-
new Readable({
|
|
39
|
-
read(_size) {
|
|
40
|
-
const next = changelog.shift();
|
|
41
|
-
if (next instanceof Error) {
|
|
42
|
-
this.destroy(next);
|
|
43
|
-
} else if (typeof next === 'function') {
|
|
44
|
-
this.push(next(opt));
|
|
45
|
-
} else {
|
|
46
|
-
this.push(next ? Buffer.from(next, 'utf8') : null);
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
}),
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const mockRecommendedBump = ({ bump }) => {
|
|
54
|
-
conventionalRecommendedBump.mockImplementation((opt, parserOpts, cb) => {
|
|
55
|
-
if (typeof bump === 'function') bump(opt, parserOpts, cb);
|
|
56
|
-
else if (bump instanceof Error) cb(bump);
|
|
57
|
-
else cb(null, bump ? { releaseType: bump } : {});
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
module.exports = {
|
|
62
|
-
mockGitSemverTags,
|
|
63
|
-
mockGitRawCommits,
|
|
64
|
-
mockConventionalChangelog,
|
|
65
|
-
mockRecommendedBump,
|
|
66
|
-
};
|