Socket
Socket
Sign inDemoInstall

commit-and-tag-version

Package Overview
Dependencies
155
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 11.3.0 to 12.0.0

.github/dependabot.yml

12

CHANGELOG.md

@@ -5,2 +5,14 @@ # Changelog

## [12.0.0](https://github.com/absolute-version/commit-and-tag-version/compare/v11.3.0...v12.0.0) (2023-10-31)
### ⚠ BREAKING CHANGES
* Drop support for node 14, 16. Now supports node 18 and 20.
### Bug Fixes
* Drop support for node 14, 16. Now supports node 18 and 20. ([b1a58bc](https://github.com/absolute-version/commit-and-tag-version/commit/b1a58bc2a786da48fbcec248204ff8631c79606e))
* preserve frontmatter when updating changelog ([#108](https://github.com/absolute-version/commit-and-tag-version/issues/108)) ([abdcfe2](https://github.com/absolute-version/commit-and-tag-version/commit/abdcfe295023f46c8724463940fff6a220434fad))
## [11.3.0](https://github.com/absolute-version/commit-and-tag-version/compare/v11.2.4...v11.3.0) (2023-10-10)

@@ -7,0 +19,0 @@

35

lib/lifecycles/changelog.js

@@ -21,2 +21,23 @@ const chalk = require('chalk')

/**
* Front matter is only extracted and therefore retained in final output where Changelog "header" begins with #Changelog,
* e.g. meets Standard-Version (last release) or commit-and-tag-version(current) format
*/
function extractFrontMatter (oldContent) {
const headerStart = oldContent.indexOf('# Changelog')
return headerStart !== -1 || headerStart !== 0
? oldContent.substring(0, headerStart)
: ''
}
/**
* find the position of the last release and remove header
*/
function extractChangelogBody (oldContent) {
const oldContentStart = oldContent.search(START_OF_LAST_RELEASE_PATTERN)
return oldContentStart !== -1
? oldContent.substring(oldContentStart)
: oldContent
}
function outputChangelog (args, newVersion) {

@@ -27,8 +48,8 @@ return new Promise((resolve, reject) => {

let oldContent = args.dryRun || args.releaseCount === 0 ? '' : fs.readFileSync(args.infile, 'utf-8')
const oldContentStart = oldContent.search(START_OF_LAST_RELEASE_PATTERN)
// find the position of the last release and remove header:
if (oldContentStart !== -1) {
oldContent = oldContent.substring(oldContentStart)
}
const oldContent = args.dryRun || args.releaseCount === 0 ? '' : fs.readFileSync(args.infile, 'utf-8')
const oldContentBody = extractChangelogBody(oldContent)
const changelogFrontMatter = extractFrontMatter(oldContent)
let content = ''

@@ -53,3 +74,3 @@ const context = { version: newVersion }

if (args.dryRun) console.info(`\n---\n${chalk.gray(content.trim())}\n---\n`)
else writeFile(args, args.infile, header + '\n' + (content + oldContent).replace(/\n+$/, '\n'))
else writeFile(args, args.infile, changelogFrontMatter + header + '\n' + (content + oldContentBody).replace(/\n+$/, '\n'))
return resolve()

@@ -56,0 +77,0 @@ })

24

package.json
{
"name": "commit-and-tag-version",
"version": "11.3.0",
"version": "12.0.0",
"description": "replacement for `npm version` with automatic CHANGELOG generation",

@@ -54,18 +54,20 @@ "bin": "bin/cli.js",

"git-semver-tags": "^5.0.0",
"semver": "^7.1.1",
"yargs": "^17.0.0"
"semver": "^7.5.4",
"yargs": "^17.7.2"
},
"devDependencies": {
"chai": "^4.2.0",
"@fintechstudios/eslint-plugin-chai-as-promised": "^3.1.0",
"chai": "^4.3.10",
"chai-as-promised": "^7.1.1",
"eslint": "^8.16.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint": "^8.52.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-mocha": "^10.2.0",
"eslint-plugin-n": "^15.2.0",
"eslint-plugin-promise": "^6.0.0",
"mocha": "^10.0.0",
"mock-fs": "^5.0.0",
"eslint-plugin-promise": "^6.1.1",
"mocha": "^10.2.0",
"mock-fs": "^5.2.0",
"mockery": "^2.1.0",
"nyc": "^15.1.0",
"shelljs": "^0.8.4",
"shelljs": "^0.8.5",
"std-mocks": "^1.0.1",

@@ -72,0 +74,0 @@ "strip-ansi": "^6.0.0"

@@ -5,5 +5,7 @@ # Commit and Tag Version

> **`Why was it renamed commit-and-tag-version?`**. I didn't want to scope the package or name it `standard-version-fork`, and it was a good opportunity to make the purpose of the tool clearer. I also wanted to distinguish it from the other tool in this organisation, [`absolute-version`](https://github.com/absolute-version/absolute-version-js), which just prints version information for pre-releases. To migrate, you can drop in `commit-and-tag-version` in place of `standard-version`. There are no changes in 9.5.0, other than to add the package.json config key `commit-and-tag-version` (the previous configuration key `standard-version` will still work).
> **`Can I simply swap the library to migrate?`** To migrate, you can drop in `commit-and-tag-version` in place of `standard-version`. There are no changes in 9.5.0, other than to add the package.json config key `commit-and-tag-version` (the previous configuration key `standard-version` will still work). 10.x drops support for deprecated node versions, 11.x is a formatting change if you're relying on the exact markdown format in the changelog, and 12.x drops support for node 14/16.
> **`Why was it renamed commit-and-tag-version?`**. I didn't want to scope the package or name it `standard-version-fork`, and it was a good opportunity to make the purpose of the tool clearer. I also wanted to distinguish it from the other tool in this organisation, [`absolute-version`](https://github.com/absolute-version/absolute-version-js), which just prints version information for pre-releases.
A utility for versioning using [semver](https://semver.org/) and CHANGELOG generation powered by [Conventional Commits](https://conventionalcommits.org).

@@ -10,0 +12,0 @@

@@ -67,3 +67,3 @@ /* global describe it beforeEach afterEach */

describe('config files', () => {
describe('config files', function () {
beforeEach(function () {

@@ -70,0 +70,0 @@ shell.rm('-rf', 'tmp')

@@ -168,7 +168,9 @@ /* global describe it afterEach */

describe('CHANGELOG.md exists', function () {
it('appends the new release above the last release, removing the old header (legacy format)', async function () {
it('appends the new release above the last release, removing the old header (legacy format), and does not retain any front matter', async function () {
const frontMatter =
'---\nstatus: new\n---\n'
mock({
bump: 'patch',
changelog: 'release 1.0.1\n',
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' },
fs: { 'CHANGELOG.md': frontMatter + 'legacy header format<a name="1.0.0">\n' },
tags: ['v1.0.0']

@@ -180,4 +182,58 @@ })

content.should.not.match(/legacy header format/)
content.should.not.match(/---status: new---/)
})
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 () {
const { header } = require('../defaults')
const standardVersionHeader =
'# 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.'
const frontMatter =
'---\nstatus: new\n---\n'
const changelog101 =
'### [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n'
const changelog100 =
'### [1.0.0](/compare/v0.0.1...v1.0.0) (YYYY-MM-DD)\n\n\n### Features\n\n* Version one feature set\n'
const initialChangelog = frontMatter + '\n' + standardVersionHeader + '\n' + changelog100
mock({
bump: 'patch',
changelog: changelog101,
fs: { 'CHANGELOG.md': initialChangelog },
tags: ['v1.0.0']
})
await exec()
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.equal(frontMatter + '\n' + header + '\n' + changelog101 + changelog100)
})
it('appends the new release above the last release, removing the old header (new format), and retains any front matter', async function () {
const { header } = require('../defaults')
const frontMatter =
'---\nstatus: new\n---\n'
const changelog101 =
'### [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n'
const changelog100 =
'### [1.0.0](/compare/v0.0.1...v1.0.0) (YYYY-MM-DD)\n\n\n### Features\n\n* Version one feature set\n'
const initialChangelog = frontMatter + '\n' + header + '\n' + changelog100
mock({
bump: 'patch',
changelog: changelog101,
fs: { 'CHANGELOG.md': initialChangelog },
tags: ['v1.0.0']
})
await exec()
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.equal(frontMatter + '\n' + header + '\n' + changelog101 + changelog100)
})
it('appends the new release above the last release, removing the old header (new format)', async function () {

@@ -220,7 +276,7 @@ const { header } = require('../defaults')

mock({ bump: 'minor', fs: { 'CHANGELOG.md': '' } })
expect(exec('--changelogHeader="## 3.0.2"')).to.be.rejectedWith(/custom changelog header must not match/)
await expect(exec('--changelogHeader="## 3.0.2"')).to.be.rejectedWith(/custom changelog header must not match/)
})
})
describe('lifecycle scripts', () => {
describe('lifecycle scripts', function () {
describe('prerelease hook', function () {

@@ -248,3 +304,3 @@ it('should run the prerelease hook when provided', async function () {

expect(exec({
await expect(exec({
scripts: {

@@ -339,3 +395,3 @@ prerelease: "node -e \"throw new Error('prerelease' + ' fail')\""

expect(exec({
await expect(exec({
scripts: {

@@ -345,14 +401,42 @@ postbump: "node -e \"throw new Error('postbump' + ' fail')\""

})).to.be.rejectedWith(/postbump fail/)
expect(exec('--patch')).to.be.rejectedWith(/postbump fail/)
})
})
})
describe('manual-release', function () {
describe('release-types', function () {
const regularTypes = ['major', 'minor', 'patch']
const nextVersion = { major: '2.0.0', minor: '1.1.0', patch: '1.0.1' }
describe('manual-release', function () {
describe('release-types', function () {
const regularTypes = ['major', 'minor', 'patch']
const nextVersion = { major: '2.0.0', minor: '1.1.0', patch: '1.0.1' }
regularTypes.forEach(function (type) {
it('creates a ' + type + ' release', async function () {
regularTypes.forEach(function (type) {
it('creates a ' + type + ' release', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' }
})
await exec('--release-as ' + type)
getPackageVersion().should.equal(nextVersion[type])
})
})
// this is for pre-releases
regularTypes.forEach(function (type) {
it('creates a pre' + type + ' release', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' }
})
await exec('--release-as ' + type + ' --prerelease ' + type)
getPackageVersion().should.equal(`${nextVersion[type]}-${type}.0`)
})
})
it('exits with error if an invalid release type is provided', async function () {
mock({ bump: 'minor', fs: { 'CHANGELOG.md': '' } })
await expect(exec('--release-as invalid')).to.be.rejectedWith(/releaseAs must be one of/)
})
})
describe('release-as-exact', function () {
it('releases as v100.0.0', async function () {
mock({

@@ -362,10 +446,7 @@ bump: 'patch',

})
await exec('--release-as ' + type)
getPackageVersion().should.equal(nextVersion[type])
await exec('--release-as v100.0.0')
getPackageVersion().should.equal('100.0.0')
})
})
// this is for pre-releases
regularTypes.forEach(function (type) {
it('creates a pre' + type + ' release', async function () {
it('releases as 200.0.0-amazing', async function () {
mock({

@@ -375,665 +456,639 @@ bump: 'patch',

})
await exec('--release-as ' + type + ' --prerelease ' + type)
getPackageVersion().should.equal(`${nextVersion[type]}-${type}.0`)
await exec('--release-as 200.0.0-amazing')
getPackageVersion().should.equal('200.0.0-amazing')
})
})
it('exits with error if an invalid release type is provided', async function () {
mock({ bump: 'minor', fs: { 'CHANGELOG.md': '' } })
expect(exec('--release-as invalid')).to.be.rejectedWith(/releaseAs must be one of/)
})
})
describe('release-as-exact', function () {
it('releases as v100.0.0', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' }
it('releases as 100.0.0 with prerelease amazing', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' },
pkg: {
version: '1.0.0'
}
})
await exec('--release-as 100.0.0 --prerelease amazing')
should.equal(getPackageVersion(), '100.0.0-amazing.0')
})
await exec('--release-as v100.0.0')
getPackageVersion().should.equal('100.0.0')
})
it('releases as 200.0.0-amazing', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' }
it('release 100.0.0 with prerelease amazing bumps build', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
pkg: {
version: '100.0.0-amazing.0'
}
})
await exec('--release-as 100.0.0 --prerelease amazing')
should.equal(getPackageVersion(), '100.0.0-amazing.1')
})
await exec('--release-as 200.0.0-amazing')
getPackageVersion().should.equal('200.0.0-amazing')
})
it('releases as 100.0.0 with prerelease amazing', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' },
pkg: {
version: '1.0.0'
}
it('release 100.0.0-amazing.0 with prerelease amazing bumps build', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
pkg: {
version: '100.0.0-amazing.1'
}
})
await exec('--release-as 100.0.0-amazing.0 --prerelease amazing')
should.equal(getPackageVersion(), '100.0.0-amazing.2')
})
await exec('--release-as 100.0.0 --prerelease amazing')
should.equal(getPackageVersion(), '100.0.0-amazing.0')
})
it('release 100.0.0 with prerelease amazing bumps build', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
pkg: {
version: '100.0.0-amazing.0'
}
it('release 100.0.0 with prerelease amazing correctly sets version', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
pkg: {
version: '99.0.0-amazing.0'
}
})
await exec('--release-as 100.0.0 --prerelease amazing')
should.equal(getPackageVersion(), '100.0.0-amazing.0')
})
await exec('--release-as 100.0.0 --prerelease amazing')
should.equal(getPackageVersion(), '100.0.0-amazing.1')
})
it('release 100.0.0-amazing.0 with prerelease amazing bumps build', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
pkg: {
version: '100.0.0-amazing.1'
}
it('release 100.0.0-amazing.0 with prerelease amazing correctly sets version', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
pkg: {
version: '99.0.0-amazing.0'
}
})
await exec('--release-as 100.0.0-amazing.0 --prerelease amazing')
should.equal(getPackageVersion(), '100.0.0-amazing.0')
})
await exec('--release-as 100.0.0-amazing.0 --prerelease amazing')
should.equal(getPackageVersion(), '100.0.0-amazing.2')
})
it('release 100.0.0 with prerelease amazing correctly sets version', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
pkg: {
version: '99.0.0-amazing.0'
}
it('release 100.0.0-amazing.0 with prerelease amazing retains build metadata', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
pkg: {
version: '100.0.0-amazing.0'
}
})
await exec('--release-as 100.0.0-amazing.0+build.1234 --prerelease amazing')
should.equal(getPackageVersion(), '100.0.0-amazing.1+build.1234')
})
await exec('--release-as 100.0.0 --prerelease amazing')
should.equal(getPackageVersion(), '100.0.0-amazing.0')
})
it('release 100.0.0-amazing.0 with prerelease amazing correctly sets version', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
pkg: {
version: '99.0.0-amazing.0'
}
it('release 100.0.0-amazing.3 with prerelease amazing correctly sets prerelease version', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
pkg: {
version: '100.0.0-amazing.0'
}
})
await exec('--release-as 100.0.0-amazing.3 --prerelease amazing')
should.equal(getPackageVersion(), '100.0.0-amazing.3')
})
await exec('--release-as 100.0.0-amazing.0 --prerelease amazing')
should.equal(getPackageVersion(), '100.0.0-amazing.0')
})
it('release 100.0.0-amazing.0 with prerelease amazing retains build metadata', async function () {
it('creates a prerelease with a new minor version after two prerelease patches', async function () {
let releaseType = 'patch'
const bump = (_, __, cb) => cb(null, { releaseType })
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
pkg: {
version: '100.0.0-amazing.0'
}
bump,
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' }
})
await exec('--release-as 100.0.0-amazing.0+build.1234 --prerelease amazing')
should.equal(getPackageVersion(), '100.0.0-amazing.1+build.1234')
})
it('release 100.0.0-amazing.3 with prerelease amazing correctly sets prerelease version', async function () {
mock({
bump: 'patch',
fs: { 'CHANGELOG.md': 'legacy header format<a name="100.0.0-amazing.0">\n' },
pkg: {
version: '100.0.0-amazing.0'
}
})
await exec('--release-as 100.0.0-amazing.3 --prerelease amazing')
should.equal(getPackageVersion(), '100.0.0-amazing.3')
})
})
await exec('--release-as patch --prerelease dev')
getPackageVersion().should.equal('1.0.1-dev.0')
it('creates a prerelease with a new minor version after two prerelease patches', async function () {
let releaseType = 'patch'
const bump = (_, __, cb) => cb(null, { releaseType })
mock({
bump,
fs: { 'CHANGELOG.md': 'legacy header format<a name="1.0.0">\n' }
await exec('--prerelease dev')
getPackageVersion().should.equal('1.0.1-dev.1')
releaseType = 'minor'
await exec('--release-as minor --prerelease dev')
getPackageVersion().should.equal('1.1.0-dev.0')
await exec('--release-as minor --prerelease dev')
getPackageVersion().should.equal('1.1.0-dev.1')
await exec('--prerelease dev')
getPackageVersion().should.equal('1.1.0-dev.2')
})
await exec('--release-as patch --prerelease dev')
getPackageVersion().should.equal('1.0.1-dev.0')
it('exits with error if an invalid release version is provided', async function () {
mock({ bump: 'minor', fs: { 'CHANGELOG.md': '' } })
await exec('--prerelease dev')
getPackageVersion().should.equal('1.0.1-dev.1')
await expect(exec('--release-as 10.2')).to.be.rejectedWith(/releaseAs must be one of/)
})
releaseType = 'minor'
await exec('--release-as minor --prerelease dev')
getPackageVersion().should.equal('1.1.0-dev.0')
it('exits with error if release version conflicts with prerelease', async function () {
mock({ bump: 'minor', fs: { 'CHANGELOG.md': '' } })
await exec('--release-as minor --prerelease dev')
getPackageVersion().should.equal('1.1.0-dev.1')
await expect(exec('--release-as 1.2.3-amazing.2 --prerelease awesome')).to.be
.rejectedWith(/releaseAs and prerelease have conflicting prerelease identifiers/)
})
})
await exec('--prerelease dev')
getPackageVersion().should.equal('1.1.0-dev.2')
it('appends line feed at end of package.json', async function () {
mock({ bump: 'patch' })
await exec()
const pkgJson = fs.readFileSync('package.json', 'utf-8')
pkgJson.should.equal('{\n "version": "1.0.1"\n}\n')
})
it('exits with error if an invalid release version is provided', async function () {
mock({ bump: 'minor', fs: { 'CHANGELOG.md': '' } })
it('preserves indentation of tabs in package.json', async function () {
mock({
bump: 'patch',
fs: { 'package.json': '{\n\t"version": "1.0.0"\n}\n' }
})
await exec()
const pkgJson = fs.readFileSync('package.json', 'utf-8')
pkgJson.should.equal('{\n\t"version": "1.0.1"\n}\n')
})
expect(exec('--release-as 10.2')).to.be.rejectedWith(/releaseAs must be one of/)
it('preserves indentation of spaces in package.json', async function () {
mock({
bump: 'patch',
fs: { 'package.json': '{\n "version": "1.0.0"\n}\n' }
})
await exec()
const pkgJson = fs.readFileSync('package.json', 'utf-8')
pkgJson.should.equal('{\n "version": "1.0.1"\n}\n')
})
it('exits with error if release version conflicts with prerelease', async function () {
mock({ bump: 'minor', fs: { 'CHANGELOG.md': '' } })
it('preserves carriage return + line feed in package.json', async function () {
mock({
bump: 'patch',
fs: { 'package.json': '{\r\n "version": "1.0.0"\r\n}\r\n' }
})
await exec()
const pkgJson = fs.readFileSync('package.json', 'utf-8')
pkgJson.should.equal('{\r\n "version": "1.0.1"\r\n}\r\n')
})
expect(exec('--release-as 1.2.3-amazing.2 --prerelease awesome')).to.be
.rejectedWith(/releaseAs and prerelease have conflicting prerelease identifiers/)
it('does not print output when the --silent flag is passed', async function () {
const flush = mock()
await exec('--silent')
flush().should.eql({ stdout: [], stderr: [] })
})
})
it('appends line feed at end of package.json', async function () {
mock({ bump: 'patch' })
await exec()
const pkgJson = fs.readFileSync('package.json', 'utf-8')
pkgJson.should.equal('{\n "version": "1.0.1"\n}\n')
})
describe('commit-and-tag-version', function () {
afterEach(unmock)
it('preserves indentation of tabs in package.json', async function () {
mock({
bump: 'patch',
fs: { 'package.json': '{\n\t"version": "1.0.0"\n}\n' }
})
await exec()
const pkgJson = fs.readFileSync('package.json', 'utf-8')
pkgJson.should.equal('{\n\t"version": "1.0.1"\n}\n')
})
it('should exit on bump error', async function () {
mock({ bump: new Error('bump err') })
it('preserves indentation of spaces in package.json', async function () {
mock({
bump: 'patch',
fs: { 'package.json': '{\n "version": "1.0.0"\n}\n' }
await expect(exec()).to.be.rejectedWith(/bump err/)
})
await exec()
const pkgJson = fs.readFileSync('package.json', 'utf-8')
pkgJson.should.equal('{\n "version": "1.0.1"\n}\n')
})
it('preserves carriage return + line feed in package.json', async function () {
mock({
bump: 'patch',
fs: { 'package.json': '{\r\n "version": "1.0.0"\r\n}\r\n' }
it('should exit on changelog error', async function () {
mock({ bump: 'minor', changelog: new Error('changelog err') })
await expect(exec()).to.be.rejectedWith(/changelog err/)
})
await exec()
const pkgJson = fs.readFileSync('package.json', 'utf-8')
pkgJson.should.equal('{\r\n "version": "1.0.1"\r\n}\r\n')
})
it('does not print output when the --silent flag is passed', async function () {
const flush = mock()
await exec('--silent')
flush().should.eql({ stdout: [], stderr: [] })
})
})
it('should exit with error without a package file to bump', async function () {
mock({ bump: 'patch', pkg: false })
describe('commit-and-tag-version', function () {
afterEach(unmock)
await expect(exec({ gitTagFallback: false })).to.be.rejectedWith('no package file found')
})
it('should exit on bump error', async function () {
mock({ bump: new Error('bump err') })
it('bumps version # in bower.json', async function () {
mock({
bump: 'minor',
fs: { 'bower.json': JSON.stringify({ version: '1.0.0' }) },
tags: ['v1.0.0']
})
await exec()
JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal(
'1.1.0'
)
getPackageVersion().should.equal('1.1.0')
})
expect(exec()).to.be.rejectedWith(/bump err/)
})
it('bumps version # in manifest.json', async function () {
mock({
bump: 'minor',
fs: { 'manifest.json': JSON.stringify({ version: '1.0.0' }) },
tags: ['v1.0.0']
})
await exec()
JSON.parse(fs.readFileSync('manifest.json', 'utf-8')).version.should.equal(
'1.1.0'
)
getPackageVersion().should.equal('1.1.0')
})
it('should exit on changelog error', async function () {
mock({ bump: 'minor', changelog: new Error('changelog err') })
describe('custom `bumpFiles` support', function () {
it('mix.exs + version.txt', async function () {
const updater = 'custom-updater.js'
const updaterModule = require('./mocks/updater/customer-updater')
mock({
bump: 'minor',
fs: {
'mix.exs': fs.readFileSync('./test/mocks/mix.exs'),
'version.txt': fs.readFileSync('./test/mocks/version.txt')
},
tags: ['v1.0.0']
})
mockery.registerMock(resolve(process.cwd(), updater), updaterModule)
expect(exec()).to.be.rejectedWith(/changelog err/)
})
await exec({
bumpFiles: [
'version.txt',
{ filename: 'mix.exs', updater: 'custom-updater.js' }
]
})
fs.readFileSync('mix.exs', 'utf-8').should.contain('version: "1.1.0"')
fs.readFileSync('version.txt', 'utf-8').should.equal('1.1.0')
})
it('should exit with error without a package file to bump', async function () {
mock({ bump: 'patch', pkg: false })
it('bumps a custom `plain-text` file', async function () {
mock({
bump: 'minor',
fs: {
'VERSION_TRACKER.txt': fs.readFileSync(
'./test/mocks/VERSION-1.0.0.txt'
)
}
})
await exec({
bumpFiles: [{ filename: 'VERSION_TRACKER.txt', type: 'plain-text' }]
})
fs.readFileSync('VERSION_TRACKER.txt', 'utf-8').should.equal('1.1.0')
})
expect(exec({ gitTagFallback: false })).to.be.rejectedWith('no package file found')
})
it('displays the new version from custom bumper with --dry-run', async function () {
const updater = 'increment-updater.js'
const updaterModule = require('./mocks/updater/increment-updater')
mock({
bump: 'minor',
fs: {
'increment-version.txt': fs.readFileSync(
'./test/mocks/increment-version.txt'
)
}
})
mockery.registerMock(resolve(process.cwd(), updater), updaterModule)
it('bumps version # in bower.json', async function () {
mock({
bump: 'minor',
fs: { 'bower.json': JSON.stringify({ version: '1.0.0' }) },
tags: ['v1.0.0']
const origInfo = console.info
const capturedOutput = []
console.info = (...args) => {
capturedOutput.push(...args)
origInfo(...args)
}
try {
await exec({
bumpFiles: [{ filename: 'increment-version.txt', updater: 'increment-updater.js' }],
dryRun: true
})
const logOutput = capturedOutput.join(' ')
stripAnsi(logOutput).should.include('bumping version in increment-version.txt from 1 to 2')
} finally {
console.info = origInfo
}
})
})
await exec()
JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal(
'1.1.0'
)
getPackageVersion().should.equal('1.1.0')
})
it('bumps version # in manifest.json', async function () {
mock({
bump: 'minor',
fs: { 'manifest.json': JSON.stringify({ version: '1.0.0' }) },
tags: ['v1.0.0']
describe('custom `packageFiles` support', function () {
it('reads and writes to a custom `plain-text` file', async function () {
mock({
bump: 'minor',
fs: {
'VERSION_TRACKER.txt': fs.readFileSync(
'./test/mocks/VERSION-6.3.1.txt'
)
}
})
await exec({
packageFiles: [{ filename: 'VERSION_TRACKER.txt', type: 'plain-text' }],
bumpFiles: [{ filename: 'VERSION_TRACKER.txt', type: 'plain-text' }]
})
fs.readFileSync('VERSION_TRACKER.txt', 'utf-8').should.equal('6.4.0')
})
it('allows same object to be used in packageFiles and bumpFiles', async function () {
mock({
bump: 'minor',
fs: {
'VERSION_TRACKER.txt': fs.readFileSync(
'./test/mocks/VERSION-6.3.1.txt'
)
}
})
const origWarn = console.warn
console.warn = () => {
throw new Error('console.warn should not be called')
}
const filedesc = { filename: 'VERSION_TRACKER.txt', type: 'plain-text' }
try {
await exec({ packageFiles: [filedesc], bumpFiles: [filedesc] })
fs.readFileSync('VERSION_TRACKER.txt', 'utf-8').should.equal('6.4.0')
} finally {
console.warn = origWarn
}
})
})
await exec()
JSON.parse(fs.readFileSync('manifest.json', 'utf-8')).version.should.equal(
'1.1.0'
)
getPackageVersion().should.equal('1.1.0')
})
describe('custom `bumpFiles` support', function () {
it('mix.exs + version.txt', async function () {
const updater = 'custom-updater.js'
const updaterModule = require('./mocks/updater/customer-updater')
it('`packageFiles` are bumped along with `bumpFiles` defaults [commit-and-tag-version#533]', async function () {
mock({
bump: 'minor',
fs: {
'mix.exs': fs.readFileSync('./test/mocks/mix.exs'),
'version.txt': fs.readFileSync('./test/mocks/version.txt')
'.gitignore': '',
'package-lock.json': JSON.stringify({ version: '1.0.0' }),
'manifest.json': fs.readFileSync('./test/mocks/manifest-6.3.1.json')
},
tags: ['v1.0.0']
})
mockery.registerMock(resolve(process.cwd(), updater), updaterModule)
await exec({
bumpFiles: [
'version.txt',
{ filename: 'mix.exs', updater: 'custom-updater.js' }
silent: true,
packageFiles: [
{
filename: 'manifest.json',
type: 'json'
}
]
})
fs.readFileSync('mix.exs', 'utf-8').should.contain('version: "1.1.0"')
fs.readFileSync('version.txt', 'utf-8').should.equal('1.1.0')
JSON.parse(fs.readFileSync('manifest.json', 'utf-8')).version.should.equal(
'6.4.0'
)
JSON.parse(fs.readFileSync('package.json', 'utf-8')).version.should.equal(
'6.4.0'
)
JSON.parse(
fs.readFileSync('package-lock.json', 'utf-8')
).version.should.equal('6.4.0')
})
it('bumps a custom `plain-text` file', async function () {
it('bumps version in Gradle `build.gradle.kts` file', async function () {
const expected = fs.readFileSync('./test/mocks/build-6.4.0.gradle.kts', 'utf-8')
mock({
bump: 'minor',
fs: {
'VERSION_TRACKER.txt': fs.readFileSync(
'./test/mocks/VERSION-1.0.0.txt'
)
'build.gradle.kts': fs.readFileSync('./test/mocks/build-6.3.1.gradle.kts')
}
})
await exec({
bumpFiles: [{ filename: 'VERSION_TRACKER.txt', type: 'plain-text' }]
packageFiles: [{ filename: 'build.gradle.kts', type: 'gradle' }],
bumpFiles: [{ filename: 'build.gradle.kts', type: 'gradle' }]
})
fs.readFileSync('VERSION_TRACKER.txt', 'utf-8').should.equal('1.1.0')
fs.readFileSync('build.gradle.kts', 'utf-8').should.equal(expected)
})
it('displays the new version from custom bumper with --dry-run', async function () {
const updater = 'increment-updater.js'
const updaterModule = require('./mocks/updater/increment-updater')
it('bumps version in .NET `Project.csproj` file', async function () {
const expected = fs.readFileSync('./test/mocks/Project-6.4.0.csproj', 'utf-8')
const filename = 'Project.csproj'
mock({
bump: 'minor',
fs: {
'increment-version.txt': fs.readFileSync(
'./test/mocks/increment-version.txt'
)
[filename]: fs.readFileSync('./test/mocks/Project-6.3.1.csproj')
}
})
mockery.registerMock(resolve(process.cwd(), updater), updaterModule)
const origInfo = console.info
const capturedOutput = []
console.info = (...args) => {
capturedOutput.push(...args)
origInfo(...args)
}
try {
await exec({
bumpFiles: [{ filename: 'increment-version.txt', updater: 'increment-updater.js' }],
dryRun: true
})
const logOutput = capturedOutput.join(' ')
stripAnsi(logOutput).should.include('bumping version in increment-version.txt from 1 to 2')
} finally {
console.info = origInfo
}
await exec({
packageFiles: [{ filename, type: 'csproj' }],
bumpFiles: [{ filename, type: 'csproj' }]
})
fs.readFileSync(filename, 'utf-8').should.equal(expected)
})
})
describe('custom `packageFiles` support', function () {
it('reads and writes to a custom `plain-text` file', async function () {
it('bumps version # in npm-shrinkwrap.json', async function () {
mock({
bump: 'minor',
fs: {
'VERSION_TRACKER.txt': fs.readFileSync(
'./test/mocks/VERSION-6.3.1.txt'
)
}
'npm-shrinkwrap.json': JSON.stringify({ version: '1.0.0' })
},
tags: ['v1.0.0']
})
await exec({
packageFiles: [{ filename: 'VERSION_TRACKER.txt', type: 'plain-text' }],
bumpFiles: [{ filename: 'VERSION_TRACKER.txt', type: 'plain-text' }]
})
fs.readFileSync('VERSION_TRACKER.txt', 'utf-8').should.equal('6.4.0')
await exec()
JSON.parse(
fs.readFileSync('npm-shrinkwrap.json', 'utf-8')
).version.should.equal('1.1.0')
getPackageVersion().should.equal('1.1.0')
})
it('allows same object to be used in packageFiles and bumpFiles', async function () {
it('bumps version # in package-lock.json', async function () {
mock({
bump: 'minor',
fs: {
'VERSION_TRACKER.txt': fs.readFileSync(
'./test/mocks/VERSION-6.3.1.txt'
)
}
'.gitignore': '',
'package-lock.json': JSON.stringify({ version: '1.0.0' })
},
tags: ['v1.0.0']
})
const origWarn = console.warn
console.warn = () => {
throw new Error('console.warn should not be called')
}
const filedesc = { filename: 'VERSION_TRACKER.txt', type: 'plain-text' }
try {
await exec({ packageFiles: [filedesc], bumpFiles: [filedesc] })
fs.readFileSync('VERSION_TRACKER.txt', 'utf-8').should.equal('6.4.0')
} finally {
console.warn = origWarn
}
await exec()
JSON.parse(
fs.readFileSync('package-lock.json', 'utf-8')
).version.should.equal('1.1.0')
getPackageVersion().should.equal('1.1.0')
})
})
it('`packageFiles` are bumped along with `bumpFiles` defaults [commit-and-tag-version#533]', async function () {
mock({
bump: 'minor',
fs: {
'.gitignore': '',
'package-lock.json': JSON.stringify({ version: '1.0.0' }),
'manifest.json': fs.readFileSync('./test/mocks/manifest-6.3.1.json')
},
tags: ['v1.0.0']
})
describe('skip', function () {
it('allows bump and changelog generation to be skipped', async function () {
const changelogContent = 'legacy header format<a name="1.0.0">\n'
mock({
bump: 'minor',
changelog: 'foo\n',
fs: { 'CHANGELOG.md': changelogContent }
})
await exec({
silent: true,
packageFiles: [
{
filename: 'manifest.json',
type: 'json'
}
]
await exec('--skip.bump true --skip.changelog true')
getPackageVersion().should.equal('1.0.0')
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.equal(changelogContent)
})
})
JSON.parse(fs.readFileSync('manifest.json', 'utf-8')).version.should.equal(
'6.4.0'
)
JSON.parse(fs.readFileSync('package.json', 'utf-8')).version.should.equal(
'6.4.0'
)
JSON.parse(
fs.readFileSync('package-lock.json', 'utf-8')
).version.should.equal('6.4.0')
})
it('bumps version in Gradle `build.gradle.kts` file', async function () {
const expected = fs.readFileSync('./test/mocks/build-6.4.0.gradle.kts', 'utf-8')
mock({
bump: 'minor',
fs: {
'build.gradle.kts': fs.readFileSync('./test/mocks/build-6.3.1.gradle.kts')
}
})
await exec({
packageFiles: [{ filename: 'build.gradle.kts', type: 'gradle' }],
bumpFiles: [{ filename: 'build.gradle.kts', type: 'gradle' }]
})
fs.readFileSync('build.gradle.kts', 'utf-8').should.equal(expected)
})
it('bumps version in .NET `Project.csproj` file', async function () {
const expected = fs.readFileSync('./test/mocks/Project-6.4.0.csproj', 'utf-8')
const filename = 'Project.csproj'
mock({
bump: 'minor',
fs: {
[filename]: fs.readFileSync('./test/mocks/Project-6.3.1.csproj')
}
})
await exec({
packageFiles: [{ filename, type: 'csproj' }],
bumpFiles: [{ filename, type: 'csproj' }]
})
fs.readFileSync(filename, 'utf-8').should.equal(expected)
})
it('bumps version # in npm-shrinkwrap.json', async function () {
mock({
bump: 'minor',
fs: {
'npm-shrinkwrap.json': JSON.stringify({ version: '1.0.0' })
},
tags: ['v1.0.0']
})
await exec()
JSON.parse(
fs.readFileSync('npm-shrinkwrap.json', 'utf-8')
).version.should.equal('1.1.0')
getPackageVersion().should.equal('1.1.0')
})
it('bumps version # in package-lock.json', async function () {
mock({
bump: 'minor',
fs: {
'.gitignore': '',
'package-lock.json': JSON.stringify({ version: '1.0.0' })
},
tags: ['v1.0.0']
})
await exec()
JSON.parse(
fs.readFileSync('package-lock.json', 'utf-8')
).version.should.equal('1.1.0')
getPackageVersion().should.equal('1.1.0')
})
describe('skip', () => {
it('allows bump and changelog generation to be skipped', async function () {
const changelogContent = 'legacy header format<a name="1.0.0">\n'
it('does not update files present in .gitignore', async function () {
mock({
bump: 'minor',
changelog: 'foo\n',
fs: { 'CHANGELOG.md': changelogContent }
fs: {
'.gitignore': 'package-lock.json\nbower.json',
// test a defaults.packageFiles
'bower.json': JSON.stringify({ version: '1.0.0' }),
// test a defaults.bumpFiles
'package-lock.json': JSON.stringify({
name: '@org/package',
version: '1.0.0',
lockfileVersion: 1
})
},
tags: ['v1.0.0']
})
await exec('--skip.bump true --skip.changelog true')
getPackageVersion().should.equal('1.0.0')
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.equal(changelogContent)
await exec()
JSON.parse(
fs.readFileSync('package-lock.json', 'utf-8')
).version.should.equal('1.0.0')
JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal(
'1.0.0'
)
getPackageVersion().should.equal('1.1.0')
})
})
it('does not update files present in .gitignore', async () => {
mock({
bump: 'minor',
fs: {
'.gitignore': 'package-lock.json\nbower.json',
// test a defaults.packageFiles
'bower.json': JSON.stringify({ version: '1.0.0' }),
// test a defaults.bumpFiles
'package-lock.json': JSON.stringify({
name: '@org/package',
version: '1.0.0',
lockfileVersion: 1
})
},
tags: ['v1.0.0']
})
await exec()
JSON.parse(
fs.readFileSync('package-lock.json', 'utf-8')
).version.should.equal('1.0.0')
JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal(
'1.0.0'
)
getPackageVersion().should.equal('1.1.0')
})
describe('configuration', function () {
it('--header', async function () {
mock({ bump: 'minor', fs: { 'CHANGELOG.md': '' } })
await exec('--header="# Welcome to our CHANGELOG.md"')
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.match(/# Welcome to our CHANGELOG.md/)
})
describe('configuration', () => {
it('--header', async function () {
mock({ bump: 'minor', fs: { 'CHANGELOG.md': '' } })
await exec('--header="# Welcome to our CHANGELOG.md"')
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.match(/# Welcome to our CHANGELOG.md/)
it('--issuePrefixes and --issueUrlFormat', async function () {
const format = 'http://www.foo.com/{{prefix}}{{id}}'
const prefix = 'ABC-'
const changelog = ({ preset }) =>
preset.issueUrlFormat + ':' + preset.issuePrefixes
mock({ bump: 'minor', changelog })
await exec(`--issuePrefixes="${prefix}" --issueUrlFormat="${format}"`)
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.include(`${format}:${prefix}`)
})
})
it('--issuePrefixes and --issueUrlFormat', async function () {
const format = 'http://www.foo.com/{{prefix}}{{id}}'
const prefix = 'ABC-'
const changelog = ({ preset }) =>
preset.issueUrlFormat + ':' + preset.issuePrefixes
mock({ bump: 'minor', changelog })
await exec(`--issuePrefixes="${prefix}" --issueUrlFormat="${format}"`)
const content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.include(`${format}:${prefix}`)
})
})
describe('pre-major', () => {
it('bumps the minor rather than major, if version < 1.0.0', async function () {
mock({
bump: 'minor',
pkg: {
version: '0.5.0',
repository: { url: 'https://github.com/yargs/yargs.git' }
}
describe('pre-major', function () {
it('bumps the minor rather than major, if version < 1.0.0', async function () {
mock({
bump: 'minor',
pkg: {
version: '0.5.0',
repository: { url: 'https://github.com/yargs/yargs.git' }
}
})
await exec()
getPackageVersion().should.equal('0.6.0')
})
await exec()
getPackageVersion().should.equal('0.6.0')
})
it('bumps major if --release-as=major specified, if version < 1.0.0', async function () {
mock({
bump: 'major',
pkg: {
version: '0.5.0',
repository: { url: 'https://github.com/yargs/yargs.git' }
}
it('bumps major if --release-as=major specified, if version < 1.0.0', async function () {
mock({
bump: 'major',
pkg: {
version: '0.5.0',
repository: { url: 'https://github.com/yargs/yargs.git' }
}
})
await exec('-r major')
getPackageVersion().should.equal('1.0.0')
})
await exec('-r major')
getPackageVersion().should.equal('1.0.0')
})
})
})
describe('GHSL-2020-111', function () {
afterEach(unmock)
describe('GHSL-2020-111', function () {
afterEach(unmock)
it('does not allow command injection via basic configuration', async function () {
mock({ bump: 'patch' })
await exec({
noVerify: true,
infile: 'foo.txt',
releaseCommitMessageFormat: 'bla `touch exploit`'
it('does not allow command injection via basic configuration', async function () {
mock({ bump: 'patch' })
await exec({
noVerify: true,
infile: 'foo.txt',
releaseCommitMessageFormat: 'bla `touch exploit`'
})
const stat = shell.test('-f', './exploit')
stat.should.equal(false)
})
const stat = shell.test('-f', './exploit')
stat.should.equal(false)
})
})
describe('with mocked git', function () {
afterEach(unmock)
describe('with mocked git', function () {
afterEach(unmock)
it('--sign signs the commit and tag', async function () {
const gitArgs = [
['add', 'CHANGELOG.md', 'package.json'],
[
'commit',
'-S',
'CHANGELOG.md',
'package.json',
'-m',
'chore(release): 1.0.1'
],
['tag', '-s', 'v1.0.1', '-m', 'chore(release): 1.0.1'],
['rev-parse', '--abbrev-ref', 'HEAD']
]
const execFile = (_args, cmd, cmdArgs) => {
cmd.should.equal('git')
const expected = gitArgs.shift()
cmdArgs.should.deep.equal(expected)
if (expected[0] === 'rev-parse') return Promise.resolve('master')
return Promise.resolve('')
}
mock({ bump: 'patch', changelog: 'foo\n', execFile })
it('--sign signs the commit and tag', async function () {
const gitArgs = [
['add', 'CHANGELOG.md', 'package.json'],
[
'commit',
'-S',
'CHANGELOG.md',
'package.json',
'-m',
'chore(release): 1.0.1'
],
['tag', '-s', 'v1.0.1', '-m', 'chore(release): 1.0.1'],
['rev-parse', '--abbrev-ref', 'HEAD']
]
const execFile = (_args, cmd, cmdArgs) => {
cmd.should.equal('git')
const expected = gitArgs.shift()
cmdArgs.should.deep.equal(expected)
if (expected[0] === 'rev-parse') return Promise.resolve('master')
return Promise.resolve('')
}
mock({ bump: 'patch', changelog: 'foo\n', execFile })
await exec('--sign', true)
gitArgs.should.have.lengthOf(0)
})
await exec('--sign', true)
gitArgs.should.have.lengthOf(0)
})
it('--tag-force forces tag replacement', async function () {
const gitArgs = [
['add', 'CHANGELOG.md', 'package.json'],
['commit', 'CHANGELOG.md', 'package.json', '-m', 'chore(release): 1.0.1'],
['tag', '-a', '-f', 'v1.0.1', '-m', 'chore(release): 1.0.1'],
['rev-parse', '--abbrev-ref', 'HEAD']
]
const execFile = (_args, cmd, cmdArgs) => {
cmd.should.equal('git')
const expected = gitArgs.shift()
cmdArgs.should.deep.equal(expected)
if (expected[0] === 'rev-parse') return Promise.resolve('master')
return Promise.resolve('')
}
mock({ bump: 'patch', changelog: 'foo\n', execFile })
it('--tag-force forces tag replacement', async function () {
const gitArgs = [
['add', 'CHANGELOG.md', 'package.json'],
['commit', 'CHANGELOG.md', 'package.json', '-m', 'chore(release): 1.0.1'],
['tag', '-a', '-f', 'v1.0.1', '-m', 'chore(release): 1.0.1'],
['rev-parse', '--abbrev-ref', 'HEAD']
]
const execFile = (_args, cmd, cmdArgs) => {
cmd.should.equal('git')
const expected = gitArgs.shift()
cmdArgs.should.deep.equal(expected)
if (expected[0] === 'rev-parse') return Promise.resolve('master')
return Promise.resolve('')
}
mock({ bump: 'patch', changelog: 'foo\n', execFile })
await exec('--tag-force', true)
gitArgs.should.have.lengthOf(0)
})
await exec('--tag-force', true)
gitArgs.should.have.lengthOf(0)
})
it('fails if git add fails', async function () {
const gitArgs = [['add', 'CHANGELOG.md', 'package.json']]
const gitError = new Error('Command failed: git\nfailed add')
const execFile = (_args, cmd, cmdArgs) => {
cmd.should.equal('git')
const expected = gitArgs.shift()
cmdArgs.should.deep.equal(expected)
it('fails if git add fails', async function () {
const gitArgs = [['add', 'CHANGELOG.md', 'package.json']]
const gitError = new Error('Command failed: git\nfailed add')
const execFile = (_args, cmd, cmdArgs) => {
cmd.should.equal('git')
const expected = gitArgs.shift()
cmdArgs.should.deep.equal(expected)
if (expected[0] === 'add') {
return Promise.reject(gitError)
if (expected[0] === 'add') {
return Promise.reject(gitError)
}
return Promise.resolve('')
}
return Promise.resolve('')
}
mock({ bump: 'patch', changelog: 'foo\n', execFile })
mock({ bump: 'patch', changelog: 'foo\n', execFile })
expect(exec({}, true)).to.be.rejectedWith(gitError)
})
await expect(exec({}, true)).to.be.rejectedWith(gitError)
})
it('fails if git commit fails', async function () {
const gitArgs = [
['add', 'CHANGELOG.md', 'package.json'],
['commit', 'CHANGELOG.md', 'package.json', '-m', 'chore(release): 1.0.1']
]
const gitError = new Error('Command failed: git\nfailed commit')
const execFile = (_args, cmd, cmdArgs) => {
cmd.should.equal('git')
const expected = gitArgs.shift()
cmdArgs.should.deep.equal(expected)
if (expected[0] === 'commit') {
return Promise.reject(gitError)
it('fails if git commit fails', async function () {
const gitArgs = [
['add', 'CHANGELOG.md', 'package.json'],
['commit', 'CHANGELOG.md', 'package.json', '-m', 'chore(release): 1.0.1']
]
const gitError = new Error('Command failed: git\nfailed commit')
const execFile = (_args, cmd, cmdArgs) => {
cmd.should.equal('git')
const expected = gitArgs.shift()
cmdArgs.should.deep.equal(expected)
if (expected[0] === 'commit') {
return Promise.reject(gitError)
}
return Promise.resolve('')
}
return Promise.resolve('')
}
mock({ bump: 'patch', changelog: 'foo\n', execFile })
mock({ bump: 'patch', changelog: 'foo\n', execFile })
expect(exec({}, true)).to.be.rejectedWith(gitError)
})
await expect(exec({}, true)).to.be.rejectedWith(gitError)
})
it('fails if git tag fails', async function () {
const gitArgs = [
['add', 'CHANGELOG.md', 'package.json'],
['commit', 'CHANGELOG.md', 'package.json', '-m', 'chore(release): 1.0.1'],
['tag', '-a', 'v1.0.1', '-m', 'chore(release): 1.0.1']
]
const gitError = new Error('Command failed: git\nfailed tag')
const execFile = (_args, cmd, cmdArgs) => {
cmd.should.equal('git')
const expected = gitArgs.shift()
cmdArgs.should.deep.equal(expected)
if (expected[0] === 'tag') {
return Promise.reject(gitError)
it('fails if git tag fails', async function () {
const gitArgs = [
['add', 'CHANGELOG.md', 'package.json'],
['commit', 'CHANGELOG.md', 'package.json', '-m', 'chore(release): 1.0.1'],
['tag', '-a', 'v1.0.1', '-m', 'chore(release): 1.0.1']
]
const gitError = new Error('Command failed: git\nfailed tag')
const execFile = (_args, cmd, cmdArgs) => {
cmd.should.equal('git')
const expected = gitArgs.shift()
cmdArgs.should.deep.equal(expected)
if (expected[0] === 'tag') {
return Promise.reject(gitError)
}
return Promise.resolve('')
}
return Promise.resolve('')
}
mock({ bump: 'patch', changelog: 'foo\n', execFile })
mock({ bump: 'patch', changelog: 'foo\n', execFile })
expect(exec({}, true)).to.be.rejectedWith(gitError)
await expect(exec({}, true)).to.be.rejectedWith(gitError)
})
})
})

@@ -112,3 +112,3 @@ /* global describe it beforeEach afterEach */

describe('tagPrefix', () => {
describe('tagPrefix', function () {
// TODO: Use unmocked git-semver-tags and stage a git environment

@@ -247,4 +247,4 @@ it('will add prefix onto tag based on version from package', async function () {

describe('gitTagFallback', () => {
it('defaults to 1.0.0 if no tags in git history', async () => {
describe('gitTagFallback', function () {
it('defaults to 1.0.0 if no tags in git history', async function () {
shell.rm('package.json')

@@ -257,3 +257,3 @@ mock({ bump: 'minor' })

it('bases version on greatest version tag, if tags are found', async () => {
it('bases version on greatest version tag, if tags are found', async function () {
shell.rm('package.json')

@@ -267,3 +267,3 @@ mock({ bump: 'minor', tags: ['v3.9.0', 'v5.0.0', 'v3.0.0'] })

describe('configuration', () => {
describe('configuration', function () {
it('.versionrc : releaseCommitMessageFormat', async function () {

@@ -365,3 +365,3 @@ fs.writeFileSync(

mock({ bump: 'minor' })
expect(exec('--patch')).to.be.rejectedWith(/precommit-failure/)
await expect(exec('--patch')).to.be.rejectedWith(/precommit-failure/)
})

@@ -368,0 +368,0 @@

@@ -15,3 +15,3 @@ /* global describe it beforeEach, afterEach */

describe('presets', () => {
describe('presets', function () {
beforeEach(function () {

@@ -18,0 +18,0 @@ shell.rm('-rf', 'tmp')

@@ -29,3 +29,3 @@ /* global describe it */

describe('utils', () => {
describe('utils', function () {
it('detectPMByLockFile should work', async function () {

@@ -32,0 +32,0 @@ const { setLockFile } = mockNpm()

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc