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..82c0a1e8 100644 --- a/test/integration.js +++ b/test/integration.js @@ -286,6 +286,23 @@ 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', + '--temp-directory=./tmp/report', + `--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', () => { diff --git a/test/integration.js.snap b/test/integration.js.snap index fdbce704..409fbc45 100644 --- a/test/integration.js.snap +++ b/test/integration.js.snap @@ -156,7 +156,7 @@ hey ---------------------------------------|---------|----------|---------|---------|------------------------ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ---------------------------------------|---------|----------|---------|---------|------------------------ -All files | 3.21 | 12.24 | 6.38 | 3.21 | +All files | 3.19 | 12.24 | 6.38 | 3.19 | c8 | 0 | 0 | 0 | 0 | index.js | 0 | 0 | 0 | 0 | 1 c8/bin | 0 | 0 | 0 | 0 | @@ -166,12 +166,12 @@ All files | 3.21 | 12.24 | 6.38 | 3.21 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,7 +522,7 @@ hey ---------------------------------------|---------|----------|---------|---------|------------------------ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ---------------------------------------|---------|----------|---------|---------|------------------------ -All files | 3.21 | 12.24 | 6.38 | 3.21 | +All files | 3.19 | 12.24 | 6.38 | 3.19 | c8 | 0 | 0 | 0 | 0 | index.js | 0 | 0 | 0 | 0 | 1 c8/bin | 0 | 0 | 0 | 0 | @@ -532,12 +532,12 @@ All files | 3.21 | 12.24 | 6.38 | 3.21 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 +884,274 @@ 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

+
+ +
+ 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 supports --check-coverage, when generating reports 1`] = ` ",-----------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s @@ -1282,6 +1550,274 @@ 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

+
+ +
+ 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 supports --check-coverage, when generating reports 1`] = ` ",-----------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s