Skip to content

Commit 46ae2a1

Browse files
author
zhibisora
committed
Fix test for cross-spawn
1 parent d4bf73b commit 46ae2a1

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

Diff for: package-lock.json

+15-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"@jest-mock/express": "^3.0.0",
6363
"@types/content-type": "^1.1.8",
6464
"@types/cors": "^2.8.17",
65+
"@types/cross-spawn": "^6.0.6",
6566
"@types/eslint__js": "^8.42.3",
6667
"@types/eventsource": "^1.1.15",
6768
"@types/express": "^5.0.0",

Diff for: src/client/cross-spawn.test.ts

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { StdioClientTransport } from "./stdio.js";
22
import spawn from "cross-spawn";
3+
import { JSONRPCMessage } from "../types.js";
34

45
// mock cross-spawn
56
jest.mock("cross-spawn");
@@ -9,8 +10,13 @@ describe("StdioClientTransport using cross-spawn", () => {
910
beforeEach(() => {
1011
// mock cross-spawn's return value
1112
mockSpawn.mockImplementation(() => {
12-
const mockProcess = {
13-
on: jest.fn((event: string, callback: Function) => {
13+
const mockProcess: {
14+
on: jest.Mock;
15+
stdin?: { on: jest.Mock; write: jest.Mock };
16+
stdout?: { on: jest.Mock };
17+
stderr?: null;
18+
} = {
19+
on: jest.fn((event: string, callback: () => void) => {
1420
if (event === "spawn") {
1521
callback();
1622
}
@@ -76,8 +82,19 @@ describe("StdioClientTransport using cross-spawn", () => {
7682
});
7783

7884
// get the mock process object
79-
const mockProcess = {
80-
on: jest.fn((event, callback) => {
85+
const mockProcess: {
86+
on: jest.Mock;
87+
stdin: {
88+
on: jest.Mock;
89+
write: jest.Mock;
90+
once: jest.Mock;
91+
};
92+
stdout: {
93+
on: jest.Mock;
94+
};
95+
stderr: null;
96+
} = {
97+
on: jest.fn((event: string, callback: () => void) => {
8198
if (event === "spawn") {
8299
callback();
83100
}
@@ -98,7 +115,8 @@ describe("StdioClientTransport using cross-spawn", () => {
98115

99116
await transport.start();
100117

101-
const message = {
118+
// 关键修复:确保 jsonrpc 是字面量 "2.0"
119+
const message: JSONRPCMessage = {
102120
jsonrpc: "2.0",
103121
id: "test-id",
104122
method: "test-method"

0 commit comments

Comments
 (0)