From 696c7f89f6c494bc6bde7b30b783684af064c8eb Mon Sep 17 00:00:00 2001 From: Nikola Irinchev Date: Fri, 11 Apr 2025 13:40:07 +0200 Subject: [PATCH 1/2] fix: properly teardown mocks in server.test.ts --- tests/integration/server.test.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/integration/server.test.ts b/tests/integration/server.test.ts index 7b9d1b46..1d804943 100644 --- a/tests/integration/server.test.ts +++ b/tests/integration/server.test.ts @@ -1,18 +1,16 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js"; -import { Server } from "../../src/server.js"; import { setupIntegrationTest } from "./helpers.js"; describe("Server integration test", () => { let client: Client; - let server: Server; + let teardown: () => Promise; beforeEach(async () => { - ({ client, server } = await setupIntegrationTest()); + ({ client, teardown } = await setupIntegrationTest()); }); afterEach(async () => { - await client?.close(); - await server?.close(); + await teardown(); }); describe("list capabilities", () => { From c15d5d45f232b4c375c89c084101722cb6080620 Mon Sep 17 00:00:00 2001 From: Nikola Irinchev Date: Fri, 11 Apr 2025 13:42:37 +0200 Subject: [PATCH 2/2] simplify test setup in connect.test.ts --- tests/integration/tools/mongodb/connect.test.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/integration/tools/mongodb/connect.test.ts b/tests/integration/tools/mongodb/connect.test.ts index d304c266..7e5dacec 100644 --- a/tests/integration/tools/mongodb/connect.test.ts +++ b/tests/integration/tools/mongodb/connect.test.ts @@ -14,6 +14,10 @@ describe("Connect tool", () => { cluster = await runMongoDB(); }, 60_000); + beforeEach(async () => { + ({ client, teardown: serverClientTeardown } = await setupIntegrationTest()); + }); + afterEach(async () => { await serverClientTeardown?.(); }); @@ -23,10 +27,6 @@ describe("Connect tool", () => { }); describe("with default config", () => { - beforeEach(async () => { - ({ client, teardown: serverClientTeardown } = await setupIntegrationTest()); - }); - it("should have correct metadata", async () => { const tools = await client.listTools(); const connectTool = tools.tools.find((tool) => tool.name === "connect"); @@ -84,8 +84,6 @@ describe("Connect tool", () => { describe("with connection string in config", () => { beforeEach(async () => { config.connectionString = cluster.connectionString; - - ({ client, teardown: serverClientTeardown } = await setupIntegrationTest()); }); it("uses the connection string from config", async () => {