Skip to content

Commit

Permalink
Add cli testing for running npm test
Browse files Browse the repository at this point in the history
Adds tests for checking that `nyc npm test` works,
one for when the npm `test` script directly refers to the
JS script and one for when npm runs nested lifecycle scripts.
This is a regression test for istanbuljs#190.
  • Loading branch information
addaleax committed Apr 5, 2016
1 parent a3b3836 commit 4d925c7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/fixtures/run-npm-test-recursive/half-covered.js
8 changes: 8 additions & 0 deletions test/fixtures/run-npm-test-recursive/package.json
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"
}
}
1 change: 1 addition & 0 deletions test/fixtures/run-npm-test/half-covered.js
6 changes: 6 additions & 0 deletions test/fixtures/run-npm-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"scripts": {
"test": "node ./half-covered.js"
}
}
31 changes: 31 additions & 0 deletions test/src/nyc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,4 +695,35 @@ describe('nyc', function () {
})
})
})

// https://github.com/bcoe/nyc/issues/190
describe('running "npm test" (CLI)', function () {
it('can run "npm test" which directly invokes a test file', function (done) {
var args = [bin, 'npm', 'test']
var directory = path.resolve(fixtures, 'run-npm-test')
var proc = spawn(process.execPath, args, {
cwd: directory,
env: { PATH: process.env.PATH }
})

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(fixtures, 'run-npm-test-recursive')
var proc = spawn(process.execPath, args, {
cwd: directory,
env: { PATH: process.env.PATH }
})

proc.on('close', function (code) {
code.should.equal(0)
done()
})
})
})
})

0 comments on commit 4d925c7

Please sign in to comment.