From 8bb67b0150e4de058b962fa45b1a81a5c8ef3edc Mon Sep 17 00:00:00 2001 From: Kilian Ciuffolo Date: Mon, 6 May 2019 14:55:56 -0700 Subject: [PATCH] fix: do not override NODE_V8_COVERAGE if set (#70) --- lib/parse-args.js | 3 ++- test/integration.js | 15 +++++++++++++++ test/integration.js.snap | 33 +++++++++++++++++++++++++++++++++ test/parse-args.js | 12 ++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/lib/parse-args.js b/lib/parse-args.js index 54be3c89..e0d0ffda 100644 --- a/lib/parse-args.js +++ b/lib/parse-args.js @@ -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: '', diff --git a/test/integration.js b/test/integration.js index b2753012..53784c6b 100644 --- a/test/integration.js +++ b/test/integration.js @@ -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, diff --git a/test/integration.js.snap b/test/integration.js.snap index 0983a0b7..9ba0f1aa 100644 --- a/test/integration.js.snap +++ b/test/integration.js.snap @@ -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 | | +-----------------------|----------|----------|----------|----------|-------------------| +," +`; diff --git a/test/parse-args.js b/test/parse-args.js index 04f29194..522519b0 100644 --- a/test/parse-args.js +++ b/test/parse-args.js @@ -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 }) }) })