Skip to content

Commit

Permalink
chore: Use snapshots for spawn output testing (#1133)
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyfarrell committed Jun 20, 2019
1 parent 914b776 commit 4bc9c14
Show file tree
Hide file tree
Showing 9 changed files with 938 additions and 1,029 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -9,14 +9,16 @@ node_js:
- 8
- 6
matrix:
## An ENOMEM error occurs with 11.6.0 under Travis-CI for Windows.
## An ENOMEM error occurs with 10+ under Travis-CI for Windows.
## Disable until we can determine the cause.
# include:
# - os: windows
# node_js: "latest"
exclude:
- os: windows
node_js: "node"
- os: windows
node_js: 10
git:
depth:
1
Expand Down
477 changes: 274 additions & 203 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -108,7 +108,6 @@
"source-map-support": "^0.5.12",
"standard": "^12.0.1",
"standard-version": "^5.0.2",
"strip-indent": "^2.0.0",
"tap": "^12.6.5",
"which": "^1.3.1",
"zero-fill": "^2.2.3"
Expand Down
265 changes: 265 additions & 0 deletions tap-snapshots/test-nyc-integration.js-TAP.test.js
Expand Up @@ -5,6 +5,27 @@
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/nyc-integration.js TAP --all includes files with both .map files and inline source-maps > stdout 1`] = `
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 44.44 | 100 | 33.33 | 44.44 | |
s1.js | 80 | 100 | 50 | 80 | 7 |
s2.js | 0 | 100 | 0 | 0 | 1,2,4,6 |
----------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP --all uses source-maps to exclude original sources from reports > stdout 1`] = `
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 100 | 0 | 0 | |
s2.js | 0 | 100 | 0 | 0 | 1,2,4,6 |
----------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP --check-coverage fails in any case when the underlying test failed > stderr 1`] = `
ERROR: Coverage for lines (33.33%) does not meet global threshold (49%)
Expand Down Expand Up @@ -218,6 +239,26 @@ end_of_record
`

exports[`test/nyc-integration.js TAP allows alternative high and low watermarks to be configured > stdout 1`] = `
-----------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------------|----------|----------|----------|----------|-------------------|
All files  | 50 | 50 | 100 | 50 |  |
 half-covered.js | 50 | 50 | 100 | 50 | 6,7,8 |
-----------------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP allows an alternative cache folder to be specified > stdout 1`] = `
-----------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------------|----------|----------|----------|----------|-------------------|
All files | 50 | 50 | 100 | 50 | |
half-covered.js | 50 | 50 | 100 | 50 | 6,7,8 |
-----------------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP allows nyc.config.js configuration to be overridden with command line args > stdout 1`] = `
TN:
SF:./ignore.js
Expand Down Expand Up @@ -291,6 +332,72 @@ end_of_record
`

exports[`test/nyc-integration.js TAP allows reserved word when es-modules is disabled > stdout 1`] = `
---------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
---------------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
not-strict.js | 100 | 100 | 100 | 100 | |
---------------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP appropriately instruments file with corresponding .map file > stdout 1`] = `
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 80 | 100 | 50 | 80 | |
s1.js | 80 | 100 | 50 | 80 | 7 |
----------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP appropriately instruments file with inline source-map > stdout 1`] = `
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
s2.js | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP can run "npm test" which directly invokes a test file > stdout 1`] = `
> @ test .
> node ./half-covered.js
-----------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------------|----------|----------|----------|----------|-------------------|
All files | 50 | 50 | 100 | 50 | |
half-covered.js | 50 | 50 | 100 | 50 | 6,7,8 |
-----------------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP can run "npm test" which indirectly invokes a test file > stdout 1`] = `
> @ test .
> npm run test:deeper
> @ test:deeper .
> npm run test:even-deeper
> @ test:even-deeper .
> node ./half-covered.js
-----------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------------|----------|----------|----------|----------|-------------------|
All files | 50 | 50 | 100 | 50 | |
half-covered.js | 50 | 50 | 100 | 50 | 6,7,8 |
-----------------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP check-coverage command is equivalent to the flag > stderr 1`] = `
ERROR: Coverage for lines (50%) does not meet global threshold (51%)
Expand All @@ -310,10 +417,120 @@ exports[`test/nyc-integration.js TAP check-coverage command is equivalent to the
`

exports[`test/nyc-integration.js TAP does not create .cache folder if cache is "false" > stdout 1`] = `
-----------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------------|----------|----------|----------|----------|-------------------|
All files | 50 | 50 | 100 | 50 | |
half-covered.js | 50 | 50 | 100 | 50 | 6,7,8 |
-----------------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP does not interpret args intended for instrumented bin > undefined 1`] = `
[ '--help', '--version' ]
`

exports[`test/nyc-integration.js TAP execute with exclude-node-modules=false > stderr 1`] = `
ERROR: Coverage for lines (0%) does not meet threshold (90%) for ./node_modules/@istanbuljs/fake-module-1/index.js
`

exports[`test/nyc-integration.js TAP execute with exclude-node-modules=false > stderr 2`] = `
ERROR: Coverage for lines (0%) does not meet threshold (90%) for ./node_modules/@istanbuljs/fake-module-1/index.js
`

exports[`test/nyc-integration.js TAP execute with exclude-node-modules=false > stderr 3`] = `
ERROR: Coverage for lines (0%) does not meet threshold (90%) for ./node_modules/@istanbuljs/fake-module-1/index.js
`

exports[`test/nyc-integration.js TAP execute with exclude-node-modules=false > stdout 1`] = `
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 100 | 100 | 0 | |
index.js | 0 | 100 | 100 | 0 | 1 |
----------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP execute with exclude-node-modules=false > stdout 2`] = `
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 100 | 100 | 0 | |
index.js | 0 | 100 | 100 | 0 | 1 |
----------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP execute with exclude-node-modules=false > stdout 3`] = `
`

