1
1
import type { File , Task , TaskResultPack , VitestRunner } from '@vitest/runner'
2
- import type { ResolvedConfig } from 'vitest'
2
+ import type { ResolvedConfig , WorkerGlobalState } from 'vitest'
3
3
import type { VitestExecutor } from 'vitest/execute'
4
4
import { rpc } from './rpc'
5
5
import { importId } from './utils'
@@ -17,6 +17,7 @@ interface CoverageHandler {
17
17
18
18
export function createBrowserRunner (
19
19
runnerClass : { new ( config : ResolvedConfig ) : VitestRunner } ,
20
+ state : WorkerGlobalState ,
20
21
coverageModule : CoverageHandler | null ,
21
22
) : { new ( options : BrowserRunnerOptions ) : VitestRunner } {
22
23
return class BrowserTestRunner extends runnerClass implements VitestRunner {
@@ -57,6 +58,14 @@ export function createBrowserRunner(
57
58
}
58
59
59
60
onCollected = async ( files : File [ ] ) : Promise < unknown > => {
61
+ files . forEach ( ( file ) => {
62
+ file . prepareDuration = state . durations . prepare
63
+ file . environmentLoad = state . durations . environment
64
+ // should be collected only for a single test file in a batch
65
+ state . durations . prepare = 0
66
+ state . durations . environment = 0
67
+ } )
68
+
60
69
if ( this . config . includeTaskLocation ) {
61
70
try {
62
71
await updateFilesLocations ( files )
@@ -89,7 +98,7 @@ export function createBrowserRunner(
89
98
90
99
let cachedRunner : VitestRunner | null = null
91
100
92
- export async function initiateRunner ( config : ResolvedConfig ) {
101
+ export async function initiateRunner ( state : WorkerGlobalState , config : ResolvedConfig ) {
93
102
if ( cachedRunner )
94
103
return cachedRunner
95
104
const [
@@ -100,7 +109,7 @@ export async function initiateRunner(config: ResolvedConfig) {
100
109
importId ( 'vitest/browser' ) as Promise < typeof import ( 'vitest/browser' ) > ,
101
110
] )
102
111
const runnerClass = config . mode === 'test' ? VitestTestRunner : NodeBenchmarkRunner
103
- const BrowserRunner = createBrowserRunner ( runnerClass , {
112
+ const BrowserRunner = createBrowserRunner ( runnerClass , state , {
104
113
takeCoverage : ( ) => takeCoverageInsideWorker ( config . coverage , { executeId : importId } ) ,
105
114
} )
106
115
if ( ! config . snapshotOptions . snapshotEnvironment )
0 commit comments