Skip to content

Commit

Permalink
fix(coverage-istanbul): reset coverage map after query
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Dec 8, 2022
1 parent c49e0ab commit 0ff7f58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/coverage-istanbul/src/index.ts
Expand Up @@ -7,5 +7,11 @@ export async function getProvider() {

export function takeCoverage() {
// @ts-expect-error -- untyped global
return globalThis[COVERAGE_STORE_KEY]
const coverage = globalThis[COVERAGE_STORE_KEY]

// Reset coverage map to prevent duplicate results if this is called twice in row
// @ts-expect-error -- untyped global
globalThis[COVERAGE_STORE_KEY] = {}

return coverage
}
8 changes: 6 additions & 2 deletions test/coverage-test/coverage-test/coverage.istanbul.test.ts
Expand Up @@ -40,8 +40,8 @@ test('istanbul json report', async () => {
const normalizedReport: CoverageFinalJson['default'] = {}

for (const [filename, coverage] of Object.entries(jsonReport)) {
coverage.path = normalize(coverage.path.replace(process.cwd(), '<root>'))
normalizedReport[filename.replace(process.cwd(), '<root>')] = coverage
coverage.path = normalizeFilename(coverage.path)
normalizedReport[normalizeFilename(filename)] = coverage
}

expect(normalizedReport).toMatchSnapshot()
Expand Down Expand Up @@ -81,3 +81,7 @@ test('file using import.meta.env is included in report', async () => {

expect(files).toContain('importEnv.ts.html')
})

function normalizeFilename(filename: string) {
return normalize(filename.replace(process.cwd(), '<root>'))
}

0 comments on commit 0ff7f58

Please sign in to comment.