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/package.json b/package.json index 18fb20be..43e067da 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "url": "git@github.com:bcoe/c8.git" }, "scripts": { - "test": "node ./bin/c8.js --reporter=html --reporter=text mocha --timeout=4000 ./test/*.js", + "test": "node ./bin/c8.js --reporter=html --reporter=text mocha --timeout=8000 ./test/*.js", "test:snap": "CHAI_JEST_SNAPSHOT_UPDATE_ALL=true npm test", "posttest": "standard", "coverage": "./bin/c8.js report --reporter=html --reporter=text-lcov | coveralls", diff --git a/test/integration.js b/test/integration.js index b2753012..7bdc3f58 100644 --- a/test/integration.js +++ b/test/integration.js @@ -1,6 +1,7 @@ /* global describe, before, beforeEach, it */ const { spawnSync } = require('child_process') +const { statSync } = require('fs') const c8Path = require.resolve('../bin/c8') const nodePath = process.execPath const chaiJestSnapshot = require('chai-jest-snapshot') @@ -26,6 +27,23 @@ 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': 'tmp/override' + } + }) + const stats = statSync('tmp/override') + stats.isDirectory().should.equal(true) + 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..1c45ccbd 100644 --- a/test/integration.js.snap +++ b/test/integration.js.snap @@ -200,3 +200,22 @@ 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 | 83.33 | 85.71 | 60 | 83.33 | | + async.js | 100 | 100 | 100 | 100 | | + normal.js | 75 | 66.67 | 33.33 | 75 | 14,15,16,18,19,20 | +-----------|----------|----------|----------|----------|-------------------| +," +`; diff --git a/test/parse-args.js b/test/parse-args.js index 04f29194..e742a4d2 100644 --- a/test/parse-args.js +++ b/test/parse-args.js @@ -6,6 +6,8 @@ const { hideInstrumenterArgs } = require('../lib/parse-args') +const { join } = require('path') + describe('parse-args', () => { describe('hideInstrumenteeArgs', () => { it('hides arguments passed to instrumented app', () => { @@ -21,6 +23,18 @@ describe('parse-args', () => { const argv = buildYargs().parse(hideInstrumenteeArgs()) const instrumenteeArgs = hideInstrumenterArgs(argv) instrumenteeArgs.should.eql(['my-app', '--help']) + argv.tempDirectory.endsWith(join('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 }) }) })