Skip to content

Commit 8b2471b

Browse files
committed
refactor: update test setup and configuration
1 parent 8472be9 commit 8b2471b

File tree

12 files changed

+302
-26
lines changed

12 files changed

+302
-26
lines changed

package-lock.json

Lines changed: 207 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"dev:stdio": "cross-env NODE_ENV=local concurrently \"tsc --noEmit --watch\" \"node scripts/dev.js\"",
2323
"dev:web": "cross-env NODE_ENV=local TRANSPORT=web concurrently \"tsc --noEmit --watch\" \"node scripts/dev.js\"",
2424
"test": "vitest run",
25-
"coverage": "vitest run --coverage"
25+
"coverage": "rimraf coverage && npm run test && c8 report --reporter=html"
2626
},
2727
"dependencies": {
2828
"@modelcontextprotocol/sdk": "^1.15.0",
@@ -48,6 +48,7 @@
4848
"@typescript-eslint/eslint-plugin": "^8.36.0",
4949
"@typescript-eslint/parser": "^8.36.0",
5050
"@vitest/coverage-v8": "^3.2.4",
51+
"c8": "^10.1.3",
5152
"concurrently": "^9.2.0",
5253
"cross-env": "^7.0.3",
5354
"esbuild": "^0.25.6",
@@ -59,6 +60,7 @@
5960
"lint-staged": "^16.1.2",
6061
"prettier": "^3.6.2",
6162
"rimraf": "^6.0.1",
63+
"tsx": "^4.20.3",
6264
"typescript": "^5.8.3",
6365
"vitest": "^3.2.4"
6466
},

src/resources/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mc
22
import type { OptionsType } from '@/types'
33

44
export const registerResources = (server: McpServer, options: OptionsType) => {
5-
// @ts-ignore
65
server.registerResource(
76
'search',
87
new ResourceTemplate('search://{keyword}', {
@@ -17,7 +16,7 @@ export const registerResources = (server: McpServer, options: OptionsType) => {
1716
contents: [
1817
{
1918
uri: uri.href,
20-
text: `hello ${keyword}`,
19+
text: `search ${keyword}`,
2120
},
2221
],
2322
}

tests/prompts/index.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { describe, expect, test } from 'vitest'
2+
3+
describe('echoPrompt', () => {
4+
test('should return correct prompt content for a valid argument', async () => {
5+
expect(
6+
await global.client.getPrompt({
7+
name: 'echo',
8+
arguments: {
9+
message: 'hello',
10+
},
11+
}),
12+
).toStrictEqual({
13+
messages: [
14+
{
15+
role: 'user',
16+
content: {
17+
type: 'text',
18+
text: 'Please process this message: hello',
19+
},
20+
},
21+
],
22+
})
23+
})
24+
})

tests/resources/index.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { describe, expect, test } from 'vitest'
2+
3+
describe('searchResource', () => {
4+
test('should return correct resource content for a valid URI', async () => {
5+
expect(
6+
await global.client.readResource({
7+
uri: 'search://hello',
8+
}),
9+
).toStrictEqual({
10+
contents: [
11+
{
12+
uri: 'search://hello',
13+
text: 'search hello',
14+
},
15+
],
16+
})
17+
})
18+
})

tests/tools/queryWatermarkJsPlusDoc.test.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { describe, expect, test } from 'vitest'
2+
3+
describe('watermarkJsPlusDocTool', () => {
4+
test('returns data for a valid input', async () => {
5+
const res = (await global.client.callTool({
6+
name: 'query-watermark-js-plus',
7+
arguments: {
8+
keyword: 'On Demand',
9+
},
10+
})) as { content: unknown[] }
11+
12+
expect(res.content.length).toBeGreaterThan(0)
13+
}, 20000)
14+
15+
test('returns a "not found" response for an unrecognized input', async () => {
16+
const res = (await global.client.callTool({
17+
name: 'query-watermark-js-plus',
18+
arguments: {
19+
keyword: 'ESLint',
20+
},
21+
})) as { content: unknown[] }
22+
expect(res.content.length).toEqual(0)
23+
}, 20000)
24+
})

0 commit comments

Comments
 (0)