Skip to content

Commit

Permalink
fix(coverage): c8 provider to work when isolate:false
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Feb 27, 2023
1 parent 895103a commit c9c489a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 3 additions & 1 deletion packages/coverage-c8/src/takeCoverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import inspector from 'node:inspector'
import type { Profiler } from 'node:inspector'

// Create a single session when coverage provider is loaded inside worker or child_process
const session = new inspector.Session()
session.connect()

// Note that this may be called multiple times in a single worker/process, depending on "isolate" configuration
export function startCoverage() {
session.connect()
session.post('Profiler.enable')
session.post('Profiler.startPreciseCoverage', {
callCount: true,
Expand Down
22 changes: 13 additions & 9 deletions test/coverage-test/testing.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ const configs = [
}],
]

for (const threads of [true, false]) {
for (const [directory, config] of configs) {
await startVitest('test', [directory], {
...config,
update: UPDATE_SNAPSHOTS,
threads,
})
for (const threads of [{ threads: true }, { threads: false }, { singleThread: true }]) {
for (const isolate of [true, false]) {
for (const [directory, config] of configs) {
await startVitest('test', [directory], {
name: `With settings: ${JSON.stringify({ ...threads, isolate, directory })}`,
...config,
update: UPDATE_SNAPSHOTS,
...threads,
isolate,
})

if (process.exitCode)
process.exit()
if (process.exitCode)
process.exit()
}
}
}

0 comments on commit c9c489a

Please sign in to comment.