From c92aefdc1268be377693d1f5223ac7807d96e2ef Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 14 Aug 2025 10:57:07 -0700 Subject: [PATCH] chore: close all clients in fixture (#878) --- tests/fixtures.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/fixtures.ts b/tests/fixtures.ts index c02d5c4..ef686b8 100644 --- a/tests/fixtures.ts +++ b/tests/fixtures.ts @@ -69,7 +69,7 @@ export const test = baseTest.extend( startClient: async ({ mcpHeadless, mcpBrowser, mcpMode }, use, testInfo) => { const configDir = path.dirname(test.info().config.configFile!); - let client: Client | undefined; + const clients: Client[] = []; await use(async options => { const args: string[] = []; @@ -87,7 +87,7 @@ export const test = baseTest.extend( args.push(`--config=${path.relative(configDir, configFile)}`); } - client = new Client({ name: options?.clientName ?? 'test', version: '1.0.0' }, options?.roots ? { capabilities: { roots: {} } } : undefined); + const client = new Client({ name: options?.clientName ?? 'test', version: '1.0.0' }, options?.roots ? { capabilities: { roots: {} } } : undefined); if (options?.roots) { client.setRequestHandler(ListRootsRequestSchema, async request => { if (options.rootsResponseDelay) @@ -104,12 +104,13 @@ export const test = baseTest.extend( process.stderr.write(data); stderrBuffer += data.toString(); }); + clients.push(client); await client.connect(transport); await client.ping(); return { client, stderr: () => stderrBuffer }; }); - await client?.close(); + await Promise.all(clients.map(client => client.close())); }, wsEndpoint: async ({ }, use) => { @@ -126,6 +127,8 @@ export const test = baseTest.extend( await use({ endpoint: `http://localhost:${port}`, start: async () => { + if (browserContext) + throw new Error('CDP server already exists'); browserContext = await chromium.launchPersistentContext(testInfo.outputPath('cdp-user-data-dir'), { channel: mcpBrowser, headless: true,