Skip to content

Commit 4572dbb

Browse files
Port tests
1 parent 9467eff commit 4572dbb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3583
-6057
lines changed

.vscode/mcp.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
"args": [
1111
"@playwright/mcp@latest"
1212
]
13+
},
14+
"context7": {
15+
"type": "http",
16+
"url": "https://mcp.context7.com/mcp"
17+
},
18+
"sequentialthinking": {
19+
"command": "npx",
20+
"args": [
21+
"-y",
22+
"@modelcontextprotocol/server-sequential-thinking"
23+
]
1324
}
14-
}
25+
} }
1526
}

mcp-server/jest.config.cjs

Lines changed: 0 additions & 39 deletions
This file was deleted.

mcp-server/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
"start": "node dist/index.js",
1111
"clean": "rm -rf dist",
1212
"type-check": "tsc --noEmit",
13-
"test": "jest",
14-
"test:watch": "jest --watch",
15-
"test:coverage": "jest --coverage"
13+
"test": "vitest run",
14+
"test:watch": "vitest",
15+
"test:coverage": "vitest run --coverage",
16+
"test:ui": "vitest --ui"
1617
},
1718
"dependencies": {
1819
"@modelcontextprotocol/sdk": "^1.17.0",
1920
"@turn-based-mcp/shared": "file:../shared"
2021
},
2122
"devDependencies": {
22-
"@types/jest": "^30.0.0",
2323
"@types/node": "^24.1.0",
24-
"jest": "^30.0.5",
25-
"ts-jest": "^29.4.0",
26-
"typescript": "^5.5.0"
24+
"@vitest/ui": "^3.2.4",
25+
"typescript": "^5.5.0",
26+
"vitest": "^3.2.4"
2727
}
2828
}

mcp-server/src/integration/integration.test.ts

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,55 @@
1+
import { vi } from 'vitest'
12
import { handleToolCall } from '../handlers/tool-handlers.js'
23
import { listResources, readResource } from '../handlers/resource-handlers.js'
34
import { listPrompts, getPrompt } from '../handlers/prompt-handlers.js'
5+
import * as httpClient from '../utils/http-client.js'
6+
7+
// Import the real constants from shared package
8+
import { GAME_TYPES, DIFFICULTIES, isSupportedGameType, DEFAULT_PLAYER_NAME, DEFAULT_AI_DIFFICULTY } from '@turn-based-mcp/shared'
49

