Skip to content

Commit 23d1631

Browse files
authored
fix: properly teardown mocks in server.test.ts (#61)
1 parent 3909e3c commit 23d1631

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

tests/integration/server.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2-
import { Server } from "../../src/server.js";
32
import { setupIntegrationTest } from "./helpers.js";
43

54
describe("Server integration test", () => {
65
let client: Client;
7-
let server: Server;
6+
let teardown: () => Promise<void>;
87

98
beforeEach(async () => {
10-
({ client, server } = await setupIntegrationTest());
9+
({ client, teardown } = await setupIntegrationTest());
1110
});
1211

1312
afterEach(async () => {
14-
await client?.close();
15-
await server?.close();
13+
await teardown();
1614
});
1715

1816
describe("list capabilities", () => {

tests/integration/tools/mongodb/connect.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ describe("Connect tool", () => {
1414
cluster = await runMongoDB();
1515
}, 60_000);
1616

17+
beforeEach(async () => {
18+
({ client, teardown: serverClientTeardown } = await setupIntegrationTest());
19+
});
20+
1721
afterEach(async () => {
1822
await serverClientTeardown?.();
1923
});
@@ -23,10 +27,6 @@ describe("Connect tool", () => {
2327
});
2428

2529
describe("with default config", () => {
26-
beforeEach(async () => {
27-
({ client, teardown: serverClientTeardown } = await setupIntegrationTest());
28-
});
29-
3030
it("should have correct metadata", async () => {
3131
const tools = await client.listTools();
3232
const connectTool = tools.tools.find((tool) => tool.name === "connect");
@@ -84,8 +84,6 @@ describe("Connect tool", () => {
8484
describe("with connection string in config", () => {
8585
beforeEach(async () => {
8686
config.connectionString = cluster.connectionString;
87-
88-
({ client, teardown: serverClientTeardown } = await setupIntegrationTest());
8987
});
9088

9189
it("uses the connection string from config", async () => {

0 commit comments

Comments
 (0)