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

fix: improve performance combining coverage on large codebases #753

Merged
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
25 changes: 9 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 Down Expand Up @@ -59,6 +58,13 @@ const nycReportOptions = (function getNycOption() {

const nycFilename = join(nycReportOptions['temp-dir'], 'out.json')

let coverageMap = (() => {
const previousCoverage = existsSync(nycFilename)
? JSON.parse(readFileSync(nycFilename, 'utf8'))
: {}
return istanbul.createCoverageMap(previousCoverage)
})()

function saveCoverage(coverage) {
if (!existsSync(nycReportOptions.tempDir)) {
mkdirSync(nycReportOptions.tempDir, { recursive: true })
Expand Down Expand Up @@ -122,7 +128,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 +154,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 +164,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
Loading