@@ -23,7 +23,8 @@ createMultipleTabsTest(WASQLiteVFS.OPFSCoopSyncVFS);
2323async function createIframeWithPowerSyncClient (
2424 dbFilename : string ,
2525 identifier : string ,
26- vfs ?: WASQLiteVFS
26+ vfs ?: WASQLiteVFS ,
27+ waitForConnection ?: boolean
2728) : Promise < IframeClient > {
2829 const iframe = document . createElement ( 'iframe' ) ;
2930 // Make iframe visible for debugging
@@ -81,7 +82,7 @@ async function createIframeWithPowerSyncClient(
8182 </div>
8283 <script type="module">
8384 import { setupPowerSyncInIframe } from '${ modulePath } ';
84- setupPowerSyncInIframe('${ dbFilename } ', '${ identifier } ', ${ vfs ? `'${ vfs } '` : 'undefined' } );
85+ setupPowerSyncInIframe('${ dbFilename } ', '${ identifier } ', ${ vfs ? `'${ vfs } '` : 'undefined' } , ${ waitForConnection ? 'true' : 'false' } );
8586 </script>
8687</body>
8788</html>` ;
@@ -251,7 +252,7 @@ function createMultipleTabsTest(vfs?: WASQLiteVFS) {
251252 const dbFilename = `test-multi-tab-${ uuid ( ) } .db` ;
252253
253254 // Configurable number of tabs to create (excluding the long-lived tab)
254- const NUM_TABS = 50 ;
255+ const NUM_TABS = 20 ;
255256
256257 it ( 'should handle simultaneous close and reopen of tabs' , async ( ) => {
257258 // Step 1: Open a long-lived reference tab that stays open throughout the test
@@ -379,15 +380,10 @@ function createMultipleTabsTest(vfs?: WASQLiteVFS) {
379380 expect ( queryResult . length ) . toBe ( 1 ) ;
380381 expect ( ( queryResult [ 0 ] as { value : number } ) . value ) . toBe ( 1 ) ;
381382
382- /**
383- * Wait a little for the state to settle.
384- */
385- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
386-
387383 // Step 6: Create a new tab which should trigger a connect. The shared sync worker should reconnect.
388384 // This ensures the shared sync worker is not stuck and is properly handling new connections
389385 const newTabIdentifier = `new-tab-${ Date . now ( ) } ` ;
390- const newTab = await createIframeWithPowerSyncClient ( dbFilename , newTabIdentifier , vfs ) ;
386+ const newTab = await createIframeWithPowerSyncClient ( dbFilename , newTabIdentifier , vfs , true ) ;
391387 onTestFinished ( async ( ) => {
392388 try {
393389 await newTab . cleanup ( ) ;
0 commit comments