commit-and-tag-version 11.2.2 → 11.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yaml +1 -1
- package/.github/workflows/release-please.yml +1 -1
- package/CHANGELOG.md +15 -0
- package/lib/lifecycles/bump.js +46 -6
- package/package.json +2 -1
- package/test/config-files.spec.js +8 -11
- package/test/core.spec.js +149 -87
- package/test/git.spec.js +7 -11
|
@@ -16,7 +16,7 @@ jobs:
|
|
|
16
16
|
OS: ${{ matrix.os }}
|
|
17
17
|
NODE_VERSION: ${{ matrix.node }}
|
|
18
18
|
steps:
|
|
19
|
-
- uses: actions/checkout@
|
|
19
|
+
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
|
|
20
20
|
- run: git fetch --prune --unshallow
|
|
21
21
|
- run: git config --global user.name 'Actions'
|
|
22
22
|
- run: git config --global user.email 'dummy@example.org'
|
|
@@ -15,7 +15,7 @@ jobs:
|
|
|
15
15
|
release-type: node
|
|
16
16
|
package-name: commit-and-tag-version
|
|
17
17
|
# The logic below handles the npm publication:
|
|
18
|
-
- uses: actions/checkout@
|
|
18
|
+
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
|
|
19
19
|
# these if statements ensure that a publication only occurs when
|
|
20
20
|
# a new release is created:
|
|
21
21
|
if: ${{ steps.release.outputs.release_created }}
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [11.2.4](https://github.com/absolute-version/commit-and-tag-version/compare/v11.2.3...v11.2.4) (2023-10-02)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* allow bump task to handle versions with build metadata ([33913ee](https://github.com/absolute-version/commit-and-tag-version/commit/33913ee03bff2dfc26c9ffc942e1191c1f767949))
|
|
11
|
+
* handle invalid versions passed to releaseAs ([33913ee](https://github.com/absolute-version/commit-and-tag-version/commit/33913ee03bff2dfc26c9ffc942e1191c1f767949))
|
|
12
|
+
|
|
13
|
+
## [11.2.3](https://github.com/absolute-version/commit-and-tag-version/compare/v11.2.2...v11.2.3) (2023-08-22)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **bump:** propagate the parserOpts from args to conventionalRecommendedBump, fixing an issue with custom headerPatterns ([#89](https://github.com/absolute-version/commit-and-tag-version/issues/89)) ([bc685be](https://github.com/absolute-version/commit-and-tag-version/commit/bc685be46ca90417a03867717393bb9018e6036c))
|
|
19
|
+
|
|
5
20
|
## [11.2.2](https://github.com/absolute-version/commit-and-tag-version/compare/v11.2.1...v11.2.2) (2023-06-18)
|
|
6
21
|
|
|
7
22
|
|
package/lib/lifecycles/bump.js
CHANGED
|
@@ -20,16 +20,46 @@ async function Bump (args, version) {
|
|
|
20
20
|
configsToUpdate = {}
|
|
21
21
|
|
|
22
22
|
if (args.skip.bump) return version
|
|
23
|
+
|
|
24
|
+
if (args.releaseAs && !(['major', 'minor', 'patch'].includes(args.releaseAs.toLowerCase()) || semver.valid(args.releaseAs))) {
|
|
25
|
+
throw new Error("releaseAs must be one of 'major', 'minor' or 'patch', or a valid semvar version.")
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
let newVersion = version
|
|
24
29
|
await runLifecycleScript(args, 'prerelease')
|
|
25
30
|
const stdout = await runLifecycleScript(args, 'prebump')
|
|
26
|
-
if (stdout
|
|
27
|
-
|
|
31
|
+
if (stdout?.trim().length) {
|
|
32
|
+
const prebumpString = stdout.trim()
|
|
33
|
+
if (semver.valid(prebumpString)) args.releaseAs = prebumpString
|
|
34
|
+
}
|
|
28
35
|
if (!args.firstRelease) {
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
if (semver.valid(args.releaseAs)) {
|
|
37
|
+
const releaseAs = new semver.SemVer(args.releaseAs)
|
|
38
|
+
if (isString(args.prerelease) && releaseAs.prerelease.length && releaseAs.prerelease.slice(0, -1).join('.') !== args.prerelease) {
|
|
39
|
+
// If both releaseAs and the prerelease identifier are supplied, they must match. The behavior
|
|
40
|
+
// for a mismatch is undefined, so error out instead.
|
|
41
|
+
throw new Error('releaseAs and prerelease have conflicting prerelease identifiers')
|
|
42
|
+
} else if (isString(args.prerelease) && releaseAs.prerelease.length) {
|
|
43
|
+
newVersion = releaseAs.version
|
|
44
|
+
} else if (isString(args.prerelease)) {
|
|
45
|
+
newVersion = `${releaseAs.major}.${releaseAs.minor}.${releaseAs.patch}-${args.prerelease}.0`
|
|
46
|
+
} else {
|
|
47
|
+
newVersion = releaseAs.version
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Check if the previous version is the same version and prerelease, and increment if so
|
|
51
|
+
if (isString(args.prerelease) && ['prerelease', null].includes(semver.diff(version, newVersion)) && semver.lte(newVersion, version)) {
|
|
52
|
+
newVersion = semver.inc(version, 'prerelease', args.prerelease)
|
|
53
|
+
}
|
|
31
54
|
|
|
32
|
-
|
|
55
|
+
// Append any build info from releaseAs
|
|
56
|
+
newVersion = semvarToVersionStr(newVersion, releaseAs.build)
|
|
57
|
+
} else {
|
|
58
|
+
const release = await bumpVersion(args.releaseAs, version, args)
|
|
59
|
+
const releaseType = getReleaseType(args.prerelease, release.releaseType, version)
|
|
60
|
+
|
|
61
|
+
newVersion = semver.inc(version, releaseType, args.prerelease)
|
|
62
|
+
}
|
|
33
63
|
updateConfigs(args, newVersion)
|
|
34
64
|
} else {
|
|
35
65
|
checkpoint(args, 'skip version bump on first release', [], chalk.red(figures.cross))
|
|
@@ -42,6 +72,16 @@ Bump.getUpdatedConfigs = function () {
|
|
|
42
72
|
return configsToUpdate
|
|
43
73
|
}
|
|
44
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Convert a semver object to a full version string including build metadata
|
|
77
|
+
* @param {string} semverVersion The semvar version string
|
|
78
|
+
* @param {string[]} semverBuild An array of the build metadata elements, to be joined with '.'
|
|
79
|
+
* @returns {string}
|
|
80
|
+
*/
|
|
81
|
+
function semvarToVersionStr (semverVersion, semverBuild) {
|
|
82
|
+
return [semverVersion, semverBuild.join('.')].filter(Boolean).join('+')
|
|
83
|
+
}
|
|
84
|
+
|
|
45
85
|
function getReleaseType (prerelease, expectedReleaseType, currentVersion) {
|
|
46
86
|
if (isString(prerelease)) {
|
|
47
87
|
if (isInPrerelease(currentVersion)) {
|
|
@@ -124,7 +164,7 @@ function bumpVersion (releaseAs, currentVersion, args) {
|
|
|
124
164
|
path: args.path,
|
|
125
165
|
tagPrefix: args.tagPrefix,
|
|
126
166
|
lernaPackage: args.lernaPackage
|
|
127
|
-
}, function (err, release) {
|
|
167
|
+
}, args.parserOpts, function (err, release) {
|
|
128
168
|
if (err) return reject(err)
|
|
129
169
|
else return resolve(release)
|
|
130
170
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commit-and-tag-version",
|
|
3
|
-
"version": "11.2.
|
|
3
|
+
"version": "11.2.4",
|
|
4
4
|
"description": "replacement for `npm version` with automatic CHANGELOG generation",
|
|
5
5
|
"bin": "bin/cli.js",
|
|
6
6
|
"scripts": {
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"chai": "^4.2.0",
|
|
59
|
+
"chai-as-promised": "^7.1.1",
|
|
59
60
|
"eslint": "^8.16.0",
|
|
60
61
|
"eslint-config-standard": "^17.0.0",
|
|
61
62
|
"eslint-plugin-import": "^2.26.0",
|
|
@@ -8,7 +8,9 @@ const { Readable } = require('stream')
|
|
|
8
8
|
const mockery = require('mockery')
|
|
9
9
|
const stdMocks = require('std-mocks')
|
|
10
10
|
|
|
11
|
-
require('chai')
|
|
11
|
+
const chai = require('chai')
|
|
12
|
+
const expect = chai.expect
|
|
13
|
+
chai.use(require('chai-as-promised'))
|
|
12
14
|
|
|
13
15
|
function exec () {
|
|
14
16
|
const cli = require('../command')
|
|
@@ -22,15 +24,15 @@ function exec () {
|
|
|
22
24
|
*
|
|
23
25
|
* Mocks should be unregistered in test cleanup by calling unmock()
|
|
24
26
|
*
|
|
25
|
-
* bump?: 'major' | 'minor' | 'patch' | Error | (opt, cb) => { cb(err) | cb(null, { releaseType }) }
|
|
27
|
+
* bump?: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) }
|
|
26
28
|
* changelog?: string | Error | Array<string | Error | (opt) => string | null>
|
|
27
29
|
* tags?: string[] | Error
|
|
28
30
|
*/
|
|
29
31
|
function mock ({ bump, changelog, tags } = {}) {
|
|
30
32
|
mockery.enable({ warnOnUnregistered: false, useCleanCache: true })
|
|
31
33
|
|
|
32
|
-
mockery.registerMock('conventional-recommended-bump', function (opt, cb) {
|
|
33
|
-
if (typeof bump === 'function') bump(opt, cb)
|
|
34
|
+
mockery.registerMock('conventional-recommended-bump', function (opt, parserOpts, cb) {
|
|
35
|
+
if (typeof bump === 'function') bump(opt, parserOpts, cb)
|
|
34
36
|
else if (bump instanceof Error) cb(bump)
|
|
35
37
|
else cb(null, bump ? { releaseType: bump } : {})
|
|
36
38
|
})
|
|
@@ -168,12 +170,7 @@ describe('config files', () => {
|
|
|
168
170
|
it('throws an error when a non-object is returned from .versionrc.js', async function () {
|
|
169
171
|
mock({ bump: 'minor' })
|
|
170
172
|
fs.writeFileSync('.versionrc.js', 'module.exports = 3', 'utf-8')
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
/* istanbul ignore next */
|
|
174
|
-
throw new Error('Unexpected success')
|
|
175
|
-
} catch (error) {
|
|
176
|
-
error.message.should.match(/Invalid configuration/)
|
|
177
|
-
}
|
|
173
|
+
|
|
174
|
+
expect(exec).to.throw(/Invalid configuration/)
|
|
178
175
|
})
|
|
179
176
|
})
|
package/test/core.spec.js
CHANGED
|
@@ -14,7 +14,10 @@ const stripAnsi = require('strip-ansi')
|
|
|
14
14
|
const cli = require('../command')
|
|
15
15
|
const formatCommitMessage = require('../lib/format-commit-message')
|
|
16
16
|
|
|
17
|
-
const
|
|
17
|
+
const chai = require('chai')
|
|
18
|
+
const should = chai.should()
|
|
19
|
+
const expect = chai.expect
|
|
20
|
+
chai.use(require('chai-as-promised'))
|
|
18
21
|
|
|
19
22
|
// set by mock()
|
|
20
23
|
let standardVersion
|
|
@@ -36,7 +39,7 @@ function getPackageVersion () {
|
|
|
36
39
|
*
|
|
37
40
|
* Mocks should be unregistered in test cleanup by calling unmock()
|
|
38
41
|
*
|
|
39
|
-
* bump?: 'major' | 'minor' | 'patch' | Error | (opt, cb) => { cb(err) | cb(null, { releaseType }) }
|
|
42
|
+
* bump?: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) }
|
|
40
43
|
* changelog?: string | Error | Array<string | Error | (opt) => string | null>
|
|
41
44
|
* execFile?: ({ dryRun, silent }, cmd, cmdArgs) => Promise<string>
|
|
42
45
|
* fs?: { [string]: string | Buffer | any }
|
|
@@ -46,8 +49,8 @@ function getPackageVersion () {
|
|
|
46
49
|
function mock ({ bump, changelog, execFile, fs, pkg, tags } = {}) {
|
|
47
50
|
mockery.enable({ warnOnUnregistered: false, useCleanCache: true })
|
|
48
51
|
|
|
49
|
-
mockery.registerMock('conventional-recommended-bump', function (opt, cb) {
|
|
50
|
-
if (typeof bump === 'function') bump(opt, cb)
|
|
52
|
+
mockery.registerMock('conventional-recommended-bump', function (opt, parserOpts, cb) {
|
|
53
|
+
if (typeof bump === 'function') bump(opt, parserOpts, cb)
|
|
51
54
|
else if (bump instanceof Error) cb(bump)
|
|
52
55
|
else cb(null, bump ? { releaseType: bump } : {})
|
|
53
56
|
})
|
|
@@ -157,12 +160,7 @@ describe('cli', function () {
|
|
|
157
160
|
mock({ bump: 'minor', changelog: 'foo\n' })
|
|
158
161
|
await exec('--skip.changelog true')
|
|
159
162
|
getPackageVersion().should.equal('1.1.0')
|
|
160
|
-
|
|
161
|
-
fs.readFileSync('CHANGELOG.md', 'utf-8')
|
|
162
|
-
throw new Error('File should not exist')
|
|
163
|
-
} catch (err) {
|
|
164
|
-
err.code.should.equal('ENOENT')
|
|
165
|
-
}
|
|
163
|
+
expect(() => fs.readFileSync('CHANGELOG.md', 'utf-8')).to.throw(/ENOENT/)
|
|
166
164
|
})
|
|
167
165
|
})
|
|
168
166
|
|
|
@@ -217,12 +215,7 @@ describe('cli', function () {
|
|
|
217
215
|
|
|
218
216
|
it('[DEPRECATED] (--changelogHeader) exits with error if changelog header matches last version search regex', async function () {
|
|
219
217
|
mock({ bump: 'minor', fs: { 'CHANGELOG.md': '' } })
|
|
220
|
-
|
|
221
|
-
await exec('--changelogHeader="## 3.0.2"')
|
|
222
|
-
throw new Error('That should not have worked')
|
|
223
|
-
} catch (error) {
|
|
224
|
-
error.message.should.match(/custom changelog header must not match/)
|
|
225
|
-
}
|
|
218
|
+
expect(exec('--changelogHeader="## 3.0.2"')).to.be.rejectedWith(/custom changelog header must not match/)
|
|
226
219
|
})
|
|
227
220
|
})
|
|
228
221
|
|
|
@@ -249,17 +242,11 @@ describe('cli', function () {
|
|
|
249
242
|
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' }
|
|
250
243
|
})
|
|
251
244
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
})
|
|
258
|
-
/* istanbul ignore next */
|
|
259
|
-
throw new Error('Unexpected success')
|
|
260
|
-
} catch (error) {
|
|
261
|
-
error.message.should.match(/prerelease fail/)
|
|
262
|
-
}
|
|
245
|
+
expect(exec({
|
|
246
|
+
scripts: {
|
|
247
|
+
prerelease: "node -e \"throw new Error('prerelease' + ' fail')\""
|
|
248
|
+
}
|
|
249
|
+
})).to.be.rejectedWith(/prerelease fail/)
|
|
263
250
|
})
|
|
264
251
|
})
|
|
265
252
|
|
|
@@ -277,6 +264,49 @@ describe('cli', function () {
|
|
|
277
264
|
})
|
|
278
265
|
const { stdout } = flush()
|
|
279
266
|
stdout.join('').should.match(/9\.9\.9/)
|
|
267
|
+
getPackageVersion().should.equal('9.9.9')
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
it('should not allow prebump hook to return a releaseAs command', async function () {
|
|
271
|
+
mock({
|
|
272
|
+
bump: 'minor',
|
|
273
|
+
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' }
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
await exec({
|
|
277
|
+
scripts: {
|
|
278
|
+
prebump: "node -e \"console.log('major')\""
|
|
279
|
+
}
|
|
280
|
+
})
|
|
281
|
+
getPackageVersion().should.equal('1.1.0')
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
it('should allow prebump hook to return an arbitrary string', async function () {
|
|
285
|
+
mock({
|
|
286
|
+
bump: 'minor',
|
|
287
|
+
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' }
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
await exec({
|
|
291
|
+
scripts: {
|
|
292
|
+
prebump: "node -e \"console.log('Hello World')\""
|
|
293
|
+
}
|
|
294
|
+
})
|
|
295
|
+
getPackageVersion().should.equal('1.1.0')
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
it('should allow prebump hook to return a version with build info', async function () {
|
|
299
|
+
mock({
|
|
300
|
+
bump: 'minor',
|
|
301
|
+
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' }
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
await exec({
|
|
305
|
+
scripts: {
|
|
306
|
+
prebump: "node -e \"console.log('9.9.9-test+build')\""
|
|
307
|
+
}
|
|
308
|
+
})
|
|
309
|
+
getPackageVersion().should.equal('9.9.9-test+build')
|
|
280
310
|
})
|
|
281
311
|
})
|
|
282
312
|
|
|
@@ -302,18 +332,12 @@ describe('cli', function () {
|
|
|
302
332
|
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' }
|
|
303
333
|
})
|
|
304
334
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
await exec('--patch')
|
|
312
|
-
/* istanbul ignore next */
|
|
313
|
-
throw new Error('Unexpected success')
|
|
314
|
-
} catch (error) {
|
|
315
|
-
error.message.should.match(/postbump fail/)
|
|
316
|
-
}
|
|
335
|
+
expect(exec({
|
|
336
|
+
scripts: {
|
|
337
|
+
postbump: "node -e \"throw new Error('postbump' + ' fail')\""
|
|
338
|
+
}
|
|
339
|
+
})).to.be.rejectedWith(/postbump fail/)
|
|
340
|
+
expect(exec('--patch')).to.be.rejectedWith(/postbump fail/)
|
|
317
341
|
})
|
|
318
342
|
})
|
|
319
343
|
})
|
|
@@ -345,6 +369,12 @@ describe('cli', function () {
|
|
|
345
369
|
getPackageVersion().should.equal(`${nextVersion[type]}-${type}.0`)
|
|
346
370
|
})
|
|
347
371
|
})
|
|
372
|
+
|
|
373
|
+
it('exits with error if an invalid release type is provided', async function () {
|
|
374
|
+
mock({ bump: 'minor', fs: { 'CHANGELOG.md': '' } })
|
|
375
|
+
|
|
376
|
+
expect(exec('--release-as invalid')).to.be.rejectedWith(/releaseAs must be one of/)
|
|
377
|
+
})
|
|
348
378
|
})
|
|
349
379
|
|
|
350
380
|
describe('release-as-exact', function () {
|
|
@@ -395,17 +425,65 @@ describe('cli', function () {
|
|
|
395
425
|
bump: 'patch',
|
|
396
426
|
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
|
|
397
427
|
pkg: {
|
|
398
|
-
version: '100.0.0-amazing.
|
|
428
|
+
version: '100.0.0-amazing.1'
|
|
399
429
|
}
|
|
400
430
|
})
|
|
401
431
|
await exec('--release-as 100.0.0-amazing.0 --prerelease amazing')
|
|
402
|
-
should.equal(getPackageVersion(), '100.0.0-amazing.
|
|
432
|
+
should.equal(getPackageVersion(), '100.0.0-amazing.2')
|
|
433
|
+
})
|
|
434
|
+
|
|
435
|
+
it('release 100.0.0 with prerelease amazing correctly sets version', async function () {
|
|
436
|
+
mock({
|
|
437
|
+
bump: 'patch',
|
|
438
|
+
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
|
|
439
|
+
pkg: {
|
|
440
|
+
version: '99.0.0-amazing.0'
|
|
441
|
+
}
|
|
442
|
+
})
|
|
443
|
+
await exec('--release-as 100.0.0 --prerelease amazing')
|
|
444
|
+
should.equal(getPackageVersion(), '100.0.0-amazing.0')
|
|
445
|
+
})
|
|
446
|
+
|
|
447
|
+
it('release 100.0.0-amazing.0 with prerelease amazing correctly sets version', async function () {
|
|
448
|
+
mock({
|
|
449
|
+
bump: 'patch',
|
|
450
|
+
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
|
|
451
|
+
pkg: {
|
|
452
|
+
version: '99.0.0-amazing.0'
|
|
453
|
+
}
|
|
454
|
+
})
|
|
455
|
+
await exec('--release-as 100.0.0-amazing.0 --prerelease amazing')
|
|
456
|
+
should.equal(getPackageVersion(), '100.0.0-amazing.0')
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
it('release 100.0.0-amazing.0 with prerelease amazing retains build metadata', async function () {
|
|
460
|
+
mock({
|
|
461
|
+
bump: 'patch',
|
|
462
|
+
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
|
|
463
|
+
pkg: {
|
|
464
|
+
version: '100.0.0-amazing.0'
|
|
465
|
+
}
|
|
466
|
+
})
|
|
467
|
+
await exec('--release-as 100.0.0-amazing.0+build.1234 --prerelease amazing')
|
|
468
|
+
should.equal(getPackageVersion(), '100.0.0-amazing.1+build.1234')
|
|
469
|
+
})
|
|
470
|
+
|
|
471
|
+
it('release 100.0.0-amazing.3 with prerelease amazing correctly sets prerelease version', async function () {
|
|
472
|
+
mock({
|
|
473
|
+
bump: 'patch',
|
|
474
|
+
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
|
|
475
|
+
pkg: {
|
|
476
|
+
version: '100.0.0-amazing.0'
|
|
477
|
+
}
|
|
478
|
+
})
|
|
479
|
+
await exec('--release-as 100.0.0-amazing.3 --prerelease amazing')
|
|
480
|
+
should.equal(getPackageVersion(), '100.0.0-amazing.3')
|
|
403
481
|
})
|
|
404
482
|
})
|
|
405
483
|
|
|
406
484
|
it('creates a prerelease with a new minor version after two prerelease patches', async function () {
|
|
407
485
|
let releaseType = 'patch'
|
|
408
|
-
const bump = (_, cb) => cb(null, { releaseType })
|
|
486
|
+
const bump = (_, __, cb) => cb(null, { releaseType })
|
|
409
487
|
mock({
|
|
410
488
|
bump,
|
|
411
489
|
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' }
|
|
@@ -427,6 +505,19 @@ describe('cli', function () {
|
|
|
427
505
|
await exec('--prerelease dev')
|
|
428
506
|
getPackageVersion().should.equal('1.1.0-dev.2')
|
|
429
507
|
})
|
|
508
|
+
|
|
509
|
+
it('exits with error if an invalid release version is provided', async function () {
|
|
510
|
+
mock({ bump: 'minor', fs: { 'CHANGELOG.md': '' } })
|
|
511
|
+
|
|
512
|
+
expect(exec('--release-as 10.2')).to.be.rejectedWith(/releaseAs must be one of/)
|
|
513
|
+
})
|
|
514
|
+
|
|
515
|
+
it('exits with error if release version conflicts with prerelease', async function () {
|
|
516
|
+
mock({ bump: 'minor', fs: { 'CHANGELOG.md': '' } })
|
|
517
|
+
|
|
518
|
+
expect(exec('--release-as 1.2.3-amazing.2 --prerelease awesome')).to.be
|
|
519
|
+
.rejectedWith(/releaseAs and prerelease have conflicting prerelease identifiers/)
|
|
520
|
+
})
|
|
430
521
|
})
|
|
431
522
|
|
|
432
523
|
it('appends line feed at end of package.json', async function () {
|
|
@@ -478,35 +569,20 @@ describe('commit-and-tag-version', function () {
|
|
|
478
569
|
|
|
479
570
|
it('should exit on bump error', async function () {
|
|
480
571
|
mock({ bump: new Error('bump err') })
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
/* istanbul ignore next */
|
|
484
|
-
throw new Error('Unexpected success')
|
|
485
|
-
} catch (err) {
|
|
486
|
-
err.message.should.match(/bump err/)
|
|
487
|
-
}
|
|
572
|
+
|
|
573
|
+
expect(exec()).to.be.rejectedWith(/bump err/)
|
|
488
574
|
})
|
|
489
575
|
|
|
490
576
|
it('should exit on changelog error', async function () {
|
|
491
577
|
mock({ bump: 'minor', changelog: new Error('changelog err') })
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
/* istanbul ignore next */
|
|
495
|
-
throw new Error('Unexpected success')
|
|
496
|
-
} catch (err) {
|
|
497
|
-
err.message.should.match(/changelog err/)
|
|
498
|
-
}
|
|
578
|
+
|
|
579
|
+
expect(exec()).to.be.rejectedWith(/changelog err/)
|
|
499
580
|
})
|
|
500
581
|
|
|
501
582
|
it('should exit with error without a package file to bump', async function () {
|
|
502
583
|
mock({ bump: 'patch', pkg: false })
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
/* istanbul ignore next */
|
|
506
|
-
throw new Error('Unexpected success')
|
|
507
|
-
} catch (err) {
|
|
508
|
-
err.message.should.equal('no package file found')
|
|
509
|
-
}
|
|
584
|
+
|
|
585
|
+
expect(exec({ gitTagFallback: false })).to.be.rejectedWith('no package file found')
|
|
510
586
|
})
|
|
511
587
|
|
|
512
588
|
it('bumps version # in bower.json', async function () {
|
|
@@ -880,24 +956,20 @@ describe('with mocked git', function () {
|
|
|
880
956
|
|
|
881
957
|
it('fails if git add fails', async function () {
|
|
882
958
|
const gitArgs = [['add', 'CHANGELOG.md', 'package.json']]
|
|
959
|
+
const gitError = new Error('Command failed: git\nfailed add')
|
|
883
960
|
const execFile = (_args, cmd, cmdArgs) => {
|
|
884
961
|
cmd.should.equal('git')
|
|
885
962
|
const expected = gitArgs.shift()
|
|
886
963
|
cmdArgs.should.deep.equal(expected)
|
|
964
|
+
|
|
887
965
|
if (expected[0] === 'add') {
|
|
888
|
-
return Promise.reject(
|
|
966
|
+
return Promise.reject(gitError)
|
|
889
967
|
}
|
|
890
968
|
return Promise.resolve('')
|
|
891
969
|
}
|
|
892
970
|
mock({ bump: 'patch', changelog: 'foo\n', execFile })
|
|
893
971
|
|
|
894
|
-
|
|
895
|
-
await exec({}, true)
|
|
896
|
-
/* istanbul ignore next */
|
|
897
|
-
throw new Error('Unexpected success')
|
|
898
|
-
} catch (error) {
|
|
899
|
-
error.message.should.match(/failed add/)
|
|
900
|
-
}
|
|
972
|
+
expect(exec({}, true)).to.be.rejectedWith(gitError)
|
|
901
973
|
})
|
|
902
974
|
|
|
903
975
|
it('fails if git commit fails', async function () {
|
|
@@ -905,24 +977,19 @@ describe('with mocked git', function () {
|
|
|
905
977
|
['add', 'CHANGELOG.md', 'package.json'],
|
|
906
978
|
['commit', 'CHANGELOG.md', 'package.json', '-m', 'chore(release): 1.0.1']
|
|
907
979
|
]
|
|
980
|
+
const gitError = new Error('Command failed: git\nfailed commit')
|
|
908
981
|
const execFile = (_args, cmd, cmdArgs) => {
|
|
909
982
|
cmd.should.equal('git')
|
|
910
983
|
const expected = gitArgs.shift()
|
|
911
984
|
cmdArgs.should.deep.equal(expected)
|
|
912
985
|
if (expected[0] === 'commit') {
|
|
913
|
-
return Promise.reject(
|
|
986
|
+
return Promise.reject(gitError)
|
|
914
987
|
}
|
|
915
988
|
return Promise.resolve('')
|
|
916
989
|
}
|
|
917
990
|
mock({ bump: 'patch', changelog: 'foo\n', execFile })
|
|
918
991
|
|
|
919
|
-
|
|
920
|
-
await exec({}, true)
|
|
921
|
-
/* istanbul ignore next */
|
|
922
|
-
throw new Error('Unexpected success')
|
|
923
|
-
} catch (error) {
|
|
924
|
-
error.message.should.match(/failed commit/)
|
|
925
|
-
}
|
|
992
|
+
expect(exec({}, true)).to.be.rejectedWith(gitError)
|
|
926
993
|
})
|
|
927
994
|
|
|
928
995
|
it('fails if git tag fails', async function () {
|
|
@@ -931,23 +998,18 @@ describe('with mocked git', function () {
|
|
|
931
998
|
['commit', 'CHANGELOG.md', 'package.json', '-m', 'chore(release): 1.0.1'],
|
|
932
999
|
['tag', '-a', 'v1.0.1', '-m', 'chore(release): 1.0.1']
|
|
933
1000
|
]
|
|
1001
|
+
const gitError = new Error('Command failed: git\nfailed tag')
|
|
934
1002
|
const execFile = (_args, cmd, cmdArgs) => {
|
|
935
1003
|
cmd.should.equal('git')
|
|
936
1004
|
const expected = gitArgs.shift()
|
|
937
1005
|
cmdArgs.should.deep.equal(expected)
|
|
938
1006
|
if (expected[0] === 'tag') {
|
|
939
|
-
return Promise.reject(
|
|
1007
|
+
return Promise.reject(gitError)
|
|
940
1008
|
}
|
|
941
1009
|
return Promise.resolve('')
|
|
942
1010
|
}
|
|
943
1011
|
mock({ bump: 'patch', changelog: 'foo\n', execFile })
|
|
944
1012
|
|
|
945
|
-
|
|
946
|
-
await exec({}, true)
|
|
947
|
-
/* istanbul ignore next */
|
|
948
|
-
throw new Error('Unexpected success')
|
|
949
|
-
} catch (error) {
|
|
950
|
-
error.message.should.match(/failed tag/)
|
|
951
|
-
}
|
|
1013
|
+
expect(exec({}, true)).to.be.rejectedWith(gitError)
|
|
952
1014
|
})
|
|
953
1015
|
})
|
package/test/git.spec.js
CHANGED
|
@@ -8,7 +8,9 @@ const { Readable } = require('stream')
|
|
|
8
8
|
const mockery = require('mockery')
|
|
9
9
|
const stdMocks = require('std-mocks')
|
|
10
10
|
|
|
11
|
-
require('chai')
|
|
11
|
+
const chai = require('chai')
|
|
12
|
+
const expect = chai.expect
|
|
13
|
+
chai.use(require('chai-as-promised'))
|
|
12
14
|
|
|
13
15
|
function exec (opt = '') {
|
|
14
16
|
if (typeof opt === 'string') {
|
|
@@ -38,7 +40,7 @@ function getPackageVersion () {
|
|
|
38
40
|
/**
|
|
39
41
|
* Mock external conventional-changelog modules
|
|
40
42
|
*
|
|
41
|
-
* bump: 'major' | 'minor' | 'patch' | Error | (opt, cb) => { cb(err) | cb(null, { releaseType }) }
|
|
43
|
+
* bump: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) }
|
|
42
44
|
* changelog?: string | Error | Array<string | Error | (opt) => string | null>
|
|
43
45
|
* tags?: string[] | Error
|
|
44
46
|
*/
|
|
@@ -46,8 +48,8 @@ function mock ({ bump, changelog, tags }) {
|
|
|
46
48
|
if (bump === undefined) throw new Error('bump must be defined for mock()')
|
|
47
49
|
mockery.enable({ warnOnUnregistered: false, useCleanCache: true })
|
|
48
50
|
|
|
49
|
-
mockery.registerMock('conventional-recommended-bump', function (opt, cb) {
|
|
50
|
-
if (typeof bump === 'function') bump(opt, cb)
|
|
51
|
+
mockery.registerMock('conventional-recommended-bump', function (opt, parserOpts, cb) {
|
|
52
|
+
if (typeof bump === 'function') bump(opt, parserOpts, cb)
|
|
51
53
|
else if (bump instanceof Error) cb(bump)
|
|
52
54
|
else cb(null, { releaseType: bump })
|
|
53
55
|
})
|
|
@@ -356,13 +358,7 @@ describe('git', function () {
|
|
|
356
358
|
)
|
|
357
359
|
|
|
358
360
|
mock({ bump: 'minor' })
|
|
359
|
-
|
|
360
|
-
await exec('--patch')
|
|
361
|
-
/* istanbul ignore next */
|
|
362
|
-
throw new Error('Unexpected success')
|
|
363
|
-
} catch (error) {
|
|
364
|
-
error.message.should.match(/precommit-failure/)
|
|
365
|
-
}
|
|
361
|
+
expect(exec('--patch')).to.be.rejectedWith(/precommit-failure/)
|
|
366
362
|
})
|
|
367
363
|
|
|
368
364
|
it('should allow an alternate commit message to be provided by precommit script', async function () {
|