Skip to content

Commit

Permalink
fix: do not override NODE_V8_COVERAGE if set (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kilian Ciuffolo authored and bcoe committed Jun 23, 2019
1 parent dadc6b8 commit 8bb67b0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/parse-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ function buildYargs (withCommands = false) {
type: 'boolean'
})
.option('temp-directory', {
describe: 'directory V8 coverage data is written to and read from'
describe: 'directory V8 coverage data is written to and read from',
default: process.env.NODE_V8_COVERAGE
})
.option('resolve', {
default: '',
Expand Down
15 changes: 15 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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
33 changes: 33 additions & 0 deletions test/integration.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,36 @@ All files | 70.37 | 66.67 | 60 | 70.37 | |
------------|----------|----------|----------|----------|-------------------|
,"
`;

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 | 89.77 | 74.21 | 88.14 | 89.77 | |
bin | 69.81 | 64.29 | 92.86 | 69.81 | |
c8.js | 69.81 | 64.29 | 92.86 | 69.81 |... 49,50,51,52,53 |
lib | 93.33 | 72.73 | 100 | 93.33 | |
is-cjs-esm-bridge.js | 90 | 70 | 100 | 90 | 9 |
parse-args.js | 97.69 | 47.83 | 100 | 97.69 | 99,107,108 |
report.js | 90.29 | 83.64 | 100 | 90.29 |... 40,160,161,162 |
lib/commands | 89.53 | 85.71 | 75 | 89.53 | |
check-coverage.js | 88.33 | 93.33 | 75 | 88.33 |... 46,57,58,59,60 |
report.js | 92.31 | 76.92 | 75 | 92.31 | 9,10 |
test/fixtures | 89.19 | 94.44 | 70 | 89.19 | |
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 | 75 | 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
Original file line number Diff line number Diff line change
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 8bb67b0

Please sign in to comment.