( method: 'run' | 'collect', files: FileSpecification[], config: SerializedConfig, moduleRunner: TestModuleRunner, environment: Environment, traces: Traces, )
| 19 | |
| 20 | // browser shouldn't call this! |
| 21 | export async function run( |
| 22 | method: 'run' | 'collect', |
| 23 | files: FileSpecification[], |
| 24 | config: SerializedConfig, |
| 25 | moduleRunner: TestModuleRunner, |
| 26 | environment: Environment, |
| 27 | traces: Traces, |
| 28 | ): Promise<void> { |
| 29 | const workerState = getWorkerState() |
| 30 | |
| 31 | const [testRunner] = await Promise.all([ |
| 32 | traces.$('vitest.runtime.runner', () => resolveTestRunner(config, moduleRunner, traces)), |
| 33 | traces.$('vitest.runtime.global_env', () => setupGlobalEnv(config, environment)), |
| 34 | traces.$('vitest.runtime.coverage.start', () => startCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate })), |
| 35 | traces.$('vitest.runtime.snapshot.environment', async () => { |
| 36 | if (!workerState.config.snapshotOptions.snapshotEnvironment) { |
| 37 | workerState.config.snapshotOptions.snapshotEnvironment |
| 38 | = await resolveSnapshotEnvironment(config, moduleRunner) |
| 39 | } |
| 40 | }), |
| 41 | ]) |
| 42 | |
| 43 | workerState.onCancel((reason) => { |
| 44 | closeInspector(config) |
| 45 | testRunner.cancel?.(reason) |
| 46 | }) |
| 47 | |
| 48 | workerState.durations.prepare = performance.now() - workerState.durations.prepare |
| 49 | await traces.$( |
| 50 | `vitest.test.runner.${method}`, |
| 51 | async () => { |
| 52 | for (const file of files) { |
| 53 | if (config.isolate) { |
| 54 | moduleRunner.mocker?.reset() |
| 55 | resetModules(workerState.evaluatedModules, true) |
| 56 | } |
| 57 | |
| 58 | workerState.filepath = file.filepath |
| 59 | |
| 60 | if (method === 'run') { |
| 61 | const collectAsyncLeaks = config.detectAsyncLeaks ? detectAsyncLeaks(file.filepath, workerState.ctx.projectName) : undefined |
| 62 | |
| 63 | await traces.$( |
| 64 | `vitest.test.runner.${method}.module`, |
| 65 | { attributes: { 'code.file.path': file.filepath } }, |
| 66 | () => startTests([file], testRunner), |
| 67 | ) |
| 68 | |
| 69 | const leaks = await collectAsyncLeaks?.() |
| 70 | |
| 71 | if (leaks?.length) { |
| 72 | workerState.rpc.onAsyncLeaks(leaks) |
| 73 | } |
| 74 | } |
| 75 | else { |
| 76 | await traces.$( |
| 77 | `vitest.test.runner.${method}.module`, |
| 78 | { attributes: { 'code.file.path': file.filepath } }, |
no test coverage detected