diff --git a/package.json b/package.json index ab8f73a5a..e610b1373 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "replacement for `npm version` with automatic CHANGELOG generation", "bin": "bin/cli.js", "scripts": { + "fix": "eslint . --fix", "posttest": "eslint .", "test": "nyc mocha --timeout=30000 test.js", "release": "bin/cli.js" @@ -60,7 +61,7 @@ "eslint-plugin-promise": "4.2.1", "eslint-plugin-standard": "4.0.1", "mocha": "7.2.0", - "mock-git": "2.0.0", + "mock-git": "^2.0.0", "mockery": "2.1.0", "nyc": "14.1.1", "shelljs": "0.8.4" diff --git a/test.js b/test.js index 0a60ab82e..5b011fdba 100644 --- a/test.js +++ b/test.js @@ -13,6 +13,8 @@ const formatCommitMessage = require('./lib/format-commit-message') const cli = require('./command') const standardVersion = require('./index') +const isWindows = process.platform === 'win32' + require('chai').should() const cliPath = path.resolve(__dirname, './bin/cli.js') @@ -248,74 +250,77 @@ describe('cli', function () { }) }) - describe('with mocked git', function () { - it('--sign signs the commit and tag', function () { - // mock git with file that writes args to gitcapture.log - return mockGit('require("fs").appendFileSync("gitcapture.log", JSON.stringify(process.argv.splice(2)) + "\\n")') - .then(function (unmock) { - execCli('--sign').code.should.equal(0) - - const captured = shell.cat('gitcapture.log').stdout.split('\n').map(function (line) { - return line ? JSON.parse(line) : line + // TODO: investigate why mock-git does not play well with execFile on Windows. + if (!isWindows) { + describe('with mocked git', function () { + it('--sign signs the commit and tag', function () { + // mock git with file that writes args to gitcapture.log + return mockGit('require("fs").appendFileSync("gitcapture.log", JSON.stringify(process.argv.splice(2)) + "\\n")') + .then(function (unmock) { + execCli('--sign').code.should.equal(0) + + const captured = shell.cat('gitcapture.log').stdout.split('\n').map(function (line) { + return line ? JSON.parse(line) : line + }) + /* eslint-disable no-useless-escape */ + captured[captured.length - 4].should.deep.equal(['commit', '-S', 'CHANGELOG.md', 'package.json', '-m', '\"chore(release): 1.0.1\"']) + captured[captured.length - 3].should.deep.equal(['tag', '-s', 'v1.0.1', '-m', '\"chore(release): 1.0.1\"']) + /* eslint-enable no-useless-escape */ + unmock() }) - /* eslint-disable no-useless-escape */ - captured[captured.length - 4].should.deep.equal(['commit', '-S', 'CHANGELOG.md', 'package.json', '-m', '\"chore(release): 1.0.1\"']) - captured[captured.length - 3].should.deep.equal(['tag', '-s', 'v1.0.1', '-m', '\"chore(release): 1.0.1\"']) - /* eslint-enable no-useless-escape */ - unmock() - }) - }) + }) - it('exits with error code if git commit fails', function () { - // mock git by throwing on attempt to commit - return mockGit('console.error("commit yourself"); process.exit(128);', 'commit') - .then(function (unmock) { - const result = execCli() - result.code.should.equal(1) - result.stderr.should.match(/commit yourself/) + it('exits with error code if git commit fails', function () { + // mock git by throwing on attempt to commit + return mockGit('console.error("commit yourself"); process.exit(128);', 'commit') + .then(function (unmock) { + const result = execCli() + result.code.should.equal(1) + result.stderr.should.match(/commit yourself/) - unmock() - }) - }) + unmock() + }) + }) - it('exits with error code if git add fails', function () { - // mock git by throwing on attempt to add - return mockGit('console.error("addition is hard"); process.exit(128);', 'add') - .then(function (unmock) { - const result = execCli() - result.code.should.equal(1) - result.stderr.should.match(/addition is hard/) + it('exits with error code if git add fails', function () { + // mock git by throwing on attempt to add + return mockGit('console.error("addition is hard"); process.exit(128);', 'add') + .then(function (unmock) { + const result = execCli() + result.code.should.equal(1) + result.stderr.should.match(/addition is hard/) - unmock() - }) - }) + unmock() + }) + }) - it('exits with error code if git tag fails', function () { - // mock git by throwing on attempt to commit - return mockGit('console.error("tag, you\'re it"); process.exit(128);', 'tag') - .then(function (unmock) { - const result = execCli() - result.code.should.equal(1) - result.stderr.should.match(/tag, you're it/) + it('exits with error code if git tag fails', function () { + // mock git by throwing on attempt to commit + return mockGit('console.error("tag, you\'re it"); process.exit(128);', 'tag') + .then(function (unmock) { + const result = execCli() + result.code.should.equal(1) + result.stderr.should.match(/tag, you're it/) - unmock() - }) - }) + unmock() + }) + }) - it('doesn\'t fail fast on stderr output from git', function () { - // mock git by throwing on attempt to commit - return mockGit('console.error("haha, kidding, this is just a warning"); process.exit(0);', 'add') - .then(function (unmock) { - writePackageJson('1.0.0') + it('doesn\'t fail fast on stderr output from git', function () { + // mock git by throwing on attempt to commit + return mockGit('console.error("haha, kidding, this is just a warning"); process.exit(0);', 'add') + .then(function (unmock) { + writePackageJson('1.0.0') - const result = execCli() - result.code.should.equal(1) - result.stderr.should.match(/haha, kidding, this is just a warning/) + const result = execCli() + result.code.should.equal(1) + result.stderr.should.match(/haha, kidding, this is just a warning/) - unmock() - }) + unmock() + }) + }) }) - }) + } describe('lifecycle scripts', () => { describe('prerelease hook', function () {