commit-and-tag-version 12.0.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 +43 -8
- package/.gitattributes +2 -0
- package/.github/workflows/ci.yaml +10 -3
- package/.prettierrc +3 -0
- package/CHANGELOG.md +7 -0
- package/README.md +4 -0
- 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 +70 -51
- 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 +14 -21
- 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 +1369 -704
- 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 +25 -41
- package/test/config-files.spec.js +0 -176
- package/test/git.spec.js +0 -480
- package/test/preset.spec.js +0 -52
package/test/core.spec.js
CHANGED
|
@@ -1,1086 +1,1751 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const shell = require('shelljs');
|
|
4
|
+
const stripAnsi = require('strip-ansi');
|
|
5
|
+
const fs = require('fs');
|
|
4
6
|
|
|
5
|
-
const
|
|
6
|
-
const fs = require('fs')
|
|
7
|
-
const { resolve } = require('path')
|
|
8
|
-
const { Readable } = require('stream')
|
|
9
|
-
const mockFS = require('mock-fs')
|
|
10
|
-
const mockery = require('mockery')
|
|
11
|
-
const stdMocks = require('std-mocks')
|
|
12
|
-
const stripAnsi = require('strip-ansi')
|
|
7
|
+
const mockers = require('./mocks/jest-mocks');
|
|
13
8
|
|
|
14
|
-
const
|
|
15
|
-
const formatCommitMessage = require('../lib/format-commit-message')
|
|
9
|
+
const runExecFile = require('../lib/run-execFile');
|
|
16
10
|
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const expect = chai.expect
|
|
20
|
-
chai.use(require('chai-as-promised'))
|
|
11
|
+
const cli = require('../command');
|
|
12
|
+
const formatCommitMessage = require('../lib/format-commit-message');
|
|
21
13
|
|
|
22
14
|
// set by mock()
|
|
23
|
-
let standardVersion
|
|
15
|
+
let standardVersion;
|
|
16
|
+
let readFileSyncSpy;
|
|
17
|
+
let lstatSyncSpy;
|
|
24
18
|
|
|
25
|
-
|
|
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');
|
|
27
|
+
|
|
28
|
+
const { readFileSync: readFileSyncActual, lstatSync: lstatSyncActual } = fs;
|
|
29
|
+
|
|
30
|
+
function exec(opt = '', git) {
|
|
26
31
|
if (typeof opt === 'string') {
|
|
27
|
-
opt = cli.parse(`commit-and-tag-version ${opt}`)
|
|
32
|
+
opt = cli.parse(`commit-and-tag-version ${opt}`);
|
|
28
33
|
}
|
|
29
|
-
if (!git) opt.skip = Object.assign({}, opt.skip, { commit: true, tag: true })
|
|
30
|
-
return standardVersion(opt)
|
|
34
|
+
if (!git) opt.skip = Object.assign({}, opt.skip, { commit: true, tag: true });
|
|
35
|
+
return standardVersion(opt);
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
function
|
|
34
|
-
return
|
|
38
|
+
function attemptingToReadPackageJson(path) {
|
|
39
|
+
return path.includes('package.json') || path.includes('package-lock.json');
|
|
35
40
|
}
|
|
36
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @param fs - reference to 'fs' - needs to be defined in the root test class so that mocking works correctly
|
|
44
|
+
* @param readFileSyncActual - actual implementation of fs.readFileSync - reference should be defined as a variable in root test class so we can unset spy after
|
|
45
|
+
* @param existingChangelog ?: string - Existing CHANGELOG.md content
|
|
46
|
+
* @param testFiles ?: object[] - with Path and Value fields, for mocking readFileSynch on packageFiles such as package.json, bower.json, manifest.json
|
|
47
|
+
* @param realTestFiles ?: object[] - with Filename (e.g. mix.exs) and Path to real file in a directory
|
|
48
|
+
* @return Jest spy on readFileSync
|
|
49
|
+
*/
|
|
50
|
+
const mockReadFilesFromDisk = ({
|
|
51
|
+
fs,
|
|
52
|
+
readFileSyncActual,
|
|
53
|
+
existingChangelog,
|
|
54
|
+
testFiles,
|
|
55
|
+
realTestFiles,
|
|
56
|
+
}) =>
|
|
57
|
+
jest.spyOn(fs, 'readFileSync').mockImplementation((path, opts) => {
|
|
58
|
+
if (path === 'CHANGELOG.md') {
|
|
59
|
+
if (existingChangelog) {
|
|
60
|
+
return existingChangelog;
|
|
61
|
+
}
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// If deliberately set to null when mocking, don't create a fake package.json
|
|
66
|
+
if (testFiles === null && attemptingToReadPackageJson(path)) {
|
|
67
|
+
return '{}';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (testFiles) {
|
|
71
|
+
const file = testFiles.find((otherFile) => {
|
|
72
|
+
return path.includes(otherFile.path);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (file) {
|
|
76
|
+
if (file.value instanceof String || typeof file.value === 'string') {
|
|
77
|
+
return file.value;
|
|
78
|
+
}
|
|
79
|
+
return JSON.stringify(file.value);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// For scenarios where we have defined testFiles such as bower.json
|
|
83
|
+
// Do not create a fake package.json file
|
|
84
|
+
if (attemptingToReadPackageJson(path)) {
|
|
85
|
+
return '{}';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// If no package files defined and not explicitly set to null, create a fake package json
|
|
90
|
+
// otherwise fs will read the real package.json in the root of this project!
|
|
91
|
+
if (attemptingToReadPackageJson(path)) {
|
|
92
|
+
return JSON.stringify({ version: '1.0.0' });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (realTestFiles) {
|
|
96
|
+
const testFile = realTestFiles.find((testFile) => {
|
|
97
|
+
return path.includes(testFile.filename);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (testFile) {
|
|
101
|
+
return readFileSyncActual(testFile.path, opts);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return readFileSyncActual(path, opts);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @param fs - reference to 'fs' - needs to be defined in the root test class so that mocking works correctly
|
|
110
|
+
* @param lstatSyncActual - actual implementation of fs.lstatSync
|
|
111
|
+
* @param testFiles ?: object[] - with Path and Value fields, for mocking lstatSync on packageFiles such as package.json, bower.json, manifest.json
|
|
112
|
+
* @param realTestFiles ?: object[] - with Filename (e.g. mix.exs) and Path to real file in a directory
|
|
113
|
+
* @return Jest spy on lstatSync
|
|
114
|
+
*/
|
|
115
|
+
const mockFsLStat = ({ fs, lstatSyncActual, testFiles, realTestFiles }) =>
|
|
116
|
+
jest.spyOn(fs, 'lstatSync').mockImplementation((path) => {
|
|
117
|
+
if (testFiles) {
|
|
118
|
+
const file = testFiles.find((otherFile) => {
|
|
119
|
+
return path.includes(otherFile.path);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (file) {
|
|
123
|
+
return {
|
|
124
|
+
isFile: () => true,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (realTestFiles) {
|
|
130
|
+
const file = realTestFiles.find((otherFile) => {
|
|
131
|
+
return path.includes(otherFile.filename);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
if (file) {
|
|
135
|
+
return {
|
|
136
|
+
isFile: () => true,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return lstatSyncActual(path);
|
|
142
|
+
});
|
|
143
|
+
|
|
37
144
|
/**
|
|
38
145
|
* Mock external conventional-changelog modules
|
|
39
146
|
*
|
|
40
147
|
* Mocks should be unregistered in test cleanup by calling unmock()
|
|
41
148
|
*
|
|
42
149
|
* bump?: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) }
|
|
43
|
-
* changelog?: string | Error | Array<string | Error | (opt) => string | null>
|
|
150
|
+
* changelog?: string | Error | Array<string | Error | (opt) => string | null> - Changelog to be "generated" by conventional-changelog when reading commit history
|
|
44
151
|
* execFile?: ({ dryRun, silent }, cmd, cmdArgs) => Promise<string>
|
|
45
|
-
* fs?: { [string]: string | Buffer | any }
|
|
46
|
-
* pkg?: { [string]: any }
|
|
47
152
|
* tags?: string[] | Error
|
|
153
|
+
* existingChangelog?: string - Existing CHANGELOG.md content
|
|
154
|
+
* testFiles?: object[] - with Path and Value fields, for mocking readFileSynch on packageFiles such as package.json, bower.json, manifest.json
|
|
155
|
+
* realTestFiles?: object[] - with Filename (e.g. mix.exs) and Path to real file in test directory
|
|
48
156
|
*/
|
|
49
|
-
function mock
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.push(next(opt))
|
|
69
|
-
} else {
|
|
70
|
-
this.push(next ? Buffer.from(next, 'utf8') : null)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
mockery.registerMock('git-semver-tags', function (cb) {
|
|
77
|
-
if (tags instanceof Error) cb(tags)
|
|
78
|
-
else cb(null, tags | [])
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
if (typeof execFile === 'function') {
|
|
82
|
-
// called from commit & tag lifecycle methods
|
|
83
|
-
mockery.registerMock('../run-execFile', execFile)
|
|
84
|
-
}
|
|
157
|
+
function mock({
|
|
158
|
+
bump,
|
|
159
|
+
changelog,
|
|
160
|
+
tags,
|
|
161
|
+
existingChangelog,
|
|
162
|
+
testFiles,
|
|
163
|
+
realTestFiles,
|
|
164
|
+
} = {}) {
|
|
165
|
+
mockers.mockRecommendedBump({ bump });
|
|
166
|
+
|
|
167
|
+
if (!Array.isArray(changelog)) changelog = [changelog];
|
|
168
|
+
|
|
169
|
+
mockers.mockConventionalChangelog({
|
|
170
|
+
changelog,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
mockers.mockGitSemverTags({
|
|
174
|
+
tags,
|
|
175
|
+
});
|
|
85
176
|
|
|
86
177
|
// needs to be set after mockery, but before mock-fs
|
|
87
|
-
standardVersion = require('../index')
|
|
178
|
+
standardVersion = require('../index');
|
|
179
|
+
|
|
180
|
+
// For fake and injected test files pretend they exist at root level when Fs queries lstat
|
|
181
|
+
// Package.json works without this as it'll check the one in this actual repo...
|
|
182
|
+
lstatSyncSpy = mockFsLStat({
|
|
183
|
+
fs,
|
|
184
|
+
lstatSyncActual,
|
|
185
|
+
testFiles,
|
|
186
|
+
realTestFiles,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
readFileSyncSpy = mockReadFilesFromDisk({
|
|
190
|
+
fs,
|
|
191
|
+
readFileSyncActual,
|
|
192
|
+
existingChangelog,
|
|
193
|
+
testFiles,
|
|
194
|
+
realTestFiles,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Spies on writeFileSync to capture calls and ensure we don't actually try write anything to disc
|
|
198
|
+
writeFileSyncSpy = jest.spyOn(fs, 'writeFileSync').mockImplementation();
|
|
199
|
+
}
|
|
88
200
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
fs['package.json'] = JSON.stringify({ version: '1.0.0' })
|
|
94
|
-
}
|
|
95
|
-
mockFS(fs)
|
|
201
|
+
function clearCapturedSpyCalls() {
|
|
202
|
+
consoleInfoSpy.mockClear();
|
|
203
|
+
consoleErrorSpy.mockClear();
|
|
204
|
+
}
|
|
96
205
|
|
|
97
|
-
|
|
98
|
-
|
|
206
|
+
function restoreMocksToRealImplementation() {
|
|
207
|
+
readFileSyncSpy.mockRestore();
|
|
208
|
+
writeFileSyncSpy.mockRestore();
|
|
209
|
+
lstatSyncSpy.mockRestore();
|
|
99
210
|
}
|
|
100
211
|
|
|
101
|
-
function unmock
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
standardVersion = null
|
|
107
|
-
|
|
108
|
-
// push out prints from the Mocha reporter
|
|
109
|
-
const { stdout } = stdMocks.flush()
|
|
110
|
-
for (const str of stdout) {
|
|
111
|
-
if (str.startsWith(' ')) process.stdout.write(str)
|
|
112
|
-
}
|
|
212
|
+
function unmock() {
|
|
213
|
+
clearCapturedSpyCalls();
|
|
214
|
+
|
|
215
|
+
restoreMocksToRealImplementation();
|
|
216
|
+
|
|
217
|
+
standardVersion = null;
|
|
113
218
|
}
|
|
114
219
|
|
|
115
220
|
describe('format-commit-message', function () {
|
|
116
221
|
it('works for no {{currentTag}}', function () {
|
|
117
|
-
formatCommitMessage('chore(release): 1.0.0', '1.0.0').
|
|
118
|
-
'chore(release): 1.0.0'
|
|
119
|
-
)
|
|
120
|
-
})
|
|
222
|
+
expect(formatCommitMessage('chore(release): 1.0.0', '1.0.0')).toEqual(
|
|
223
|
+
'chore(release): 1.0.0',
|
|
224
|
+
);
|
|
225
|
+
});
|
|
121
226
|
it('works for one {{currentTag}}', function () {
|
|
122
|
-
|
|
123
|
-
'chore(release): 1.0.0'
|
|
124
|
-
)
|
|
125
|
-
})
|
|
227
|
+
expect(
|
|
228
|
+
formatCommitMessage('chore(release): {{currentTag}}', '1.0.0'),
|
|
229
|
+
).toEqual('chore(release): 1.0.0');
|
|
230
|
+
});
|
|
126
231
|
it('works for two {{currentTag}}', function () {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
|
|
232
|
+
expect(
|
|
233
|
+
formatCommitMessage(
|
|
234
|
+
'chore(release): {{currentTag}} \n\n* CHANGELOG: https://github.com/absolute-version/commit-and-tag-version/blob/v{{currentTag}}/CHANGELOG.md',
|
|
235
|
+
'1.0.0',
|
|
236
|
+
),
|
|
237
|
+
).toEqual(
|
|
238
|
+
'chore(release): 1.0.0 \n\n* CHANGELOG: https://github.com/absolute-version/commit-and-tag-version/blob/v1.0.0/CHANGELOG.md',
|
|
239
|
+
);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
135
242
|
|
|
136
243
|
describe('cli', function () {
|
|
137
|
-
afterEach(unmock)
|
|
244
|
+
afterEach(unmock);
|
|
138
245
|
|
|
139
246
|
describe('CHANGELOG.md does not exist', function () {
|
|
140
247
|
it('populates changelog with commits since last tag by default', async function () {
|
|
141
|
-
mock({ bump: 'patch', changelog: 'patch release\n', tags: ['v1.0.0'] })
|
|
142
|
-
await exec()
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
248
|
+
mock({ bump: 'patch', changelog: 'patch release\n', tags: ['v1.0.0'] });
|
|
249
|
+
await exec();
|
|
250
|
+
verifyNewChangelogContentMatches({
|
|
251
|
+
writeFileSyncSpy,
|
|
252
|
+
expectedContent: /patch release/,
|
|
253
|
+
});
|
|
254
|
+
});
|
|
146
255
|
|
|
147
256
|
it('includes all commits if --first-release is true', async function () {
|
|
148
257
|
mock({
|
|
149
258
|
bump: 'minor',
|
|
150
259
|
changelog: 'first commit\npatch release\n',
|
|
151
|
-
|
|
152
|
-
})
|
|
153
|
-
await exec('--first-release')
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
260
|
+
testFiles: [{ path: 'package.json', value: { version: '1.0.1' } }],
|
|
261
|
+
});
|
|
262
|
+
await exec('--first-release');
|
|
263
|
+
verifyNewChangelogContentMatches({
|
|
264
|
+
writeFileSyncSpy,
|
|
265
|
+
expectedContent: /patch release/,
|
|
266
|
+
});
|
|
267
|
+
verifyNewChangelogContentMatches({
|
|
268
|
+
writeFileSyncSpy,
|
|
269
|
+
expectedContent: /first commit/,
|
|
270
|
+
});
|
|
271
|
+
});
|
|
158
272
|
|
|
159
273
|
it('skipping changelog will not create a changelog file', async function () {
|
|
160
|
-
mock({ bump: 'minor', changelog: 'foo\n' })
|
|
161
|
-
await exec('--skip.changelog true')
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
274
|
+
mock({ bump: 'minor', changelog: 'foo\n' });
|
|
275
|
+
await exec('--skip.changelog true');
|
|
276
|
+
|
|
277
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '1.1.0' });
|
|
278
|
+
expect(writeFileSyncSpy).not.toHaveBeenCalledWith('CHANGELOG.md');
|
|
279
|
+
});
|
|
280
|
+
});
|
|
166
281
|
|
|
167
282
|
describe('CHANGELOG.md exists', function () {
|
|
283
|
+
afterEach(unmock);
|
|
284
|
+
|
|
168
285
|
it('appends the new release above the last release, removing the old header (legacy format), and does not retain any front matter', async function () {
|
|
169
|
-
const frontMatter =
|
|
170
|
-
'---\nstatus: new\n---\n'
|
|
286
|
+
const frontMatter = '---\nstatus: new\n---\n';
|
|
171
287
|
mock({
|
|
172
288
|
bump: 'patch',
|
|
173
289
|
changelog: 'release 1.0.1\n',
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
290
|
+
existingChangelog:
|
|
291
|
+
frontMatter + 'legacy header format<a name="1.0.0">\n',
|
|
292
|
+
tags: ['v1.0.0'],
|
|
293
|
+
});
|
|
294
|
+
await exec();
|
|
295
|
+
|
|
296
|
+
verifyNewChangelogContentMatches({
|
|
297
|
+
writeFileSyncSpy,
|
|
298
|
+
expectedContent: /1\.0\.1/,
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
verifyNewChangelogContentDoesNotMatch({
|
|
302
|
+
writeFileSyncSpy,
|
|
303
|
+
expectedContent: /legacy header format/,
|
|
304
|
+
});
|
|
305
|
+
verifyNewChangelogContentDoesNotMatch({
|
|
306
|
+
writeFileSyncSpy,
|
|
307
|
+
expectedContent: /---status: new---/,
|
|
308
|
+
});
|
|
309
|
+
});
|
|
183
310
|
|
|
184
311
|
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 () {
|
|
185
|
-
const { header } = require('../defaults')
|
|
312
|
+
const { header } = require('../defaults');
|
|
186
313
|
|
|
187
314
|
const standardVersionHeader =
|
|
188
|
-
|
|
315
|
+
'# 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.';
|
|
189
316
|
|
|
190
|
-
const frontMatter =
|
|
191
|
-
'---\nstatus: new\n---\n'
|
|
317
|
+
const frontMatter = '---\nstatus: new\n---\n';
|
|
192
318
|
|
|
193
319
|
const changelog101 =
|
|
194
|
-
|
|
320
|
+
'### [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n';
|
|
195
321
|
|
|
196
322
|
const changelog100 =
|
|
197
|
-
|
|
323
|
+
'### [1.0.0](/compare/v0.0.1...v1.0.0) (YYYY-MM-DD)\n\n\n### Features\n\n* Version one feature set\n';
|
|
198
324
|
|
|
199
|
-
const initialChangelog =
|
|
325
|
+
const initialChangelog =
|
|
326
|
+
frontMatter + '\n' + standardVersionHeader + '\n' + changelog100;
|
|
200
327
|
|
|
201
328
|
mock({
|
|
202
329
|
bump: 'patch',
|
|
203
330
|
changelog: changelog101,
|
|
204
|
-
|
|
205
|
-
tags: ['v1.0.0']
|
|
206
|
-
})
|
|
207
|
-
await exec()
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
331
|
+
existingChangelog: initialChangelog,
|
|
332
|
+
tags: ['v1.0.0'],
|
|
333
|
+
});
|
|
334
|
+
await exec();
|
|
335
|
+
|
|
336
|
+
verifyNewChangelogContentEquals({
|
|
337
|
+
writeFileSyncSpy,
|
|
338
|
+
expectedContent:
|
|
339
|
+
frontMatter + '\n' + header + '\n' + changelog101 + changelog100,
|
|
340
|
+
});
|
|
341
|
+
});
|
|
211
342
|
|
|
212
343
|
it('appends the new release above the last release, removing the old header (new format), and retains any front matter', async function () {
|
|
213
|
-
const { header } = require('../defaults')
|
|
214
|
-
const frontMatter =
|
|
215
|
-
'---\nstatus: new\n---\n'
|
|
344
|
+
const { header } = require('../defaults');
|
|
345
|
+
const frontMatter = '---\nstatus: new\n---\n';
|
|
216
346
|
|
|
217
347
|
const changelog101 =
|
|
218
|
-
|
|
348
|
+
'### [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n';
|
|
219
349
|
|
|
220
350
|
const changelog100 =
|
|
221
|
-
|
|
351
|
+
'### [1.0.0](/compare/v0.0.1...v1.0.0) (YYYY-MM-DD)\n\n\n### Features\n\n* Version one feature set\n';
|
|
222
352
|
|
|
223
|
-
const initialChangelog =
|
|
353
|
+
const initialChangelog =
|
|
354
|
+
frontMatter + '\n' + header + '\n' + changelog100;
|
|
224
355
|
|
|
225
356
|
mock({
|
|
226
357
|
bump: 'patch',
|
|
227
358
|
changelog: changelog101,
|
|
228
|
-
|
|
229
|
-
tags: ['v1.0.0']
|
|
230
|
-
})
|
|
231
|
-
await exec()
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
359
|
+
existingChangelog: initialChangelog,
|
|
360
|
+
tags: ['v1.0.0'],
|
|
361
|
+
});
|
|
362
|
+
await exec();
|
|
363
|
+
|
|
364
|
+
verifyNewChangelogContentEquals({
|
|
365
|
+
writeFileSyncSpy,
|
|
366
|
+
expectedContent:
|
|
367
|
+
frontMatter + '\n' + header + '\n' + changelog101 + changelog100,
|
|
368
|
+
});
|
|
369
|
+
});
|
|
236
370
|
|
|
237
371
|
it('appends the new release above the last release, removing the old header (new format)', async function () {
|
|
238
|
-
const { header } = require('../defaults')
|
|
372
|
+
const { header } = require('../defaults');
|
|
239
373
|
const changelog1 =
|
|
240
|
-
'### [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n'
|
|
241
|
-
mock({ bump: 'patch', changelog: changelog1, tags: ['v1.0.0'] })
|
|
242
|
-
await exec()
|
|
243
|
-
|
|
244
|
-
|
|
374
|
+
'### [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n';
|
|
375
|
+
mock({ bump: 'patch', changelog: changelog1, tags: ['v1.0.0'] });
|
|
376
|
+
await exec();
|
|
377
|
+
const content = header + '\n' + changelog1;
|
|
378
|
+
verifyNewChangelogContentEquals({
|
|
379
|
+
writeFileSyncSpy,
|
|
380
|
+
expectedContent: content,
|
|
381
|
+
});
|
|
245
382
|
|
|
246
383
|
const changelog2 =
|
|
247
|
-
'### [1.0.2](/compare/v1.0.1...v1.0.2) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* another patch release ABCDEFXY\n'
|
|
248
|
-
unmock()
|
|
384
|
+
'### [1.0.2](/compare/v1.0.1...v1.0.2) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* another patch release ABCDEFXY\n';
|
|
385
|
+
unmock();
|
|
386
|
+
|
|
249
387
|
mock({
|
|
250
388
|
bump: 'patch',
|
|
251
389
|
changelog: changelog2,
|
|
252
|
-
|
|
253
|
-
tags: ['v1.0.0', 'v1.0.1']
|
|
254
|
-
})
|
|
255
|
-
await exec()
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
390
|
+
existingChangelog: content,
|
|
391
|
+
tags: ['v1.0.0', 'v1.0.1'],
|
|
392
|
+
});
|
|
393
|
+
await exec();
|
|
394
|
+
verifyNewChangelogContentEquals({
|
|
395
|
+
writeFileSyncSpy,
|
|
396
|
+
expectedContent: header + '\n' + changelog2 + changelog1,
|
|
397
|
+
});
|
|
398
|
+
});
|
|
259
399
|
|
|
260
400
|
it('[DEPRECATED] (--changelogHeader) allows for a custom changelog header', async function () {
|
|
261
|
-
const header = '# Pork Chop Log'
|
|
401
|
+
const header = '# Pork Chop Log';
|
|
262
402
|
mock({
|
|
263
403
|
bump: 'minor',
|
|
264
404
|
changelog: header + '\n',
|
|
265
|
-
|
|
266
|
-
})
|
|
267
|
-
await exec(`--changelogHeader="${header}"`)
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
405
|
+
existingChangelog: '',
|
|
406
|
+
});
|
|
407
|
+
await exec(`--changelogHeader="${header}"`);
|
|
408
|
+
verifyNewChangelogContentMatches({
|
|
409
|
+
writeFileSyncSpy,
|
|
410
|
+
expectedContent: new RegExp(header),
|
|
411
|
+
});
|
|
412
|
+
});
|
|
271
413
|
|
|
272
414
|
it('[DEPRECATED] (--changelogHeader) exits with error if changelog header matches last version search regex', async function () {
|
|
273
|
-
mock({ bump: 'minor',
|
|
274
|
-
await expect(exec('--changelogHeader="## 3.0.2"')).
|
|
275
|
-
|
|
276
|
-
|
|
415
|
+
mock({ bump: 'minor', existingChangelog: '' });
|
|
416
|
+
await expect(exec('--changelogHeader="## 3.0.2"')).rejects.toThrow(
|
|
417
|
+
/custom changelog header must not match/,
|
|
418
|
+
);
|
|
419
|
+
});
|
|
420
|
+
});
|
|
277
421
|
|
|
278
422
|
describe('lifecycle scripts', function () {
|
|
423
|
+
afterEach(unmock);
|
|
424
|
+
|
|
279
425
|
describe('prerelease hook', function () {
|
|
280
426
|
it('should run the prerelease hook when provided', async function () {
|
|
281
|
-
|
|
427
|
+
mock({
|
|
282
428
|
bump: 'minor',
|
|
283
|
-
|
|
284
|
-
})
|
|
429
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
430
|
+
});
|
|
285
431
|
|
|
286
432
|
await exec({
|
|
287
433
|
scripts: {
|
|
288
|
-
prerelease: "node -e \"console.error('prerelease' + ' ran')\""
|
|
289
|
-
}
|
|
290
|
-
})
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
434
|
+
prerelease: "node -e \"console.error('prerelease' + ' ran')\"",
|
|
435
|
+
},
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
const expectedLog = 'prerelease ran';
|
|
439
|
+
verifyLogPrinted({ consoleInfoSpy: consoleErrorSpy, expectedLog });
|
|
440
|
+
});
|
|
294
441
|
|
|
295
442
|
it('should abort if the hook returns a non-zero exit code', async function () {
|
|
296
443
|
mock({
|
|
297
444
|
bump: 'minor',
|
|
298
|
-
|
|
299
|
-
})
|
|
300
|
-
|
|
301
|
-
await expect(
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
445
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
await expect(
|
|
449
|
+
exec({
|
|
450
|
+
scripts: {
|
|
451
|
+
prerelease: "node -e \"throw new Error('prerelease' + ' fail')\"",
|
|
452
|
+
},
|
|
453
|
+
}),
|
|
454
|
+
).rejects.toThrow(/prerelease fail/);
|
|
455
|
+
});
|
|
456
|
+
});
|
|
308
457
|
|
|
309
458
|
describe('prebump hook', function () {
|
|
310
459
|
it('should allow prebump hook to return an alternate version #', async function () {
|
|
311
|
-
|
|
460
|
+
mock({
|
|
312
461
|
bump: 'minor',
|
|
313
|
-
|
|
314
|
-
})
|
|
462
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
463
|
+
});
|
|
315
464
|
|
|
316
465
|
await exec({
|
|
317
466
|
scripts: {
|
|
318
|
-
prebump:
|
|
319
|
-
}
|
|
320
|
-
})
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
})
|
|
467
|
+
prebump: 'node -e "console.log(Array.of(9, 9, 9).join(\'.\'))"',
|
|
468
|
+
},
|
|
469
|
+
});
|
|
470
|
+
verifyLogPrinted({ consoleInfoSpy, expectedLog: '9.9.9' });
|
|
471
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '9.9.9' });
|
|
472
|
+
});
|
|
325
473
|
|
|
326
474
|
it('should not allow prebump hook to return a releaseAs command', async function () {
|
|
327
475
|
mock({
|
|
328
476
|
bump: 'minor',
|
|
329
|
-
|
|
330
|
-
})
|
|
477
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
478
|
+
});
|
|
331
479
|
|
|
332
480
|
await exec({
|
|
333
481
|
scripts: {
|
|
334
|
-
prebump:
|
|
335
|
-
}
|
|
336
|
-
})
|
|
337
|
-
|
|
338
|
-
})
|
|
482
|
+
prebump: 'node -e "console.log(\'major\')"',
|
|
483
|
+
},
|
|
484
|
+
});
|
|
485
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '1.1.0' });
|
|
486
|
+
});
|
|
339
487
|
|
|
340
488
|
it('should allow prebump hook to return an arbitrary string', async function () {
|
|
341
489
|
mock({
|
|
342
490
|
bump: 'minor',
|
|
343
|
-
|
|
344
|
-
})
|
|
491
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
492
|
+
});
|
|
345
493
|
|
|
346
494
|
await exec({
|
|
347
495
|
scripts: {
|
|
348
|
-
prebump:
|
|
349
|
-
}
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
})
|
|
496
|
+
prebump: 'node -e "console.log(\'Hello World\')"',
|
|
497
|
+
},
|
|
498
|
+
});
|
|
499
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '1.1.0' });
|
|
500
|
+
});
|
|
353
501
|
|
|
354
502
|
it('should allow prebump hook to return a version with build info', async function () {
|
|
355
503
|
mock({
|
|
356
504
|
bump: 'minor',
|
|
357
|
-
|
|
358
|
-
})
|
|
505
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
506
|
+
});
|
|
359
507
|
|
|
360
508
|
await exec({
|
|
361
509
|
scripts: {
|
|
362
|
-
prebump:
|
|
363
|
-
}
|
|
364
|
-
})
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
510
|
+
prebump: 'node -e "console.log(\'9.9.9-test+build\')"',
|
|
511
|
+
},
|
|
512
|
+
});
|
|
513
|
+
verifyPackageVersion({
|
|
514
|
+
writeFileSyncSpy,
|
|
515
|
+
expectedVersion: '9.9.9-test+build',
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
});
|
|
368
519
|
|
|
369
520
|
describe('postbump hook', function () {
|
|
370
521
|
it('should run the postbump hook when provided', async function () {
|
|
371
|
-
|
|
522
|
+
mock({
|
|
372
523
|
bump: 'minor',
|
|
373
|
-
|
|
374
|
-
})
|
|
524
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
525
|
+
});
|
|
375
526
|
|
|
376
527
|
await exec({
|
|
377
528
|
scripts: {
|
|
378
|
-
postbump: "node -e \"console.error('postbump' + ' ran')\""
|
|
379
|
-
}
|
|
380
|
-
})
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
529
|
+
postbump: "node -e \"console.error('postbump' + ' ran')\"",
|
|
530
|
+
},
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
const expectedLog = 'postbump ran';
|
|
534
|
+
verifyLogPrinted({ consoleInfoSpy: consoleErrorSpy, expectedLog });
|
|
535
|
+
});
|
|
384
536
|
|
|
385
537
|
it('should run the postbump and exit with error when postbump fails', async function () {
|
|
386
538
|
mock({
|
|
387
539
|
bump: 'minor',
|
|
388
|
-
|
|
389
|
-
})
|
|
390
|
-
|
|
391
|
-
await expect(
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
540
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
await expect(
|
|
544
|
+
exec({
|
|
545
|
+
scripts: {
|
|
546
|
+
postbump: "node -e \"throw new Error('postbump' + ' fail')\"",
|
|
547
|
+
},
|
|
548
|
+
}),
|
|
549
|
+
).rejects.toThrow(/postbump fail/);
|
|
550
|
+
});
|
|
551
|
+
});
|
|
398
552
|
|
|
399
553
|
describe('manual-release', function () {
|
|
400
554
|
describe('release-types', function () {
|
|
401
|
-
const regularTypes = ['major', 'minor', 'patch']
|
|
402
|
-
const nextVersion = { major: '2.0.0', minor: '1.1.0', patch: '1.0.1' }
|
|
555
|
+
const regularTypes = ['major', 'minor', 'patch'];
|
|
556
|
+
const nextVersion = { major: '2.0.0', minor: '1.1.0', patch: '1.0.1' };
|
|
403
557
|
|
|
404
558
|
regularTypes.forEach(function (type) {
|
|
405
559
|
it('creates a ' + type + ' release', async function () {
|
|
406
560
|
mock({
|
|
407
561
|
bump: 'patch',
|
|
408
|
-
|
|
409
|
-
})
|
|
410
|
-
await exec('--release-as ' + type)
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
562
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
563
|
+
});
|
|
564
|
+
await exec('--release-as ' + type);
|
|
565
|
+
verifyPackageVersion({
|
|
566
|
+
writeFileSyncSpy,
|
|
567
|
+
expectedVersion: nextVersion[type],
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
});
|
|
414
571
|
|
|
415
572
|
// this is for pre-releases
|
|
416
573
|
regularTypes.forEach(function (type) {
|
|
417
574
|
it('creates a pre' + type + ' release', async function () {
|
|
418
575
|
mock({
|
|
419
576
|
bump: 'patch',
|
|
420
|
-
|
|
421
|
-
})
|
|
422
|
-
await exec('--release-as ' + type + ' --prerelease ' + type)
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
577
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
578
|
+
});
|
|
579
|
+
await exec('--release-as ' + type + ' --prerelease ' + type);
|
|
580
|
+
verifyPackageVersion({
|
|
581
|
+
writeFileSyncSpy,
|
|
582
|
+
expectedVersion: `${nextVersion[type]}-${type}.0`,
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
});
|
|
426
586
|
|
|
427
587
|
it('exits with error if an invalid release type is provided', async function () {
|
|
428
|
-
mock({ bump: 'minor',
|
|
588
|
+
mock({ bump: 'minor', existingChangelog: '' });
|
|
429
589
|
|
|
430
|
-
await expect(exec('--release-as invalid')).
|
|
431
|
-
|
|
432
|
-
|
|
590
|
+
await expect(exec('--release-as invalid')).rejects.toThrow(
|
|
591
|
+
/releaseAs must be one of/,
|
|
592
|
+
);
|
|
593
|
+
});
|
|
594
|
+
});
|
|
433
595
|
|
|
434
596
|
describe('release-as-exact', function () {
|
|
435
597
|
it('releases as v100.0.0', async function () {
|
|
436
598
|
mock({
|
|
437
599
|
bump: 'patch',
|
|
438
|
-
|
|
439
|
-
})
|
|
440
|
-
await exec('--release-as v100.0.0')
|
|
441
|
-
|
|
442
|
-
|
|
600
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
601
|
+
});
|
|
602
|
+
await exec('--release-as v100.0.0');
|
|
603
|
+
verifyPackageVersion({
|
|
604
|
+
writeFileSyncSpy,
|
|
605
|
+
expectedVersion: '100.0.0',
|
|
606
|
+
});
|
|
607
|
+
});
|
|
443
608
|
|
|
444
609
|
it('releases as 200.0.0-amazing', async function () {
|
|
445
610
|
mock({
|
|
446
611
|
bump: 'patch',
|
|
447
|
-
|
|
448
|
-
})
|
|
449
|
-
await exec('--release-as 200.0.0-amazing')
|
|
450
|
-
|
|
451
|
-
|
|
612
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
613
|
+
});
|
|
614
|
+
await exec('--release-as 200.0.0-amazing');
|
|
615
|
+
verifyPackageVersion({
|
|
616
|
+
writeFileSyncSpy,
|
|
617
|
+
expectedVersion: '200.0.0-amazing',
|
|
618
|
+
});
|
|
619
|
+
});
|
|
452
620
|
|
|
453
621
|
it('releases as 100.0.0 with prerelease amazing', async function () {
|
|
454
622
|
mock({
|
|
455
623
|
bump: 'patch',
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
624
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
625
|
+
testFiles: [
|
|
626
|
+
{
|
|
627
|
+
path: 'package.json',
|
|
628
|
+
value: {
|
|
629
|
+
version: '1.0.0',
|
|
630
|
+
},
|
|
631
|
+
},
|
|
632
|
+
],
|
|
633
|
+
});
|
|
634
|
+
await exec('--release-as 100.0.0 --prerelease amazing');
|
|
635
|
+
verifyPackageVersion({
|
|
636
|
+
writeFileSyncSpy,
|
|
637
|
+
expectedVersion: '100.0.0-amazing.0',
|
|
638
|
+
});
|
|
639
|
+
});
|
|
464
640
|
|
|
465
641
|
it('release 100.0.0 with prerelease amazing bumps build', async function () {
|
|
466
642
|
mock({
|
|
467
643
|
bump: 'patch',
|
|
468
|
-
fs: {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
644
|
+
fs: {
|
|
645
|
+
'CHANGELOG.md':
|
|
646
|
+
'legacy header format<a name="100.0.0-amazing.0">\n',
|
|
647
|
+
},
|
|
648
|
+
testFiles: [
|
|
649
|
+
{
|
|
650
|
+
path: 'package.json',
|
|
651
|
+
value: {
|
|
652
|
+
version: '100.0.0-amazing.0',
|
|
653
|
+
},
|
|
654
|
+
},
|
|
655
|
+
],
|
|
656
|
+
});
|
|
657
|
+
await exec('--release-as 100.0.0 --prerelease amazing');
|
|
658
|
+
verifyPackageVersion({
|
|
659
|
+
writeFileSyncSpy,
|
|
660
|
+
expectedVersion: '100.0.0-amazing.1',
|
|
661
|
+
});
|
|
662
|
+
});
|
|
476
663
|
|
|
477
664
|
it('release 100.0.0-amazing.0 with prerelease amazing bumps build', async function () {
|
|
478
665
|
mock({
|
|
479
666
|
bump: 'patch',
|
|
480
|
-
fs: {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
667
|
+
fs: {
|
|
668
|
+
'CHANGELOG.md':
|
|
669
|
+
'legacy header format<a name="100.0.0-amazing.0">\n',
|
|
670
|
+
},
|
|
671
|
+
testFiles: [
|
|
672
|
+
{
|
|
673
|
+
path: 'package.json',
|
|
674
|
+
value: {
|
|
675
|
+
version: '100.0.0-amazing.1',
|
|
676
|
+
},
|
|
677
|
+
},
|
|
678
|
+
],
|
|
679
|
+
});
|
|
680
|
+
await exec('--release-as 100.0.0-amazing.0 --prerelease amazing');
|
|
681
|
+
verifyPackageVersion({
|
|
682
|
+
writeFileSyncSpy,
|
|
683
|
+
expectedVersion: '100.0.0-amazing.2',
|
|
684
|
+
});
|
|
685
|
+
});
|
|
488
686
|
|
|
489
687
|
it('release 100.0.0 with prerelease amazing correctly sets version', async function () {
|
|
490
688
|
mock({
|
|
491
689
|
bump: 'patch',
|
|
492
|
-
fs: {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
690
|
+
fs: {
|
|
691
|
+
'CHANGELOG.md':
|
|
692
|
+
'legacy header format<a name="100.0.0-amazing.0">\n',
|
|
693
|
+
},
|
|
694
|
+
testFiles: [
|
|
695
|
+
{
|
|
696
|
+
path: 'package.json',
|
|
697
|
+
value: {
|
|
698
|
+
version: '99.0.0-amazing.0',
|
|
699
|
+
},
|
|
700
|
+
},
|
|
701
|
+
],
|
|
702
|
+
});
|
|
703
|
+
await exec('--release-as 100.0.0 --prerelease amazing');
|
|
704
|
+
verifyPackageVersion({
|
|
705
|
+
writeFileSyncSpy,
|
|
706
|
+
expectedVersion: '100.0.0-amazing.0',
|
|
707
|
+
});
|
|
708
|
+
});
|
|
500
709
|
|
|
501
710
|
it('release 100.0.0-amazing.0 with prerelease amazing correctly sets version', async function () {
|
|
502
711
|
mock({
|
|
503
712
|
bump: 'patch',
|
|
504
|
-
fs: {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
713
|
+
fs: {
|
|
714
|
+
'CHANGELOG.md':
|
|
715
|
+
'legacy header format<a name="100.0.0-amazing.0">\n',
|
|
716
|
+
},
|
|
717
|
+
testFiles: [
|
|
718
|
+
{
|
|
719
|
+
path: 'package.json',
|
|
720
|
+
value: {
|
|
721
|
+
version: '99.0.0-amazing.0',
|
|
722
|
+
},
|
|
723
|
+
},
|
|
724
|
+
],
|
|
725
|
+
});
|
|
726
|
+
await exec('--release-as 100.0.0-amazing.0 --prerelease amazing');
|
|
727
|
+
verifyPackageVersion({
|
|
728
|
+
writeFileSyncSpy,
|
|
729
|
+
expectedVersion: '100.0.0-amazing.0',
|
|
730
|
+
});
|
|
731
|
+
});
|
|
512
732
|
|
|
513
733
|
it('release 100.0.0-amazing.0 with prerelease amazing retains build metadata', async function () {
|
|
514
734
|
mock({
|
|
515
735
|
bump: 'patch',
|
|
516
|
-
fs: {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
736
|
+
fs: {
|
|
737
|
+
'CHANGELOG.md':
|
|
738
|
+
'legacy header format<a name="100.0.0-amazing.0">\n',
|
|
739
|
+
},
|
|
740
|
+
testFiles: [
|
|
741
|
+
{
|
|
742
|
+
path: 'package.json',
|
|
743
|
+
value: {
|
|
744
|
+
version: '100.0.0-amazing.0',
|
|
745
|
+
},
|
|
746
|
+
},
|
|
747
|
+
],
|
|
748
|
+
});
|
|
749
|
+
await exec(
|
|
750
|
+
'--release-as 100.0.0-amazing.0+build.1234 --prerelease amazing',
|
|
751
|
+
);
|
|
752
|
+
verifyPackageVersion({
|
|
753
|
+
writeFileSyncSpy,
|
|
754
|
+
expectedVersion: '100.0.0-amazing.1+build.1234',
|
|
755
|
+
});
|
|
756
|
+
});
|
|
524
757
|
|
|
525
758
|
it('release 100.0.0-amazing.3 with prerelease amazing correctly sets prerelease version', async function () {
|
|
526
759
|
mock({
|
|
527
760
|
bump: 'patch',
|
|
528
|
-
fs: {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
761
|
+
fs: {
|
|
762
|
+
'CHANGELOG.md':
|
|
763
|
+
'legacy header format<a name="100.0.0-amazing.0">\n',
|
|
764
|
+
},
|
|
765
|
+
testFiles: [
|
|
766
|
+
{
|
|
767
|
+
path: 'package.json',
|
|
768
|
+
value: {
|
|
769
|
+
version: '100.0.0-amazing.0',
|
|
770
|
+
},
|
|
771
|
+
},
|
|
772
|
+
],
|
|
773
|
+
});
|
|
774
|
+
await exec('--release-as 100.0.0-amazing.3 --prerelease amazing');
|
|
775
|
+
verifyPackageVersion({
|
|
776
|
+
writeFileSyncSpy,
|
|
777
|
+
expectedVersion: '100.0.0-amazing.3',
|
|
778
|
+
});
|
|
779
|
+
});
|
|
780
|
+
});
|
|
537
781
|
|
|
538
782
|
it('creates a prerelease with a new minor version after two prerelease patches', async function () {
|
|
539
|
-
let releaseType = 'patch'
|
|
540
|
-
const bump = (_, __, cb) => cb(null, { releaseType })
|
|
783
|
+
let releaseType = 'patch';
|
|
541
784
|
mock({
|
|
542
|
-
bump,
|
|
543
|
-
|
|
544
|
-
})
|
|
785
|
+
bump: (_, __, cb) => cb(null, { releaseType }),
|
|
786
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
787
|
+
});
|
|
545
788
|
|
|
546
|
-
|
|
547
|
-
|
|
789
|
+
let version = '1.0.1-dev.0';
|
|
790
|
+
await exec('--release-as patch --prerelease dev');
|
|
791
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: version });
|
|
548
792
|
|
|
549
|
-
|
|
550
|
-
|
|
793
|
+
unmock();
|
|
794
|
+
mock({
|
|
795
|
+
bump: (_, __, cb) => cb(null, { releaseType }),
|
|
796
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
797
|
+
testFiles: [{ path: 'package.json', value: { version } }],
|
|
798
|
+
});
|
|
551
799
|
|
|
552
|
-
|
|
553
|
-
await exec('--
|
|
554
|
-
|
|
800
|
+
version = '1.0.1-dev.1';
|
|
801
|
+
await exec('--prerelease dev');
|
|
802
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: version });
|
|
555
803
|
|
|
556
|
-
|
|
557
|
-
|
|
804
|
+
releaseType = 'minor';
|
|
805
|
+
unmock();
|
|
806
|
+
mock({
|
|
807
|
+
bump: (_, __, cb) => cb(null, { releaseType }),
|
|
808
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
809
|
+
testFiles: [{ path: 'package.json', value: { version } }],
|
|
810
|
+
});
|
|
558
811
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
812
|
+
version = '1.1.0-dev.0';
|
|
813
|
+
await exec('--release-as minor --prerelease dev');
|
|
814
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: version });
|
|
815
|
+
|
|
816
|
+
unmock();
|
|
817
|
+
mock({
|
|
818
|
+
bump: (_, __, cb) => cb(null, { releaseType }),
|
|
819
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
820
|
+
testFiles: [{ path: 'package.json', value: { version } }],
|
|
821
|
+
});
|
|
822
|
+
|
|
823
|
+
version = '1.1.0-dev.1';
|
|
824
|
+
await exec('--release-as minor --prerelease dev');
|
|
825
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: version });
|
|
826
|
+
|
|
827
|
+
unmock();
|
|
828
|
+
mock({
|
|
829
|
+
bump: (_, __, cb) => cb(null, { releaseType }),
|
|
830
|
+
existingChangelog: 'legacy header format<a name="1.0.0">\n',
|
|
831
|
+
testFiles: [{ path: 'package.json', value: { version } }],
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
version = '1.1.0-dev.2';
|
|
835
|
+
await exec('--prerelease dev');
|
|
836
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: version });
|
|
837
|
+
});
|
|
562
838
|
|
|
563
839
|
it('exits with error if an invalid release version is provided', async function () {
|
|
564
|
-
mock({ bump: 'minor',
|
|
840
|
+
mock({ bump: 'minor', existingChangelog: '' });
|
|
565
841
|
|
|
566
|
-
await expect(exec('--release-as 10.2')).
|
|
567
|
-
|
|
842
|
+
await expect(exec('--release-as 10.2')).rejects.toThrow(
|
|
843
|
+
/releaseAs must be one of/,
|
|
844
|
+
);
|
|
845
|
+
});
|
|
568
846
|
|
|
569
847
|
it('exits with error if release version conflicts with prerelease', async function () {
|
|
570
|
-
mock({ bump: 'minor',
|
|
848
|
+
mock({ bump: 'minor', existingChangelog: '' });
|
|
571
849
|
|
|
572
|
-
await expect(
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
850
|
+
await expect(
|
|
851
|
+
exec('--release-as 1.2.3-amazing.2 --prerelease awesome'),
|
|
852
|
+
).rejects.toThrow(
|
|
853
|
+
/releaseAs and prerelease have conflicting prerelease identifiers/,
|
|
854
|
+
);
|
|
855
|
+
});
|
|
856
|
+
});
|
|
576
857
|
|
|
577
858
|
it('appends line feed at end of package.json', async function () {
|
|
578
|
-
mock({ bump: 'patch' })
|
|
579
|
-
await exec()
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
859
|
+
mock({ bump: 'patch' });
|
|
860
|
+
await exec();
|
|
861
|
+
verifyFileContentEquals({
|
|
862
|
+
writeFileSyncSpy,
|
|
863
|
+
content: '{\n "version": "1.0.1"\n}\n',
|
|
864
|
+
});
|
|
865
|
+
});
|
|
583
866
|
|
|
584
867
|
it('preserves indentation of tabs in package.json', async function () {
|
|
585
868
|
mock({
|
|
586
869
|
bump: 'patch',
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
870
|
+
testFiles: [
|
|
871
|
+
{ path: 'package.json', value: '{\n\t"version": "1.0.0"\n}\n' },
|
|
872
|
+
],
|
|
873
|
+
});
|
|
874
|
+
await exec();
|
|
875
|
+
// TODO: a) not bumping to 1.0.1, b) need to check how jest might handle tabbing etc
|
|
876
|
+
verifyFileContentEquals({
|
|
877
|
+
writeFileSyncSpy,
|
|
878
|
+
content: '{\n\t"version": "1.0.1"\n}\n',
|
|
879
|
+
});
|
|
880
|
+
});
|
|
593
881
|
|
|
594
882
|
it('preserves indentation of spaces in package.json', async function () {
|
|
595
883
|
mock({
|
|
596
884
|
bump: 'patch',
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
885
|
+
testFiles: [
|
|
886
|
+
{ path: 'package.json', value: '{\n "version": "1.0.0"\n}\n' },
|
|
887
|
+
],
|
|
888
|
+
});
|
|
889
|
+
await exec();
|
|
890
|
+
verifyFileContentEquals({
|
|
891
|
+
writeFileSyncSpy,
|
|
892
|
+
content: '{\n "version": "1.0.1"\n}\n',
|
|
893
|
+
});
|
|
894
|
+
});
|
|
603
895
|
|
|
604
896
|
it('preserves carriage return + line feed in package.json', async function () {
|
|
605
897
|
mock({
|
|
606
898
|
bump: 'patch',
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
899
|
+
testFiles: [
|
|
900
|
+
{ path: 'package.json', value: '{\r\n "version": "1.0.0"\r\n}\r\n' },
|
|
901
|
+
],
|
|
902
|
+
});
|
|
903
|
+
await exec();
|
|
904
|
+
verifyFileContentEquals({
|
|
905
|
+
writeFileSyncSpy,
|
|
906
|
+
content: '{\r\n "version": "1.0.1"\r\n}\r\n',
|
|
907
|
+
});
|
|
908
|
+
});
|
|
613
909
|
|
|
614
910
|
it('does not print output when the --silent flag is passed', async function () {
|
|
615
|
-
|
|
616
|
-
await exec('--silent')
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
911
|
+
mock();
|
|
912
|
+
await exec('--silent');
|
|
913
|
+
expect(consoleErrorSpy).not.toHaveBeenCalled();
|
|
914
|
+
expect(consoleInfoSpy).not.toHaveBeenCalled();
|
|
915
|
+
});
|
|
916
|
+
});
|
|
620
917
|
|
|
621
918
|
describe('commit-and-tag-version', function () {
|
|
622
|
-
afterEach(unmock)
|
|
919
|
+
afterEach(unmock);
|
|
623
920
|
|
|
624
921
|
it('should exit on bump error', async function () {
|
|
625
|
-
mock({ bump: new Error('bump err') })
|
|
922
|
+
mock({ bump: new Error('bump err') });
|
|
626
923
|
|
|
627
|
-
await expect(exec()).
|
|
628
|
-
})
|
|
924
|
+
await expect(exec()).rejects.toThrow(/bump err/);
|
|
925
|
+
});
|
|
629
926
|
|
|
630
927
|
it('should exit on changelog error', async function () {
|
|
631
|
-
mock({ bump: 'minor', changelog: new Error('changelog err') })
|
|
928
|
+
mock({ bump: 'minor', changelog: new Error('changelog err') });
|
|
632
929
|
|
|
633
|
-
await expect(exec()).
|
|
634
|
-
})
|
|
930
|
+
await expect(exec()).rejects.toThrow(/changelog err/);
|
|
931
|
+
});
|
|
635
932
|
|
|
636
933
|
it('should exit with error without a package file to bump', async function () {
|
|
637
|
-
mock({ bump: 'patch',
|
|
934
|
+
mock({ bump: 'patch', testFiles: null });
|
|
638
935
|
|
|
639
|
-
await expect(exec({ gitTagFallback: false })).
|
|
640
|
-
|
|
936
|
+
await expect(exec({ gitTagFallback: false })).rejects.toThrow(
|
|
937
|
+
'no package file found',
|
|
938
|
+
);
|
|
939
|
+
});
|
|
641
940
|
|
|
642
941
|
it('bumps version # in bower.json', async function () {
|
|
643
942
|
mock({
|
|
644
943
|
bump: 'minor',
|
|
645
|
-
|
|
646
|
-
tags: ['v1.0.0']
|
|
647
|
-
})
|
|
648
|
-
await exec()
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
944
|
+
testFiles: [{ path: 'bower.json', value: { version: '1.0.0' } }],
|
|
945
|
+
tags: ['v1.0.0'],
|
|
946
|
+
});
|
|
947
|
+
await exec();
|
|
948
|
+
|
|
949
|
+
verifyPackageVersion({
|
|
950
|
+
writeFileSyncSpy,
|
|
951
|
+
expectedVersion: '1.1.0',
|
|
952
|
+
filename: 'bower.json',
|
|
953
|
+
});
|
|
954
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '1.1.0' });
|
|
955
|
+
});
|
|
654
956
|
|
|
655
957
|
it('bumps version # in manifest.json', async function () {
|
|
656
958
|
mock({
|
|
657
959
|
bump: 'minor',
|
|
658
|
-
|
|
659
|
-
tags: ['v1.0.0']
|
|
660
|
-
})
|
|
661
|
-
await exec()
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
960
|
+
testFiles: [{ path: 'manifest.json', value: { version: '1.0.0' } }],
|
|
961
|
+
tags: ['v1.0.0'],
|
|
962
|
+
});
|
|
963
|
+
await exec();
|
|
964
|
+
|
|
965
|
+
verifyPackageVersion({
|
|
966
|
+
writeFileSyncSpy,
|
|
967
|
+
expectedVersion: '1.1.0',
|
|
968
|
+
filename: 'manifest.json',
|
|
969
|
+
});
|
|
970
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '1.1.0' });
|
|
971
|
+
});
|
|
667
972
|
|
|
668
973
|
describe('custom `bumpFiles` support', function () {
|
|
974
|
+
afterEach(unmock);
|
|
975
|
+
|
|
669
976
|
it('mix.exs + version.txt', async function () {
|
|
670
|
-
const updater = 'custom-updater.js'
|
|
671
|
-
const updaterModule = require('./mocks/updater/customer-updater')
|
|
672
977
|
mock({
|
|
673
978
|
bump: 'minor',
|
|
674
|
-
|
|
675
|
-
'mix.exs':
|
|
676
|
-
'version.txt':
|
|
677
|
-
|
|
678
|
-
tags: ['v1.0.0']
|
|
679
|
-
})
|
|
680
|
-
mockery.registerMock(resolve(process.cwd(), updater), updaterModule)
|
|
979
|
+
realTestFiles: [
|
|
980
|
+
{ filename: 'mix.exs', path: './test/mocks/mix.exs' },
|
|
981
|
+
{ filename: 'version.txt', path: './test/mocks/version.txt' },
|
|
982
|
+
],
|
|
983
|
+
tags: ['v1.0.0'],
|
|
984
|
+
});
|
|
681
985
|
|
|
682
986
|
await exec({
|
|
683
987
|
bumpFiles: [
|
|
684
988
|
'version.txt',
|
|
685
|
-
{
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
989
|
+
{
|
|
990
|
+
filename: 'mix.exs',
|
|
991
|
+
updater: './test/mocks/updater/customer-updater',
|
|
992
|
+
},
|
|
993
|
+
],
|
|
994
|
+
});
|
|
995
|
+
|
|
996
|
+
verifyPackageVersion({
|
|
997
|
+
writeFileSyncSpy,
|
|
998
|
+
expectedVersion: '1.1.0',
|
|
999
|
+
filename: 'mix.exs',
|
|
1000
|
+
asString: true,
|
|
1001
|
+
});
|
|
1002
|
+
|
|
1003
|
+
verifyPackageVersion({
|
|
1004
|
+
writeFileSyncSpy,
|
|
1005
|
+
expectedVersion: '1.1.0',
|
|
1006
|
+
filename: 'version.txt',
|
|
1007
|
+
asString: true,
|
|
1008
|
+
});
|
|
1009
|
+
});
|
|
691
1010
|
|
|
692
1011
|
it('bumps a custom `plain-text` file', async function () {
|
|
693
1012
|
mock({
|
|
694
1013
|
bump: 'minor',
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
'
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
1014
|
+
realTestFiles: [
|
|
1015
|
+
{
|
|
1016
|
+
filename: 'VERSION_TRACKER.txt',
|
|
1017
|
+
path: './test/mocks/VERSION-1.0.0.txt',
|
|
1018
|
+
},
|
|
1019
|
+
],
|
|
1020
|
+
});
|
|
701
1021
|
await exec({
|
|
702
|
-
bumpFiles: [{ filename: 'VERSION_TRACKER.txt', type: 'plain-text' }]
|
|
703
|
-
})
|
|
704
|
-
|
|
705
|
-
|
|
1022
|
+
bumpFiles: [{ filename: 'VERSION_TRACKER.txt', type: 'plain-text' }],
|
|
1023
|
+
});
|
|
1024
|
+
verifyPackageVersion({
|
|
1025
|
+
writeFileSyncSpy,
|
|
1026
|
+
expectedVersion: '1.1.0',
|
|
1027
|
+
filename: 'VERSION_TRACKER.txt',
|
|
1028
|
+
asString: true,
|
|
1029
|
+
});
|
|
1030
|
+
});
|
|
706
1031
|
|
|
707
1032
|
it('displays the new version from custom bumper with --dry-run', async function () {
|
|
708
|
-
const updater = 'increment-updater.js'
|
|
709
|
-
const updaterModule = require('./mocks/updater/increment-updater')
|
|
710
1033
|
mock({
|
|
711
1034
|
bump: 'minor',
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
'
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
const origInfo = console.info
|
|
721
|
-
const capturedOutput = []
|
|
1035
|
+
realTestFiles: [
|
|
1036
|
+
{
|
|
1037
|
+
filename: 'increment-version.txt',
|
|
1038
|
+
path: './test/mocks/increment-version.txt',
|
|
1039
|
+
},
|
|
1040
|
+
],
|
|
1041
|
+
});
|
|
1042
|
+
|
|
1043
|
+
const origInfo = console.info;
|
|
1044
|
+
const capturedOutput = [];
|
|
722
1045
|
console.info = (...args) => {
|
|
723
|
-
capturedOutput.push(...args)
|
|
724
|
-
origInfo(...args)
|
|
725
|
-
}
|
|
1046
|
+
capturedOutput.push(...args);
|
|
1047
|
+
origInfo(...args);
|
|
1048
|
+
};
|
|
1049
|
+
|
|
726
1050
|
try {
|
|
727
1051
|
await exec({
|
|
728
|
-
bumpFiles: [
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
1052
|
+
bumpFiles: [
|
|
1053
|
+
{
|
|
1054
|
+
filename: 'increment-version.txt',
|
|
1055
|
+
updater: './test/mocks/updater/increment-updater',
|
|
1056
|
+
},
|
|
1057
|
+
],
|
|
1058
|
+
dryRun: true,
|
|
1059
|
+
});
|
|
1060
|
+
|
|
1061
|
+
const logOutput = capturedOutput.join(' ');
|
|
1062
|
+
expect(stripAnsi(logOutput)).toContain(
|
|
1063
|
+
'bumping version in increment-version.txt from 1 to 2',
|
|
1064
|
+
);
|
|
733
1065
|
} finally {
|
|
734
|
-
console.info = origInfo
|
|
1066
|
+
console.info = origInfo;
|
|
735
1067
|
}
|
|
736
|
-
})
|
|
737
|
-
})
|
|
1068
|
+
});
|
|
1069
|
+
});
|
|
738
1070
|
|
|
739
1071
|
describe('custom `packageFiles` support', function () {
|
|
1072
|
+
afterEach(unmock);
|
|
1073
|
+
|
|
740
1074
|
it('reads and writes to a custom `plain-text` file', async function () {
|
|
741
1075
|
mock({
|
|
742
1076
|
bump: 'minor',
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
'
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
1077
|
+
realTestFiles: [
|
|
1078
|
+
{
|
|
1079
|
+
filename: 'VERSION_TRACKER.txt',
|
|
1080
|
+
path: './test/mocks/VERSION-6.3.1.txt',
|
|
1081
|
+
},
|
|
1082
|
+
],
|
|
1083
|
+
});
|
|
1084
|
+
|
|
749
1085
|
await exec({
|
|
750
|
-
packageFiles: [
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
1086
|
+
packageFiles: [
|
|
1087
|
+
{ filename: 'VERSION_TRACKER.txt', type: 'plain-text' },
|
|
1088
|
+
],
|
|
1089
|
+
bumpFiles: [{ filename: 'VERSION_TRACKER.txt', type: 'plain-text' }],
|
|
1090
|
+
});
|
|
1091
|
+
|
|
1092
|
+
verifyPackageVersion({
|
|
1093
|
+
writeFileSyncSpy,
|
|
1094
|
+
expectedVersion: '6.4.0',
|
|
1095
|
+
filename: 'VERSION_TRACKER.txt',
|
|
1096
|
+
asString: true,
|
|
1097
|
+
});
|
|
1098
|
+
});
|
|
755
1099
|
|
|
756
1100
|
it('allows same object to be used in packageFiles and bumpFiles', async function () {
|
|
757
1101
|
mock({
|
|
758
1102
|
bump: 'minor',
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
'
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
1103
|
+
realTestFiles: [
|
|
1104
|
+
{
|
|
1105
|
+
filename: 'VERSION_TRACKER.txt',
|
|
1106
|
+
path: './test/mocks/VERSION-6.3.1.txt',
|
|
1107
|
+
},
|
|
1108
|
+
],
|
|
1109
|
+
});
|
|
1110
|
+
const origWarn = console.warn;
|
|
1111
|
+
|
|
766
1112
|
console.warn = () => {
|
|
767
|
-
throw new Error('console.warn should not be called')
|
|
768
|
-
}
|
|
769
|
-
|
|
1113
|
+
throw new Error('console.warn should not be called');
|
|
1114
|
+
};
|
|
1115
|
+
|
|
1116
|
+
const filedesc = {
|
|
1117
|
+
filename: 'VERSION_TRACKER.txt',
|
|
1118
|
+
type: 'plain-text',
|
|
1119
|
+
};
|
|
1120
|
+
|
|
770
1121
|
try {
|
|
771
|
-
await exec({ packageFiles: [filedesc], bumpFiles: [filedesc] })
|
|
772
|
-
|
|
1122
|
+
await exec({ packageFiles: [filedesc], bumpFiles: [filedesc] });
|
|
1123
|
+
verifyPackageVersion({
|
|
1124
|
+
writeFileSyncSpy,
|
|
1125
|
+
expectedVersion: '6.4.0',
|
|
1126
|
+
filename: 'VERSION_TRACKER.txt',
|
|
1127
|
+
asString: true,
|
|
1128
|
+
});
|
|
773
1129
|
} finally {
|
|
774
|
-
console.warn = origWarn
|
|
1130
|
+
console.warn = origWarn;
|
|
775
1131
|
}
|
|
776
|
-
})
|
|
777
|
-
})
|
|
1132
|
+
});
|
|
1133
|
+
});
|
|
778
1134
|
|
|
779
1135
|
it('`packageFiles` are bumped along with `bumpFiles` defaults [commit-and-tag-version#533]', async function () {
|
|
780
1136
|
mock({
|
|
781
1137
|
bump: 'minor',
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
1138
|
+
testFiles: [
|
|
1139
|
+
{
|
|
1140
|
+
path: '.gitignore',
|
|
1141
|
+
value: '',
|
|
1142
|
+
},
|
|
1143
|
+
{
|
|
1144
|
+
path: 'package-lock.json',
|
|
1145
|
+
value: { version: '1.0.0' },
|
|
1146
|
+
},
|
|
1147
|
+
],
|
|
1148
|
+
realTestFiles: [
|
|
1149
|
+
{
|
|
1150
|
+
filename: 'manifest.json',
|
|
1151
|
+
path: './test/mocks/manifest-6.3.1.json',
|
|
1152
|
+
},
|
|
1153
|
+
],
|
|
1154
|
+
tags: ['v1.0.0'],
|
|
1155
|
+
});
|
|
789
1156
|
|
|
790
1157
|
await exec({
|
|
791
|
-
silent: true,
|
|
792
1158
|
packageFiles: [
|
|
793
1159
|
{
|
|
794
1160
|
filename: 'manifest.json',
|
|
795
|
-
type: 'json'
|
|
796
|
-
}
|
|
797
|
-
]
|
|
798
|
-
})
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
1161
|
+
type: 'json',
|
|
1162
|
+
},
|
|
1163
|
+
],
|
|
1164
|
+
});
|
|
1165
|
+
|
|
1166
|
+
verifyPackageVersion({
|
|
1167
|
+
writeFileSyncSpy,
|
|
1168
|
+
expectedVersion: '6.4.0',
|
|
1169
|
+
filename: 'package.json',
|
|
1170
|
+
});
|
|
1171
|
+
verifyPackageVersion({
|
|
1172
|
+
writeFileSyncSpy,
|
|
1173
|
+
expectedVersion: '6.4.0',
|
|
1174
|
+
filename: 'package-lock.json',
|
|
1175
|
+
});
|
|
1176
|
+
verifyPackageVersion({
|
|
1177
|
+
writeFileSyncSpy,
|
|
1178
|
+
expectedVersion: '6.4.0',
|
|
1179
|
+
filename: 'manifest.json',
|
|
1180
|
+
});
|
|
1181
|
+
});
|
|
810
1182
|
|
|
811
1183
|
it('bumps version in Gradle `build.gradle.kts` file', async function () {
|
|
812
|
-
const expected = fs.readFileSync(
|
|
1184
|
+
const expected = fs.readFileSync(
|
|
1185
|
+
'./test/mocks/build-6.4.0.gradle.kts',
|
|
1186
|
+
'utf-8',
|
|
1187
|
+
);
|
|
1188
|
+
|
|
813
1189
|
mock({
|
|
814
1190
|
bump: 'minor',
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
1191
|
+
realTestFiles: [
|
|
1192
|
+
{
|
|
1193
|
+
filename: 'build.gradle.kts',
|
|
1194
|
+
path: './test/mocks/build-6.3.1.gradle.kts',
|
|
1195
|
+
},
|
|
1196
|
+
],
|
|
1197
|
+
});
|
|
1198
|
+
|
|
819
1199
|
await exec({
|
|
820
1200
|
packageFiles: [{ filename: 'build.gradle.kts', type: 'gradle' }],
|
|
821
|
-
bumpFiles: [{ filename: 'build.gradle.kts', type: 'gradle' }]
|
|
822
|
-
})
|
|
823
|
-
|
|
824
|
-
|
|
1201
|
+
bumpFiles: [{ filename: 'build.gradle.kts', type: 'gradle' }],
|
|
1202
|
+
});
|
|
1203
|
+
|
|
1204
|
+
// filePath is the first arg passed to writeFileSync
|
|
1205
|
+
const filename = 'build.gradle.kts';
|
|
1206
|
+
const packageJsonWriteFileSynchCall = findWriteFileCallForPath({
|
|
1207
|
+
writeFileSyncSpy,
|
|
1208
|
+
filename,
|
|
1209
|
+
});
|
|
1210
|
+
|
|
1211
|
+
if (!packageJsonWriteFileSynchCall) {
|
|
1212
|
+
throw new Error(`writeFileSynch not invoked with path ${filename}`);
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
const calledWithContentStr = packageJsonWriteFileSynchCall[1];
|
|
1216
|
+
expect(calledWithContentStr).toEqual(expected);
|
|
1217
|
+
});
|
|
825
1218
|
|
|
826
1219
|
it('bumps version in .NET `Project.csproj` file', async function () {
|
|
827
|
-
const expected = fs.readFileSync(
|
|
828
|
-
|
|
1220
|
+
const expected = fs.readFileSync(
|
|
1221
|
+
'./test/mocks/Project-6.4.0.csproj',
|
|
1222
|
+
'utf-8',
|
|
1223
|
+
);
|
|
1224
|
+
const filename = 'Project.csproj';
|
|
829
1225
|
mock({
|
|
830
1226
|
bump: 'minor',
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
1227
|
+
realTestFiles: [
|
|
1228
|
+
{
|
|
1229
|
+
filename,
|
|
1230
|
+
path: './test/mocks/Project-6.3.1.csproj',
|
|
1231
|
+
},
|
|
1232
|
+
],
|
|
1233
|
+
});
|
|
835
1234
|
await exec({
|
|
836
1235
|
packageFiles: [{ filename, type: 'csproj' }],
|
|
837
|
-
bumpFiles: [{ filename, type: 'csproj' }]
|
|
838
|
-
})
|
|
839
|
-
|
|
840
|
-
|
|
1236
|
+
bumpFiles: [{ filename, type: 'csproj' }],
|
|
1237
|
+
});
|
|
1238
|
+
|
|
1239
|
+
// filePath is the first arg passed to writeFileSync
|
|
1240
|
+
const packageJsonWriteFileSynchCall = findWriteFileCallForPath({
|
|
1241
|
+
writeFileSyncSpy,
|
|
1242
|
+
filename,
|
|
1243
|
+
});
|
|
1244
|
+
|
|
1245
|
+
if (!packageJsonWriteFileSynchCall) {
|
|
1246
|
+
throw new Error(`writeFileSynch not invoked with path ${filename}`);
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
const calledWithContentStr = packageJsonWriteFileSynchCall[1];
|
|
1250
|
+
expect(calledWithContentStr).toEqual(expected);
|
|
1251
|
+
});
|
|
841
1252
|
|
|
842
1253
|
it('bumps version # in npm-shrinkwrap.json', async function () {
|
|
843
1254
|
mock({
|
|
844
1255
|
bump: 'minor',
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
1256
|
+
testFiles: [
|
|
1257
|
+
{
|
|
1258
|
+
path: 'npm-shrinkwrap.json',
|
|
1259
|
+
value: { version: '1.0.0' },
|
|
1260
|
+
},
|
|
1261
|
+
],
|
|
1262
|
+
tags: ['v1.0.0'],
|
|
1263
|
+
});
|
|
1264
|
+
|
|
1265
|
+
await exec();
|
|
1266
|
+
|
|
1267
|
+
verifyPackageVersion({
|
|
1268
|
+
writeFileSyncSpy,
|
|
1269
|
+
expectedVersion: '1.1.0',
|
|
1270
|
+
filename: 'npm-shrinkwrap.json',
|
|
1271
|
+
});
|
|
1272
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '1.1.0' });
|
|
1273
|
+
});
|
|
856
1274
|
|
|
857
1275
|
it('bumps version # in package-lock.json', async function () {
|
|
858
1276
|
mock({
|
|
859
1277
|
bump: 'minor',
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
1278
|
+
testFiles: [
|
|
1279
|
+
{
|
|
1280
|
+
path: '.gitignore',
|
|
1281
|
+
value: '',
|
|
1282
|
+
},
|
|
1283
|
+
{
|
|
1284
|
+
path: 'package-lock.json',
|
|
1285
|
+
value: { version: '1.0.0' },
|
|
1286
|
+
},
|
|
1287
|
+
],
|
|
1288
|
+
tags: ['v1.0.0'],
|
|
1289
|
+
});
|
|
1290
|
+
await exec();
|
|
1291
|
+
|
|
1292
|
+
verifyPackageVersion({
|
|
1293
|
+
writeFileSyncSpy,
|
|
1294
|
+
expectedVersion: '1.1.0',
|
|
1295
|
+
filename: 'package-lock.json',
|
|
1296
|
+
});
|
|
1297
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '1.1.0' });
|
|
1298
|
+
});
|
|
872
1299
|
|
|
873
1300
|
describe('skip', function () {
|
|
874
1301
|
it('allows bump and changelog generation to be skipped', async function () {
|
|
875
|
-
const changelogContent = 'legacy header format<a name="1.0.0">\n'
|
|
1302
|
+
const changelogContent = 'legacy header format<a name="1.0.0">\n';
|
|
876
1303
|
mock({
|
|
877
1304
|
bump: 'minor',
|
|
878
1305
|
changelog: 'foo\n',
|
|
879
|
-
|
|
880
|
-
})
|
|
1306
|
+
existingChangelog: changelogContent,
|
|
1307
|
+
});
|
|
1308
|
+
|
|
1309
|
+
await exec('--skip.bump true --skip.changelog true');
|
|
881
1310
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
})
|
|
887
|
-
})
|
|
1311
|
+
expect(writeFileSyncSpy).not.toHaveBeenCalledWith('package.json');
|
|
1312
|
+
expect(writeFileSyncSpy).not.toHaveBeenCalledWith('CHANGELOG.md');
|
|
1313
|
+
});
|
|
1314
|
+
});
|
|
888
1315
|
|
|
889
1316
|
it('does not update files present in .gitignore', async function () {
|
|
1317
|
+
const DotGitIgnore = require('dotgitignore');
|
|
1318
|
+
jest.mock('dotgitignore');
|
|
1319
|
+
|
|
1320
|
+
DotGitIgnore.mockImplementation(() => {
|
|
1321
|
+
return {
|
|
1322
|
+
ignore: (filename) => {
|
|
1323
|
+
if (filename === 'package-lock.json' || filename === 'bower.json') {
|
|
1324
|
+
return true;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
return false;
|
|
1328
|
+
},
|
|
1329
|
+
};
|
|
1330
|
+
});
|
|
1331
|
+
|
|
890
1332
|
mock({
|
|
891
1333
|
bump: 'minor',
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
)
|
|
912
|
-
|
|
913
|
-
|
|
1334
|
+
testFiles: [
|
|
1335
|
+
{
|
|
1336
|
+
path: 'bower.json',
|
|
1337
|
+
value: { version: '1.0.0' },
|
|
1338
|
+
},
|
|
1339
|
+
{
|
|
1340
|
+
path: 'package-lock.json',
|
|
1341
|
+
value: {
|
|
1342
|
+
name: '@org/package',
|
|
1343
|
+
version: '1.0.0',
|
|
1344
|
+
lockfileVersion: 1,
|
|
1345
|
+
},
|
|
1346
|
+
},
|
|
1347
|
+
],
|
|
1348
|
+
tags: ['v1.0.0'],
|
|
1349
|
+
});
|
|
1350
|
+
await exec();
|
|
1351
|
+
|
|
1352
|
+
// does not bump these as in .gitignore
|
|
1353
|
+
expect(writeFileSyncSpy).not.toHaveBeenCalledWith('package-lock.json');
|
|
1354
|
+
expect(writeFileSyncSpy).not.toHaveBeenCalledWith('bower.json');
|
|
1355
|
+
|
|
1356
|
+
// should still bump version in package.json
|
|
1357
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '1.1.0' });
|
|
1358
|
+
|
|
1359
|
+
DotGitIgnore.mockRestore();
|
|
1360
|
+
});
|
|
914
1361
|
|
|
915
1362
|
describe('configuration', function () {
|
|
916
1363
|
it('--header', async function () {
|
|
917
|
-
mock({ bump: 'minor',
|
|
918
|
-
await exec('--header="# Welcome to our CHANGELOG.md"')
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
1364
|
+
mock({ bump: 'minor', existingChangelog: '' });
|
|
1365
|
+
await exec('--header="# Welcome to our CHANGELOG.md"');
|
|
1366
|
+
|
|
1367
|
+
verifyNewChangelogContentMatches({
|
|
1368
|
+
writeFileSyncSpy,
|
|
1369
|
+
expectedContent: /# Welcome to our CHANGELOG.md/,
|
|
1370
|
+
});
|
|
1371
|
+
});
|
|
922
1372
|
|
|
923
1373
|
it('--issuePrefixes and --issueUrlFormat', async function () {
|
|
924
|
-
const format = 'http://www.foo.com/{{prefix}}{{id}}'
|
|
925
|
-
const prefix = 'ABC-'
|
|
1374
|
+
const format = 'http://www.foo.com/{{prefix}}{{id}}';
|
|
1375
|
+
const prefix = 'ABC-';
|
|
926
1376
|
const changelog = ({ preset }) =>
|
|
927
|
-
preset.issueUrlFormat + ':' + preset.issuePrefixes
|
|
928
|
-
mock({ bump: 'minor', changelog })
|
|
929
|
-
await exec(`--issuePrefixes="${prefix}" --issueUrlFormat="${format}"`)
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
1377
|
+
preset.issueUrlFormat + ':' + preset.issuePrefixes;
|
|
1378
|
+
mock({ bump: 'minor', changelog });
|
|
1379
|
+
await exec(`--issuePrefixes="${prefix}" --issueUrlFormat="${format}"`);
|
|
1380
|
+
|
|
1381
|
+
verifyNewChangelogContentMatches({
|
|
1382
|
+
writeFileSyncSpy,
|
|
1383
|
+
expectedContent: `${format}:${prefix}`,
|
|
1384
|
+
});
|
|
1385
|
+
});
|
|
1386
|
+
});
|
|
934
1387
|
|
|
935
1388
|
describe('pre-major', function () {
|
|
936
1389
|
it('bumps the minor rather than major, if version < 1.0.0', async function () {
|
|
937
1390
|
mock({
|
|
938
1391
|
bump: 'minor',
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1392
|
+
testFiles: [
|
|
1393
|
+
{
|
|
1394
|
+
path: 'package.json',
|
|
1395
|
+
value: {
|
|
1396
|
+
version: '0.5.0',
|
|
1397
|
+
repository: { url: 'https://github.com/yargs/yargs.git' },
|
|
1398
|
+
},
|
|
1399
|
+
},
|
|
1400
|
+
],
|
|
1401
|
+
});
|
|
1402
|
+
await exec();
|
|
1403
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '0.6.0' });
|
|
1404
|
+
});
|
|
947
1405
|
|
|
948
1406
|
it('bumps major if --release-as=major specified, if version < 1.0.0', async function () {
|
|
949
1407
|
mock({
|
|
950
1408
|
bump: 'major',
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
1409
|
+
testFiles: [
|
|
1410
|
+
{
|
|
1411
|
+
path: 'package.json',
|
|
1412
|
+
value: {
|
|
1413
|
+
version: '0.5.0',
|
|
1414
|
+
repository: { url: 'https://github.com/yargs/yargs.git' },
|
|
1415
|
+
},
|
|
1416
|
+
},
|
|
1417
|
+
],
|
|
1418
|
+
});
|
|
1419
|
+
await exec('-r major');
|
|
1420
|
+
verifyPackageVersion({ writeFileSyncSpy, expectedVersion: '1.0.0' });
|
|
1421
|
+
});
|
|
1422
|
+
});
|
|
1423
|
+
});
|
|
961
1424
|
|
|
962
1425
|
describe('GHSL-2020-111', function () {
|
|
963
|
-
afterEach(unmock)
|
|
1426
|
+
afterEach(unmock);
|
|
964
1427
|
|
|
965
1428
|
it('does not allow command injection via basic configuration', async function () {
|
|
966
|
-
mock({ bump: 'patch' })
|
|
1429
|
+
mock({ bump: 'patch' });
|
|
967
1430
|
await exec({
|
|
968
1431
|
noVerify: true,
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
})
|
|
1432
|
+
releaseCommitMessageFormat: 'bla `touch exploit`',
|
|
1433
|
+
});
|
|
1434
|
+
const stat = shell.test('-f', './exploit');
|
|
1435
|
+
expect(stat).toEqual(false);
|
|
1436
|
+
});
|
|
1437
|
+
});
|
|
976
1438
|
|
|
977
1439
|
describe('with mocked git', function () {
|
|
978
|
-
afterEach(unmock)
|
|
1440
|
+
afterEach(unmock);
|
|
979
1441
|
|
|
980
1442
|
it('--sign signs the commit and tag', async function () {
|
|
981
1443
|
const gitArgs = [
|
|
982
|
-
['add', 'CHANGELOG.md', 'package.json'],
|
|
1444
|
+
['add', 'CHANGELOG.md', 'package.json', 'package-lock.json'],
|
|
983
1445
|
[
|
|
984
1446
|
'commit',
|
|
985
1447
|
'-S',
|
|
986
1448
|
'CHANGELOG.md',
|
|
987
1449
|
'package.json',
|
|
1450
|
+
'package-lock.json',
|
|
988
1451
|
'-m',
|
|
989
|
-
'chore(release): 1.0.1'
|
|
1452
|
+
'chore(release): 1.0.1',
|
|
990
1453
|
],
|
|
991
1454
|
['tag', '-s', 'v1.0.1', '-m', 'chore(release): 1.0.1'],
|
|
992
|
-
['rev-parse', '--abbrev-ref', 'HEAD']
|
|
993
|
-
]
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1455
|
+
['rev-parse', '--abbrev-ref', 'HEAD'],
|
|
1456
|
+
];
|
|
1457
|
+
|
|
1458
|
+
runExecFile.mockImplementation((_args, cmd, cmdArgs) => {
|
|
1459
|
+
expect(cmd).toEqual('git');
|
|
1460
|
+
|
|
1461
|
+
const expected = gitArgs.shift();
|
|
1462
|
+
expect(cmdArgs).toEqual(expected);
|
|
1463
|
+
|
|
1464
|
+
if (expected[0] === 'rev-parse') return Promise.resolve('master');
|
|
1465
|
+
|
|
1466
|
+
return Promise.resolve('');
|
|
1467
|
+
});
|
|
1468
|
+
|
|
1469
|
+
mock({
|
|
1470
|
+
bump: 'patch',
|
|
1471
|
+
changelog: 'foo\n',
|
|
1472
|
+
});
|
|
1002
1473
|
|
|
1003
|
-
await exec('--sign', true)
|
|
1004
|
-
gitArgs.
|
|
1005
|
-
})
|
|
1474
|
+
await exec('--sign', true);
|
|
1475
|
+
expect(gitArgs).toHaveLength(0);
|
|
1476
|
+
});
|
|
1477
|
+
|
|
1478
|
+
it('--signedoff adds signed-off-by to the commit message', async function () {
|
|
1479
|
+
const gitArgs = [
|
|
1480
|
+
['add', 'CHANGELOG.md', 'package.json', 'package-lock.json'],
|
|
1481
|
+
[
|
|
1482
|
+
'commit',
|
|
1483
|
+
'--signoff',
|
|
1484
|
+
'CHANGELOG.md',
|
|
1485
|
+
'package.json',
|
|
1486
|
+
'package-lock.json',
|
|
1487
|
+
'-m',
|
|
1488
|
+
'chore(release): 1.0.1',
|
|
1489
|
+
],
|
|
1490
|
+
['tag', '-a', 'v1.0.1', '-m', 'chore(release): 1.0.1'],
|
|
1491
|
+
['rev-parse', '--abbrev-ref', 'HEAD'],
|
|
1492
|
+
];
|
|
1493
|
+
|
|
1494
|
+
runExecFile.mockImplementation((_args, cmd, cmdArgs) => {
|
|
1495
|
+
expect(cmd).toEqual('git');
|
|
1496
|
+
|
|
1497
|
+
const expected = gitArgs.shift();
|
|
1498
|
+
expect(cmdArgs).toEqual(expected);
|
|
1499
|
+
|
|
1500
|
+
if (expected[0] === 'rev-parse') return Promise.resolve('master');
|
|
1501
|
+
|
|
1502
|
+
return Promise.resolve('');
|
|
1503
|
+
});
|
|
1504
|
+
|
|
1505
|
+
mock({
|
|
1506
|
+
bump: 'patch',
|
|
1507
|
+
changelog: 'foo\n',
|
|
1508
|
+
});
|
|
1509
|
+
|
|
1510
|
+
await exec('--signoff', true);
|
|
1511
|
+
expect(gitArgs).toHaveLength(0);
|
|
1512
|
+
});
|
|
1006
1513
|
|
|
1007
1514
|
it('--tag-force forces tag replacement', async function () {
|
|
1008
1515
|
const gitArgs = [
|
|
1009
|
-
['add', 'CHANGELOG.md', 'package.json'],
|
|
1010
|
-
[
|
|
1516
|
+
['add', 'CHANGELOG.md', 'package.json', 'package-lock.json'],
|
|
1517
|
+
[
|
|
1518
|
+
'commit',
|
|
1519
|
+
'CHANGELOG.md',
|
|
1520
|
+
'package.json',
|
|
1521
|
+
'package-lock.json',
|
|
1522
|
+
'-m',
|
|
1523
|
+
'chore(release): 1.0.1',
|
|
1524
|
+
],
|
|
1011
1525
|
['tag', '-a', '-f', 'v1.0.1', '-m', 'chore(release): 1.0.1'],
|
|
1012
|
-
['rev-parse', '--abbrev-ref', 'HEAD']
|
|
1013
|
-
]
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
}
|
|
1021
|
-
mock({ bump: 'patch', changelog: 'foo\n', execFile })
|
|
1526
|
+
['rev-parse', '--abbrev-ref', 'HEAD'],
|
|
1527
|
+
];
|
|
1528
|
+
|
|
1529
|
+
runExecFile.mockImplementation((_args, cmd, cmdArgs) => {
|
|
1530
|
+
expect(cmd).toEqual('git');
|
|
1531
|
+
|
|
1532
|
+
const expected = gitArgs.shift();
|
|
1533
|
+
expect(cmdArgs).toEqual(expected);
|
|
1022
1534
|
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1535
|
+
if (expected[0] === 'rev-parse') return Promise.resolve('master');
|
|
1536
|
+
|
|
1537
|
+
return Promise.resolve('');
|
|
1538
|
+
});
|
|
1539
|
+
|
|
1540
|
+
mock({ bump: 'patch', changelog: 'foo\n' });
|
|
1541
|
+
|
|
1542
|
+
await exec('--tag-force', true);
|
|
1543
|
+
expect(gitArgs).toHaveLength(0);
|
|
1544
|
+
});
|
|
1026
1545
|
|
|
1027
1546
|
it('fails if git add fails', async function () {
|
|
1028
|
-
const gitArgs = [
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1547
|
+
const gitArgs = [
|
|
1548
|
+
['add', 'CHANGELOG.md', 'package.json', 'package-lock.json'],
|
|
1549
|
+
];
|
|
1550
|
+
const gitError = new Error('Command failed: git\nfailed add');
|
|
1551
|
+
|
|
1552
|
+
runExecFile.mockImplementation((_args, cmd, cmdArgs) => {
|
|
1553
|
+
expect(cmd).toEqual('git');
|
|
1554
|
+
|
|
1555
|
+
const expected = gitArgs.shift();
|
|
1556
|
+
expect(cmdArgs).toEqual(expected);
|
|
1034
1557
|
|
|
1035
1558
|
if (expected[0] === 'add') {
|
|
1036
|
-
return Promise.reject(gitError)
|
|
1559
|
+
return Promise.reject(gitError);
|
|
1037
1560
|
}
|
|
1038
|
-
return Promise.resolve('')
|
|
1039
|
-
}
|
|
1040
|
-
mock({ bump: 'patch', changelog: 'foo\n', execFile })
|
|
1561
|
+
return Promise.resolve('');
|
|
1562
|
+
});
|
|
1041
1563
|
|
|
1042
|
-
|
|
1043
|
-
|
|
1564
|
+
mock({ bump: 'patch', changelog: 'foo\n' });
|
|
1565
|
+
|
|
1566
|
+
await expect(exec({}, true)).rejects.toThrow(gitError);
|
|
1567
|
+
});
|
|
1044
1568
|
|
|
1045
1569
|
it('fails if git commit fails', async function () {
|
|
1046
1570
|
const gitArgs = [
|
|
1047
|
-
['add', 'CHANGELOG.md', 'package.json'],
|
|
1048
|
-
[
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1571
|
+
['add', 'CHANGELOG.md', 'package.json', 'package-lock.json'],
|
|
1572
|
+
[
|
|
1573
|
+
'commit',
|
|
1574
|
+
'CHANGELOG.md',
|
|
1575
|
+
'package.json',
|
|
1576
|
+
'package-lock.json',
|
|
1577
|
+
'-m',
|
|
1578
|
+
'chore(release): 1.0.1',
|
|
1579
|
+
],
|
|
1580
|
+
];
|
|
1581
|
+
const gitError = new Error('Command failed: git\nfailed commit');
|
|
1582
|
+
|
|
1583
|
+
runExecFile.mockImplementation((_args, cmd, cmdArgs) => {
|
|
1584
|
+
expect(cmd).toEqual('git');
|
|
1585
|
+
|
|
1586
|
+
const expected = gitArgs.shift();
|
|
1587
|
+
expect(cmdArgs).toEqual(expected);
|
|
1588
|
+
|
|
1055
1589
|
if (expected[0] === 'commit') {
|
|
1056
|
-
return Promise.reject(gitError)
|
|
1590
|
+
return Promise.reject(gitError);
|
|
1057
1591
|
}
|
|
1058
|
-
return Promise.resolve('')
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1592
|
+
return Promise.resolve('');
|
|
1593
|
+
});
|
|
1594
|
+
|
|
1595
|
+
mock({ bump: 'patch', changelog: 'foo\n' });
|
|
1061
1596
|
|
|
1062
|
-
await expect(exec({}, true)).
|
|
1063
|
-
})
|
|
1597
|
+
await expect(exec({}, true)).rejects.toThrow(gitError);
|
|
1598
|
+
});
|
|
1064
1599
|
|
|
1065
1600
|
it('fails if git tag fails', async function () {
|
|
1066
1601
|
const gitArgs = [
|
|
1067
|
-
['add', 'CHANGELOG.md', 'package.json'],
|
|
1068
|
-
[
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1602
|
+
['add', 'CHANGELOG.md', 'package.json', 'package-lock.json'],
|
|
1603
|
+
[
|
|
1604
|
+
'commit',
|
|
1605
|
+
'CHANGELOG.md',
|
|
1606
|
+
'package.json',
|
|
1607
|
+
'package-lock.json',
|
|
1608
|
+
'-m',
|
|
1609
|
+
'chore(release): 1.0.1',
|
|
1610
|
+
],
|
|
1611
|
+
['tag', '-a', 'v1.0.1', '-m', 'chore(release): 1.0.1'],
|
|
1612
|
+
];
|
|
1613
|
+
const gitError = new Error('Command failed: git\nfailed tag');
|
|
1614
|
+
|
|
1615
|
+
runExecFile.mockImplementation((_args, cmd, cmdArgs) => {
|
|
1616
|
+
expect(cmd).toEqual('git');
|
|
1617
|
+
|
|
1618
|
+
const expected = gitArgs.shift();
|
|
1619
|
+
expect(cmdArgs).toEqual(expected);
|
|
1620
|
+
|
|
1076
1621
|
if (expected[0] === 'tag') {
|
|
1077
|
-
return Promise.reject(gitError)
|
|
1622
|
+
return Promise.reject(gitError);
|
|
1078
1623
|
}
|
|
1079
|
-
return Promise.resolve('')
|
|
1624
|
+
return Promise.resolve('');
|
|
1625
|
+
});
|
|
1626
|
+
|
|
1627
|
+
mock({ bump: 'patch', changelog: 'foo\n' });
|
|
1628
|
+
|
|
1629
|
+
await expect(exec({}, true)).rejects.toThrow(gitError);
|
|
1630
|
+
});
|
|
1631
|
+
});
|
|
1632
|
+
|
|
1633
|
+
// ------- Verifiers ------
|
|
1634
|
+
function findWriteFileCallForPath({ writeFileSyncSpy, filename }) {
|
|
1635
|
+
// filePath is the first arg passed to writeFileSync
|
|
1636
|
+
return writeFileSyncSpy.mock.calls.find((args) =>
|
|
1637
|
+
args[0].includes(filename),
|
|
1638
|
+
);
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
function verifyPackageVersion({
|
|
1642
|
+
writeFileSyncSpy,
|
|
1643
|
+
expectedVersion,
|
|
1644
|
+
filename = 'package.json',
|
|
1645
|
+
asString = false,
|
|
1646
|
+
}) {
|
|
1647
|
+
// filePath is the first arg passed to writeFileSync
|
|
1648
|
+
const packageJsonWriteFileSynchCall = findWriteFileCallForPath({
|
|
1649
|
+
writeFileSyncSpy,
|
|
1650
|
+
filename,
|
|
1651
|
+
});
|
|
1652
|
+
|
|
1653
|
+
if (!packageJsonWriteFileSynchCall) {
|
|
1654
|
+
throw new Error(`writeFileSynch not invoked with path ${filename}`);
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
const calledWithContentStr = packageJsonWriteFileSynchCall[1];
|
|
1658
|
+
if (!asString) {
|
|
1659
|
+
// parse to JSON and verify has property
|
|
1660
|
+
const calledWithContent = JSON.parse(calledWithContentStr);
|
|
1661
|
+
|
|
1662
|
+
expect(calledWithContent).toHaveProperty('version');
|
|
1663
|
+
expect(calledWithContent.version).toEqual(expectedVersion);
|
|
1664
|
+
} else {
|
|
1665
|
+
// for non-JSON files i.e. .exs and .txt just verify version exists
|
|
1666
|
+
if (filename.includes('.exs')) {
|
|
1667
|
+
expect(calledWithContentStr).toMatch(`version: "${expectedVersion}"`);
|
|
1668
|
+
} else {
|
|
1669
|
+
expect(calledWithContentStr).toMatch(expectedVersion);
|
|
1080
1670
|
}
|
|
1081
|
-
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
function verifyFileContentEquals({
|
|
1675
|
+
writeFileSyncSpy,
|
|
1676
|
+
content,
|
|
1677
|
+
filename = 'package.json',
|
|
1678
|
+
}) {
|
|
1679
|
+
// filePath is the first arg passed to writeFileSync
|
|
1680
|
+
const packageJsonWriteFileSynchCall = findWriteFileCallForPath({
|
|
1681
|
+
writeFileSyncSpy,
|
|
1682
|
+
filename,
|
|
1683
|
+
});
|
|
1684
|
+
|
|
1685
|
+
if (!packageJsonWriteFileSynchCall) {
|
|
1686
|
+
throw new Error('writeFileSynch not invoked with path package.json');
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
const calledWithContentStr = packageJsonWriteFileSynchCall[1];
|
|
1082
1690
|
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1691
|
+
expect(calledWithContentStr).toEqual(content);
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
function verifyNewChangelogContentMatches({
|
|
1695
|
+
writeFileSyncSpy,
|
|
1696
|
+
expectedContent,
|
|
1697
|
+
}) {
|
|
1698
|
+
const changelogWriteFileSynchCall = findWriteFileCallForPath({
|
|
1699
|
+
writeFileSyncSpy,
|
|
1700
|
+
filename: 'CHANGELOG.md',
|
|
1701
|
+
});
|
|
1702
|
+
|
|
1703
|
+
if (!changelogWriteFileSynchCall) {
|
|
1704
|
+
throw new Error('writeFileSynch not invoked with path CHANGELOG.md');
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
const calledWithContent = changelogWriteFileSynchCall[1];
|
|
1708
|
+
expect(calledWithContent).toMatch(expectedContent);
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
function verifyNewChangelogContentEquals({
|
|
1712
|
+
writeFileSyncSpy,
|
|
1713
|
+
expectedContent,
|
|
1714
|
+
}) {
|
|
1715
|
+
const changelogWriteFileSynchCall = findWriteFileCallForPath({
|
|
1716
|
+
writeFileSyncSpy,
|
|
1717
|
+
filename: 'CHANGELOG.md',
|
|
1718
|
+
});
|
|
1719
|
+
|
|
1720
|
+
if (!changelogWriteFileSynchCall) {
|
|
1721
|
+
throw new Error('writeFileSynch not invoked with path CHANGELOG.md');
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
const calledWithContent = changelogWriteFileSynchCall[1];
|
|
1725
|
+
expect(calledWithContent).toEqual(expectedContent);
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
function verifyNewChangelogContentDoesNotMatch({
|
|
1729
|
+
writeFileSyncSpy,
|
|
1730
|
+
expectedContent,
|
|
1731
|
+
}) {
|
|
1732
|
+
const changelogWriteFileSynchCall = findWriteFileCallForPath({
|
|
1733
|
+
writeFileSyncSpy,
|
|
1734
|
+
filename: 'CHANGELOG.md',
|
|
1735
|
+
});
|
|
1736
|
+
|
|
1737
|
+
if (!changelogWriteFileSynchCall) {
|
|
1738
|
+
throw new Error('writeFileSynch not invoked with path CHANGELOG.md');
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
const calledWithContent = changelogWriteFileSynchCall[1];
|
|
1742
|
+
expect(calledWithContent).not.toMatch(expectedContent);
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
function verifyLogPrinted({ consoleInfoSpy, expectedLog }) {
|
|
1746
|
+
const consoleInfoLogs = consoleInfoSpy.mock.calls.map((args) => args[0]);
|
|
1747
|
+
const desiredLog = consoleInfoLogs.find((log) => log.includes(expectedLog));
|
|
1748
|
+
expect(desiredLog).not.toBeUndefined();
|
|
1749
|
+
expect(desiredLog).toMatch(expectedLog);
|
|
1750
|
+
}
|
|
1751
|
+
});
|