Skip to content

Commit

Permalink
feat: improve performance combining coverage on large codebases
Browse files Browse the repository at this point in the history
  • Loading branch information
koenvangeert committed Dec 7, 2023
1 parent d066085 commit 8784890
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions task.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const {
includeAllFiles
} = require('./task-utils')
const { fixSourcePaths } = require('./support-utils')
const { removePlaceholders } = require('./common-utils')

const debug = require('debug')('code-coverage')

Expand All @@ -30,6 +29,7 @@ const pkg = existsSync(pkgFilename)
const scripts = pkg.scripts || {}
const DEFAULT_CUSTOM_COVERAGE_SCRIPT_NAME = 'coverage:report'
const customNycReportScript = scripts[DEFAULT_CUSTOM_COVERAGE_SCRIPT_NAME]
let coverageMap = istanbul.createCoverageMap({})

const nycReportOptions = (function getNycOption() {
// /~https://github.com/istanbuljs/nyc#common-configuration-options
Expand Down Expand Up @@ -122,7 +122,7 @@ const tasks = {
resetCoverage({ isInteractive }) {
if (isInteractive) {
debug('reset code coverage in interactive mode')
const coverageMap = istanbul.createCoverageMap({})
coverageMap = istanbul.createCoverageMap({})
saveCoverage(coverageMap)
}
/*
Expand All @@ -148,21 +148,7 @@ const tasks = {

fixSourcePaths(coverage)

const previousCoverage = existsSync(nycFilename)
? JSON.parse(readFileSync(nycFilename, 'utf8'))
: {}

// previous code coverage object might have placeholder entries
// for files that we have not seen yet,
// but the user expects to include in the coverage report
// the merge function messes up, so we should remove any placeholder entries
// and re-insert them again when creating the report
removePlaceholders(previousCoverage)

const coverageMap = istanbul.createCoverageMap(previousCoverage)
coverageMap.merge(coverage)
saveCoverage(coverageMap)
debug('wrote coverage file %s', nycFilename)

return null
},
Expand All @@ -172,6 +158,7 @@ const tasks = {
* NPM script to generate HTML report
*/
coverageReport() {
saveCoverage(coverageMap)
if (!existsSync(nycFilename)) {
console.warn('Cannot find coverage file %s', nycFilename)
console.warn('Skipping coverage report')
Expand Down

0 comments on commit 8784890

Please sign in to comment.