Skip to content

Commit 11ea3f1

Browse files
committed
test: add vitest config and test for cli
1 parent 04dac7d commit 11ea3f1

File tree

6 files changed

+215
-16
lines changed

6 files changed

+215
-16
lines changed

.changeset/wise-cameras-bathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'create-mcp-kit': patch
3+
---
4+
5+
test: add vitest config and test for cli

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"scripts": {
77
"prepare": "husky",
88
"build": "pnpm -r --aggregate-output --filter=./packages/* build",
9-
"dev": "pnpm -r --aggregate-output --filter=./packages/create dev",
10-
"start": "pnpm -r --aggregate-output --filter=./packages/create start",
9+
"dev": "pnpm -r --aggregate-output --filter=./packages/create-mcp-kit dev",
10+
"start": "pnpm -r --aggregate-output --filter=./packages/create-mcp-kit start",
1111
"test": "pnpm -r --aggregate-output --filter=./packages/* test",
1212
"coverage": "pnpm -r --aggregate-output --filter=./packages/* coverage",
1313
"changeset": "changeset",
@@ -46,12 +46,14 @@
4646
"eslint": "^9.32.0",
4747
"eslint-plugin-import": "^2.32.0",
4848
"eslint-plugin-prettier": "^5.5.3",
49+
"execa": "^9.6.0",
4950
"globals": "^16.3.0",
5051
"husky": "^9.1.7",
5152
"lint-staged": "^16.1.2",
5253
"prettier": "^3.6.2",
5354
"rimraf": "^6.0.1",
5455
"rolldown": "1.0.0-beta.27",
56+
"tsx": "^4.20.3",
5557
"typescript": "^5.8.3",
5658
"vitest": "^3.2.4"
5759
}

packages/create-mcp-kit/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"build:types": "tsc --noEmit",
4141
"build": "cross-env NODE_ENV=production && npm run clean:dist && npm run build:types && rolldown -c rolldown.config.ts",
4242
"dev": "cross-env NODE_ENV=local && rolldown -c rolldown.config.ts --watch",
43-
"start": "node ./dist/index.js"
43+
"start": "node ./dist/index.js",
44+
"test": "vitest run"
4445
},
4546
"bugs": {
4647
"url": "https://github.com/my-mcp-hub/mcp-kit/issues"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { tmpdir } from 'os'
2+
import { join, resolve } from 'path'
3+
import { mkdirSync, rmSync } from 'fs'
4+
import { describe, test, expect } from 'vitest'
5+
import { execa } from 'execa'
6+
7+
describe('test index cli', () => {
8+
test('should create project', async () => {
9+
const testDir = join(tmpdir(), `test-cli-${Date.now()}`)
10+
mkdirSync(testDir, { recursive: true })
11+
const userInput = ['\x0D', '\x0D', '\x0D', '\x0D', 'y\x0D']
12+
const scriptPath = resolve('./src/index.ts')
13+
const subprocess = execa('tsx', [scriptPath], {
14+
// stdio: ['pipe', 'inherit', 'inherit'],
15+
cwd: testDir,
16+
timeout: 30000,
17+
})
18+
userInput.forEach((input, index) => {
19+
setTimeout(
20+
() => {
21+
subprocess.stdin.write(input)
22+
},
23+
1000 * (index + 1),
24+
)
25+
})
26+
const result = await subprocess
27+
expect(result.stdout).toContain('Project created successfully!')
28+
rmSync(testDir, { recursive: true, force: true })
29+
}, 30000)
30+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
environment: 'node',
6+
include: ['./tests/**/*.test.ts'],
7+
coverage: {
8+
provider: 'v8',
9+
include: ['src/**/*.ts'],
10+
},
11+
},
12+
})

0 commit comments

Comments
 (0)