@@ -69,7 +69,7 @@ export const test = baseTest.extend<TestFixtures & TestOptions, WorkerFixtures>(
6969
7070 startClient : async ( { mcpHeadless, mcpBrowser, mcpMode } , use , testInfo ) => {
7171 const configDir = path . dirname ( test . info ( ) . config . configFile ! ) ;
72- let client : Client | undefined ;
72+ const clients : Client [ ] = [ ] ;
7373
7474 await use ( async options => {
7575 const args : string [ ] = [ ] ;
@@ -87,7 +87,7 @@ export const test = baseTest.extend<TestFixtures & TestOptions, WorkerFixtures>(
8787 args . push ( `--config=${ path . relative ( configDir , configFile ) } ` ) ;
8888 }
8989
90- client = new Client ( { name : options ?. clientName ?? 'test' , version : '1.0.0' } , options ?. roots ? { capabilities : { roots : { } } } : undefined ) ;
90+ const client = new Client ( { name : options ?. clientName ?? 'test' , version : '1.0.0' } , options ?. roots ? { capabilities : { roots : { } } } : undefined ) ;
9191 if ( options ?. roots ) {
9292 client . setRequestHandler ( ListRootsRequestSchema , async request => {
9393 if ( options . rootsResponseDelay )
@@ -104,12 +104,13 @@ export const test = baseTest.extend<TestFixtures & TestOptions, WorkerFixtures>(
104104 process . stderr . write ( data ) ;
105105 stderrBuffer += data . toString ( ) ;
106106 } ) ;
107+ clients . push ( client ) ;
107108 await client . connect ( transport ) ;
108109 await client . ping ( ) ;
109110 return { client, stderr : ( ) => stderrBuffer } ;
110111 } ) ;
111112
112- await client ? .close ( ) ;
113+ await Promise . all ( clients . map ( client => client . close ( ) ) ) ;
113114 } ,
114115
115116 wsEndpoint : async ( { } , use ) => {
@@ -126,6 +127,8 @@ export const test = baseTest.extend<TestFixtures & TestOptions, WorkerFixtures>(
126127 await use ( {
127128 endpoint : `http://localhost:${ port } ` ,
128129 start : async ( ) => {
130+ if ( browserContext )
131+ throw new Error ( 'CDP server already exists' ) ;
129132 browserContext = await chromium . launchPersistentContext ( testInfo . outputPath ( 'cdp-user-data-dir' ) , {
130133 channel : mcpBrowser ,
131134 headless : true ,
0 commit comments