@@ -58,6 +58,7 @@ export function createBrowserRunner(
5858 public config : SerializedConfig
5959 public hashMap = browserHashMap
6060 public sourceMapCache = new Map < string , any > ( )
61+ private sourceMapPrefetches = new Map < string , Promise < any > > ( )
6162 public method = 'run' as TestExecutionMethod
6263 private commands : CommandsManager
6364
@@ -218,7 +219,13 @@ export function createBrowserRunner(
218219 if ( ! ( 'filepath' in suite ) ) {
219220 return
220221 }
221- const map = await rpc ( ) . getBrowserFileSourceMap ( suite . filepath )
222+ // usually resolved already: the request is fired as soon as the
223+ // file finishes importing, while collection is still running
224+ const map = await (
225+ this . sourceMapPrefetches . get ( suite . filepath )
226+ ?? rpc ( ) . getBrowserFileSourceMap ( suite . filepath )
227+ )
228+ this . sourceMapPrefetches . delete ( suite . filepath )
222229 this . sourceMapCache . set ( suite . filepath , map )
223230 const snapshotEnvironment = this . config . snapshotOptions . snapshotEnvironment
224231 if ( snapshotEnvironment instanceof VitestBrowserSnapshotEnvironment ) {
@@ -334,6 +341,15 @@ export function createBrowserRunner(
334341 catch ( err ) {
335342 throw new Error ( `Failed to import test file ${ filepath } ` , { cause : err } )
336343 }
344+
345+ if ( mode === 'collect' && ! this . sourceMapPrefetches . has ( filepath ) ) {
346+ // the file is transformed now, so the server can hand out its map;
347+ // request it early so onBeforeRunSuite doesn't have to wait
348+ this . sourceMapPrefetches . set (
349+ filepath ,
350+ rpc ( ) . getBrowserFileSourceMap ( filepath ) . catch ( ( ) => undefined ) ,
351+ )
352+ }
337353 }
338354
339355 trace = < T > ( name : string , attributes : Record < string , any > | ( ( ) => T ) , cb ?: ( ) => T ) : T => {
0 commit comments