chore: close all clients in fixture (#878)
This commit is contained in:
@@ -69,7 +69,7 @@ export const test = baseTest.extend<TestFixtures & TestOptions, WorkerFixtures>(
|
|||||||
|
|
||||||
startClient: async ({ mcpHeadless, mcpBrowser, mcpMode }, use, testInfo) => {
|
startClient: async ({ mcpHeadless, mcpBrowser, mcpMode }, use, testInfo) => {
|
||||||
const configDir = path.dirname(test.info().config.configFile!);
|
const configDir = path.dirname(test.info().config.configFile!);
|
||||||
let client: Client | undefined;
|
const clients: Client[] = [];
|
||||||
|
|
||||||
await use(async options => {
|
await use(async options => {
|
||||||
const args: string[] = [];
|
const args: string[] = [];
|
||||||
@@ -87,7 +87,7 @@ export const test = baseTest.extend<TestFixtures & TestOptions, WorkerFixtures>(
|
|||||||
args.push(`--config=${path.relative(configDir, configFile)}`);
|
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) {
|
if (options?.roots) {
|
||||||
client.setRequestHandler(ListRootsRequestSchema, async request => {
|
client.setRequestHandler(ListRootsRequestSchema, async request => {
|
||||||
if (options.rootsResponseDelay)
|
if (options.rootsResponseDelay)
|
||||||
@@ -104,12 +104,13 @@ export const test = baseTest.extend<TestFixtures & TestOptions, WorkerFixtures>(
|
|||||||
process.stderr.write(data);
|
process.stderr.write(data);
|
||||||
stderrBuffer += data.toString();
|
stderrBuffer += data.toString();
|
||||||
});
|
});
|
||||||
|
clients.push(client);
|
||||||
await client.connect(transport);
|
await client.connect(transport);
|
||||||
await client.ping();
|
await client.ping();
|
||||||
return { client, stderr: () => stderrBuffer };
|
return { client, stderr: () => stderrBuffer };
|
||||||
});
|
});
|
||||||
|
|
||||||
await client?.close();
|
await Promise.all(clients.map(client => client.close()));
|
||||||
},
|
},
|
||||||
|
|
||||||
wsEndpoint: async ({ }, use) => {
|
wsEndpoint: async ({ }, use) => {
|
||||||
@@ -126,6 +127,8 @@ export const test = baseTest.extend<TestFixtures & TestOptions, WorkerFixtures>(
|
|||||||
await use({
|
await use({
|
||||||
endpoint: `http://localhost:${port}`,
|
endpoint: `http://localhost:${port}`,
|
||||||
start: async () => {
|
start: async () => {
|
||||||
|
if (browserContext)
|
||||||
|
throw new Error('CDP server already exists');
|
||||||
browserContext = await chromium.launchPersistentContext(testInfo.outputPath('cdp-user-data-dir'), {
|
browserContext = await chromium.launchPersistentContext(testInfo.outputPath('cdp-user-data-dir'), {
|
||||||
channel: mcpBrowser,
|
channel: mcpBrowser,
|
||||||
headless: true,
|
headless: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user