From ee3d0304eb1fb8bc2d3df47fec649e2b8f44961e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Sun, 20 Oct 2024 19:53:23 +0300 Subject: [PATCH 1/6] test: add failing test for #6736 --- .../coverage-test/fixtures/setup.isolation.ts | 6 +++ test/coverage-test/fixtures/src/branch.ts | 7 +++ .../fixtures/test/isolation-1-fixture.test.ts | 9 ++++ .../fixtures/test/isolation-2-fixture.test.ts | 10 ++++ test/coverage-test/test/isolation.test.ts | 49 +++++++++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 test/coverage-test/fixtures/setup.isolation.ts create mode 100644 test/coverage-test/fixtures/src/branch.ts create mode 100644 test/coverage-test/fixtures/test/isolation-1-fixture.test.ts create mode 100644 test/coverage-test/fixtures/test/isolation-2-fixture.test.ts create mode 100644 test/coverage-test/test/isolation.test.ts diff --git a/test/coverage-test/fixtures/setup.isolation.ts b/test/coverage-test/fixtures/setup.isolation.ts new file mode 100644 index 000000000000..8dcfeeeaaca9 --- /dev/null +++ b/test/coverage-test/fixtures/setup.isolation.ts @@ -0,0 +1,6 @@ +import { beforeAll } from "vitest"; +import { branch } from "./src/branch"; + +beforeAll(() => { + branch(1); +}); diff --git a/test/coverage-test/fixtures/src/branch.ts b/test/coverage-test/fixtures/src/branch.ts new file mode 100644 index 000000000000..e82becd43fc3 --- /dev/null +++ b/test/coverage-test/fixtures/src/branch.ts @@ -0,0 +1,7 @@ +export const branch = async (a: number) => { + if (a === 15) { + return true; + } + + return false; +}; diff --git a/test/coverage-test/fixtures/test/isolation-1-fixture.test.ts b/test/coverage-test/fixtures/test/isolation-1-fixture.test.ts new file mode 100644 index 000000000000..4c4390781dc6 --- /dev/null +++ b/test/coverage-test/fixtures/test/isolation-1-fixture.test.ts @@ -0,0 +1,9 @@ +import { test } from "vitest"; +import { multiply, remainder, subtract, sum } from "../src/math"; + +test("Should run function sucessfully", async () => { + sum(1, 1); + subtract(1,2) + multiply(3,4) + remainder(6,7) +}); diff --git a/test/coverage-test/fixtures/test/isolation-2-fixture.test.ts b/test/coverage-test/fixtures/test/isolation-2-fixture.test.ts new file mode 100644 index 000000000000..543a5c94594d --- /dev/null +++ b/test/coverage-test/fixtures/test/isolation-2-fixture.test.ts @@ -0,0 +1,10 @@ +import { test } from "vitest"; +import { branch } from "../src/branch"; + +test("cover some lines", async () => { + branch(15); +}); + +test("cover lines", async () => { + branch(2); +}); diff --git a/test/coverage-test/test/isolation.test.ts b/test/coverage-test/test/isolation.test.ts new file mode 100644 index 000000000000..007faf0c90d2 --- /dev/null +++ b/test/coverage-test/test/isolation.test.ts @@ -0,0 +1,49 @@ +import type { WorkspaceSpec } from 'vitest/node' +import { expect } from 'vitest' +import { readCoverageMap, runVitest, test } from '../utils' + +for (const isolate of [true, false]) { + test(`{ isolate: ${isolate} }`, async () => { + await runVitest({ + include: ['fixtures/test/isolation-*'], + setupFiles: ['fixtures/setup.isolation.ts'], + sequence: { sequencer: Sorter }, + + isolate, + fileParallelism: false, + + coverage: { + all: false, + reporter: 'json', + }, + }) + + const coverageMap = await readCoverageMap() + + const branches = coverageMap.fileCoverageFor('/fixtures/src/branch.ts') + expect(branches.toSummary().lines.pct).toBe(100) + expect(branches.toSummary().statements.pct).toBe(100) + expect(branches.toSummary().functions.pct).toBe(100) + expect(branches.toSummary().branches.pct).toBe(100) + + const math = coverageMap.fileCoverageFor('/fixtures/src/math.ts') + expect(math.toSummary().lines.pct).toBe(100) + expect(math.toSummary().statements.pct).toBe(100) + expect(math.toSummary().functions.pct).toBe(100) + expect(math.toSummary().branches.pct).toBe(100) + }) +} +class Sorter { + sort(files: WorkspaceSpec[]) { + return files.sort((a) => { + if (a.moduleId.includes('isolation-1')) { + return -1 + } + return 1 + }) + } + + shard(files: WorkspaceSpec[]) { + return files + } +} From b5a7900b4b5e6f986859200bee383145fea0630a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Tue, 19 Nov 2024 18:22:30 +0200 Subject: [PATCH 2/6] fix(coverage): `isolate: false` with istanbul provider --- packages/coverage-istanbul/src/index.ts | 66 ++++++++++++++--------- test/coverage-test/test/isolation.test.ts | 9 ++-- test/coverage-test/vitest.config.ts | 2 +- 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/packages/coverage-istanbul/src/index.ts b/packages/coverage-istanbul/src/index.ts index 692885b66ffd..c9539885d663 100644 --- a/packages/coverage-istanbul/src/index.ts +++ b/packages/coverage-istanbul/src/index.ts @@ -1,33 +1,49 @@ +import type { CoverageMapData } from 'istanbul-lib-coverage' +import type { CoverageProviderModule } from 'vitest/node' import type { IstanbulCoverageProvider } from './provider' import { COVERAGE_STORE_KEY } from './constants' -export async function getProvider(): Promise { - // 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 - 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 { + // to not bundle the provider + const providerPath = './provider.js' + const { IstanbulCoverageProvider } = (await import( + /* @vite-ignore */ + providerPath + )) as typeof import('./provider') + + return new IstanbulCoverageProvider() + }, +} diff --git a/test/coverage-test/test/isolation.test.ts b/test/coverage-test/test/isolation.test.ts index 007faf0c90d2..e5a0993b29a9 100644 --- a/test/coverage-test/test/isolation.test.ts +++ b/test/coverage-test/test/isolation.test.ts @@ -1,9 +1,12 @@ import type { WorkspaceSpec } from 'vitest/node' -import { expect } from 'vitest' -import { readCoverageMap, runVitest, test } from '../utils' +import { expect, test } from 'vitest' +import { isV8Provider, readCoverageMap, runVitest } from '../utils' for (const isolate of [true, false]) { - test(`{ isolate: ${isolate} }`, async () => { + // TODO: Requires #6736 + const fails = isV8Provider() && isolate === false + + test(`{ isolate: ${isolate} }`, { fails }, async () => { await runVitest({ include: ['fixtures/test/isolation-*'], setupFiles: ['fixtures/setup.isolation.ts'], diff --git a/test/coverage-test/vitest.config.ts b/test/coverage-test/vitest.config.ts index b312ca47069d..88e7a0e286ac 100644 --- a/test/coverage-test/vitest.config.ts +++ b/test/coverage-test/vitest.config.ts @@ -2,7 +2,7 @@ import { defineConfig } from 'vitest/config' export default defineConfig({ test: { - reporters: 'basic', + reporters: 'verbose', isolate: false, poolOptions: { threads: { From afb0b355a50fc8dedbc4be0634e94cf10bfe3cd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Sun, 24 Nov 2024 10:44:58 +0200 Subject: [PATCH 3/6] fix(coverage): `isolate: false` with v8 provider --- packages/browser/src/client/tester/tester.ts | 4 ++-- packages/coverage-v8/src/index.ts | 18 +++++++++++++++--- packages/vitest/src/integrations/coverage.ts | 6 ++++-- packages/vitest/src/node/types/coverage.ts | 4 ++-- packages/vitest/src/runtime/runBaseTests.ts | 17 +++++++---------- packages/vitest/src/runtime/runVmTests.ts | 4 ++-- test/coverage-test/test/isolation.test.ts | 7 ++----- 7 files changed, 34 insertions(+), 26 deletions(-) diff --git a/packages/browser/src/client/tester/tester.ts b/packages/browser/src/client/tester/tester.ts index aa86e0f31cb9..424e22e274b7 100644 --- a/packages/browser/src/client/tester/tester.ts +++ b/packages/browser/src/client/tester/tester.ts @@ -122,7 +122,7 @@ async function executeTests(method: 'run' | 'collect', files: string[]) { try { await Promise.all([ setupCommonEnv(config), - startCoverageInsideWorker(config.coverage, executor), + startCoverageInsideWorker(config.coverage, executor, { isolate: config.browser.isolate }), (async () => { const VitestIndex = await import('vitest') Object.defineProperty(window, '__vitest_index__', { @@ -160,7 +160,7 @@ async function executeTests(method: 'run' | 'collect', files: string[]) { }, 'Cleanup Error') } state.environmentTeardownRun = true - await stopCoverageInsideWorker(config.coverage, executor).catch((error) => { + await stopCoverageInsideWorker(config.coverage, executor, { isolate: config.browser.isolate }).catch((error) => { client.rpc.onUnhandledError({ name: error.name, message: error.message, diff --git a/packages/coverage-v8/src/index.ts b/packages/coverage-v8/src/index.ts index 4001d627c81a..8fdc43640d08 100644 --- a/packages/coverage-v8/src/index.ts +++ b/packages/coverage-v8/src/index.ts @@ -1,12 +1,20 @@ +import type { CoverageProviderModule } from 'vitest/node' import type { V8CoverageProvider } from './provider' import inspector, { type Profiler } from 'node:inspector' import { provider } from 'std-env' import { loadProvider } from './load-provider' const session = new inspector.Session() +let enabled = false + +export default { + startCoverage({ isolate }) { + if (isolate === false && enabled) { + return + } + + enabled = true -export default { - startCoverage(): void { session.connect() session.post('Profiler.enable') session.post('Profiler.startPreciseCoverage', { @@ -34,7 +42,11 @@ export default { }) }, - stopCoverage(): void { + stopCoverage({ isolate }) { + if (isolate === false) { + return + } + session.post('Profiler.stopPreciseCoverage') session.post('Profiler.disable') session.disconnect() diff --git a/packages/vitest/src/integrations/coverage.ts b/packages/vitest/src/integrations/coverage.ts index db3e8090cff7..a4244e21ecb1 100644 --- a/packages/vitest/src/integrations/coverage.ts +++ b/packages/vitest/src/integrations/coverage.ts @@ -79,11 +79,12 @@ export async function getCoverageProvider( export async function startCoverageInsideWorker( options: SerializedCoverageConfig | undefined, loader: Loader, + runtimeOptions: { isolate: boolean }, ) { const coverageModule = await resolveCoverageProviderModule(options, loader) if (coverageModule) { - return coverageModule.startCoverage?.() + return coverageModule.startCoverage?.(runtimeOptions) } return null @@ -105,11 +106,12 @@ export async function takeCoverageInsideWorker( export async function stopCoverageInsideWorker( options: SerializedCoverageConfig | undefined, loader: Loader, + runtimeOptions: { isolate: boolean }, ) { const coverageModule = await resolveCoverageProviderModule(options, loader) if (coverageModule) { - return coverageModule.stopCoverage?.() + return coverageModule.stopCoverage?.(runtimeOptions) } return null diff --git a/packages/vitest/src/node/types/coverage.ts b/packages/vitest/src/node/types/coverage.ts index 3984c7b250f8..c2f3f408bbeb 100644 --- a/packages/vitest/src/node/types/coverage.ts +++ b/packages/vitest/src/node/types/coverage.ts @@ -66,7 +66,7 @@ export interface CoverageProviderModule { /** * Executed before tests are run in the worker thread. */ - startCoverage?: () => unknown | Promise + startCoverage?: (runtimeOptions: { isolate: boolean }) => unknown | Promise /** * Executed on after each run in the worker thread. Possible to return a payload passed to the provider @@ -76,7 +76,7 @@ export interface CoverageProviderModule { /** * Executed after all tests have been run in the worker thread. */ - stopCoverage?: () => unknown | Promise + stopCoverage?: (runtimeOptions: { isolate: boolean }) => unknown | Promise } export type CoverageReporter = keyof ReportOptions | (string & {}) diff --git a/packages/vitest/src/runtime/runBaseTests.ts b/packages/vitest/src/runtime/runBaseTests.ts index b15e5767970a..a00262950ac6 100644 --- a/packages/vitest/src/runtime/runBaseTests.ts +++ b/packages/vitest/src/runtime/runBaseTests.ts @@ -25,8 +25,12 @@ export async function run( ): Promise { const workerState = getWorkerState() + const isIsolatedThreads = config.pool === 'threads' && (config.poolOptions?.threads?.isolate ?? true) + const isIsolatedForks = config.pool === 'forks' && (config.poolOptions?.forks?.isolate ?? true) + const isolate = isIsolatedThreads || isIsolatedForks + await setupGlobalEnv(config, environment, executor) - await startCoverageInsideWorker(config.coverage, executor) + await startCoverageInsideWorker(config.coverage, executor, { isolate }) if (config.chaiConfig) { setupChaiConfig(config.chaiConfig) @@ -50,14 +54,7 @@ export async function run( = performance.now() - workerState.durations.environment for (const file of files) { - const isIsolatedThreads - = config.pool === 'threads' - && (config.poolOptions?.threads?.isolate ?? true) - const isIsolatedForks - = config.pool === 'forks' - && (config.poolOptions?.forks?.isolate ?? true) - - if (isIsolatedThreads || isIsolatedForks) { + if (isolate) { executor.mocker.reset() resetModules(workerState.moduleCache, true) } @@ -77,7 +74,7 @@ export async function run( vi.restoreAllMocks() } - await stopCoverageInsideWorker(config.coverage, executor) + await stopCoverageInsideWorker(config.coverage, executor, { isolate }) }, ) diff --git a/packages/vitest/src/runtime/runVmTests.ts b/packages/vitest/src/runtime/runVmTests.ts index bc22d124e72a..8193c0a34833 100644 --- a/packages/vitest/src/runtime/runVmTests.ts +++ b/packages/vitest/src/runtime/runVmTests.ts @@ -62,7 +62,7 @@ export async function run( getSourceMap: source => workerState.moduleCache.getSourceMap(source), }) - await startCoverageInsideWorker(config.coverage, executor) + await startCoverageInsideWorker(config.coverage, executor, { isolate: false }) if (config.chaiConfig) { setupChaiConfig(config.chaiConfig) @@ -101,7 +101,7 @@ export async function run( vi.restoreAllMocks() } - await stopCoverageInsideWorker(config.coverage, executor) + await stopCoverageInsideWorker(config.coverage, executor, { isolate: false }) } function resolveCss(mod: NodeJS.Module) { diff --git a/test/coverage-test/test/isolation.test.ts b/test/coverage-test/test/isolation.test.ts index e5a0993b29a9..9d32038fecb3 100644 --- a/test/coverage-test/test/isolation.test.ts +++ b/test/coverage-test/test/isolation.test.ts @@ -1,12 +1,9 @@ import type { WorkspaceSpec } from 'vitest/node' import { expect, test } from 'vitest' -import { isV8Provider, readCoverageMap, runVitest } from '../utils' +import { readCoverageMap, runVitest } from '../utils' for (const isolate of [true, false]) { - // TODO: Requires #6736 - const fails = isV8Provider() && isolate === false - - test(`{ isolate: ${isolate} }`, { fails }, async () => { + test(`{ isolate: ${isolate} }`, async () => { await runVitest({ include: ['fixtures/test/isolation-*'], setupFiles: ['fixtures/setup.isolation.ts'], From 87c9a56d0f0bd2e964e5ae3faf1ad389089ae74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Mon, 9 Dec 2024 10:40:12 +0200 Subject: [PATCH 4/6] fix(coverage): `isolate: false` with browser mode --- packages/coverage-v8/src/browser.ts | 15 +++++++++++---- test/coverage-test/test/isolation.test.ts | 8 +++++++- test/coverage-test/utils.ts | 1 + test/coverage-test/vitest.workspace.custom.ts | 2 ++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/coverage-v8/src/browser.ts b/packages/coverage-v8/src/browser.ts index 3f3940892129..3ae9f51f463a 100644 --- a/packages/coverage-v8/src/browser.ts +++ b/packages/coverage-v8/src/browser.ts @@ -1,13 +1,21 @@ +import type { CoverageProviderModule } from 'vitest/node' import type { V8CoverageProvider } from './provider' import { cdp } from '@vitest/browser/context' import { loadProvider } from './load-provider' const session = cdp() +let enabled = false type ScriptCoverage = Awaited>> -export default { +export default { async startCoverage() { + if (enabled) { + return + } + + enabled = true + await session.send('Profiler.enable') await session.send('Profiler.startPreciseCoverage', { callCount: true, @@ -32,9 +40,8 @@ export default { return { result } }, - async stopCoverage() { - await session.send('Profiler.stopPreciseCoverage') - await session.send('Profiler.disable') + stopCoverage() { + // Browser mode should not stop coverage as same V8 instance is shared between tests }, async getProvider(): Promise { diff --git a/test/coverage-test/test/isolation.test.ts b/test/coverage-test/test/isolation.test.ts index 9d32038fecb3..02414bf6008b 100644 --- a/test/coverage-test/test/isolation.test.ts +++ b/test/coverage-test/test/isolation.test.ts @@ -14,7 +14,12 @@ for (const isolate of [true, false]) { coverage: { all: false, - reporter: 'json', + reporter: ['json', 'html'], + }, + + // @ts-expect-error -- merged in runVitest + browser: { + isolate, }, }) @@ -33,6 +38,7 @@ for (const isolate of [true, false]) { expect(math.toSummary().branches.pct).toBe(100) }) } + class Sorter { sort(files: WorkspaceSpec[]) { return files.sort((a) => { diff --git a/test/coverage-test/utils.ts b/test/coverage-test/utils.ts index 5efe5731bd07..0486120b93fa 100644 --- a/test/coverage-test/utils.ts +++ b/test/coverage-test/utils.ts @@ -51,6 +51,7 @@ export async function runVitest(config: UserConfig, options = { throwOnError: tr headless: true, name: 'chromium', provider: 'playwright', + ...config.browser, }, }) diff --git a/test/coverage-test/vitest.workspace.custom.ts b/test/coverage-test/vitest.workspace.custom.ts index 6974b93ca907..361bce3f3414 100644 --- a/test/coverage-test/vitest.workspace.custom.ts +++ b/test/coverage-test/vitest.workspace.custom.ts @@ -66,6 +66,7 @@ export default defineWorkspace([ BROWSER_TESTS, // Other non-provider-specific tests that should be run on browser mode as well + '**/isolation.test.ts', '**/include-exclude.test.ts', '**/allow-external.test.ts', '**/ignore-hints.test.ts', @@ -90,6 +91,7 @@ export default defineWorkspace([ BROWSER_TESTS, // Other non-provider-specific tests that should be run on browser mode as well + '**/isolation.test.ts', '**/include-exclude.test.ts', '**/allow-external.test.ts', '**/ignore-hints.test.ts', From 3bb8f6620def9584da04182e8f9ed5bcb50e1754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Mon, 9 Dec 2024 10:55:06 +0200 Subject: [PATCH 5/6] test: pool variations --- test/coverage-test/test/isolation.test.ts | 75 ++++++++++++++--------- test/coverage-test/vitest.config.ts | 3 + 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/test/coverage-test/test/isolation.test.ts b/test/coverage-test/test/isolation.test.ts index 02414bf6008b..7a84b419b461 100644 --- a/test/coverage-test/test/isolation.test.ts +++ b/test/coverage-test/test/isolation.test.ts @@ -2,41 +2,56 @@ import type { WorkspaceSpec } from 'vitest/node' import { expect, test } from 'vitest' import { readCoverageMap, runVitest } from '../utils' +const pools = ['forks'] + +if (!process.env.COVERAGE_BROWSER) { + pools.push('threads') + + const [major] = process.version.slice(1).split('.').map(num => Number(num)) + + if (major < 22) { + pools.push('vmForks', 'vmThreads') + } +} + for (const isolate of [true, false]) { - test(`{ isolate: ${isolate} }`, async () => { - await runVitest({ - include: ['fixtures/test/isolation-*'], - setupFiles: ['fixtures/setup.isolation.ts'], - sequence: { sequencer: Sorter }, - - isolate, - fileParallelism: false, - - coverage: { - all: false, - reporter: ['json', 'html'], - }, - - // @ts-expect-error -- merged in runVitest - browser: { + for (const pool of pools) { + test(`{ isolate: ${isolate}, pool: "${pool}" }`, async () => { + await runVitest({ + include: ['fixtures/test/isolation-*'], + setupFiles: ['fixtures/setup.isolation.ts'], + sequence: { sequencer: Sorter }, + + pool, isolate, - }, - }) + fileParallelism: false, + + coverage: { + all: false, + reporter: ['json', 'html'], + }, - const coverageMap = await readCoverageMap() + // @ts-expect-error -- merged in runVitest + browser: { + isolate, + }, + }) - const branches = coverageMap.fileCoverageFor('/fixtures/src/branch.ts') - expect(branches.toSummary().lines.pct).toBe(100) - expect(branches.toSummary().statements.pct).toBe(100) - expect(branches.toSummary().functions.pct).toBe(100) - expect(branches.toSummary().branches.pct).toBe(100) + const coverageMap = await readCoverageMap() - const math = coverageMap.fileCoverageFor('/fixtures/src/math.ts') - expect(math.toSummary().lines.pct).toBe(100) - expect(math.toSummary().statements.pct).toBe(100) - expect(math.toSummary().functions.pct).toBe(100) - expect(math.toSummary().branches.pct).toBe(100) - }) + const branches = coverageMap.fileCoverageFor('/fixtures/src/branch.ts') + expect(branches.toSummary().lines.pct).toBe(100) + expect(branches.toSummary().statements.pct).toBe(100) + expect(branches.toSummary().functions.pct).toBe(100) + expect(branches.toSummary().branches.pct).toBe(100) + + const math = coverageMap.fileCoverageFor('/fixtures/src/math.ts') + expect(math.toSummary().lines.pct).toBe(100) + expect(math.toSummary().statements.pct).toBe(100) + expect(math.toSummary().functions.pct).toBe(100) + expect(math.toSummary().branches.pct).toBe(100) + }) + } } class Sorter { diff --git a/test/coverage-test/vitest.config.ts b/test/coverage-test/vitest.config.ts index 88e7a0e286ac..f07d07c42a30 100644 --- a/test/coverage-test/vitest.config.ts +++ b/test/coverage-test/vitest.config.ts @@ -1,6 +1,9 @@ import { defineConfig } from 'vitest/config' export default defineConfig({ + server: { + watch: null, + }, test: { reporters: 'verbose', isolate: false, From c89f42b677f26c811c924c49f163a9252a3f9e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Mon, 9 Dec 2024 12:03:33 +0200 Subject: [PATCH 6/6] refactor: rwview --- packages/coverage-istanbul/src/index.ts | 4 ++-- packages/coverage-v8/src/browser.ts | 4 ++-- packages/coverage-v8/src/index.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/coverage-istanbul/src/index.ts b/packages/coverage-istanbul/src/index.ts index c9539885d663..1a317c8c908d 100644 --- a/packages/coverage-istanbul/src/index.ts +++ b/packages/coverage-istanbul/src/index.ts @@ -3,7 +3,7 @@ import type { CoverageProviderModule } from 'vitest/node' import type { IstanbulCoverageProvider } from './provider' import { COVERAGE_STORE_KEY } from './constants' -export default { +export default { takeCoverage() { // @ts-expect-error -- untyped global return globalThis[COVERAGE_STORE_KEY] @@ -46,4 +46,4 @@ export default { return new IstanbulCoverageProvider() }, -} +} satisfies CoverageProviderModule diff --git a/packages/coverage-v8/src/browser.ts b/packages/coverage-v8/src/browser.ts index 3ae9f51f463a..1891c7df296f 100644 --- a/packages/coverage-v8/src/browser.ts +++ b/packages/coverage-v8/src/browser.ts @@ -8,7 +8,7 @@ let enabled = false type ScriptCoverage = Awaited>> -export default { +export default { async startCoverage() { if (enabled) { return @@ -47,7 +47,7 @@ export default { async getProvider(): Promise { return loadProvider() }, -} +} satisfies CoverageProviderModule function filterResult(coverage: ScriptCoverage['result'][number]): boolean { if (!coverage.url.startsWith(window.location.origin)) { diff --git a/packages/coverage-v8/src/index.ts b/packages/coverage-v8/src/index.ts index 8fdc43640d08..9497648ea65b 100644 --- a/packages/coverage-v8/src/index.ts +++ b/packages/coverage-v8/src/index.ts @@ -7,7 +7,7 @@ import { loadProvider } from './load-provider' const session = new inspector.Session() let enabled = false -export default { +export default { startCoverage({ isolate }) { if (isolate === false && enabled) { return @@ -55,7 +55,7 @@ export default { async getProvider(): Promise { return loadProvider() }, -} +} satisfies CoverageProviderModule function filterResult(coverage: Profiler.ScriptCoverage): boolean { if (!coverage.url.startsWith('file://')) {