Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ class Report {
if (/^file:\/\//.test(v8ScriptCov.url)) {
try {
v8ScriptCov.url = fileURLToPath(v8ScriptCov.url)
fileIndex.add(v8ScriptCov.url)
} catch (err) {
debuglog(`${err.stack}`)
continue
Expand All @@ -496,6 +495,7 @@ class Report {
if ((!this.omitRelative || isAbsolute(v8ScriptCov.url))) {
if (this.excludeAfterRemap || this._shouldInstrument(v8ScriptCov.url)) {
result.push(v8ScriptCov)
fileIndex.add(v8ScriptCov.url)
}
}
}
Expand Down
39 changes: 39 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const { resolve } = require('path')
const { spawnSync } = require('child_process')
const { statSync, rm } = require('fs')
const { dirname } = require('path')
const { pathToFileURL } = require('url')
const createReport = require('../lib/report')
const c8Path = require.resolve('../bin/c8')
const nodePath = process.execPath
const tsNodePath = './node_modules/.bin/ts-node'
Expand Down Expand Up @@ -592,6 +594,43 @@ beforeEach(function () {
])
output.toString('utf8').should.matchSnapshot()
})

it('should only track files that pass shouldInstrument in fileIndex', () => {
const report = createReport({
include: ['fake/src/**/*.js'],
exclude: [],
tempDirectory: 'tmp/filtered-fileindex',
reportsDirectory: 'coverage/filtered-fileindex',
reporter: ['text']
})

const includedFile = resolve('fake/src/should-be-in-fileindex.js')
const excludedFile = resolve('fake/lib/should-not-be-in-fileindex.js')
const entryFile = resolve('fake/should-not-be-in-fileindex.js')

const fileIndex = new Set()
const fakeCovEntry = (scriptId, filepath) => ({
scriptId,
url: pathToFileURL(filepath).href,
functions: [{
functionName: '',
ranges: [{ startOffset: 0, endOffset: 100, count: 1 }],
isBlockCoverage: true
}]
})

report._normalizeProcessCov({
result: [
fakeCovEntry('1', includedFile),
fakeCovEntry('2', excludedFile),
fakeCovEntry('3', entryFile)
]
}, fileIndex)

fileIndex.has(includedFile).should.equal(true)
fileIndex.has(excludedFile).should.equal(false)
fileIndex.has(entryFile).should.equal(false)
})
})
// see: https://github.com/bcoe/c8/issues/149
it('cobertura report escapes special characters', () => {
Expand Down