@@ -36,6 +36,7 @@ const pages = [
3636let playground : IsolatedPlayground ;
3737let server : StartedServer ;
3838let browser : Browser ;
39+ let context : BrowserContext ;
3940let signedInState : Awaited < ReturnType < BrowserContext [ 'storageState' ] > > ;
4041let page : Page ;
4142let diagnostics : ( ) => string ;
@@ -54,26 +55,22 @@ beforeAll(async () => {
5455 ) ;
5556 browser = await launchPagesBrowser ( ) ;
5657
57- // A fresh copy has its own D1 database. Create a real session once, then give
58- // each signed-in scenario an independent cookie jar containing that session.
59- const context = await browser . newContext ( ) ;
60- try {
61- const response = await context . request . post ( `${ server . base } /api/demo-login` ) ;
62- expect ( response . status ( ) , await response . text ( ) ) . toBe ( 200 ) ;
63- const profile = await context . request . get ( `${ server . base } /api/profile` ) ;
64- expect ( profile . status ( ) ) . toBe ( 200 ) ;
65- expect ( await profile . json ( ) ) . toEqual ( { name : 'Demo user' , email : EMAIL } ) ;
66- signedInState = await context . storageState ( ) ;
67- } finally {
68- await context . close ( ) ;
69- }
58+ // A fresh copy has its own D1 database. Create a real session once and
59+ // restore its cookies before each signed-in scenario.
60+ context = await browser . newContext ( ) ;
61+ const response = await context . request . post ( `${ server . base } /api/demo-login` ) ;
62+ expect ( response . status ( ) , await response . text ( ) ) . toBe ( 200 ) ;
63+ const profile = await context . request . get ( `${ server . base } /api/profile` ) ;
64+ expect ( profile . status ( ) ) . toBe ( 200 ) ;
65+ expect ( await profile . json ( ) ) . toEqual ( { name : 'Demo user' , email : EMAIL } ) ;
66+ signedInState = await context . storageState ( ) ;
7067} ) ;
7168
7269afterEach ( async ( { task } ) => {
7370 if ( task . result ?. state === 'fail' ) {
7471 console . error ( `${ diagnostics ?.( ) ?? '' } \n${ server ?. output ( ) ?? '' } ` ) ;
7572 }
76- await page ?. context ( ) . close ( ) ;
73+ await page ?. close ( ) ;
7774} ) ;
7875
7976afterAll ( async ( ) => {
@@ -85,7 +82,10 @@ afterAll(async () => {
8582} ) ;
8683
8784async function newPage ( signedIn = false ) {
88- const context = await browser . newContext ( { storageState : signedIn ? signedInState : undefined } ) ;
85+ // Keep the dev server's connections and module cache across this large
86+ // matrix. Recreating the network context exhausts Chromium socket buffers
87+ // on Windows. Each test still gets a fresh page and reset browser storage.
88+ await context . setStorageState ( signedIn ? signedInState : { cookies : [ ] , origins : [ ] } ) ;
8989 page = await context . newPage ( ) ;
9090 page . setDefaultTimeout ( 10_000 ) ;
9191 diagnostics = collectBrowserDiagnostics ( page ) ;
0 commit comments