diff --git a/lib/commands/report.js b/lib/commands/report.js index ec6e7fcc..b033422c 100644 --- a/lib/commands/report.js +++ b/lib/commands/report.js @@ -37,7 +37,8 @@ exports.outputReport = async function (argv) { skipFull: argv.skipFull, excludeNodeModules: argv.excludeNodeModules, mergeAsync: argv.mergeAsync, - monocartArgv: (argv.experimentalMonocart || process.env.EXPERIMENTAL_MONOCART) ? argv : null + monocartArgv: (argv.experimentalMonocart || process.env.EXPERIMENTAL_MONOCART) ? argv : null, + defaultSummarizer: argv.defaultSummarizer }) await report.run() if (argv.checkCoverage) await checkCoverages(argv, report) diff --git a/lib/parse-args.js b/lib/parse-args.js index 84ff8e3e..61db9244 100644 --- a/lib/parse-args.js +++ b/lib/parse-args.js @@ -76,6 +76,13 @@ function buildYargs (withCommands = false) { group: 'Reporting options', describe: 'apply exclude logic to files after they are remapped by a source-map' }) + .option('default-summarizer', { + type: 'string', + default: 'pkg', + choices: ['pkg', 'nested', 'flat'], + group: 'Reporting options', + describe: 'for some reporters you can change the summary and hierarchy of reported files' + }) .options('skip-full', { default: false, type: 'boolean', diff --git a/lib/report.js b/lib/report.js index 1fa51dfc..f81b1812 100644 --- a/lib/report.js +++ b/lib/report.js @@ -37,7 +37,8 @@ class Report { skipFull, excludeNodeModules, mergeAsync, - monocartArgv + monocartArgv, + defaultSummarizer }) { this.reporter = reporter this.reporterOptions = reporterOptions || {} @@ -62,6 +63,7 @@ class Report { this.skipFull = skipFull this.mergeAsync = mergeAsync this.monocartArgv = monocartArgv + this.defaultSummarizer = defaultSummarizer } _getSrc (src) { @@ -81,6 +83,7 @@ class Report { const context = libReport.createContext({ dir: this.reportsDirectory, watermarks: this.watermarks, + defaultSummarizer: this.defaultSummarizer, coverageMap: await this.getCoverageMapFromAllCoverageFiles() }) @@ -127,7 +130,6 @@ class Report { function getSourceFilter () { return argv.sourceFilter || argv.filter || function (sourcePath) { if (argv.excludeAfterRemap) { - // console.log(sourcePath) return exclude.shouldInstrument(sourcePath) } return true diff --git a/test/integration.js b/test/integration.js index 8e00be0b..f5906526 100644 --- a/test/integration.js +++ b/test/integration.js @@ -286,6 +286,22 @@ beforeEach(function () { status.should.equal(1) output.toString('utf8').should.matchSnapshot() }) + + it('passes defaultSummarizer to report', () => { + spawnSync(nodePath, [ + c8Path, + 'report', + '--exclude="test/*.js"', + '--clean=true', + '--reporter=html', + '--default-summarizer=flat', + `--merge-async=${mergeAsync}` + ]) + const html = readFileSync(resolve(process.cwd(), './coverage/index.html'), 'utf8') + // Remove timestamp added in HTML report. + .replace(/[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+.[0-9]+Z/g, '') + html.toString('utf8').should.matchSnapshot() + }) }) describe('ESM Modules', () => { @@ -595,16 +611,6 @@ beforeEach(function () { }) // see: https://github.com/bcoe/c8/issues/149 it('cobertura report escapes special characters', () => { - spawnSync(nodePath, [ - c8Path, - '--exclude="test/*.js"', - '--temp-directory=tmp/cobertura', - '--clean=true', - '--reporter=cobertura', - `--merge-async=${mergeAsync}`, - nodePath, - require.resolve('./fixtures/computed-method') - ]) const cobertura = readFileSync(resolve(process.cwd(), './coverage/cobertura-coverage.xml'), 'utf8') .replace(/[0-9]{13,}/, 'nnnn') .replace(/.*<\/source>/, '/foo/file') diff --git a/test/integration.js.snap b/test/integration.js.snap index fdbce704..6016c916 100644 --- a/test/integration.js.snap +++ b/test/integration.js.snap @@ -156,22 +156,23 @@ hey ---------------------------------------|---------|----------|---------|---------|------------------------ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ---------------------------------------|---------|----------|---------|---------|------------------------ -All files | 3.21 | 12.24 | 6.38 | 3.21 | +All files | 3.14 | 12 | 6.25 | 3.14 | 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-43 c8/coverage | 0 | 0 | 0 | 0 | block-navigation.js | 0 | 0 | 0 | 0 | 1-87 + bundle.js | 0 | 0 | 0 | 0 | 1-30 prettify.js | 0 | 0 | 0 | 0 | 1-2 sorter.js | 0 | 0 | 0 | 0 | 1-196 c8/lib | 0 | 0 | 0 | 0 | - parse-args.js | 0 | 0 | 0 | 0 | 1-229 - report.js | 0 | 0 | 0 | 0 | 1-542 + parse-args.js | 0 | 0 | 0 | 0 | 1-236 + report.js | 0 | 0 | 0 | 0 | 1-544 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-44 + report.js | 0 | 0 | 0 | 0 | 1-45 c8/test/fixtures | 29.08 | 35.29 | 20 | 29.08 | async.js | 100 | 100 | 100 | 100 | c8-ignore-next.js | 54.54 | 0 | 0 | 54.54 | 1,3-4,9,12,17-19,21-22 @@ -522,22 +523,23 @@ hey ---------------------------------------|---------|----------|---------|---------|------------------------ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ---------------------------------------|---------|----------|---------|---------|------------------------ -All files | 3.21 | 12.24 | 6.38 | 3.21 | +All files | 3.14 | 12 | 6.25 | 3.14 | 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-43 c8/coverage | 0 | 0 | 0 | 0 | block-navigation.js | 0 | 0 | 0 | 0 | 1-87 + bundle.js | 0 | 0 | 0 | 0 | 1-30 prettify.js | 0 | 0 | 0 | 0 | 1-2 sorter.js | 0 | 0 | 0 | 0 | 1-196 c8/lib | 0 | 0 | 0 | 0 | - parse-args.js | 0 | 0 | 0 | 0 | 1-229 - report.js | 0 | 0 | 0 | 0 | 1-542 + parse-args.js | 0 | 0 | 0 | 0 | 1-236 + report.js | 0 | 0 | 0 | 0 | 1-544 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-44 + report.js | 0 | 0 | 0 | 0 | 1-45 c8/test/fixtures | 29.08 | 35.29 | 20 | 29.08 | async.js | 100 | 100 | 100 | 100 | c8-ignore-next.js | 54.54 | 0 | 0 | 54.54 | 1,3-4,9,12,17-19,21-22 @@ -884,6 +886,379 @@ All files | 83.33 | 85.71 | 60 | 83.33 | ," `; +exports[`c8 mergeAsync report passes defaultSummarizer settings 1`] = ` +" + + + + + Code coverage report for All files + + + + + + + + + +
+
+

All files

+
+ +
+ 83.33% + Statements + 30/36 +
+ + +
+ 85.71% + Branches + 6/7 +
+ + +
+ 60% + Functions + 3/5 +
+ + +
+ 83.33% + Lines + 30/36 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
async.js +
+
100%12/12100%4/4100%2/2100%12/12
normal.js +
+
75%18/2466.66%2/333.33%1/375%18/24
+
+
+
+ + + + + + + + " +`; + +exports[`c8 mergeAsync report passes defaultSummarizer to report 1`] = ` +" + + + + + Code coverage report for All files + + + + + + + + + +
+
+

All files

+
+ +
+ 97.39% + Statements + 1046/1074 +
+ + +
+ 88.43% + Branches + 153/173 +
+ + +
+ 100% + Functions + 46/46 +
+ + +
+ 97.39% + Lines + 1046/1074 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
bin/c8.js +
+
95.34%41/43100%8/8100%1/195.34%41/43
lib/commands/check-coverage.js +
+
100%70/7093.33%14/15100%4/4100%70/70
lib/commands/report.js +
+
100%45/45100%11/11100%2/2100%45/45
lib/parse-args.js +
+
98.3%232/23675%9/12100%5/598.3%232/236
lib/report.js +
+
97.61%531/54489.71%96/107100%28/2897.61%531/544
lib/source-map-from-file.js +
+
91%91/10071.42%10/14100%4/491%91/100
test/fixtures/import-mcr.js +
+
100%12/1275%3/4100%2/2100%12/12
test/fixtures/report/report-multi-dir-external.js +
+
100%12/12100%1/1100%0/0100%12/12
test/fixtures/report/report-single-dir-external.js +
+
100%12/12100%1/1100%0/0100%12/12
+
+
+
+ + + + + + + + " +`; + exports[`c8 mergeAsync report supports --check-coverage, when generating reports 1`] = ` ",-----------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s @@ -1282,6 +1657,334 @@ All files | 83.33 | 85.71 | 60 | 83.33 | ," `; +exports[`c8 report passes defaultSummarizer settings 1`] = ` +" + + + + + Code coverage report for All files + + + + + + + + + +
+
+

All files

+
+ +
+ 83.33% + Statements + 30/36 +
+ + +
+ 85.71% + Branches + 6/7 +
+ + +
+ 60% + Functions + 3/5 +
+ + +
+ 83.33% + Lines + 30/36 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
async.js +
+
100%12/12100%4/4100%2/2100%12/12
normal.js +
+
75%18/2466.66%2/333.33%1/375%18/24
+
+
+
+ + + + + + + + " +`; + +exports[`c8 report passes defaultSummarizer to report 1`] = ` +" + + + + + Code coverage report for All files + + + + + + + + + +
+
+

All files

+
+ +
+ 76.2% + Statements + 791/1038 +
+ + +
+ 84.15% + Branches + 85/101 +
+ + +
+ 78.78% + Functions + 26/33 +
+ + +
+ 76.2% + Lines + 791/1038 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
bin/c8.js +
+
95.34%41/43100%8/8100%1/195.34%41/43
lib/commands/check-coverage.js +
+
100%70/7092.85%13/14100%4/4100%70/70
lib/commands/report.js +
+
100%45/4588.88%8/9100%2/2100%45/45
lib/parse-args.js +
+
98.3%232/23675%9/12100%5/598.3%232/236
lib/report.js +
+
64.15%349/54481.81%45/5576.47%13/1764.15%349/544
lib/source-map-from-file.js +
+
54%54/10066.66%2/325%1/454%54/100
+
+
+
+ + + + + + + + " +`; + exports[`c8 report supports --check-coverage, when generating reports 1`] = ` ",-----------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s