exports[`test/nyc-integration.js TAP extracts coverage headers from unexecuted files > undefined 1`] = `
[
[
"all",
true
],
[
"instrument",
false
],
[
"instrumenter",
"./lib/instrumenters/noop"
],
[
"silent",
true
],
[
"sourceMap",
false
]
]
`

exports[`test/nyc-integration.js TAP forbids reserved word when es-modules is not disabled > stderr 1`] = `
Failed to instrument ./not-strict.js
`

exports[`test/nyc-integration.js TAP forbids reserved word when es-modules is not disabled > stdout 1`] = `
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 0 | 0 | 0 | |
----------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP handles --clean / --no-clean properly > stdout 1`] = `
1
------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
------------|----------|----------|----------|----------|-------------------|
All files | 50 | 25 | 100 | 50 | |
by-arg2.js | 50 | 25 | 100 | 50 | 4,5,7 |
------------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP handles --clean / --no-clean properly > stdout 2`] = `
2
------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
------------|----------|----------|----------|----------|-------------------|
All files | 83.33 | 75 | 100 | 83.33 | |
by-arg2.js | 83.33 | 75 | 100 | 83.33 | 7 |
------------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP hooks provide coverage for requireJS and AMD modules > stdout 1`] = `
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
Expand Down Expand Up @@ -526,6 +743,15 @@ end_of_record
`

exports[`test/nyc-integration.js TAP nyc instrument fails on file with \`package\` keyword when es-modules is enabled > stderr 1`] = `
Failed to instrument ./not-strict.js
`

exports[`test/nyc-integration.js TAP nyc instrument fails on file with \`package\` keyword when es-modules is enabled > stdout 1`] = `
`

exports[`test/nyc-integration.js TAP passes configuration via environment variables > undefined 1`] = `
[
[
Expand Down Expand Up @@ -597,3 +823,42 @@ All files | 62.5 | 100 | 40 | 62.5 | |
----------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP setting instrument to "false" configures noop instrumenter > undefined 1`] = `
[
[
"instrument",
false
],
[
"instrumenter",
"./lib/instrumenters/noop"
],
[
"silent",
true
],
[
"sourceMap",
false
]
]
`

exports[`test/nyc-integration.js TAP skip-empty does not display 0-line files > stdout 1`] = `
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
----------|----------|----------|----------|----------|-------------------|
`

exports[`test/nyc-integration.js TAP skip-full does not display files with 100% statement, branch, and function coverage > stdout 1`] = `
-----------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------------|----------|----------|----------|----------|-------------------|
All files | 62.5 | 50 | 100 | 62.5 | |
half-covered.js | 50 | 50 | 100 | 50 | 6,7,8 |
-----------------|----------|----------|----------|----------|-------------------|
`
27 changes: 27 additions & 0 deletions test/helpers/env-check-config.js
@@ -0,0 +1,27 @@
'use strict'

const runNYC = require('./run-nyc')

module.exports = function envCheckConfig (t, { configArgs, checkOptions }) {
return runNYC({
tempDir: t.tempDir,
leavePathSep: true,
args: [
...configArgs,
process.execPath,
'./env.js'
]
}).then(({ stdout, stderr, status }) => {
const config = JSON.parse(JSON.parse(stdout).NYC_CONFIG)

t.is(status, 0)
t.is(stderr, '')
t.matchSnapshot(
JSON.stringify(
checkOptions.sort().map(option => [option, config[option]]),
null,
2
)
)
})
}
3 changes: 2 additions & 1 deletion test/helpers/index.js
Expand Up @@ -8,5 +8,6 @@ module.exports = {
testSuccess: require('./test-success'),
testFailure: require('./test-failure'),
runNYC: require('./run-nyc'),
tempDirSetup: require('./temp-dir-setup')
tempDirSetup: require('./temp-dir-setup'),
envCheckConfig: require('./env-check-config')
}
10 changes: 7 additions & 3 deletions test/helpers/run-nyc.js
Expand Up @@ -3,7 +3,7 @@
const { nycBin, fixturesCLI } = require('./paths')
const spawn = require('./spawn')

const env = {
const envPath = {
PATH: process.env.PATH
}

Expand All @@ -25,13 +25,17 @@ function sanitizeString (str, cwd, leavePathSep) {
return str
}

function runNYC ({ args, tempDir, leavePathSep, cwd = fixturesCLI }) {
function runNYC ({ args, tempDir, leavePathSep, cwd = fixturesCLI, env = {} }) {
const runArgs = [nycBin].concat(tempDir ? ['--temp-dir', tempDir] : [], args)
return spawn(process.execPath, runArgs, {
cwd: cwd,
env
env: Object.assign({}, envPath, env)
}).then(({ status, stderr, stdout }) => ({
status,
originalText: {
stderr,
stdout
},
stderr: sanitizeString(stderr, cwd, leavePathSep),
stdout: sanitizeString(stdout, cwd, leavePathSep)
}))
Expand Down

0 comments on commit 4bc9c14

Please sign in to comment.