@@ -12,6 +12,15 @@ const ID_ALL = '__vitest_all__'
1212
1313const iframes = new Map < string , HTMLIFrameElement > ( )
1414
15+ let promiseTesters : Promise < void > | undefined
16+ getBrowserState ( ) . createTesters = async ( files ) => {
17+ await promiseTesters
18+ promiseTesters = createTesters ( files ) . finally ( ( ) => {
19+ promiseTesters = undefined
20+ } )
21+ await promiseTesters
22+ }
23+
1524function debug ( ...args : unknown [ ] ) {
1625 const debug = getConfig ( ) . env . VITEST_BROWSER_DEBUG
1726 if ( debug && debug !== 'false' )
@@ -20,7 +29,7 @@ function debug(...args: unknown[]) {
2029
2130function createIframe ( container : HTMLDivElement , file : string ) {
2231 if ( iframes . has ( file ) ) {
23- container . removeChild ( iframes . get ( file ) ! )
32+ iframes . get ( file ) ! . remove ( )
2433 iframes . delete ( file )
2534 }
2635
@@ -75,7 +84,6 @@ async function getContainer(config: ResolvedConfig): Promise<HTMLDivElement> {
7584}
7685
7786client . ws . addEventListener ( 'open' , async ( ) => {
78- const config = getConfig ( )
7987 const testFiles = getBrowserState ( ) . files
8088
8189 debug ( 'test files' , testFiles . join ( ', ' ) )
@@ -86,7 +94,6 @@ client.ws.addEventListener('open', async () => {
8694 return
8795 }
8896
89- const container = await getContainer ( config )
9097 const runningFiles = new Set < string > ( testFiles )
9198
9299 channel . addEventListener ( 'message' , async ( e : MessageEvent < IframeChannelEvent > ) : Promise < void > => {
@@ -137,6 +144,13 @@ client.ws.addEventListener('open', async () => {
137144 }
138145 } )
139146
147+ await createTesters ( testFiles )
148+ } )
149+
150+ async function createTesters ( testFiles : string [ ] ) {
151+ const config = getConfig ( )
152+ const container = await getContainer ( config )
153+
140154 if ( config . browser . ui ) {
141155 container . className = ''
142156 container . textContent = ''
@@ -174,7 +188,7 @@ client.ws.addEventListener('open', async () => {
174188 } )
175189 }
176190 }
177- } )
191+ }
178192
179193function generateFileId ( file : string ) {
180194 const config = getConfig ( )
0 commit comments