From 8bb67b0150e4de058b962fa45b1a81a5c8ef3edc Mon Sep 17 00:00:00 2001 From: Kilian Ciuffolo Date: Mon, 6 May 2019 14:55:56 -0700 Subject: [PATCH 1/4] 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 }) }) }) From 40db7fc59aad2fef438de2448506d815a891743f Mon Sep 17 00:00:00 2001 From: bcoe Date: Sun, 23 Jun 2019 13:15:10 -0700 Subject: [PATCH 2/4] chore: see kilianc's work over finish line --- test/integration.js | 5 ++++- test/integration.js.snap | 28 +++++++--------------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/test/integration.js b/test/integration.js index 53784c6b..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') @@ -35,9 +36,11 @@ describe('c8', () => { require.resolve('./fixtures/normal') ], { env: { - 'NODE_V8_COVERAGE': './coverage/tmp_' + 'NODE_V8_COVERAGE': 'tmp/override' } }) + const stats = statSync('tmp/override') + stats.isDirectory().should.equal(true) output.toString('utf8').should.matchSnapshot() }) diff --git a/test/integration.js.snap b/test/integration.js.snap index 9ba0f1aa..1c45ccbd 100644 --- a/test/integration.js.snap +++ b/test/integration.js.snap @@ -210,26 +210,12 @@ 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 | | ------------------------|----------|----------|----------|----------|-------------------| +-----------|----------|----------|----------|----------|-------------------| +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 | +-----------|----------|----------|----------|----------|-------------------| ," `; From e0fa89fa4858c626f3dd4dbca03d013b4ec35546 Mon Sep 17 00:00:00 2001 From: bcoe Date: Sun, 23 Jun 2019 13:27:53 -0700 Subject: [PATCH 3/4] chore: handle Windows paths --- test/parse-args.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/parse-args.js b/test/parse-args.js index 522519b0..5d66709e 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', () => { @@ -31,7 +33,7 @@ describe('parse-args', () => { 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) + argv.tempDirectory.endsWith(join('coverage', 'tmp_')).should.be.equal(true) process.env.NODE_V8_COVERAGE = NODE_V8_COVERAGE }) }) From c9decd26c23c7613fd46f9cc1068f0818dceaa4c Mon Sep 17 00:00:00 2001 From: bcoe Date: Sun, 23 Jun 2019 13:38:08 -0700 Subject: [PATCH 4/4] test: wrestle with windows directories --- package.json | 2 +- test/parse-args.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 18f2968a..a94ffde1 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/parse-args.js b/test/parse-args.js index 5d66709e..e742a4d2 100644 --- a/test/parse-args.js +++ b/test/parse-args.js @@ -23,7 +23,7 @@ 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) + argv.tempDirectory.endsWith(join('coverage', 'tmp')).should.be.equal(true) }) }) @@ -33,7 +33,7 @@ describe('parse-args', () => { process.env.NODE_V8_COVERAGE = './coverage/tmp_' process.argv = ['node', 'c8', '--foo=99', 'my-app', '--help'] const argv = buildYargs().parse(hideInstrumenteeArgs()) - argv.tempDirectory.endsWith(join('coverage', 'tmp_')).should.be.equal(true) + argv.tempDirectory.endsWith('/coverage/tmp_').should.be.equal(true) process.env.NODE_V8_COVERAGE = NODE_V8_COVERAGE }) })