11import type { File , Task , TaskResultPack , VitestRunner } from '@vitest/runner'
2- import type { ResolvedConfig } from 'vitest'
2+ import type { ResolvedConfig , WorkerGlobalState } from 'vitest'
33import type { VitestExecutor } from 'vitest/execute'
44import { rpc } from './rpc'
55import { importId } from './utils'
@@ -17,6 +17,7 @@ interface CoverageHandler {
1717
1818export function createBrowserRunner (
1919 runnerClass : { new ( config : ResolvedConfig ) : VitestRunner } ,
20+ state : WorkerGlobalState ,
2021 coverageModule : CoverageHandler | null ,
2122) : { new ( options : BrowserRunnerOptions ) : VitestRunner } {
2223 return class BrowserTestRunner extends runnerClass implements VitestRunner {
@@ -57,6 +58,14 @@ export function createBrowserRunner(
5758 }
5859
5960 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+
6069 if ( this . config . includeTaskLocation ) {
6170 try {
6271 await updateFilesLocations ( files )
@@ -89,7 +98,7 @@ export function createBrowserRunner(
8998
9099let cachedRunner : VitestRunner | null = null
91100
92- export async function initiateRunner ( config : ResolvedConfig ) {
101+ export async function initiateRunner ( state : WorkerGlobalState , config : ResolvedConfig ) {
93102 if ( cachedRunner )
94103 return cachedRunner
95104 const [
@@ -100,7 +109,7 @@ export async function initiateRunner(config: ResolvedConfig) {
100109 importId ( 'vitest/browser' ) as Promise < typeof import ( 'vitest/browser' ) > ,
101110 ] )
102111 const runnerClass = config . mode === 'test' ? VitestTestRunner : NodeBenchmarkRunner
103- const BrowserRunner = createBrowserRunner ( runnerClass , {
112+ const BrowserRunner = createBrowserRunner ( runnerClass , state , {
104113 takeCoverage : ( ) => takeCoverageInsideWorker ( config . coverage , { executeId : importId } ) ,
105114 } )
106115 if ( ! config . snapshotOptions . snapshotEnvironment )
0 commit comments