Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: starting point for passing through default-summarizer #554

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/commands/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions lib/parse-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 4 additions & 2 deletions lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class Report {
skipFull,
excludeNodeModules,
mergeAsync,
monocartArgv
monocartArgv,
defaultSummarizer
}) {
this.reporter = reporter
this.reporterOptions = reporterOptions || {}
Expand All @@ -62,6 +63,7 @@ class Report {
this.skipFull = skipFull
this.mergeAsync = mergeAsync
this.monocartArgv = monocartArgv
this.defaultSummarizer = defaultSummarizer
}

_getSrc (src) {
Expand All @@ -81,6 +83,7 @@ class Report {
const context = libReport.createContext({
dir: this.reportsDirectory,
watermarks: this.watermarks,
defaultSummarizer: this.defaultSummarizer,
coverageMap: await this.getCoverageMapFromAllCoverageFiles()
})

Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading
Loading