Skip to content

Commit da84ec4

Browse files
authored
test(windows): skip mock-git tests for Windows (#616)
1 parent 871201f commit da84ec4

File tree

2 files changed

+64
-58
lines changed

2 files changed

+64
-58
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "replacement for `npm version` with automatic CHANGELOG generation",
55
"bin": "bin/cli.js",
66
"scripts": {
7+
"fix": "eslint . --fix",
78
"posttest": "eslint .",
89
"test": "nyc mocha --timeout=30000 test.js",
910
"release": "bin/cli.js"
@@ -60,7 +61,7 @@
6061
"eslint-plugin-promise": "4.2.1",
6162
"eslint-plugin-standard": "4.0.1",
6263
"mocha": "7.2.0",
63-
"mock-git": "2.0.0",
64+
"mock-git": "^2.0.0",
6465
"mockery": "2.1.0",
6566
"nyc": "14.1.1",
6667
"shelljs": "0.8.4"

test.js

+62-57
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const formatCommitMessage = require('./lib/format-commit-message')
1313
const cli = require('./command')
1414
const standardVersion = require('./index')
1515

16+
const isWindows = process.platform === 'win32'
17+
1618
require('chai').should()
1719

1820
const cliPath = path.resolve(__dirname, './bin/cli.js')
@@ -248,74 +250,77 @@ describe('cli', function () {
248250
})
249251
})
250252

251-
describe('with mocked git', function () {
252-
it('--sign signs the commit and tag', function () {
253-
// mock git with file that writes args to gitcapture.log
254-
return mockGit('require("fs").appendFileSync("gitcapture.log", JSON.stringify(process.argv.splice(2)) + "\\n")')
255-
.then(function (unmock) {
256-
execCli('--sign').code.should.equal(0)
257-
258-
const captured = shell.cat('gitcapture.log').stdout.split('\n').map(function (line) {
259-
return line ? JSON.parse(line) : line
253+
// TODO: investigate why mock-git does not play well with execFile on Windows.
254+
if (!isWindows) {
255+
describe('with mocked git', function () {
256+
it('--sign signs the commit and tag', function () {
257+
// mock git with file that writes args to gitcapture.log
258+
return mockGit('require("fs").appendFileSync("gitcapture.log", JSON.stringify(process.argv.splice(2)) + "\\n")')
259+
.then(function (unmock) {
260+
execCli('--sign').code.should.equal(0)
261+
262+
const captured = shell.cat('gitcapture.log').stdout.split('\n').map(function (line) {
263+
return line ? JSON.parse(line) : line
264+
})
265+
/* eslint-disable no-useless-escape */
266+
captured[captured.length - 4].should.deep.equal(['commit', '-S', 'CHANGELOG.md', 'package.json', '-m', '\"chore(release): 1.0.1\"'])
267+
captured[captured.length - 3].should.deep.equal(['tag', '-s', 'v1.0.1', '-m', '\"chore(release): 1.0.1\"'])
268+
/* eslint-enable no-useless-escape */
269+
unmock()
260270
})
261-
/* eslint-disable no-useless-escape */
262-
captured[captured.length - 4].should.deep.equal(['commit', '-S', 'CHANGELOG.md', 'package.json', '-m', '\"chore(release): 1.0.1\"'])
263-
captured[captured.length - 3].should.deep.equal(['tag', '-s', 'v1.0.1', '-m', '\"chore(release): 1.0.1\"'])
264-
/* eslint-enable no-useless-escape */
265-
unmock()
266-
})
267-
})
271+
})
268272

269-
it('exits with error code if git commit fails', function () {
270-
// mock git by throwing on attempt to commit
271-
return mockGit('console.error("commit yourself"); process.exit(128);', 'commit')
272-
.then(function (unmock) {
273-
const result = execCli()
274-
result.code.should.equal(1)
275-
result.stderr.should.match(/commit yourself/)
273+
it('exits with error code if git commit fails', function () {
274+
// mock git by throwing on attempt to commit
275+
return mockGit('console.error("commit yourself"); process.exit(128);', 'commit')
276+
.then(function (unmock) {
277+
const result = execCli()
278+
result.code.should.equal(1)
279+
result.stderr.should.match(/commit yourself/)
276280

277-
unmock()
278-
})
279-
})
281+
unmock()
282+
})
283+
})
280284

281-
it('exits with error code if git add fails', function () {
282-
// mock git by throwing on attempt to add
283-
return mockGit('console.error("addition is hard"); process.exit(128);', 'add')
284-
.then(function (unmock) {
285-
const result = execCli()
286-
result.code.should.equal(1)
287-
result.stderr.should.match(/addition is hard/)
285+
it('exits with error code if git add fails', function () {
286+
// mock git by throwing on attempt to add
287+
return mockGit('console.error("addition is hard"); process.exit(128);', 'add')
288+
.then(function (unmock) {
289+
const result = execCli()
290+
result.code.should.equal(1)
291+
result.stderr.should.match(/addition is hard/)
288292

289-
unmock()
290-
})
291-
})
293+
unmock()
294+
})
295+
})
292296

293-
it('exits with error code if git tag fails', function () {
294-
// mock git by throwing on attempt to commit
295-
return mockGit('console.error("tag, you\'re it"); process.exit(128);', 'tag')
296-
.then(function (unmock) {
297-
const result = execCli()
298-
result.code.should.equal(1)
299-
result.stderr.should.match(/tag, you're it/)
297+
it('exits with error code if git tag fails', function () {
298+
// mock git by throwing on attempt to commit
299+
return mockGit('console.error("tag, you\'re it"); process.exit(128);', 'tag')
300+
.then(function (unmock) {
301+
const result = execCli()
302+
result.code.should.equal(1)
303+
result.stderr.should.match(/tag, you're it/)
300304

301-
unmock()
302-
})
303-
})
305+
unmock()
306+
})
307+
})
304308

305-
it('doesn\'t fail fast on stderr output from git', function () {
306-
// mock git by throwing on attempt to commit
307-
return mockGit('console.error("haha, kidding, this is just a warning"); process.exit(0);', 'add')
308-
.then(function (unmock) {
309-
writePackageJson('1.0.0')
309+
it('doesn\'t fail fast on stderr output from git', function () {
310+
// mock git by throwing on attempt to commit
311+
return mockGit('console.error("haha, kidding, this is just a warning"); process.exit(0);', 'add')
312+
.then(function (unmock) {
313+
writePackageJson('1.0.0')
310314

311-
const result = execCli()
312-
result.code.should.equal(1)
313-
result.stderr.should.match(/haha, kidding, this is just a warning/)
315+
const result = execCli()
316+
result.code.should.equal(1)
317+
result.stderr.should.match(/haha, kidding, this is just a warning/)
314318

315-
unmock()
316-
})
319+
unmock()
320+
})
321+
})
317322
})
318-
})
323+
}
319324

320325
describe('lifecycle scripts', () => {
321326
describe('prerelease hook', function () {

0 commit comments

Comments
 (0)