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 976b33c
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 30 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
15 changes: 15 additions & 0 deletions test/integration.js
Expand Up @@ -23,6 +23,21 @@ describe('c8', () => {
output.toString('utf8').should.matchSnapshot()
})

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

it('merges reports from subprocesses together', () => {
const { output } = spawnSync(nodePath, [
c8Path,
Expand Down
88 changes: 60 additions & 28 deletions test/integration.js.snap
Expand Up @@ -5,11 +5,11 @@ 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 |
All files | 95.81 | 84.21 | 90.32 | 95.81 | |
bin | 86.49 | 71.43 | 100 | 86.49 | |
c8.js | 86.49 | 71.43 | 100 | 86.49 | 25,26,27,30,31 |
lib | 97.51 | 80 | 100 | 97.51 | |
parse-args.js | 98.46 | 54.55 | 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 |
Expand Down Expand Up @@ -37,11 +37,11 @@ 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 | 95.72 | 79.71 | 89.66 | 95.72 | |
bin | 86.49 | 66.67 | 100 | 86.49 | |
c8.js | 86.49 | 66.67 | 100 | 86.49 | 25,26,27,30,31 |
lib | 97.51 | 75.76 | 100 | 97.51 | |
parse-args.js | 98.46 | 54.55 | 100 | 98.46 | 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 |
Expand All @@ -52,7 +52,7 @@ All files | 96.12 | 82.09 | 89.66 | 96.12 |
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 (95.72%) does not meet global threshold (101%)
"
`;

Expand All @@ -65,7 +65,7 @@ ERROR: Coverage for lines (75%) does not meet threshold (80%) for test/fixtures/
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 (95.29%) 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,11 +99,11 @@ 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 |
All files | 95.72 | 83.1 | 89.66 | 95.72 | |
bin | 86.49 | 71.43 | 100 | 86.49 | |
c8.js | 86.49 | 71.43 | 100 | 86.49 | 25,26,27,30,31 |
lib | 97.51 | 80 | 100 | 97.51 | |
parse-args.js | 98.46 | 54.55 | 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 |
Expand All @@ -121,11 +121,11 @@ 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 |
All files | 96.15 | 83.1 | 93.1 | 96.15 | |
bin | 86.49 | 66.67 | 100 | 86.49 | |
c8.js | 86.49 | 66.67 | 100 | 86.49 | 25,26,27,30,31 |
lib | 97.51 | 80 | 100 | 97.51 | |
parse-args.js | 98.46 | 54.55 | 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 |
Expand All @@ -136,7 +136,7 @@ All files | 96.55 | 85.51 | 93.1 | 96.55 |
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 (96.15%) does not meet global threshold (101%)
"
`;

Expand All @@ -158,3 +158,35 @@ 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 | 95.81 | 82.29 | 91.89 | 95.81 | |
bin | 86.49 | 74.07 | 100 | 86.49 | |
c8.js | 86.49 | 74.07 | 100 | 86.49 | 25,26,27,30,31 |
lib | 97.51 | 80 | 100 | 97.51 | |
parse-args.js | 98.46 | 54.55 | 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 |
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 |
import.mjs | 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 | |
--------------------|----------|----------|----------|----------|-------------------|
,"
`;
12 changes: 12 additions & 0 deletions test/parse-args.js
Expand Up @@ -21,6 +21,18 @@ 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', () => {
const NODE_V8_COVERAGE = process.env.NODE_V8_COVERAGE
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 = NODE_V8_COVERAGE
})
})
})

0 comments on commit 976b33c

Please sign in to comment.