510
// Mock the web API calls for testing
6-
jest.mock('../utils/http-client.js', () => ({
7-
httpGet: jest.fn(),
8-
httpPost: jest.fn(),
9-
getGameViaAPI: jest.fn(),
10-
createGameViaAPI: jest.fn(),
11-
submitMoveViaAPI: jest.fn(),
12-
getGamesByType: jest.fn()
11+
vi.mock('../utils/http-client.js', () => ({
12+
httpGet: vi.fn(),
13+
httpPost: vi.fn(),
14+
getGameViaAPI: vi.fn(),
15+
createGameViaAPI: vi.fn(),
16+
submitMoveViaAPI: vi.fn(),
17+
getGamesByType: vi.fn()
1318
}))
1419

15-
// Mock shared library
16-
jest.mock('@turn-based-mcp/shared', () => ({
17-
TicTacToeGame: jest.fn(() => ({
18-
getValidMoves: jest.fn(() => [{ row: 0, col: 0 }])
19-
})),
20-
RockPaperScissorsGame: jest.fn(() => ({}))
21-
}))
20+
// Mock only the game classes from shared library
21+
vi.mock('@turn-based-mcp/shared', async (importOriginal) => {
22+
const actual = await importOriginal() as any
23+
return {
24+
...actual,
25+
TicTacToeGame: vi.fn(() => ({
26+
getValidMoves: vi.fn(() => [{ row: 0, col: 0 }])
27+
})),
28+
RockPaperScissorsGame: vi.fn(() => ({}))
29+
}
30+
})
2231

2332
// Mock AI modules
24-
jest.mock('../ai/tic-tac-toe-ai.js', () => ({
25-
TicTacToeAI: jest.fn(() => ({
26-
makeMove: jest.fn(() => ({ row: 0, col: 0 }))
33+
vi.mock('../ai/tic-tac-toe-ai.js', () => ({
34+
TicTacToeAI: vi.fn(() => ({
35+
makeMove: vi.fn(() => ({ row: 0, col: 0 }))
2736
}))
2837
}))
2938

30-
jest.mock('../ai/rock-paper-scissors-ai.js', () => ({
31-
RockPaperScissorsAI: jest.fn(() => ({
32-
makeChoice: jest.fn(() => 'rock')
39+
vi.mock('../ai/rock-paper-scissors-ai.js', () => ({
40+
RockPaperScissorsAI: vi.fn(() => ({
41+
makeChoice: vi.fn(() => 'rock')
3342
}))
3443
}))
3544

3645
describe('MCP Server Integration', () => {
3746
beforeEach(() => {
38-
jest.clearAllMocks()
47+
vi.clearAllMocks()
3948
})
4049

4150
describe('Resource Handlers', () => {
4251
it('should list resources correctly', async () => {
43-
const mockGetGamesByType = require('../utils/http-client.js').getGamesByType
52+
const mockGetGamesByType = vi.mocked(httpClient.getGamesByType)
4453
mockGetGamesByType.mockResolvedValue([
4554
{
4655
gameState: {
@@ -70,7 +79,7 @@ describe('MCP Server Integration', () => {
7079
})
7180

7281
it('should read game type resource correctly', async () => {
73-
const mockGetGamesByType = require('../utils/http-client.js').getGamesByType
82+
const mockGetGamesByType = vi.mocked(httpClient.getGamesByType)
7483
mockGetGamesByType.mockResolvedValue([
7584
{
7685
gameState: {
@@ -95,7 +104,7 @@ describe('MCP Server Integration', () => {
95104
})
96105

97106
it('should read individual game resource correctly', async () => {
98-
const mockGetGameViaAPI = require('../utils/http-client.js').getGameViaAPI
107+
const mockGetGameViaAPI = vi.mocked(httpClient.getGameViaAPI)
99108
mockGetGameViaAPI.mockResolvedValue({
100109
gameState: {
101110
id: 'test-game-1',
@@ -118,7 +127,7 @@ describe('MCP Server Integration', () => {
118127

119128
describe('Tool Handlers', () => {
120129
it('should create tic-tac-toe game correctly', async () => {
121-
const mockCreateGameViaAPI = require('../utils/http-client.js').createGameViaAPI
130+
const mockCreateGameViaAPI = vi.mocked(httpClient.createGameViaAPI)
122131
mockCreateGameViaAPI.mockResolvedValue({
123132
gameState: {
124133
id: 'new-game-id',
@@ -136,8 +145,8 @@ describe('MCP Server Integration', () => {
136145
})
137146

138147
it('should handle play moves correctly', async () => {
139-
const mockGetGameViaAPI = require('../utils/http-client.js').getGameViaAPI
140-
const mockSubmitMoveViaAPI = require('../utils/http-client.js').submitMoveViaAPI
148+
const mockGetGameViaAPI = vi.mocked(httpClient.getGameViaAPI)
149+
const mockSubmitMoveViaAPI = vi.mocked(httpClient.submitMoveViaAPI)
141150

142151
mockGetGameViaAPI.mockResolvedValue({
143152
gameState: {

mcp-server/src/integration/mcp-rps-security.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
import { vi } from 'vitest'
12
import { getRPSGameForMCP, makeRPSMove } from '@turn-based-mcp/shared'
23
import type { GameSession } from '@turn-based-mcp/shared'
34
import type { RPSGameState, RPSMove } from '@turn-based-mcp/shared'
45

56
// Mock fetch for testing
6-
global.fetch = jest.fn()
7-
const mockFetch = global.fetch as jest.MockedFunction<typeof fetch>
7+
global.fetch = vi.fn()
8+
const mockFetch = global.fetch as vi.MockedFunction<typeof fetch>
89

910
describe('MCP Server RPS Security Integration', () => {
1011
beforeEach(() => {
11-
jest.clearAllMocks()
12+
vi.clearAllMocks()
1213
process.env.WEB_API_BASE = 'http://localhost:3000'
1314
})
1415

mcp-server/vitest.config.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
environment: 'node',
6+
globals: true,
7+
setupFiles: ['./vitest.setup.ts'],
8+
coverage: {
9+
provider: 'v8',
10+
reporter: ['text', 'lcov', 'html'],
11+
thresholds: {
12+
branches: 85,
13+
functions: 85,
14+
lines: 85,
15+
statements: 85
16+
},
17+
include: ['src/**/*.{ts,tsx}'],
18+
exclude: ['src/**/*.d.ts', 'src/**/index.ts']
19+
}
20+
},
21+
})
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/**
2-
* Jest setup for mcp-server package tests
2+
* Vitest setup for mcp-server package tests
33
*
44
* Sets up test database before all tests and cleans up after
55
*/
66

7-
const { setupTestDatabase, teardownTestDatabase } = require('@turn-based-mcp/shared')
7+
import { setupTestDatabase, teardownTestDatabase } from '@turn-based-mcp/shared'
8+
import { beforeAll, afterAll } from 'vitest'
89

910
// Setup test database before all tests
1011
beforeAll(async () => {

0 commit comments

Comments
 (0)