-
-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: adds CLI integration testing, where there was no integration tes…
…ting before.
- Loading branch information
Showing
11 changed files
with
214 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node | ||
npm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// shebang gets added before this line | ||
var which = require('which') | ||
var assert = require('assert') | ||
var foreground = require('foreground-child') | ||
|
||
// strip first PATH folder | ||
process.env.PATH = process.env.PATH.replace(/^.+?[:;]/, '') | ||
|
||
foreground('npm', process.argv.slice(2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var a = 0 | ||
|
||
throw new Error | ||
|
||
if (a === 0) { | ||
a++; | ||
a--; | ||
a++; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var a = 0 | ||
|
||
a++ | ||
|
||
if (a === 0) { | ||
a++; | ||
a--; | ||
a++; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var a = 0 | ||
|
||
a++ | ||
|
||
if (a === 0) { | ||
a++; | ||
a--; | ||
a++; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"test": "npm run test:deeper", | ||
"test:deeper": "npm run test:even-deeper", | ||
"test:even-deeper": "node ./half-covered.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var a = 0 | ||
|
||
a++ | ||
|
||
if (a === 0) { | ||
a++; | ||
a--; | ||
a++; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"test": "node ./half-covered.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* global describe, it */ | ||
|
||
var path = require('path') | ||
var fs = require('fs') | ||
var spawn = require('child_process').spawn | ||
var isWindows = require('is-windows')() | ||
var fixturesCLI = path.resolve(__dirname, '../fixtures/cli') | ||
var fakebin = path.resolve(fixturesCLI, 'fakebin') | ||
var bin = path.resolve(__dirname, '../../bin/nyc') | ||
|
||
require('chai').should() | ||
require('tap').mochaGlobals() | ||
|
||
describe('the nyc cli', function () { | ||
var env = { PATH: process.env.PATH } | ||
|
||
describe('--check-coverage', function () { | ||
it('fails when the expected coverage is below a threshold', function (done) { | ||
var args = [bin, '--check-coverage', '--lines', '51', process.execPath, './half-covered.js'] | ||
var message = 'ERROR: Coverage for lines (50%) does not meet global threshold (51%)' | ||
|
||
var proc = spawn(process.execPath, args, { | ||
cwd: fixturesCLI, | ||
env: env | ||
}) | ||
|
||
var stderr = '' | ||
proc.stderr.on('data', function (chunk) { | ||
stderr += chunk | ||
}) | ||
|
||
proc.on('close', function (code) { | ||
code.should.not.equal(0) | ||
stderr.trim().should.equal(message) | ||
done() | ||
}) | ||
}) | ||
|
||
it('succeeds when the expected coverage is above a threshold', function (done) { | ||
var args = [bin, '--check-coverage', '--lines', '49', process.execPath, './half-covered.js'] | ||
|
||
var proc = spawn(process.execPath, args, { | ||
cwd: fixturesCLI, | ||
env: env | ||
}) | ||
|
||
proc.on('close', function (code) { | ||
code.should.equal(0) | ||
done() | ||
}) | ||
}) | ||
|
||
// https://github.com/bcoe/nyc/issues/209 | ||
it('fails in any case when the underlying test failed', function (done) { | ||
var args = [bin, '--check-coverage', '--lines', '49', process.execPath, './half-covered-failing.js'] | ||
|
||
var proc = spawn(process.execPath, args, { | ||
cwd: fixturesCLI, | ||
env: env | ||
}) | ||
|
||
proc.on('close', function (code) { | ||
code.should.not.equal(0) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
// https://github.com/bcoe/nyc/issues/190 | ||
describe('running "npm test"', function () { | ||
it('can run "npm test" which directly invokes a test file', function (done) { | ||
var args = [bin, 'npm', 'test'] | ||
var directory = path.resolve(fixturesCLI, 'run-npm-test') | ||
var proc = spawn(process.execPath, args, { | ||
cwd: directory, | ||
env: env | ||
}) | ||
|
||
proc.on('close', function (code) { | ||
code.should.equal(0) | ||
done() | ||
}) | ||
}) | ||
|
||
it('can run "npm test" which indirectly invokes a test file', function (done) { | ||
var args = [bin, 'npm', 'test'] | ||
var directory = path.resolve(fixturesCLI, 'run-npm-test-recursive') | ||
var proc = spawn(process.execPath, args, { | ||
cwd: directory, | ||
env: env | ||
}) | ||
|
||
proc.on('close', function (code) { | ||
code.should.equal(0) | ||
done() | ||
}) | ||
}) | ||
|
||
function writeFakeNPM (shebang) { | ||
var targetPath = path.resolve(fakebin, 'npm') | ||
var source = fs.readFileSync(path.resolve(fakebin, 'npm-template.js')) | ||
fs.writeFileSync(targetPath, '#!' + shebang + '\n' + source) | ||
fs.chmodSync(targetPath, 493) // 0o755 | ||
} | ||
|
||
it('can run "npm test", absolute shebang edition', function (done) { | ||
if (isWindows) return done() | ||
|
||
writeFakeNPM(process.execPath) | ||
|
||
var args = [bin, 'npm', 'test'] | ||
var directory = path.resolve(fixturesCLI, 'run-npm-test-recursive') | ||
var proc = spawn(process.execPath, args, { | ||
cwd: directory, | ||
env: { | ||
PATH: fakebin + ':' + env.PATH | ||
} | ||
}) | ||
|
||
proc.on('close', function (code) { | ||
code.should.equal(0) | ||
done() | ||
}) | ||
}) | ||
|
||
it('can run "npm test", weird bash+dirname shebang edition', function (done) { | ||
if (isWindows) return done() | ||
|
||
// This string is taken verbatim from tools/install.py in Node core v5.x | ||
writeFakeNPM('/bin/sh\n// 2>/dev/null; exec "`dirname "$0"`/node" "$0" "$@"') | ||
fs.symlinkSync(process.execPath, path.resolve(fakebin, 'node')) | ||
|
||
var args = [bin, 'npm', 'test'] | ||
var directory = path.resolve(fixturesCLI, 'run-npm-test-recursive') | ||
var proc = spawn(process.execPath, args, { | ||
cwd: directory, | ||
env: { | ||
PATH: fakebin + ':' + env.PATH | ||
} | ||
}) | ||
|
||
proc.on('close', function (code) { | ||
code.should.equal(0) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) |