Skip to content

Commit c5194a9

Browse files
committed
test: setup vitest with client lifecycle hooks
1 parent 8cf44ec commit c5194a9

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

vitest.setup.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
import 'dotenv/config'
2+
import { afterAll, beforeAll } from 'vitest'
23
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
34
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
45

5-
const serverParams = new StdioClientTransport({
6-
command: 'c8',
7-
args: ['--reporter=lcov', '--reporter=text', 'tsx', './src/index.ts'],
8-
env: {
9-
...process.env,
10-
NODE_V8_COVERAGE: './coverage/tmp',
11-
},
6+
beforeAll(async () => {
7+
const serverParams = new StdioClientTransport({
8+
command: 'c8',
9+
args: ['--reporter=lcov', '--reporter=text', 'tsx', './src/index.ts'],
10+
env: {
11+
...process.env,
12+
NODE_V8_COVERAGE: './coverage/tmp',
13+
},
14+
})
15+
const client = new Client({
16+
name: 'doc-mcp-client',
17+
version: '1.0.0',
18+
})
19+
await client.connect(serverParams)
20+
global.client = client
1221
})
13-
const client = new Client({
14-
name: 'doc-mcp-client',
15-
version: '1.0.0',
16-
})
17-
await client.connect(serverParams)
1822

19-
global.client = client
23+
afterAll(async () => {
24+
await global.client.close()
25+
})

0 commit comments

Comments
 (0)