commit-and-tag-version 12.0.0 → 12.2.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 +14 -0
- package/README.md +17 -4
- 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 +44 -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/maven.js +44 -0
- package/lib/updaters/types/plain-text.js +4 -4
- package/lib/write-file.js +4 -4
- package/package.json +16 -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 +1438 -705
- 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/pom-6.3.1-crlf.xml +30 -0
- package/test/mocks/pom-6.3.1-lf.xml +30 -0
- package/test/mocks/pom-6.4.0-crlf.xml +30 -0
- package/test/mocks/pom-6.4.0-lf.xml +30 -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/git.spec.js
DELETED
|
@@ -1,480 +0,0 @@
|
|
|
1
|
-
/* global describe it beforeEach afterEach */
|
|
2
|
-
|
|
3
|
-
'use strict'
|
|
4
|
-
|
|
5
|
-
const shell = require('shelljs')
|
|
6
|
-
const fs = require('fs')
|
|
7
|
-
const { Readable } = require('stream')
|
|
8
|
-
const mockery = require('mockery')
|
|
9
|
-
const stdMocks = require('std-mocks')
|
|
10
|
-
|
|
11
|
-
const chai = require('chai')
|
|
12
|
-
const expect = chai.expect
|
|
13
|
-
chai.use(require('chai-as-promised'))
|
|
14
|
-
|
|
15
|
-
function exec (opt = '') {
|
|
16
|
-
if (typeof opt === 'string') {
|
|
17
|
-
const cli = require('../command')
|
|
18
|
-
opt = cli.parse(`commit-and-tag-version ${opt}`)
|
|
19
|
-
}
|
|
20
|
-
return require('../index')(opt)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function writePackageJson (version, option) {
|
|
24
|
-
const pkg = Object.assign({}, option, { version })
|
|
25
|
-
fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function writeHook (hookName, causeError, script) {
|
|
29
|
-
shell.mkdir('-p', 'scripts')
|
|
30
|
-
let content = script || 'console.error("' + hookName + ' ran")'
|
|
31
|
-
content += causeError ? '\nthrow new Error("' + hookName + '-failure")' : ''
|
|
32
|
-
fs.writeFileSync('scripts/' + hookName + '.js', content, 'utf-8')
|
|
33
|
-
fs.chmodSync('scripts/' + hookName + '.js', '755')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getPackageVersion () {
|
|
37
|
-
return JSON.parse(fs.readFileSync('package.json', 'utf-8')).version
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Mock external conventional-changelog modules
|
|
42
|
-
*
|
|
43
|
-
* bump: 'major' | 'minor' | 'patch' | Error | (opt, parserOpts, cb) => { cb(err) | cb(null, { releaseType }) }
|
|
44
|
-
* changelog?: string | Error | Array<string | Error | (opt) => string | null>
|
|
45
|
-
* tags?: string[] | Error
|
|
46
|
-
*/
|
|
47
|
-
function mock ({ bump, changelog, tags }) {
|
|
48
|
-
if (bump === undefined) throw new Error('bump must be defined for mock()')
|
|
49
|
-
mockery.enable({ warnOnUnregistered: false, useCleanCache: true })
|
|
50
|
-
|
|
51
|
-
mockery.registerMock('conventional-recommended-bump', function (opt, parserOpts, cb) {
|
|
52
|
-
if (typeof bump === 'function') bump(opt, parserOpts, cb)
|
|
53
|
-
else if (bump instanceof Error) cb(bump)
|
|
54
|
-
else cb(null, { releaseType: bump })
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
if (!Array.isArray(changelog)) changelog = [changelog]
|
|
58
|
-
mockery.registerMock(
|
|
59
|
-
'conventional-changelog',
|
|
60
|
-
(opt) =>
|
|
61
|
-
new Readable({
|
|
62
|
-
read (_size) {
|
|
63
|
-
const next = changelog.shift()
|
|
64
|
-
if (next instanceof Error) {
|
|
65
|
-
this.destroy(next)
|
|
66
|
-
} else if (typeof next === 'function') {
|
|
67
|
-
this.push(next(opt))
|
|
68
|
-
} else {
|
|
69
|
-
this.push(next ? Buffer.from(next, 'utf8') : null)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
mockery.registerMock('git-semver-tags', function (_, cb) {
|
|
76
|
-
if (tags instanceof Error) cb(tags)
|
|
77
|
-
else cb(null, tags || [])
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
stdMocks.use()
|
|
81
|
-
return () => stdMocks.flush()
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
describe('git', function () {
|
|
85
|
-
beforeEach(function () {
|
|
86
|
-
shell.rm('-rf', 'tmp')
|
|
87
|
-
shell.config.silent = true
|
|
88
|
-
shell.mkdir('tmp')
|
|
89
|
-
shell.cd('tmp')
|
|
90
|
-
shell.exec('git init')
|
|
91
|
-
shell.exec('git config commit.gpgSign false')
|
|
92
|
-
shell.exec('git config core.autocrlf false')
|
|
93
|
-
shell.exec('git commit --allow-empty -m"root-commit"')
|
|
94
|
-
writePackageJson('1.0.0')
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
afterEach(function () {
|
|
98
|
-
shell.cd('../')
|
|
99
|
-
shell.rm('-rf', 'tmp')
|
|
100
|
-
|
|
101
|
-
mockery.deregisterAll()
|
|
102
|
-
mockery.disable()
|
|
103
|
-
stdMocks.restore()
|
|
104
|
-
|
|
105
|
-
// push out prints from the Mocha reporter
|
|
106
|
-
const { stdout } = stdMocks.flush()
|
|
107
|
-
for (const str of stdout) {
|
|
108
|
-
if (str.startsWith(' ')) process.stdout.write(str)
|
|
109
|
-
}
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
describe('tagPrefix', function () {
|
|
113
|
-
// TODO: Use unmocked git-semver-tags and stage a git environment
|
|
114
|
-
it('will add prefix onto tag based on version from package', async function () {
|
|
115
|
-
writePackageJson('1.2.0')
|
|
116
|
-
mock({ bump: 'minor', tags: ['p-v1.2.0'] })
|
|
117
|
-
await exec('--tag-prefix p-v')
|
|
118
|
-
shell.exec('git tag').stdout.should.match(/p-v1\.3\.0/)
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('will add prefix onto tag via when gitTagFallback is true and no package [cli]', async function () {
|
|
122
|
-
shell.rm('package.json')
|
|
123
|
-
mock({
|
|
124
|
-
bump: 'minor',
|
|
125
|
-
tags: ['android/production/v1.2.0', 'android/production/v1.0.0']
|
|
126
|
-
})
|
|
127
|
-
await exec('--tag-prefix android/production/v')
|
|
128
|
-
shell
|
|
129
|
-
.exec('git tag')
|
|
130
|
-
.stdout.should.match(/android\/production\/v1\.3\.0/)
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
it('will add prefix onto tag via when gitTagFallback is true and no package [options]', async function () {
|
|
134
|
-
mock({
|
|
135
|
-
bump: 'minor',
|
|
136
|
-
tags: ['android/production/v1.2.0', 'android/production/v1.0.0']
|
|
137
|
-
})
|
|
138
|
-
await exec({ tagPrefix: 'android/production/v', packageFiles: [] })
|
|
139
|
-
shell
|
|
140
|
-
.exec('git tag')
|
|
141
|
-
.stdout.should.match(/android\/production\/v1\.3\.0/)
|
|
142
|
-
})
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it('formats the commit and tag messages appropriately', async function () {
|
|
146
|
-
mock({ bump: 'minor', tags: ['v1.0.0'] })
|
|
147
|
-
await exec({})
|
|
148
|
-
// check last commit message
|
|
149
|
-
shell
|
|
150
|
-
.exec('git log --oneline -n1')
|
|
151
|
-
.stdout.should.match(/chore\(release\): 1\.1\.0/)
|
|
152
|
-
// check annotated tag message
|
|
153
|
-
shell
|
|
154
|
-
.exec('git tag -l -n1 v1.1.0')
|
|
155
|
-
.stdout.should.match(/chore\(release\): 1\.1\.0/)
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
it('formats the tag if --first-release is true', async function () {
|
|
159
|
-
writePackageJson('1.0.1')
|
|
160
|
-
mock({ bump: 'minor' })
|
|
161
|
-
await exec('--first-release')
|
|
162
|
-
shell.exec('git tag').stdout.should.match(/1\.0\.1/)
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
it('commits all staged files', async function () {
|
|
166
|
-
fs.writeFileSync(
|
|
167
|
-
'CHANGELOG.md',
|
|
168
|
-
'legacy header format<a name="1.0.0">\n',
|
|
169
|
-
'utf-8'
|
|
170
|
-
)
|
|
171
|
-
fs.writeFileSync('STUFF.md', 'stuff\n', 'utf-8')
|
|
172
|
-
shell.exec('git add STUFF.md')
|
|
173
|
-
|
|
174
|
-
mock({ bump: 'patch', changelog: 'release 1.0.1\n', tags: ['v1.0.0'] })
|
|
175
|
-
await exec('--commit-all')
|
|
176
|
-
const status = shell.exec('git status --porcelain') // see http://unix.stackexchange.com/questions/155046/determine-if-git-working-directory-is-clean-from-a-script
|
|
177
|
-
status.should.equal('')
|
|
178
|
-
status.should.not.match(/STUFF.md/)
|
|
179
|
-
|
|
180
|
-
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
|
|
181
|
-
content.should.match(/1\.0\.1/)
|
|
182
|
-
content.should.not.match(/legacy header format/)
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
it('does not run git hooks if the --no-verify flag is passed', async function () {
|
|
186
|
-
fs.writeFileSync(
|
|
187
|
-
'.git/hooks/pre-commit',
|
|
188
|
-
'#!/bin/sh\necho "precommit ran"\nexit 1',
|
|
189
|
-
'utf-8'
|
|
190
|
-
)
|
|
191
|
-
fs.chmodSync('.git/hooks/pre-commit', '755')
|
|
192
|
-
|
|
193
|
-
mock({ bump: 'minor' })
|
|
194
|
-
await exec('--no-verify')
|
|
195
|
-
await exec('-n')
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
it('replaces tags if version not bumped', async function () {
|
|
199
|
-
mock({ bump: 'minor', tags: ['v1.0.0'] })
|
|
200
|
-
await exec({})
|
|
201
|
-
shell.exec('git describe').stdout.should.match(/v1\.1\.0/)
|
|
202
|
-
await exec('--tag-force --skip.bump')
|
|
203
|
-
shell.exec('git describe').stdout.should.match(/v1\.1\.0/)
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
it('allows the commit phase to be skipped', async function () {
|
|
207
|
-
const changelogContent = 'legacy header format<a name="1.0.0">\n'
|
|
208
|
-
writePackageJson('1.0.0')
|
|
209
|
-
fs.writeFileSync('CHANGELOG.md', changelogContent, 'utf-8')
|
|
210
|
-
|
|
211
|
-
mock({ bump: 'minor', changelog: 'new feature\n' })
|
|
212
|
-
await exec('--skip.commit true')
|
|
213
|
-
getPackageVersion().should.equal('1.1.0')
|
|
214
|
-
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
|
|
215
|
-
content.should.match(/new feature/)
|
|
216
|
-
shell.exec('git log --oneline -n1').stdout.should.match(/root-commit/)
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
it('dry-run skips all non-idempotent steps', async function () {
|
|
220
|
-
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
|
|
221
|
-
const flush = mock({
|
|
222
|
-
bump: 'minor',
|
|
223
|
-
changelog: '### Features\n',
|
|
224
|
-
tags: ['v1.0.0']
|
|
225
|
-
})
|
|
226
|
-
await exec('--dry-run')
|
|
227
|
-
const { stdout } = flush()
|
|
228
|
-
stdout.join('').should.match(/### Features/)
|
|
229
|
-
shell.exec('git log --oneline -n1').stdout.should.match(/root-commit/)
|
|
230
|
-
shell.exec('git tag').stdout.should.match(/1\.0\.0/)
|
|
231
|
-
getPackageVersion().should.equal('1.0.0')
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
it('works fine without specifying a tag id when prereleasing', async function () {
|
|
235
|
-
writePackageJson('1.0.0')
|
|
236
|
-
fs.writeFileSync(
|
|
237
|
-
'CHANGELOG.md',
|
|
238
|
-
'legacy header format<a name="1.0.0">\n',
|
|
239
|
-
'utf-8'
|
|
240
|
-
)
|
|
241
|
-
mock({ bump: 'minor' })
|
|
242
|
-
await exec('--prerelease')
|
|
243
|
-
getPackageVersion().should.equal('1.1.0-0')
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
describe('gitTagFallback', function () {
|
|
247
|
-
it('defaults to 1.0.0 if no tags in git history', async function () {
|
|
248
|
-
shell.rm('package.json')
|
|
249
|
-
mock({ bump: 'minor' })
|
|
250
|
-
await exec({})
|
|
251
|
-
const output = shell.exec('git tag')
|
|
252
|
-
output.stdout.should.include('v1.1.0')
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
it('bases version on greatest version tag, if tags are found', async function () {
|
|
256
|
-
shell.rm('package.json')
|
|
257
|
-
mock({ bump: 'minor', tags: ['v3.9.0', 'v5.0.0', 'v3.0.0'] })
|
|
258
|
-
await exec({})
|
|
259
|
-
const output = shell.exec('git tag')
|
|
260
|
-
output.stdout.should.include('v5.1.0')
|
|
261
|
-
})
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
describe('configuration', function () {
|
|
265
|
-
it('.versionrc : releaseCommitMessageFormat', async function () {
|
|
266
|
-
fs.writeFileSync(
|
|
267
|
-
'.versionrc',
|
|
268
|
-
JSON.stringify({
|
|
269
|
-
releaseCommitMessageFormat:
|
|
270
|
-
'This commit represents release: {{currentTag}}'
|
|
271
|
-
}),
|
|
272
|
-
'utf-8'
|
|
273
|
-
)
|
|
274
|
-
mock({ bump: 'minor' })
|
|
275
|
-
await exec('')
|
|
276
|
-
shell
|
|
277
|
-
.exec('git log --oneline -n1')
|
|
278
|
-
.should.include('This commit represents release: 1.1.0')
|
|
279
|
-
})
|
|
280
|
-
|
|
281
|
-
it('--releaseCommitMessageFormat', async function () {
|
|
282
|
-
mock({ bump: 'minor' })
|
|
283
|
-
await exec(
|
|
284
|
-
'--releaseCommitMessageFormat="{{currentTag}} is the version."'
|
|
285
|
-
)
|
|
286
|
-
shell
|
|
287
|
-
.exec('git log --oneline -n1')
|
|
288
|
-
.should.include('1.1.0 is the version.')
|
|
289
|
-
})
|
|
290
|
-
|
|
291
|
-
it('[LEGACY] supports --message (and single %s replacement)', async function () {
|
|
292
|
-
mock({ bump: 'minor' })
|
|
293
|
-
await exec('--message="V:%s"')
|
|
294
|
-
shell.exec('git log --oneline -n1').should.include('V:1.1.0')
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
it('[LEGACY] supports -m (and multiple %s replacements)', async function () {
|
|
298
|
-
mock({ bump: 'minor' })
|
|
299
|
-
await exec('--message="V:%s is the %s."')
|
|
300
|
-
shell
|
|
301
|
-
.exec('git log --oneline -n1')
|
|
302
|
-
.should.include('V:1.1.0 is the 1.1.0.')
|
|
303
|
-
})
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
describe('precommit hook', function () {
|
|
307
|
-
it('should run the precommit hook when provided via .versionrc.json (#371)', async function () {
|
|
308
|
-
fs.writeFileSync(
|
|
309
|
-
'.versionrc.json',
|
|
310
|
-
JSON.stringify({
|
|
311
|
-
scripts: { precommit: 'node scripts/precommit' }
|
|
312
|
-
}),
|
|
313
|
-
'utf-8'
|
|
314
|
-
)
|
|
315
|
-
|
|
316
|
-
writeHook('precommit')
|
|
317
|
-
fs.writeFileSync(
|
|
318
|
-
'CHANGELOG.md',
|
|
319
|
-
'legacy header format<a name="1.0.0">\n',
|
|
320
|
-
'utf-8'
|
|
321
|
-
)
|
|
322
|
-
const flush = mock({ bump: 'minor' })
|
|
323
|
-
await exec('')
|
|
324
|
-
const { stderr } = flush()
|
|
325
|
-
stderr[0].should.match(/precommit ran/)
|
|
326
|
-
})
|
|
327
|
-
|
|
328
|
-
it('should run the precommit hook when provided', async function () {
|
|
329
|
-
writePackageJson('1.0.0', {
|
|
330
|
-
'commit-and-tag-version': {
|
|
331
|
-
scripts: { precommit: 'node scripts/precommit' }
|
|
332
|
-
}
|
|
333
|
-
})
|
|
334
|
-
writeHook('precommit')
|
|
335
|
-
fs.writeFileSync(
|
|
336
|
-
'CHANGELOG.md',
|
|
337
|
-
'legacy header format<a name="1.0.0">\n',
|
|
338
|
-
'utf-8'
|
|
339
|
-
)
|
|
340
|
-
|
|
341
|
-
const flush = mock({ bump: 'minor' })
|
|
342
|
-
await exec('--patch')
|
|
343
|
-
const { stderr } = flush()
|
|
344
|
-
stderr[0].should.match(/precommit ran/)
|
|
345
|
-
})
|
|
346
|
-
|
|
347
|
-
it('should run the precommit hook and exit with error when precommit fails', async function () {
|
|
348
|
-
writePackageJson('1.0.0', {
|
|
349
|
-
'commit-and-tag-version': {
|
|
350
|
-
scripts: { precommit: 'node scripts/precommit' }
|
|
351
|
-
}
|
|
352
|
-
})
|
|
353
|
-
writeHook('precommit', true)
|
|
354
|
-
fs.writeFileSync(
|
|
355
|
-
'CHANGELOG.md',
|
|
356
|
-
'legacy header format<a name="1.0.0">\n',
|
|
357
|
-
'utf-8'
|
|
358
|
-
)
|
|
359
|
-
|
|
360
|
-
mock({ bump: 'minor' })
|
|
361
|
-
await expect(exec('--patch')).to.be.rejectedWith(/precommit-failure/)
|
|
362
|
-
})
|
|
363
|
-
|
|
364
|
-
it('should allow an alternate commit message to be provided by precommit script', async function () {
|
|
365
|
-
writePackageJson('1.0.0', {
|
|
366
|
-
'commit-and-tag-version': {
|
|
367
|
-
scripts: { precommit: 'node scripts/precommit' }
|
|
368
|
-
}
|
|
369
|
-
})
|
|
370
|
-
writeHook(
|
|
371
|
-
'precommit',
|
|
372
|
-
false,
|
|
373
|
-
'console.log("releasing %s delivers #222")'
|
|
374
|
-
)
|
|
375
|
-
fs.writeFileSync(
|
|
376
|
-
'CHANGELOG.md',
|
|
377
|
-
'legacy header format<a name="1.0.0">\n',
|
|
378
|
-
'utf-8'
|
|
379
|
-
)
|
|
380
|
-
|
|
381
|
-
mock({ bump: 'minor' })
|
|
382
|
-
await exec('--patch')
|
|
383
|
-
shell.exec('git log --oneline -n1').should.match(/delivers #222/)
|
|
384
|
-
})
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
describe('Run ... to publish', function () {
|
|
388
|
-
it('does normally display `npm publish`', async function () {
|
|
389
|
-
const flush = mock({ bump: 'patch' })
|
|
390
|
-
await exec('')
|
|
391
|
-
flush()
|
|
392
|
-
.stdout.join('')
|
|
393
|
-
.should.match(/npm publish/)
|
|
394
|
-
})
|
|
395
|
-
|
|
396
|
-
it('can display publish hints with custom npm client name', async function () {
|
|
397
|
-
const flush = mock({ bump: 'patch' })
|
|
398
|
-
await exec('--npmPublishHint "yarn publish"')
|
|
399
|
-
flush()
|
|
400
|
-
.stdout.join('')
|
|
401
|
-
.should.match(/yarn publish/)
|
|
402
|
-
})
|
|
403
|
-
|
|
404
|
-
it('does not display `npm publish` if the package is private', async function () {
|
|
405
|
-
writePackageJson('1.0.0', { private: true })
|
|
406
|
-
const flush = mock({ bump: 'patch' })
|
|
407
|
-
await exec('')
|
|
408
|
-
flush()
|
|
409
|
-
.stdout.join('')
|
|
410
|
-
.should.not.match(/npm publish/)
|
|
411
|
-
})
|
|
412
|
-
|
|
413
|
-
it('does not display `npm publish` if there is no package.json', async function () {
|
|
414
|
-
shell.rm('package.json')
|
|
415
|
-
const flush = mock({ bump: 'patch' })
|
|
416
|
-
await exec('')
|
|
417
|
-
flush()
|
|
418
|
-
.stdout.join('')
|
|
419
|
-
.should.not.match(/npm publish/)
|
|
420
|
-
})
|
|
421
|
-
|
|
422
|
-
it('does not display `all staged files` without the --commit-all flag', async function () {
|
|
423
|
-
const flush = mock({ bump: 'patch' })
|
|
424
|
-
await exec('')
|
|
425
|
-
flush()
|
|
426
|
-
.stdout.join('')
|
|
427
|
-
.should.not.match(/all staged files/)
|
|
428
|
-
})
|
|
429
|
-
|
|
430
|
-
it('does display `all staged files` if the --commit-all flag is passed', async function () {
|
|
431
|
-
const flush = mock({ bump: 'patch' })
|
|
432
|
-
await exec('--commit-all')
|
|
433
|
-
flush()
|
|
434
|
-
.stdout.join('')
|
|
435
|
-
.should.match(/all staged files/)
|
|
436
|
-
})
|
|
437
|
-
|
|
438
|
-
it('advises use of --tag prerelease for publishing to npm', async function () {
|
|
439
|
-
writePackageJson('1.0.0')
|
|
440
|
-
fs.writeFileSync(
|
|
441
|
-
'CHANGELOG.md',
|
|
442
|
-
'legacy header format<a name="1.0.0">\n',
|
|
443
|
-
'utf-8'
|
|
444
|
-
)
|
|
445
|
-
|
|
446
|
-
const flush = mock({ bump: 'patch' })
|
|
447
|
-
await exec('--prerelease')
|
|
448
|
-
const { stdout } = flush()
|
|
449
|
-
stdout.join('').should.include('--tag prerelease')
|
|
450
|
-
})
|
|
451
|
-
|
|
452
|
-
it('advises use of --tag alpha for publishing to npm when tagging alpha', async function () {
|
|
453
|
-
writePackageJson('1.0.0')
|
|
454
|
-
fs.writeFileSync(
|
|
455
|
-
'CHANGELOG.md',
|
|
456
|
-
'legacy header format<a name="1.0.0">\n',
|
|
457
|
-
'utf-8'
|
|
458
|
-
)
|
|
459
|
-
|
|
460
|
-
const flush = mock({ bump: 'patch' })
|
|
461
|
-
await exec('--prerelease alpha')
|
|
462
|
-
const { stdout } = flush()
|
|
463
|
-
stdout.join('').should.include('--tag alpha')
|
|
464
|
-
})
|
|
465
|
-
|
|
466
|
-
it('does not advise use of --tag prerelease for private modules', async function () {
|
|
467
|
-
writePackageJson('1.0.0', { private: true })
|
|
468
|
-
fs.writeFileSync(
|
|
469
|
-
'CHANGELOG.md',
|
|
470
|
-
'legacy header format<a name="1.0.0">\n',
|
|
471
|
-
'utf-8'
|
|
472
|
-
)
|
|
473
|
-
|
|
474
|
-
const flush = mock({ bump: 'minor' })
|
|
475
|
-
await exec('--prerelease')
|
|
476
|
-
const { stdout } = flush()
|
|
477
|
-
stdout.join('').should.not.include('--tag prerelease')
|
|
478
|
-
})
|
|
479
|
-
})
|
|
480
|
-
})
|
package/test/preset.spec.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/* global describe it beforeEach, afterEach */
|
|
2
|
-
|
|
3
|
-
const shell = require('shelljs')
|
|
4
|
-
const fs = require('fs')
|
|
5
|
-
|
|
6
|
-
require('chai').should()
|
|
7
|
-
|
|
8
|
-
function exec (opt) {
|
|
9
|
-
const cli = require('../command')
|
|
10
|
-
opt = cli.parse(`commit-and-tag-version ${opt} --silent`)
|
|
11
|
-
opt.skip = { commit: true, tag: true }
|
|
12
|
-
return require('../index')(opt)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
describe('presets', function () {
|
|
16
|
-
beforeEach(function () {
|
|
17
|
-
shell.rm('-rf', 'tmp')
|
|
18
|
-
shell.config.silent = true
|
|
19
|
-
shell.mkdir('tmp')
|
|
20
|
-
shell.cd('tmp')
|
|
21
|
-
shell.exec('git init')
|
|
22
|
-
shell.exec('git config commit.gpgSign false')
|
|
23
|
-
shell.exec('git config core.autocrlf false')
|
|
24
|
-
shell.exec('git commit --allow-empty -m "initial commit"')
|
|
25
|
-
shell.exec('git commit --allow-empty -m "feat: A feature commit."')
|
|
26
|
-
shell.exec('git commit --allow-empty -m "perf: A performance change."')
|
|
27
|
-
shell.exec('git commit --allow-empty -m "chore: A chore commit."')
|
|
28
|
-
shell.exec('git commit --allow-empty -m "ci: A ci commit."')
|
|
29
|
-
shell.exec('git commit --allow-empty -m "custom: A custom commit."')
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
afterEach(function () {
|
|
33
|
-
shell.cd('../')
|
|
34
|
-
shell.rm('-rf', 'tmp')
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it('Conventional Commits (default)', async function () {
|
|
38
|
-
await exec()
|
|
39
|
-
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
|
|
40
|
-
content.should.contain('### Features')
|
|
41
|
-
content.should.not.contain('### Performance Improvements')
|
|
42
|
-
content.should.not.contain('### Custom')
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('Angular', async function () {
|
|
46
|
-
await exec('--preset angular')
|
|
47
|
-
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
|
|
48
|
-
content.should.contain('### Features')
|
|
49
|
-
content.should.contain('### Performance Improvements')
|
|
50
|
-
content.should.not.contain('### Custom')
|
|
51
|
-
})
|
|
52
|
-
})
|