-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(coverage):
isolate: false
with istanbul provider
- Loading branch information
1 parent
09c4b53
commit e05960d
Showing
3 changed files
with
47 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,48 @@ | ||
import type { CoverageMapData } from 'istanbul-lib-coverage' | ||
import type { IstanbulCoverageProvider } from './provider' | ||
import { COVERAGE_STORE_KEY } from './constants' | ||
|
||
export async function getProvider(): Promise<IstanbulCoverageProvider> { | ||
// to not bundle the provider | ||
const providerPath = './provider.js' | ||
const { IstanbulCoverageProvider } = (await import( | ||
/* @vite-ignore */ | ||
providerPath | ||
)) as typeof import('./provider') | ||
return new IstanbulCoverageProvider() | ||
} | ||
|
||
export function takeCoverage(): any { | ||
// @ts-expect-error -- untyped global | ||
const coverage = globalThis[COVERAGE_STORE_KEY] | ||
export default { | ||
takeCoverage() { | ||
// @ts-expect-error -- untyped global | ||
return 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] = {} | ||
startCoverage() { | ||
// @ts-expect-error -- untyped global | ||
const coverageMap = globalThis[COVERAGE_STORE_KEY] as CoverageMapData | ||
|
||
return coverage | ||
} | ||
// When isolated, there are no previous results | ||
if (!coverageMap) { | ||
return | ||
} | ||
|
||
const _default: { | ||
getProvider: () => Promise<IstanbulCoverageProvider> | ||
takeCoverage: () => any | ||
} = { | ||
getProvider, | ||
takeCoverage, | ||
} | ||
for (const filename in coverageMap) { | ||
const branches = coverageMap[filename].b | ||
|
||
for (const key in branches) { | ||
branches[key] = branches[key].map(() => 0) | ||
} | ||
|
||
export default _default | ||
for (const metric of ['f', 's'] as const) { | ||
const entry = coverageMap[filename][metric] | ||
|
||
for (const key in entry) { | ||
entry[key] = 0 | ||
} | ||
} | ||
} | ||
}, | ||
|
||
async getProvider(): Promise<IstanbulCoverageProvider> { | ||
// to not bundle the provider | ||
const providerPath = './provider.js' | ||
const { IstanbulCoverageProvider } = (await import( | ||
/* @vite-ignore */ | ||
providerPath | ||
)) as typeof import('./provider') | ||
|
||
return new IstanbulCoverageProvider() | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters