Skip to content

Commit

Permalink
fix: do not override NODE_V8_COVERAGE if set (bcoe#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kilian Ciuffolo committed Apr 20, 2019
1 parent 5ea4313 commit 0706789
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 45 deletions.
5 changes: 4 additions & 1 deletion bin/c8.js
Expand Up @@ -26,7 +26,10 @@ let argv = buildYargs().parse(instrumenterArgs)
await promisify(fs.mkdir)(argv.tempDirectory, { recursive: true })
}

process.env.NODE_V8_COVERAGE = argv.tempDirectory
if (!process.env.NODE_V8_COVERAGE) {
process.env.NODE_V8_COVERAGE = argv.tempDirectory
}

foreground(hideInstrumenterArgs(argv), () => {
outputReport(argv)
})
Expand Down
2 changes: 1 addition & 1 deletion lib/parse-args.js
Expand Up @@ -61,7 +61,7 @@ function buildYargs (withCommands = false) {
type: 'boolean'
})
.option('temp-directory', {
default: './coverage/tmp',
default: process.env.NODE_V8_COVERAGE || './coverage/tmp',
describe: 'directory V8 coverage data is written to and read from'
})
.option('resolve', {
Expand Down
13 changes: 13 additions & 0 deletions test/integration.js
Expand Up @@ -48,6 +48,19 @@ describe('c8', () => {
)
})

it('supports exeternally set NODE_V8_COVERAGE', () => {
process.env.NODE_V8_COVERAGE = './coverage/tmp_'
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--clean=false',
nodePath,
require.resolve('./fixtures/normal')
])
output.toString('utf8').should.matchSnapshot()
process.env.NODE_V8_COVERAGE = ''
})

