Skip to content

Commit

Permalink
chore: seeing kilianc's work over finish line
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Jun 23, 2019
2 parents 211ac27 + c9decd2 commit a8c64f1
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/parse-args.js
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
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
18 changes: 18 additions & 0 deletions 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')
Expand All @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions test/integration.js.snap
Expand Up @@ -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 |
-----------|----------|----------|----------|----------|-------------------|
,"
`;
14 changes: 14 additions & 0 deletions test/parse-args.js
Expand Up @@ -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', () => {
Expand All @@ -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
})
})
})

0 comments on commit a8c64f1

Please sign in to comment.