Skip to content

Commit b899675

Browse files
Add temporary test database handling for isolated test environments (#10)
Co-authored-by: Cursor Agent <[email protected]>
1 parent 3979b80 commit b899675

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

exercises/03.resources/05.problem.linked/src/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
13
import { invariant } from '@epic-web/invariant'
24
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
35
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
46
import { test, beforeAll, afterAll, expect } from 'vitest'
57

68
let client: Client
9+
const EPIC_ME_DB_PATH = `./test.ignored/db.${process.env.VITEST_WORKER_ID}.sqlite`
710

811
beforeAll(async () => {
12+
const dir = path.dirname(EPIC_ME_DB_PATH)
13+
await fs.mkdir(dir, { recursive: true })
914
client = new Client({
1015
name: 'EpicMeTester',
1116
version: '1.0.0',
1217
})
1318
const transport = new StdioClientTransport({
1419
command: 'tsx',
1520
args: ['src/index.ts'],
21+
env: {
22+
...process.env,
23+
EPIC_ME_DB_PATH,
24+
},
1625
})
1726
await client.connect(transport)
1827
})
1928

2029
afterAll(async () => {
2130
await client.transport?.close()
31+
await fs.unlink(EPIC_ME_DB_PATH)
2232
})
2333

2434
test('Tool Definition', async () => {

exercises/03.resources/05.solution.linked/src/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
13
import { invariant } from '@epic-web/invariant'
24
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
35
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
46
import { test, beforeAll, afterAll, expect } from 'vitest'
57

68
let client: Client
9+
const EPIC_ME_DB_PATH = `./test.ignored/db.${process.env.VITEST_WORKER_ID}.sqlite`
710

811
beforeAll(async () => {
12+
const dir = path.dirname(EPIC_ME_DB_PATH)
13+
await fs.mkdir(dir, { recursive: true })
914
client = new Client({
1015
name: 'EpicMeTester',
1116
version: '1.0.0',
1217
})
1318
const transport = new StdioClientTransport({
1419
command: 'tsx',
1520
args: ['src/index.ts'],
21+
env: {
22+
...process.env,
23+
EPIC_ME_DB_PATH,
24+
},
1625
})
1726
await client.connect(transport)
1827
})
1928

2029
afterAll(async () => {
2130
await client.transport?.close()
31+
await fs.unlink(EPIC_ME_DB_PATH)
2232
})
2333

2434
test('Tool Definition', async () => {

exercises/03.resources/06.problem.embedded/src/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
13
import { invariant } from '@epic-web/invariant'
24
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
35
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
46
import { test, beforeAll, afterAll, expect } from 'vitest'
57

68
let client: Client
9+
const EPIC_ME_DB_PATH = `./test.ignored/db.${process.env.VITEST_WORKER_ID}.sqlite`
710

811
beforeAll(async () => {
12+
const dir = path.dirname(EPIC_ME_DB_PATH)
13+
await fs.mkdir(dir, { recursive: true })
914
client = new Client({
1015
name: 'EpicMeTester',
1116
version: '1.0.0',
1217
})
1318
const transport = new StdioClientTransport({
1419
command: 'tsx',
1520
args: ['src/index.ts'],
21+
env: {
22+
...process.env,
23+
EPIC_ME_DB_PATH,
24+
},
1625
})
1726
await client.connect(transport)
1827
})
1928

2029
afterAll(async () => {
2130
await client.transport?.close()
31+
await fs.unlink(EPIC_ME_DB_PATH)
2232
})
2333

2434
test('Tool Definition', async () => {

exercises/03.resources/06.solution.embedded/src/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
13
import { invariant } from '@epic-web/invariant'
24
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
35
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
46
import { test, beforeAll, afterAll, expect } from 'vitest'
57

68
let client: Client
9+
const EPIC_ME_DB_PATH = `./test.ignored/db.${process.env.VITEST_WORKER_ID}.sqlite`
710

811
beforeAll(async () => {
12+
const dir = path.dirname(EPIC_ME_DB_PATH)
13+
await fs.mkdir(dir, { recursive: true })
914
client = new Client({
1015
name: 'EpicMeTester',
1116
version: '1.0.0',
1217
})
1318
const transport = new StdioClientTransport({
1419
command: 'tsx',
1520
args: ['src/index.ts'],
21+
env: {
22+
...process.env,
23+
EPIC_ME_DB_PATH,
24+
},
1625
})
1726
await client.connect(transport)
1827
})
1928

2029
afterAll(async () => {
2130
await client.transport?.close()
31+
await fs.unlink(EPIC_ME_DB_PATH)
2232
})
2333

2434
test('Tool Definition', async () => {

exercises/04.prompts/03.problem.completion/src/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
13
import { invariant } from '@epic-web/invariant'
24
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
35
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
46
import { test, beforeAll, afterAll, expect } from 'vitest'
57

68
let client: Client
9+
const EPIC_ME_DB_PATH = `./test.ignored/db.${process.env.VITEST_WORKER_ID}.sqlite`
710

811
beforeAll(async () => {
12+
const dir = path.dirname(EPIC_ME_DB_PATH)
13+
await fs.mkdir(dir, { recursive: true })
914
client = new Client({
1015
name: 'EpicMeTester',
1116
version: '1.0.0',
1217
})
1318
const transport = new StdioClientTransport({
1419
command: 'tsx',
1520
args: ['src/index.ts'],
21+
env: {
22+
...process.env,
23+
EPIC_ME_DB_PATH,
24+
},
1625
})
1726
await client.connect(transport)
1827
})
1928

2029
afterAll(async () => {
2130
await client.transport?.close()
31+
await fs.unlink(EPIC_ME_DB_PATH)
2232
})
2333

2434
test('Tool Definition', async () => {

exercises/04.prompts/03.solution.completion/src/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
13
import { invariant } from '@epic-web/invariant'
24
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
35
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
46
import { test, beforeAll, afterAll, expect } from 'vitest'
57

68
let client: Client
9+
const EPIC_ME_DB_PATH = `./test.ignored/db.${process.env.VITEST_WORKER_ID}.sqlite`
710

811
beforeAll(async () => {
12+
const dir = path.dirname(EPIC_ME_DB_PATH)
13+
await fs.mkdir(dir, { recursive: true })
914
client = new Client({
1015
name: 'EpicMeTester',
1116
version: '1.0.0',
1217
})
1318
const transport = new StdioClientTransport({
1419
command: 'tsx',
1520
args: ['src/index.ts'],
21+
env: {
22+
...process.env,
23+
EPIC_ME_DB_PATH,
24+
},
1625
})
1726
await client.connect(transport)
1827
})
1928

2029
afterAll(async () => {
2130
await client.transport?.close()
31+
await fs.unlink(EPIC_ME_DB_PATH)
2232
})
2333

2434
test('Tool Definition', async () => {

0 commit comments

Comments
 (0)