From a5deb278dcdd7293e8e758ca892d0a44c6d9bba4 Mon Sep 17 00:00:00 2001 From: Brev Patterson Date: Sun, 15 May 2022 17:50:47 -0700 Subject: [PATCH] fix: `--all` now respects `--extension` flag. (#357) --- lib/report.js | 3 +- test/fixtures/custom-ext2.special | 24 +++++++ test/integration.js | 17 ++++- test/integration.js.snap | 78 ++++++++++++++++++++ test/integration.js_10.snap | 116 +++++++++++++++++++++++++----- 5 files changed, 217 insertions(+), 21 deletions(-) create mode 100644 test/fixtures/custom-ext2.special diff --git a/lib/report.js b/lib/report.js index 17485e25..d86cc611 100644 --- a/lib/report.js +++ b/lib/report.js @@ -190,12 +190,13 @@ class Report { result: emptyReports }) const workingDirs = this.src + const { extension } = this.exclude for (const workingDir of workingDirs) { this.exclude.globSync(workingDir).forEach((f) => { const fullPath = resolve(workingDir, f) if (!fileIndex.has(fullPath)) { const ext = extname(fullPath) - if (ext === '.js' || ext === '.ts' || ext === '.mjs') { + if (extension.includes(ext)) { const stat = statSync(fullPath) const sourceMap = getSourceMapFromFile(fullPath) if (sourceMap) { diff --git a/test/fixtures/custom-ext2.special b/test/fixtures/custom-ext2.special new file mode 100644 index 00000000..6b407dea --- /dev/null +++ b/test/fixtures/custom-ext2.special @@ -0,0 +1,24 @@ +require('./async') + +console.info('i am a line of code 2') + +function apple (awesome) { + if (false || true) { + console.info('what2') + } + if (true || false) { + console.log('hey2') + } +} + +function missed () { + +} + +function missed2 () { + +} + +apple() +apple() +apple() diff --git a/test/integration.js b/test/integration.js index ee5ad0e4..385b3a26 100644 --- a/test/integration.js +++ b/test/integration.js @@ -639,7 +639,22 @@ describe('c8', () => { '--extension=.js', '--extension=.special', '--temp-directory=tmp/extension', - '--clean=false', + '--clean=true', + nodePath, + require.resolve('./fixtures/custom-ext.special') + ]) + output.toString('utf8').should.matchSnapshot() + }) + + it('includes coverage when extensions specified with --all', () => { + const { output } = spawnSync(nodePath, [ + c8Path, + '--all', + '--exclude="test/*.js"', + '--extension=.js', + '--extension=.special', + '--temp-directory=tmp/extension', + '--clean=true', nodePath, require.resolve('./fixtures/custom-ext.special') ]) diff --git a/test/integration.js.snap b/test/integration.js.snap index ef03cc73..9a07de94 100644 --- a/test/integration.js.snap +++ b/test/integration.js.snap @@ -144,6 +144,84 @@ All files | 83.33 | 85.71 | 60 | 83.33 | ," `; +exports[`c8 --extension includes coverage when extensions specified with --all 1`] = ` +",hey +i am a line of code +what +hey +what +hey +what +hey +---------------------------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +---------------------------------------|---------|----------|---------|---------|------------------- +All files | 1.91 | 12 | 6.25 | 1.91 | + c8 | 0 | 0 | 0 | 0 | + index.js | 0 | 0 | 0 | 0 | 1 + c8/bin | 0 | 0 | 0 | 0 | + c8.js | 0 | 0 | 0 | 0 | 1-52 + c8/coverage | 0 | 0 | 0 | 0 | + block-navigation.js | 0 | 0 | 0 | 0 | 1-87 + prettify.js | 0 | 0 | 0 | 0 | 1-2 + sorter.js | 0 | 0 | 0 | 0 | 1-196 + c8/lib | 0 | 0 | 0 | 0 | + is-cjs-esm-bridge.js | 0 | 0 | 0 | 0 | 1-10 + parse-args.js | 0 | 0 | 0 | 0 | 1-218 + report.js | 0 | 0 | 0 | 0 | 1-337 + source-map-from-file.js | 0 | 0 | 0 | 0 | 1-100 + c8/lib/commands | 0 | 0 | 0 | 0 | + check-coverage.js | 0 | 0 | 0 | 0 | 1-70 + report.js | 0 | 0 | 0 | 0 | 1-41 + c8/test/fixtures | 15.95 | 35.29 | 20 | 15.95 | + async.js | 100 | 100 | 100 | 100 | + c8-ignore-next.js | 0 | 0 | 0 | 0 | 1-22 + c8-ignore-start-stop.js | 0 | 0 | 0 | 0 | 1-21 + computed-method.js | 0 | 0 | 0 | 0 | 1-15 + custom-ext.special | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 + custom-ext2.special | 0 | 0 | 0 | 0 | 1-24 + disable-fs-promises.js | 0 | 0 | 0 | 0 | 1-4 + issue-254.js | 0 | 0 | 0 | 0 | 1-7 + multiple-spawn.js | 0 | 0 | 0 | 0 | 1-12 + normal.js | 0 | 0 | 0 | 0 | 1-24 + shebang.js | 0 | 0 | 0 | 0 | 1-8 + subprocess.js | 0 | 0 | 0 | 0 | 1-15 + c8/test/fixtures/all/ts-compiled | 0 | 0 | 0 | 0 | + loaded.ts | 0 | 0 | 0 | 0 | 1-19 + main.ts | 0 | 0 | 0 | 0 | 1-4 + c8/test/fixtures/all/ts-compiled/dir | 0 | 0 | 0 | 0 | + unloaded.ts | 0 | 0 | 0 | 0 | 1-5 + c8/test/fixtures/all/vanilla | 0 | 0 | 0 | 0 | + loaded.js | 0 | 0 | 0 | 0 | 1-19 + main.js | 0 | 0 | 0 | 0 | 1-4 + c8/test/fixtures/all/vanilla/dir | 0 | 0 | 0 | 0 | + unloaded.js | 0 | 0 | 0 | 0 | 1-5 + c8/test/fixtures/multidir1 | 0 | 0 | 0 | 0 | + file1.js | 0 | 0 | 0 | 0 | 1 + c8/test/fixtures/multidir2 | 0 | 0 | 0 | 0 | + file2.js | 0 | 0 | 0 | 0 | 1 + c8/test/fixtures/report | 0 | 0 | 0 | 0 | + allowExternal.js | 0 | 0 | 0 | 0 | 1 + report-multi-dir-external.js | 0 | 0 | 0 | 0 | 1-12 + report-single-dir-external.js | 0 | 0 | 0 | 0 | 1-12 + srcOverride.js | 0 | 0 | 0 | 0 | 1 + c8/test/fixtures/source-maps | 0 | 0 | 0 | 0 | + branches.js | 0 | 0 | 0 | 0 | 1-20 + fake-source-map.js | 0 | 0 | 0 | 0 | 1-7 + c8/test/fixtures/source-maps/branches | 0 | 0 | 0 | 0 | + branch-1.js | 0 | 0 | 0 | 0 | 1-12 + branch-2.js | 0 | 0 | 0 | 0 | 1-9 + branches.js | 0 | 0 | 0 | 0 | 1-20 + branches.typescript.ts | 0 | 0 | 0 | 0 | 1-25 + c8/test/fixtures/source-maps/classes | 0 | 0 | 0 | 0 | + class-1.js | 0 | 0 | 0 | 0 | 1-5 + class-2.js | 0 | 0 | 0 | 0 | 1-23 + classes.js | 0 | 0 | 0 | 0 | 1-27 + classes.typescript.ts | 0 | 0 | 0 | 0 | 1-33 +---------------------------------------|---------|----------|---------|---------|------------------- +," +`; + exports[`c8 ESM Modules collects coverage for ESM modules 1`] = ` ",bar foo ------------|---------|----------|---------|---------|------------------- diff --git a/test/integration.js_10.snap b/test/integration.js_10.snap index dca7c5de..9ec617bf 100644 --- a/test/integration.js_10.snap +++ b/test/integration.js_10.snap @@ -144,6 +144,84 @@ All files | 83.33 | 85.71 | 66.66 | 83.33 | ," `; +exports[`c8 --extension includes coverage when extensions specified with --all 1`] = ` +",hey +i am a line of code +what +hey +what +hey +what +hey +---------------------------------------|---------|----------|---------|---------|------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +---------------------------------------|---------|----------|---------|---------|------------------- +All files | 1.91 | 12 | 8.16 | 1.91 | + c8 | 0 | 0 | 0 | 0 | + index.js | 0 | 0 | 0 | 0 | 1 + c8/bin | 0 | 0 | 0 | 0 | + c8.js | 0 | 0 | 0 | 0 | 1-52 + c8/coverage | 0 | 0 | 0 | 0 | + block-navigation.js | 0 | 0 | 0 | 0 | 1-87 + prettify.js | 0 | 0 | 0 | 0 | 1-2 + sorter.js | 0 | 0 | 0 | 0 | 1-196 + c8/lib | 0 | 0 | 0 | 0 | + is-cjs-esm-bridge.js | 0 | 0 | 0 | 0 | 1-10 + parse-args.js | 0 | 0 | 0 | 0 | 1-218 + report.js | 0 | 0 | 0 | 0 | 1-337 + source-map-from-file.js | 0 | 0 | 0 | 0 | 1-100 + c8/lib/commands | 0 | 0 | 0 | 0 | + check-coverage.js | 0 | 0 | 0 | 0 | 1-70 + report.js | 0 | 0 | 0 | 0 | 1-41 + c8/test/fixtures | 15.95 | 35.29 | 25 | 15.95 | + async.js | 100 | 100 | 100 | 100 | + c8-ignore-next.js | 0 | 0 | 0 | 0 | 1-22 + c8-ignore-start-stop.js | 0 | 0 | 0 | 0 | 1-21 + computed-method.js | 0 | 0 | 0 | 0 | 1-15 + custom-ext.special | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 + custom-ext2.special | 0 | 0 | 0 | 0 | 1-24 + disable-fs-promises.js | 0 | 0 | 0 | 0 | 1-4 + issue-254.js | 0 | 0 | 0 | 0 | 1-7 + multiple-spawn.js | 0 | 0 | 0 | 0 | 1-12 + normal.js | 0 | 0 | 0 | 0 | 1-24 + shebang.js | 0 | 0 | 0 | 0 | 1-8 + subprocess.js | 0 | 0 | 0 | 0 | 1-15 + c8/test/fixtures/all/ts-compiled | 0 | 0 | 0 | 0 | + loaded.ts | 0 | 0 | 0 | 0 | 1-19 + main.ts | 0 | 0 | 0 | 0 | 1-4 + c8/test/fixtures/all/ts-compiled/dir | 0 | 0 | 0 | 0 | + unloaded.ts | 0 | 0 | 0 | 0 | 1-5 + c8/test/fixtures/all/vanilla | 0 | 0 | 0 | 0 | + loaded.js | 0 | 0 | 0 | 0 | 1-19 + main.js | 0 | 0 | 0 | 0 | 1-4 + c8/test/fixtures/all/vanilla/dir | 0 | 0 | 0 | 0 | + unloaded.js | 0 | 0 | 0 | 0 | 1-5 + c8/test/fixtures/multidir1 | 0 | 0 | 0 | 0 | + file1.js | 0 | 0 | 0 | 0 | 1 + c8/test/fixtures/multidir2 | 0 | 0 | 0 | 0 | + file2.js | 0 | 0 | 0 | 0 | 1 + c8/test/fixtures/report | 0 | 0 | 0 | 0 | + allowExternal.js | 0 | 0 | 0 | 0 | 1 + report-multi-dir-external.js | 0 | 0 | 0 | 0 | 1-12 + report-single-dir-external.js | 0 | 0 | 0 | 0 | 1-12 + srcOverride.js | 0 | 0 | 0 | 0 | 1 + c8/test/fixtures/source-maps | 0 | 0 | 0 | 0 | + branches.js | 0 | 0 | 0 | 0 | 1-20 + fake-source-map.js | 0 | 0 | 0 | 0 | 1-7 + c8/test/fixtures/source-maps/branches | 0 | 0 | 0 | 0 | + branch-1.js | 0 | 0 | 0 | 0 | 1-12 + branch-2.js | 0 | 0 | 0 | 0 | 1-9 + branches.js | 0 | 0 | 0 | 0 | 1-20 + branches.typescript.ts | 0 | 0 | 0 | 0 | 1-25 + c8/test/fixtures/source-maps/classes | 0 | 0 | 0 | 0 | + class-1.js | 0 | 0 | 0 | 0 | 1-5 + class-2.js | 0 | 0 | 0 | 0 | 1-23 + classes.js | 0 | 0 | 0 | 0 | 1-27 + classes.typescript.ts | 0 | 0 | 0 | 0 | 1-33 +---------------------------------------|---------|----------|---------|---------|------------------- +," +`; + exports[`c8 check-coverage --100 1`] = ` ",hey i am a line of code @@ -179,13 +257,13 @@ hey --------------------------|---------|----------|---------|---------|-------------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------------|---------|----------|---------|---------|-------------------------------- -All files | 74.04 | 58.82 | 63.41 | 74.04 | +All files | 73.95 | 58.82 | 63.41 | 73.95 | bin | 78.84 | 60 | 66.66 | 78.84 | c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51 - lib | 78.61 | 54.23 | 73.07 | 78.61 | + lib | 78.49 | 54.23 | 73.07 | 78.49 | is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 parse-args.js | 97.24 | 58.33 | 100 | 97.24 | 159-160,181-182,195-196 - report.js | 76.19 | 57.89 | 80 | 76.19 | ...280,286-288,309-314,325-326 + report.js | 75.96 | 57.89 | 80 | 75.96 | ...281,287-289,310-315,326-327 source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98 lib/commands | 41.44 | 66.66 | 16.66 | 41.44 | check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70 @@ -194,9 +272,9 @@ All files | 74.04 | 58.82 | 63.41 | 74.04 | async.js | 100 | 100 | 100 | 100 | normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 --------------------------|---------|----------|---------|---------|-------------------------------- -,ERROR: Coverage for lines (74.04%) does not meet global threshold (101%) +,ERROR: Coverage for lines (73.95%) does not meet global threshold (101%) ERROR: Coverage for branches (58.82%) does not meet global threshold (82%) -ERROR: Coverage for statements (74.04%) does not meet global threshold (95%) +ERROR: Coverage for statements (73.95%) does not meet global threshold (95%) " `; @@ -214,9 +292,9 @@ ERROR: Coverage for branches (25%) does not meet threshold (82%) for lib/is-cjs- ERROR: Coverage for statements (90%) does not meet threshold (95%) for lib/is-cjs-esm-bridge.js ERROR: Coverage for lines (97.24%) does not meet threshold (101%) for lib/parse-args.js ERROR: Coverage for branches (58.33%) does not meet threshold (82%) for lib/parse-args.js -ERROR: Coverage for lines (76.19%) does not meet threshold (101%) for lib/report.js +ERROR: Coverage for lines (75.96%) does not meet threshold (101%) for lib/report.js ERROR: Coverage for branches (57.89%) does not meet threshold (82%) for lib/report.js -ERROR: Coverage for statements (76.19%) does not meet threshold (95%) for lib/report.js +ERROR: Coverage for statements (75.96%) does not meet threshold (95%) for lib/report.js ERROR: Coverage for lines (45%) does not meet threshold (101%) for lib/source-map-from-file.js ERROR: Coverage for statements (45%) does not meet threshold (95%) for lib/source-map-from-file.js ERROR: Coverage for lines (100%) does not meet threshold (101%) for test/fixtures/async.js @@ -227,19 +305,19 @@ ERROR: Coverage for statements (75%) does not meet threshold (95%) for test/fixt `; exports[`c8 check-coverage check-coverage command with --100 1`] = ` -",,ERROR: Coverage for lines (77.75%) does not meet global threshold (100%) +",,ERROR: Coverage for lines (77.66%) does not meet global threshold (100%) ERROR: Coverage for functions (67.44%) does not meet global threshold (100%) ERROR: Coverage for branches (62.06%) does not meet global threshold (100%) -ERROR: Coverage for statements (77.75%) does not meet global threshold (100%) +ERROR: Coverage for statements (77.66%) does not meet global threshold (100%) " `; exports[`c8 check-coverage exits with 0 if coverage within threshold 1`] = `",,"`; exports[`c8 check-coverage exits with 1 if coverage is below threshold 1`] = ` -",,ERROR: Coverage for lines (74.04%) does not meet global threshold (101%) +",,ERROR: Coverage for lines (73.95%) does not meet global threshold (101%) ERROR: Coverage for branches (58.82%) does not meet global threshold (82%) -ERROR: Coverage for statements (74.04%) does not meet global threshold (95%) +ERROR: Coverage for statements (73.95%) does not meet global threshold (95%) " `; @@ -326,13 +404,13 @@ exports[`c8 report generates report from existing temporary files 1`] = ` ",--------------------------|---------|----------|---------|---------|-------------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------------|---------|----------|---------|---------|-------------------------------- -All files | 74.04 | 58.82 | 63.41 | 74.04 | +All files | 73.95 | 58.82 | 63.41 | 73.95 | bin | 78.84 | 60 | 66.66 | 78.84 | c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51 - lib | 78.61 | 54.23 | 73.07 | 78.61 | + lib | 78.49 | 54.23 | 73.07 | 78.49 | is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 parse-args.js | 97.24 | 58.33 | 100 | 97.24 | 159-160,181-182,195-196 - report.js | 76.19 | 57.89 | 80 | 76.19 | ...280,286-288,309-314,325-326 + report.js | 75.96 | 57.89 | 80 | 75.96 | ...281,287-289,310-315,326-327 source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98 lib/commands | 41.44 | 66.66 | 16.66 | 41.44 | check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70 @@ -348,13 +426,13 @@ exports[`c8 report supports --check-coverage, when generating reports 1`] = ` ",--------------------------|---------|----------|---------|---------|-------------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------------------|---------|----------|---------|---------|-------------------------------- -All files | 74.04 | 58.82 | 63.41 | 74.04 | +All files | 73.95 | 58.82 | 63.41 | 73.95 | bin | 78.84 | 60 | 66.66 | 78.84 | c8.js | 78.84 | 60 | 66.66 | 78.84 | 22,27-29,32-33,41-43,50-51 - lib | 78.61 | 54.23 | 73.07 | 78.61 | + lib | 78.49 | 54.23 | 73.07 | 78.49 | is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9 parse-args.js | 97.24 | 58.33 | 100 | 97.24 | 159-160,181-182,195-196 - report.js | 76.19 | 57.89 | 80 | 76.19 | ...280,286-288,309-314,325-326 + report.js | 75.96 | 57.89 | 80 | 75.96 | ...281,287-289,310-315,326-327 source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98 lib/commands | 41.44 | 66.66 | 16.66 | 41.44 | check-coverage.js | 18.57 | 100 | 0 | 18.57 | 9-11,14-36,39-53,55-70 @@ -363,9 +441,9 @@ All files | 74.04 | 58.82 | 63.41 | 74.04 | async.js | 100 | 100 | 100 | 100 | normal.js | 75 | 66.66 | 33.33 | 75 | 14-16,18-20 --------------------------|---------|----------|---------|---------|-------------------------------- -,ERROR: Coverage for lines (74.04%) does not meet global threshold (101%) +,ERROR: Coverage for lines (73.95%) does not meet global threshold (101%) ERROR: Coverage for branches (58.82%) does not meet global threshold (82%) -ERROR: Coverage for statements (74.04%) does not meet global threshold (95%) +ERROR: Coverage for statements (73.95%) does not meet global threshold (95%) " `;