Skip to content

Commit 8bb67b0

Browse files
Kilian Ciuffolobcoe
authored andcommitted
fix: do not override NODE_V8_COVERAGE if set (#70)
1 parent dadc6b8 commit 8bb67b0

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

lib/parse-args.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ function buildYargs (withCommands = false) {
6262
type: 'boolean'
6363
})
6464
.option('temp-directory', {
65-
describe: 'directory V8 coverage data is written to and read from'
65+
describe: 'directory V8 coverage data is written to and read from',
66+
default: process.env.NODE_V8_COVERAGE
6667
})
6768
.option('resolve', {
6869
default: '',

test/integration.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ describe('c8', () => {
2626
output.toString('utf8').should.matchSnapshot()
2727
})
2828

29+
it('supports exeternally set NODE_V8_COVERAGE', () => {
30+
const { output } = spawnSync(nodePath, [
31+
c8Path,
32+
'--exclude="test/*.js"',
33+
'--clean=false',
34+
nodePath,
35+
require.resolve('./fixtures/normal')
36+
], {
37+
env: {
38+
'NODE_V8_COVERAGE': './coverage/tmp_'
39+
}
40+
})
41+
output.toString('utf8').should.matchSnapshot()
42+
})
43+
2944
it('merges reports from subprocesses together', () => {
3045
const { output } = spawnSync(nodePath, [
3146
c8Path,

test/integration.js.snap

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,36 @@ All files | 70.37 | 66.67 | 60 | 70.37 | |
200200
------------|----------|----------|----------|----------|-------------------|
201201
,"
202202
`;
203+
204+
exports[`c8 supports exeternally set NODE_V8_COVERAGE 1`] = `
205+
",hey
206+
i am a line of code
207+
what
208+
hey
209+
what
210+
hey
211+
what
212+
hey
213+
-----------------------|----------|----------|----------|----------|-------------------|
214+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
215+
-----------------------|----------|----------|----------|----------|-------------------|
216+
All files | 89.77 | 74.21 | 88.14 | 89.77 | |
217+
bin | 69.81 | 64.29 | 92.86 | 69.81 | |
218+
c8.js | 69.81 | 64.29 | 92.86 | 69.81 |... 49,50,51,52,53 |
219+
lib | 93.33 | 72.73 | 100 | 93.33 | |
220+
is-cjs-esm-bridge.js | 90 | 70 | 100 | 90 | 9 |
221+
parse-args.js | 97.69 | 47.83 | 100 | 97.69 | 99,107,108 |
222+
report.js | 90.29 | 83.64 | 100 | 90.29 |... 40,160,161,162 |
223+
lib/commands | 89.53 | 85.71 | 75 | 89.53 | |
224+
check-coverage.js | 88.33 | 93.33 | 75 | 88.33 |... 46,57,58,59,60 |
225+
report.js | 92.31 | 76.92 | 75 | 92.31 | 9,10 |
226+
test/fixtures | 89.19 | 94.44 | 70 | 89.19 | |
227+
async.js | 100 | 100 | 100 | 100 | |
228+
export.mjs | 71.43 | 100 | 50 | 71.43 | 2,3 |
229+
import.mjs | 100 | 100 | 100 | 100 | |
230+
multiple-spawn.js | 100 | 100 | 100 | 100 | |
231+
normal.js | 75 | 75 | 33.33 | 75 | 14,15,16,18,19,20 |
232+
subprocess.js | 100 | 100 | 100 | 100 | |
233+
-----------------------|----------|----------|----------|----------|-------------------|
234+
,"
235+
`;

test/parse-args.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ describe('parse-args', () => {
2121
const argv = buildYargs().parse(hideInstrumenteeArgs())
2222
const instrumenteeArgs = hideInstrumenterArgs(argv)
2323
instrumenteeArgs.should.eql(['my-app', '--help'])
24+
argv.tempDirectory.endsWith('/coverage/tmp').should.be.equal(true)
25+
})
26+
})
27+
28+
describe('with NODE_V8_COVERAGE already set', () => {
29+
it('should not override it', () => {
30+
const NODE_V8_COVERAGE = process.env.NODE_V8_COVERAGE
31+
process.env.NODE_V8_COVERAGE = './coverage/tmp_'
32+
process.argv = ['node', 'c8', '--foo=99', 'my-app', '--help']
33+
const argv = buildYargs().parse(hideInstrumenteeArgs())
34+
argv.tempDirectory.endsWith('/coverage/tmp_').should.be.equal(true)
35+
process.env.NODE_V8_COVERAGE = NODE_V8_COVERAGE
2436
})
2537
})
2638
})

0 commit comments

Comments
 (0)