describe('check-coverage', () => {
it('exits with 0 if coverage within threshold', () => {
const { output, status } = spawnSync(nodePath, [
Expand Down
114 changes: 71 additions & 43 deletions test/integration.js.snap
Expand Up @@ -5,15 +5,15 @@ exports[`c8 ESM Modules collects coverage for ESM modules 1`] = `
--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 96.2 | 86.49 | 90.32 | 96.2 | |
bin | 91.18 | 83.33 | 100 | 91.18 | |
c8.js | 91.18 | 83.33 | 100 | 91.18 | 25,26,27 |
lib | 97.51 | 82.35 | 100 | 97.51 | |
parse-args.js | 98.46 | 60 | 100 | 98.46 | 107,108 |
report.js | 96.69 | 91.67 | 100 | 96.69 |... 10,136,137,138 |
lib/commands | 100 | 88.89 | 100 | 100 | |
check-coverage.js | 100 | 92.31 | 100 | 100 | 17 |
report.js | 100 | 80 | 100 | 100 | 16 |
All files | 84.91 | 74.58 | 72.41 | 84.91 | |
bin | 83.78 | 50 | 100 | 83.78 | |
c8.js | 83.78 | 50 | 100 | 83.78 | 22,25,26,27,30,31 |
lib | 96.8 | 71.88 | 100 | 96.8 | |
parse-args.js | 96.92 | 40 | 100 | 96.92 | 93,94,107,108 |
report.js | 96.69 | 86.36 | 100 | 96.69 |... 10,136,137,138 |
lib/commands | 43.02 | 60 | 16.67 | 43.02 | |
check-coverage.js | 21.67 | 100 | 0 | 21.67 |... 56,57,58,59,60 |
report.js | 92.31 | 50 | 50 | 92.31 | 9,10 |
test/fixtures | 89.04 | 93.75 | 70 | 89.04 | |
async.js | 100 | 100 | 100 | 100 | |
export.mjs | 71.43 | 100 | 50 | 71.43 | 2,3 |
Expand All @@ -37,35 +37,35 @@ hey
--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 96.12 | 82.09 | 89.66 | 96.12 | |
bin | 91.18 | 80 | 100 | 91.18 | |
c8.js | 91.18 | 80 | 100 | 91.18 | 25,26,27 |
lib | 97.51 | 78.13 | 100 | 97.51 | |
parse-args.js | 98.46 | 60 | 100 | 98.46 | 107,108 |
All files | 85.01 | 73.21 | 74.07 | 85.01 | |
bin | 83.78 | 50 | 100 | 83.78 | |
c8.js | 83.78 | 50 | 100 | 83.78 | 22,25,26,27,30,31 |
lib | 96.8 | 71.88 | 100 | 96.8 | |
parse-args.js | 96.92 | 40 | 100 | 96.92 | 93,94,107,108 |
report.js | 96.69 | 86.36 | 100 | 96.69 |... 10,136,137,138 |
lib/commands | 97.67 | 82.35 | 87.5 | 97.67 | |
check-coverage.js | 100 | 92.31 | 100 | 100 | 17 |
lib/commands | 43.02 | 60 | 16.67 | 43.02 | |
check-coverage.js | 21.67 | 100 | 0 | 21.67 |... 56,57,58,59,60 |
report.js | 92.31 | 50 | 50 | 92.31 | 9,10 |
test/fixtures | 90.48 | 92.31 | 75 | 90.48 | |
async.js | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
normal.js | 75 | 66.67 | 33.33 | 75 | 14,15,16,18,19,20 |
subprocess.js | 100 | 100 | 100 | 100 | |
--------------------|----------|----------|----------|----------|-------------------|
,ERROR: Coverage for lines (96.12%) does not meet global threshold (101%)
,ERROR: Coverage for lines (85.01%) does not meet global threshold (101%)
"
`;

exports[`c8 check-coverage allows threshold to be applied on per-file basis 1`] = `
",,ERROR: Coverage for lines (78.33%) does not meet threshold (80%) for lib/commands/check-coverage.js
",,ERROR: Coverage for lines (21.67%) does not meet threshold (80%) for lib/commands/check-coverage.js
ERROR: Coverage for lines (75%) does not meet threshold (80%) for test/fixtures/normal.js
"
`;

exports[`c8 check-coverage exits with 0 if coverage within threshold 1`] = `",,"`;

exports[`c8 check-coverage exits with 1 if coverage is below threshold 1`] = `
",,ERROR: Coverage for lines (95.69%) does not meet global threshold (101%)
",,ERROR: Coverage for lines (85.01%) does not meet global threshold (101%)
"
`;

Expand All @@ -77,11 +77,11 @@ second
--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 84.91 | 72 | 74.07 | 84.91 | |
bin | 88.24 | 60 | 100 | 88.24 | |
c8.js | 88.24 | 60 | 100 | 88.24 | 22,25,26,27 |
lib | 96.09 | 66.67 | 100 | 96.09 | |
parse-args.js | 96.92 | 44.44 | 100 | 96.92 | 93,94,107,108 |
All files | 84.58 | 69.23 | 74.07 | 84.58 | |
bin | 83.78 | 50 | 100 | 83.78 | |
c8.js | 83.78 | 50 | 100 | 83.78 | 22,25,26,27,30,31 |
lib | 96.09 | 64.29 | 100 | 96.09 | |
parse-args.js | 96.92 | 40 | 100 | 96.92 | 93,94,107,108 |
report.js | 95.36 | 77.78 | 100 | 95.36 |... 10,136,137,138 |
lib/commands | 43.02 | 60 | 16.67 | 43.02 | |
check-coverage.js | 21.67 | 100 | 0 | 21.67 |... 56,57,58,59,60 |
Expand All @@ -99,15 +99,15 @@ exports[`c8 report generates report from existing temporary files 1`] = `
",--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 96.12 | 85.51 | 89.66 | 96.12 | |
bin | 91.18 | 83.33 | 100 | 91.18 | |
c8.js | 91.18 | 83.33 | 100 | 91.18 | 25,26,27 |
lib | 97.51 | 82.35 | 100 | 97.51 | |
parse-args.js | 98.46 | 60 | 100 | 98.46 | 107,108 |
report.js | 96.69 | 91.67 | 100 | 96.69 |... 10,136,137,138 |
lib/commands | 97.67 | 87.5 | 87.5 | 97.67 | |
check-coverage.js | 100 | 91.67 | 100 | 100 | 17 |
report.js | 92.31 | 75 | 50 | 92.31 | 9,10 |
All files | 85.01 | 73.21 | 74.07 | 85.01 | |
bin | 83.78 | 50 | 100 | 83.78 | |
c8.js | 83.78 | 50 | 100 | 83.78 | 22,25,26,27,30,31 |
lib | 96.8 | 71.88 | 100 | 96.8 | |
parse-args.js | 96.92 | 40 | 100 | 96.92 | 93,94,107,108 |
report.js | 96.69 | 86.36 | 100 | 96.69 |... 10,136,137,138 |
lib/commands | 43.02 | 60 | 16.67 | 43.02 | |
check-coverage.js | 21.67 | 100 | 0 | 21.67 |... 56,57,58,59,60 |
report.js | 92.31 | 50 | 50 | 92.31 | 9,10 |
test/fixtures | 90.48 | 92.31 | 75 | 90.48 | |
async.js | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
Expand All @@ -121,22 +121,22 @@ exports[`c8 report supports --check-coverage, when generating reports 1`] = `
",--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 96.55 | 85.51 | 93.1 | 96.55 | |
bin | 91.18 | 80 | 100 | 91.18 | |
c8.js | 91.18 | 80 | 100 | 91.18 | 25,26,27 |
lib | 97.51 | 82.35 | 100 | 97.51 | |
parse-args.js | 98.46 | 60 | 100 | 98.46 | 107,108 |
report.js | 96.69 | 91.67 | 100 | 96.69 |... 10,136,137,138 |
lib/commands | 100 | 88.24 | 100 | 100 | |
check-coverage.js | 100 | 91.67 | 100 | 100 | 17 |
report.js | 100 | 80 | 100 | 100 | 16 |
All files | 85.01 | 73.21 | 74.07 | 85.01 | |
bin | 83.78 | 50 | 100 | 83.78 | |
c8.js | 83.78 | 50 | 100 | 83.78 | 22,25,26,27,30,31 |
lib | 96.8 | 71.88 | 100 | 96.8 | |
parse-args.js | 96.92 | 40 | 100 | 96.92 | 93,94,107,108 |
report.js | 96.69 | 86.36 | 100 | 96.69 |... 10,136,137,138 |
lib/commands | 43.02 | 60 | 16.67 | 43.02 | |
check-coverage.js | 21.67 | 100 | 0 | 21.67 |... 56,57,58,59,60 |
report.js | 92.31 | 50 | 50 | 92.31 | 9,10 |
test/fixtures | 90.48 | 92.31 | 75 | 90.48 | |
async.js | 100 | 100 | 100 | 100 | |
multiple-spawn.js | 100 | 100 | 100 | 100 | |
normal.js | 75 | 66.67 | 33.33 | 75 | 14,15,16,18,19,20 |
subprocess.js | 100 | 100 | 100 | 100 | |
--------------------|----------|----------|----------|----------|-------------------|
,ERROR: Coverage for lines (96.55%) does not meet global threshold (101%)
,ERROR: Coverage for lines (85.01%) does not meet global threshold (101%)
"
`;

Expand All @@ -158,3 +158,31 @@ All files | 83.33 | 85.71 | 66.67 | 83.33 | |
-----------|----------|----------|----------|----------|-------------------|
,"
`;

exports[`c8 supports exeternally set NODE_V8_COVERAGE 1`] = `
",hey
i am a line of code
what
hey
what
hey
what
hey
--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 83.64 | 65.22 | 72 | 83.64 | |
bin | 83.78 | 50 | 100 | 83.78 | |
c8.js | 83.78 | 50 | 100 | 83.78 | 22,25,26,27,30,31 |
lib | 96.09 | 64.29 | 100 | 96.09 | |
parse-args.js | 96.92 | 40 | 100 | 96.92 | 93,94,107,108 |
report.js | 95.36 | 77.78 | 100 | 95.36 |... 10,136,137,138 |
lib/commands | 43.02 | 60 | 16.67 | 43.02 | |
check-coverage.js | 21.67 | 100 | 0 | 21.67 |... 56,57,58,59,60 |
report.js | 92.31 | 50 | 50 | 92.31 | 9,10 |
test/fixtures | 83.33 | 85.71 | 66.67 | 83.33 | |
async.js | 100 | 100 | 100 | 100 | |
normal.js | 75 | 66.67 | 33.33 | 75 | 14,15,16,18,19,20 |
--------------------|----------|----------|----------|----------|-------------------|
,"
`;
11 changes: 11 additions & 0 deletions test/parse-args.js
Expand Up @@ -21,6 +21,17 @@ describe('parse-args', () => {
const argv = buildYargs().parse(hideInstrumenteeArgs())
const instrumenteeArgs = hideInstrumenterArgs(argv)
instrumenteeArgs.should.eql(['my-app', '--help'])
argv.tempDirectory.endsWith('/coverage/tmp').should.be.equal(true)
})
})

describe('with NODE_V8_COVERAGE already set', () => {
it('should not override it', () => {
process.env.NODE_V8_COVERAGE = './coverage/tmp_'
process.argv = ['node', 'c8', '--foo=99', 'my-app', '--help']
const argv = buildYargs().parse(hideInstrumenteeArgs())
argv.tempDirectory.endsWith('/coverage/tmp_').should.be.equal(true)
process.env.NODE_V8_COVERAGE = ''
})
})
})

0 comments on commit 0706789

Please sign in to comment.