Skip to content

Commit

Permalink
fix: all flag not propagated to check-coverage command (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
j03m authored and bcoe committed Jan 13, 2020
1 parent 2ab701f commit 86eaf72
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/commands/check-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ exports.handler = function (argv) {
watermarks: argv.watermarks,
resolve: argv.resolve,
omitRelative: argv.omitRelative,
wrapperLength: argv.wrapperLength
wrapperLength: argv.wrapperLength,
all: argv.all
})
exports.checkCoverages(argv, report)
}
Expand Down
50 changes: 48 additions & 2 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { spawnSync } = require('child_process')
const { statSync } = require('fs')
const c8Path = require.resolve('../bin/c8')
const nodePath = process.execPath
const tsNodePath = './node_modules/.bin/ts-node'
const chaiJestSnapshot = require('chai-jest-snapshot')
const rimraf = require('rimraf')

Expand Down Expand Up @@ -321,7 +322,7 @@ describe('c8', () => {
'--exclude="test/*.js"',
'--temp-directory=tmp/source-map',
'--clean=true',
'./node_modules/.bin/ts-node',
tsNodePath,
require.resolve('./fixtures/ts-node-basic.ts')
])
output.toString('utf8').should.matchSnapshot()
Expand Down Expand Up @@ -364,10 +365,55 @@ describe('c8', () => {
'--all=true',
'--include=test/fixtures/all/ts-only/**/*.ts',
'--exclude="test/*.js"', // add an exclude to avoid default excludes of test/**
'./node_modules/.bin/ts-node',
tsNodePath,
require.resolve('./fixtures/all/ts-only/main.ts')
])
output.toString('utf8').should.matchSnapshot()
})

it('should allow for --all to be used in conjunction with --check-coverage', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--temp-directory=tmp/all-check-coverage',
'--clean=false',
'--check-coverage',
'--lines=100',
'--all=true',
'--include=test/fixtures/all/vanilla/**/*.js',
'--exclude=**/*.ts', // add an exclude to avoid default excludes of test/**
nodePath,
require.resolve('./fixtures/all/vanilla/main')
])
output.toString('utf8').should.matchSnapshot()
})

it('should allow for --all to be used with the check-coverage command (2 invocations)', () => {
// generate v8 output
spawnSync(nodePath, [
c8Path,
'--temp-directory=tmp/all-check-coverage-as-command',
'--clean=false',
'--check-coverage',
'--lines=90',
'--all=true',
'--include=test/fixtures/all/vanilla/**/*.js',
'--exclude=**/*.ts', // add an exclude to avoid default excludes of test/**
nodePath,
require.resolve('./fixtures/all/vanilla/main')
])

// invoke check-coverage as a command with --all
const { output } = spawnSync(nodePath, [
c8Path,
'check-coverage',
'--lines=90',
'--temp-directory=tmp/all-check-coverage-as-command',
'--clean=false',
'--all=true',
'--include=test/fixtures/all/vanilla/**/*.js',
'--exclude=**/*.ts' // add an exclude to avoid default excludes of test/**
])
output.toString('utf8').should.matchSnapshot()
})
})
})
23 changes: 23 additions & 0 deletions test/integration.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ All files | 64.29 | 66.67 | 50 | 64.29 |
,"
`;

exports[`c8 --all should allow for --all to be used in conjunction with --check-coverage 1`] = `
",zero
positive
negative
--------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------|---------|----------|---------|---------|-------------------
All files | 64.29 | 66.67 | 50 | 64.29 |
vanilla | 78.26 | 75 | 100 | 78.26 |
loaded.js | 73.68 | 71.43 | 100 | 73.68 | 4,5,16-18
main.js | 100 | 100 | 100 | 100 |
vanilla/dir | 0 | 0 | 0 | 0 |
unloaded.js | 0 | 0 | 0 | 0 | 1-5
--------------|---------|----------|---------|---------|-------------------
,ERROR: Coverage for lines (64.29%) does not meet global threshold (100%)
"
`;

exports[`c8 --all should allow for --all to be used with the check-coverage command (2 invocations) 1`] = `
",,ERROR: Coverage for lines (64.29%) does not meet global threshold (90%)
"
`;

exports[`c8 ESM Modules collects coverage for ESM modules 1`] = `
",bar foo
------------|---------|----------|---------|---------|-------------------
Expand Down

0 comments on commit 86eaf72

Please sign in to comment.