commit-and-tag-version 11.3.0 → 12.1.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/.eslintrc +46 -3
- package/.gitattributes +2 -0
- package/.github/dependabot.yml +19 -0
- package/.github/workflows/ci.yaml +12 -5
- package/.github/workflows/release-please.yml +3 -3
- package/.prettierrc +3 -0
- package/CHANGELOG.md +19 -0
- package/README.md +7 -1
- package/bin/cli.js +6 -6
- package/command.js +43 -37
- package/defaults.js +12 -11
- package/index.js +44 -42
- package/jest.config.js +28 -0
- package/lib/checkpoint.js +19 -8
- package/lib/configuration.js +17 -17
- package/lib/detect-package-manager.js +20 -20
- package/lib/format-commit-message.js +3 -3
- package/lib/latest-semver-tag.js +13 -11
- package/lib/lifecycles/bump.js +136 -105
- package/lib/lifecycles/changelog.js +88 -48
- package/lib/lifecycles/commit.js +41 -42
- package/lib/lifecycles/tag.js +41 -31
- package/lib/preset-loader.js +12 -10
- package/lib/print-error.js +10 -7
- package/lib/run-exec.js +10 -10
- package/lib/run-execFile.js +10 -10
- package/lib/run-lifecycle-script.js +16 -11
- package/lib/stringify-package.js +10 -10
- package/lib/updaters/index.js +40 -33
- package/lib/updaters/types/csproj.js +9 -7
- package/lib/updaters/types/gradle.js +10 -8
- package/lib/updaters/types/json.js +14 -14
- package/lib/updaters/types/plain-text.js +4 -4
- package/lib/write-file.js +4 -4
- package/package.json +20 -25
- package/test/commit-message-config.integration-test.js +106 -0
- package/test/config-files.integration-test.js +114 -0
- package/test/config-keys.integration-test.js +83 -0
- package/test/core.spec.js +1594 -874
- package/test/git.integration-test.js +363 -0
- package/test/invalid-config.integration-test.js +73 -0
- package/test/mocks/jest-mocks.js +48 -0
- package/test/mocks/updater/customer-updater.js +5 -8
- package/test/mocks/updater/increment-updater.js +5 -5
- package/test/pre-commit-hook.integration-test.js +192 -0
- package/test/preset.integration-test.js +56 -0
- package/test/stringify-package.spec.js +18 -22
- package/test/utils.spec.js +26 -42
- package/renovate.json +0 -9
- package/test/config-files.spec.js +0 -176
- package/test/git.spec.js +0 -480
- package/test/preset.spec.js +0 -52
|
@@ -0,0 +1,363 @@
|
|
|
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 = '') {
|
|
14
|
+
if (typeof opt === 'string') {
|
|
15
|
+
const cli = require('../command');
|
|
16
|
+
opt = cli.parse(`commit-and-tag-version ${opt}`);
|
|
17
|
+
}
|
|
18
|
+
return require('../index')(opt);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function writePackageJson(version, option) {
|
|
22
|
+
const pkg = Object.assign({}, option, { version });
|
|
23
|
+
fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function getPackageVersion() {
|
|
27
|
+
return JSON.parse(fs.readFileSync('package.json', 'utf-8')).version;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Mock external conventional-changelog modules
|
|
32
|
+
*
|
|
33
|
+
* bump: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) }
|
|
34
|
+
* changelog?: string | Error | Array<string | Error | (opt) => string | null>
|
|
35
|
+
* tags?: string[] | Error
|
|
36
|
+
*/
|
|
37
|
+
function mock({ bump, changelog, tags }) {
|
|
38
|
+
if (bump === undefined) throw new Error('bump must be defined for mock()');
|
|
39
|
+
|
|
40
|
+
mockers.mockRecommendedBump({ bump });
|
|
41
|
+
|
|
42
|
+
if (!Array.isArray(changelog)) changelog = [changelog];
|
|
43
|
+
mockers.mockConventionalChangelog({ changelog });
|
|
44
|
+
|
|
45
|
+
mockers.mockGitSemverTags({ tags });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getLog(expectedLog, spy = consoleInfoSpy) {
|
|
49
|
+
const consoleInfoLogs = spy.mock.calls.map((args) => args[0]);
|
|
50
|
+
return consoleInfoLogs.find((log) => log.includes(expectedLog));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function verifyLogPrinted(expectedLog, spy = consoleInfoSpy) {
|
|
54
|
+
const logType = spy === consoleInfoSpy ? 'info' : 'error';
|
|
55
|
+
const desiredLog = getLog(expectedLog, spy);
|
|
56
|
+
if (desiredLog) {
|
|
57
|
+
expect(desiredLog).toMatch(expectedLog);
|
|
58
|
+
} else {
|
|
59
|
+
expect(`no ${logType} Log printed matching`).toMatch(expectedLog);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function verifyLogNotPrinted(expectedLog, spy = consoleInfoSpy) {
|
|
64
|
+
const desiredLog = getLog(expectedLog, spy);
|
|
65
|
+
expect(desiredLog).toBeUndefined();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function clearCapturedSpyCalls() {
|
|
69
|
+
consoleInfoSpy.mockClear();
|
|
70
|
+
consoleWarnSpy.mockClear();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function resetShell() {
|
|
74
|
+
shell.cd('../');
|
|
75
|
+
shell.rm('-rf', 'git-repo-temp');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function setupTempGitRepo() {
|
|
79
|
+
shell.rm('-rf', 'git-repo-temp');
|
|
80
|
+
shell.config.silent = true;
|
|
81
|
+
shell.mkdir('git-repo-temp');
|
|
82
|
+
shell.cd('git-repo-temp');
|
|
83
|
+
shell.exec('git init');
|
|
84
|
+
shell.exec('git config commit.gpgSign false');
|
|
85
|
+
shell.exec('git config core.autocrlf false');
|
|
86
|
+
shell.exec('git commit --allow-empty -m"root-commit"');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
describe('git', function () {
|
|
90
|
+
function setup() {
|
|
91
|
+
setupTempGitRepo();
|
|
92
|
+
writePackageJson('1.0.0');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function reset() {
|
|
96
|
+
resetShell();
|
|
97
|
+
|
|
98
|
+
clearCapturedSpyCalls();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
beforeEach(function () {
|
|
102
|
+
setup();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
afterEach(function () {
|
|
106
|
+
reset();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('tagPrefix', function () {
|
|
110
|
+
beforeEach(function () {
|
|
111
|
+
setup();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
afterEach(function () {
|
|
115
|
+
reset();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// TODO: Use unmocked git-semver-tags and stage a git environment
|
|
119
|
+
it('will add prefix onto tag based on version from package', async function () {
|
|
120
|
+
writePackageJson('1.2.0');
|
|
121
|
+
mock({ bump: 'minor', tags: ['p-v1.2.0'] });
|
|
122
|
+
await exec('--tag-prefix p-v');
|
|
123
|
+
expect(shell.exec('git tag').stdout).toMatch(/p-v1\.3\.0/);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('will add prefix onto tag via when gitTagFallback is true and no package [cli]', async function () {
|
|
127
|
+
shell.rm('package.json');
|
|
128
|
+
mock({
|
|
129
|
+
bump: 'minor',
|
|
130
|
+
tags: ['android/production/v1.2.0', 'android/production/v1.0.0'],
|
|
131
|
+
});
|
|
132
|
+
await exec('--tag-prefix android/production/v');
|
|
133
|
+
expect(shell.exec('git tag').stdout).toMatch(
|
|
134
|
+
/android\/production\/v1\.3\.0/,
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('will add prefix onto tag via when gitTagFallback is true and no package [options]', async function () {
|
|
139
|
+
mock({
|
|
140
|
+
bump: 'minor',
|
|
141
|
+
tags: ['android/production/v1.2.0', 'android/production/v1.0.0'],
|
|
142
|
+
});
|
|
143
|
+
await exec({ tagPrefix: 'android/production/v', packageFiles: [] });
|
|
144
|
+
expect(shell.exec('git tag').stdout).toMatch(
|
|
145
|
+
/android\/production\/v1\.3\.0/,
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('formats the commit and tag messages appropriately', async function () {
|
|
151
|
+
mock({ bump: 'minor', tags: ['v1.0.0'] });
|
|
152
|
+
await exec({});
|
|
153
|
+
// check last commit message
|
|
154
|
+
expect(shell.exec('git log --oneline -n1').stdout).toMatch(
|
|
155
|
+
/chore\(release\): 1\.1\.0/,
|
|
156
|
+
);
|
|
157
|
+
// check annotated tag message
|
|
158
|
+
expect(shell.exec('git tag -l -n1 v1.1.0').stdout).toMatch(
|
|
159
|
+
/chore\(release\): 1\.1\.0/,
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('formats the tag if --first-release is true', async function () {
|
|
164
|
+
writePackageJson('1.0.1');
|
|
165
|
+
mock({ bump: 'minor' });
|
|
166
|
+
await exec('--first-release');
|
|
167
|
+
expect(shell.exec('git tag').stdout).toMatch(/1\.0\.1/);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('commits all staged files', async function () {
|
|
171
|
+
fs.writeFileSync(
|
|
172
|
+
'CHANGELOG.md',
|
|
173
|
+
'legacy header format<a name="1.0.0">\n',
|
|
174
|
+
'utf-8',
|
|
175
|
+
);
|
|
176
|
+
fs.writeFileSync('STUFF.md', 'stuff\n', 'utf-8');
|
|
177
|
+
shell.exec('git add STUFF.md');
|
|
178
|
+
|
|
179
|
+
mock({ bump: 'patch', changelog: 'release 1.0.1\n', tags: ['v1.0.0'] });
|
|
180
|
+
await exec('--commit-all');
|
|
181
|
+
const status = shell.exec('git status --porcelain').stdout; // see http://unix.stackexchange.com/questions/155046/determine-if-git-working-directory-is-clean-from-a-script
|
|
182
|
+
expect(status).toEqual('');
|
|
183
|
+
expect(status).not.toMatch(/STUFF.md/);
|
|
184
|
+
|
|
185
|
+
const content = fs.readFileSync('CHANGELOG.md', 'utf-8');
|
|
186
|
+
expect(content).toMatch(/1\.0\.1/);
|
|
187
|
+
expect(content).not.toMatch(/legacy header format/);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('does not run git hooks if the --no-verify flag is passed', async function () {
|
|
191
|
+
fs.writeFileSync(
|
|
192
|
+
'.git/hooks/pre-commit',
|
|
193
|
+
'#!/bin/sh\necho "precommit ran"\nexit 1',
|
|
194
|
+
'utf-8',
|
|
195
|
+
);
|
|
196
|
+
fs.chmodSync('.git/hooks/pre-commit', '755');
|
|
197
|
+
|
|
198
|
+
mock({ bump: 'minor' });
|
|
199
|
+
await exec('--no-verify');
|
|
200
|
+
await exec('-n');
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('replaces tags if version not bumped', async function () {
|
|
204
|
+
mock({ bump: 'minor', tags: ['v1.0.0'] });
|
|
205
|
+
await exec({});
|
|
206
|
+
expect(shell.exec('git describe').stdout).toMatch(/v1\.1\.0/);
|
|
207
|
+
await exec('--tag-force --skip.bump');
|
|
208
|
+
expect(shell.exec('git describe').stdout).toMatch(/v1\.1\.0/);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('allows the commit phase to be skipped', async function () {
|
|
212
|
+
const changelogContent = 'legacy header format<a name="1.0.0">\n';
|
|
213
|
+
writePackageJson('1.0.0');
|
|
214
|
+
fs.writeFileSync('CHANGELOG.md', changelogContent, 'utf-8');
|
|
215
|
+
|
|
216
|
+
mock({ bump: 'minor', changelog: 'new feature\n' });
|
|
217
|
+
await exec('--skip.commit true');
|
|
218
|
+
expect(getPackageVersion()).toEqual('1.1.0');
|
|
219
|
+
const content = fs.readFileSync('CHANGELOG.md', 'utf-8');
|
|
220
|
+
expect(content).toMatch(/new feature/);
|
|
221
|
+
expect(shell.exec('git log --oneline -n1').stdout).toMatch(/root-commit/);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('dry-run skips all non-idempotent steps', async function () {
|
|
225
|
+
shell.exec('git tag -a v1.0.0 -m "my awesome first release"');
|
|
226
|
+
mock({
|
|
227
|
+
bump: 'minor',
|
|
228
|
+
changelog: '### Features\n',
|
|
229
|
+
tags: ['v1.0.0'],
|
|
230
|
+
});
|
|
231
|
+
await exec('--dry-run');
|
|
232
|
+
verifyLogPrinted('### Features');
|
|
233
|
+
|
|
234
|
+
expect(shell.exec('git log --oneline -n1').stdout).toMatch(/root-commit/);
|
|
235
|
+
expect(shell.exec('git tag').stdout).toMatch(/1\.0\.0/);
|
|
236
|
+
expect(getPackageVersion()).toEqual('1.0.0');
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('works fine without specifying a tag id when prereleasing', async function () {
|
|
240
|
+
writePackageJson('1.0.0');
|
|
241
|
+
fs.writeFileSync(
|
|
242
|
+
'CHANGELOG.md',
|
|
243
|
+
'legacy header format<a name="1.0.0">\n',
|
|
244
|
+
'utf-8',
|
|
245
|
+
);
|
|
246
|
+
mock({ bump: 'minor' });
|
|
247
|
+
await exec('--prerelease');
|
|
248
|
+
expect(getPackageVersion()).toEqual('1.1.0-0');
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
describe('gitTagFallback', function () {
|
|
252
|
+
beforeEach(function () {
|
|
253
|
+
setup();
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
afterEach(function () {
|
|
257
|
+
reset();
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('defaults to 1.0.0 if no tags in git history', async function () {
|
|
261
|
+
shell.rm('package.json');
|
|
262
|
+
mock({ bump: 'minor' });
|
|
263
|
+
await exec({});
|
|
264
|
+
const output = shell.exec('git tag');
|
|
265
|
+
expect(output.stdout).toContain('v1.1.0');
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('bases version on greatest version tag, if tags are found', async function () {
|
|
269
|
+
shell.rm('package.json');
|
|
270
|
+
mock({ bump: 'minor', tags: ['v3.9.0', 'v5.0.0', 'v3.0.0'] });
|
|
271
|
+
await exec({});
|
|
272
|
+
const output = shell.exec('git tag');
|
|
273
|
+
expect(output.stdout).toContain('v5.1.0');
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe('Run ... to publish', function () {
|
|
278
|
+
beforeEach(function () {
|
|
279
|
+
setup();
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
afterEach(function () {
|
|
283
|
+
reset();
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('does normally display `npm publish`', async function () {
|
|
287
|
+
mock({ bump: 'patch' });
|
|
288
|
+
await exec('');
|
|
289
|
+
verifyLogPrinted('npm publish');
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('can display publish hints with custom npm client name', async function () {
|
|
293
|
+
mock({ bump: 'patch' });
|
|
294
|
+
await exec('--npmPublishHint "yarn publish"');
|
|
295
|
+
verifyLogPrinted('yarn publish');
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('does not display `npm publish` if the package is private', async function () {
|
|
299
|
+
writePackageJson('1.0.0', { private: true });
|
|
300
|
+
mock({ bump: 'patch' });
|
|
301
|
+
await exec('');
|
|
302
|
+
verifyLogNotPrinted('npm publish');
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it('does not display `npm publish` if there is no package.json', async function () {
|
|
306
|
+
shell.rm('package.json');
|
|
307
|
+
mock({ bump: 'patch' });
|
|
308
|
+
await exec('');
|
|
309
|
+
verifyLogNotPrinted('npm publish');
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('does not display `all staged files` without the --commit-all flag', async function () {
|
|
313
|
+
mock({ bump: 'patch' });
|
|
314
|
+
await exec('');
|
|
315
|
+
verifyLogNotPrinted('all staged files');
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('does display `all staged files` if the --commit-all flag is passed', async function () {
|
|
319
|
+
mock({ bump: 'patch' });
|
|
320
|
+
await exec('--commit-all');
|
|
321
|
+
verifyLogPrinted('all staged files');
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('advises use of --tag prerelease for publishing to npm', async function () {
|
|
325
|
+
writePackageJson('1.0.0');
|
|
326
|
+
fs.writeFileSync(
|
|
327
|
+
'CHANGELOG.md',
|
|
328
|
+
'legacy header format<a name="1.0.0">\n',
|
|
329
|
+
'utf-8',
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
mock({ bump: 'patch' });
|
|
333
|
+
await exec('--prerelease');
|
|
334
|
+
verifyLogPrinted('--tag prerelease');
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it('advises use of --tag alpha for publishing to npm when tagging alpha', async function () {
|
|
338
|
+
writePackageJson('1.0.0');
|
|
339
|
+
fs.writeFileSync(
|
|
340
|
+
'CHANGELOG.md',
|
|
341
|
+
'legacy header format<a name="1.0.0">\n',
|
|
342
|
+
'utf-8',
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
mock({ bump: 'patch' });
|
|
346
|
+
await exec('--prerelease alpha');
|
|
347
|
+
verifyLogPrinted('--tag alpha');
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it('does not advise use of --tag prerelease for private modules', async function () {
|
|
351
|
+
writePackageJson('1.0.0', { private: true });
|
|
352
|
+
fs.writeFileSync(
|
|
353
|
+
'CHANGELOG.md',
|
|
354
|
+
'legacy header format<a name="1.0.0">\n',
|
|
355
|
+
'utf-8',
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
mock({ bump: 'minor' });
|
|
359
|
+
await exec('--prerelease');
|
|
360
|
+
verifyLogNotPrinted('--tag prerelease');
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
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');
|
|
10
|
+
const opt = cli.parse('commit-and-tag-version');
|
|
11
|
+
opt.skip = { commit: true, tag: true };
|
|
12
|
+
return require('../index')(opt);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Mock external conventional-changelog modules
|
|
17
|
+
*
|
|
18
|
+
* Mocks should be unregistered in test cleanup by calling unmock()
|
|
19
|
+
*
|
|
20
|
+
* bump?: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) }
|
|
21
|
+
* changelog?: string | Error | Array<string | Error | (opt) => string | null>
|
|
22
|
+
* tags?: string[] | Error
|
|
23
|
+
*/
|
|
24
|
+
function mock({ bump, changelog, tags } = {}) {
|
|
25
|
+
mockers.mockRecommendedBump({ bump });
|
|
26
|
+
|
|
27
|
+
if (!Array.isArray(changelog)) changelog = [changelog];
|
|
28
|
+
|
|
29
|
+
mockers.mockConventionalChangelog({ changelog });
|
|
30
|
+
|
|
31
|
+
mockers.mockGitSemverTags({ tags });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function setupTestDirectory() {
|
|
35
|
+
shell.rm('-rf', 'invalid-config-temp');
|
|
36
|
+
shell.config.silent = true;
|
|
37
|
+
shell.mkdir('invalid-config-temp');
|
|
38
|
+
shell.cd('invalid-config-temp');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function resetShell() {
|
|
42
|
+
shell.cd('../');
|
|
43
|
+
shell.rm('-rf', 'invalid-config-temp');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* This test is very sensitive to the setup of "tmp" directories and must currently be run in it's own "Jest" runner instance.
|
|
48
|
+
* By default Jest spawns a Runner per-test file even if running serially each test in a File
|
|
49
|
+
* When we refactored from Mocha -> Jest, if this test was run as part of a larger test-suite, it would always fail, due to presence of a valid .verisonrc
|
|
50
|
+
* somewhere in the "real" or "tmp" filesystem, despite the shell code seemingly setting up and tearing down correctly
|
|
51
|
+
*/
|
|
52
|
+
describe('invalid .versionrc', function () {
|
|
53
|
+
beforeEach(function () {
|
|
54
|
+
setupTestDirectory();
|
|
55
|
+
|
|
56
|
+
fs.writeFileSync(
|
|
57
|
+
'package.json',
|
|
58
|
+
JSON.stringify({ version: '1.0.0' }),
|
|
59
|
+
'utf-8',
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterEach(function () {
|
|
64
|
+
resetShell();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('throws an error when a non-object is returned from .versionrc.js', async function () {
|
|
68
|
+
mock({ bump: 'minor' });
|
|
69
|
+
fs.writeFileSync('.versionrc.js', 'module.exports = 3', 'utf-8');
|
|
70
|
+
|
|
71
|
+
expect(exec).toThrow(/Invalid configuration/);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const gitSemverTags = require('git-semver-tags');
|
|
2
|
+
const conventionalChangelog = require('conventional-changelog');
|
|
3
|
+
const conventionalRecommendedBump = require('conventional-recommended-bump');
|
|
4
|
+
|
|
5
|
+
const { Readable } = require('stream');
|
|
6
|
+
|
|
7
|
+
jest.mock('conventional-changelog');
|
|
8
|
+
jest.mock('conventional-recommended-bump');
|
|
9
|
+
jest.mock('git-semver-tags');
|
|
10
|
+
|
|
11
|
+
const mockGitSemverTags = ({ tags = [] }) => {
|
|
12
|
+
gitSemverTags.mockImplementation((opts, cb) => {
|
|
13
|
+
if (tags instanceof Error) cb(tags);
|
|
14
|
+
else cb(null, tags);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const mockConventionalChangelog = ({ changelog }) => {
|
|
19
|
+
conventionalChangelog.mockImplementation(
|
|
20
|
+
(opt) =>
|
|
21
|
+
new Readable({
|
|
22
|
+
read(_size) {
|
|
23
|
+
const next = changelog.shift();
|
|
24
|
+
if (next instanceof Error) {
|
|
25
|
+
this.destroy(next);
|
|
26
|
+
} else if (typeof next === 'function') {
|
|
27
|
+
this.push(next(opt));
|
|
28
|
+
} else {
|
|
29
|
+
this.push(next ? Buffer.from(next, 'utf8') : null);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const mockRecommendedBump = ({ bump }) => {
|
|
37
|
+
conventionalRecommendedBump.mockImplementation((opt, parserOpts, cb) => {
|
|
38
|
+
if (typeof bump === 'function') bump(opt, parserOpts, cb);
|
|
39
|
+
else if (bump instanceof Error) cb(bump);
|
|
40
|
+
else cb(null, bump ? { releaseType: bump } : {});
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
module.exports = {
|
|
45
|
+
mockGitSemverTags,
|
|
46
|
+
mockConventionalChangelog,
|
|
47
|
+
mockRecommendedBump,
|
|
48
|
+
};
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
const REPLACER = /version: "(.*)"
|
|
1
|
+
const REPLACER = /version: "(.*)"/;
|
|
2
2
|
|
|
3
3
|
module.exports.readVersion = function (contents) {
|
|
4
|
-
return REPLACER.exec(contents)[1]
|
|
5
|
-
}
|
|
4
|
+
return REPLACER.exec(contents)[1];
|
|
5
|
+
};
|
|
6
6
|
|
|
7
7
|
module.exports.writeVersion = function (contents, version) {
|
|
8
|
-
return contents.replace(
|
|
9
|
-
|
|
10
|
-
`version: "${version}"`
|
|
11
|
-
)
|
|
12
|
-
}
|
|
8
|
+
return contents.replace(REPLACER.exec(contents)[0], `version: "${version}"`);
|
|
9
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module.exports.readVersion = function (contents) {
|
|
2
|
-
return Number.parseInt(contents)
|
|
3
|
-
}
|
|
2
|
+
return Number.parseInt(contents);
|
|
3
|
+
};
|
|
4
4
|
|
|
5
|
-
module.exports.writeVersion = function (contents
|
|
6
|
-
return this.readVersion(contents) + 1
|
|
7
|
-
}
|
|
5
|
+
module.exports.writeVersion = function (contents) {
|
|
6
|
+
return this.readVersion(contents) + 1;
|
|
7
|
+
};
|