Skip to content

Commit

Permalink
feat: starting point for passing through default-summarizer
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Dec 20, 2024
1 parent 1ec3cc4 commit 86bbe9c
Show file tree
Hide file tree
Showing 5 changed files with 740 additions and 21 deletions.
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
26 changes: 16 additions & 10 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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>.*<\/source>/, '<source>/foo/file</source>')
Expand Down
Loading

0 comments on commit 86bbe9c

Please sign in to comment.