From 86eaf72a8c7af93d6ec9699b741d11df50017a8d Mon Sep 17 00:00:00 2001 From: Joseph Mordetsky Date: Mon, 13 Jan 2020 17:50:30 -0500 Subject: [PATCH] fix: all flag not propagated to check-coverage command (#188) --- lib/commands/check-coverage.js | 3 +- test/integration.js | 50 ++++++++++++++++++++++++++++++++-- test/integration.js.snap | 23 ++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/lib/commands/check-coverage.js b/lib/commands/check-coverage.js index 7efe2e5f..e0b1105f 100644 --- a/lib/commands/check-coverage.js +++ b/lib/commands/check-coverage.js @@ -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) } diff --git a/test/integration.js b/test/integration.js index 6b5536d6..839766e0 100644 --- a/test/integration.js +++ b/test/integration.js @@ -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') @@ -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() @@ -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() + }) }) }) diff --git a/test/integration.js.snap b/test/integration.js.snap index 4d8265e0..f6936bee 100644 --- a/test/integration.js.snap +++ b/test/integration.js.snap @@ -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 ------------|---------|----------|---------|---------|-------------------