Skip to content

Commit

Permalink
test(windows): skip mock-git tests for Windows (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Jul 12, 2020
1 parent 871201f commit da84ec4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 58 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
119 changes: 62 additions & 57 deletions test.js
Expand Up @@ -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')
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit da84ec4

Please sign in to comment.