-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.ts
More file actions
72 lines (64 loc) · 2.61 KB
/
Copy pathindex.test.ts
File metadata and controls
72 lines (64 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({
dashboardStart: vi.fn(),
dashboardLog: vi.fn(),
serverRun: vi.fn(),
watcherStart: vi.fn(),
watcherOn: vi.fn(),
loggerInfo: vi.fn(),
serverConstructor: vi.fn(),
watcherConstructor: vi.fn(),
}));
vi.mock("../src/core/dashboard.js", () => ({
CommandCenterDashboard: { start: mocks.dashboardStart, log: mocks.dashboardLog },
}));
vi.mock("../src/core/server.js", () => ({
PromptRefinerServer: class {
constructor(rootPath: string) {
mocks.serverConstructor(rootPath);
}
run = mocks.serverRun;
},
}));
vi.mock("../src/watcher/index.js", () => ({
FileWatcher: class {
constructor(rootPath: string) {
mocks.watcherConstructor(rootPath);
}
on = mocks.watcherOn;
start = mocks.watcherStart;
},
}));
vi.mock("../src/core/logger.js", () => ({ RuntimeLogger: { info: mocks.loggerInfo } }));
describe("runtime bootstrap", () => {
beforeEach(() => {
vi.resetModules();
vi.clearAllMocks();
mocks.serverRun.mockResolvedValue(undefined);
delete process.env.PORT;
});
it("starts dashboard, watcher, and MCP server and forwards file events", async () => {
await import("../src/index.js");
expect(mocks.dashboardStart).toHaveBeenCalledOnce();
expect(mocks.dashboardStart).toHaveBeenCalledWith(3000, process.cwd());
expect(mocks.serverConstructor).toHaveBeenCalledWith(process.cwd());
expect(mocks.watcherConstructor).toHaveBeenCalledWith(process.cwd());
expect(mocks.watcherStart).toHaveBeenCalledOnce();
expect(mocks.serverRun).toHaveBeenCalledOnce();
const changeHandler = mocks.watcherOn.mock.calls.find(call => call[0] === "change")?.[1];
changeHandler({ event: "change", path: `${process.cwd()}\\src\\a.ts` });
expect(mocks.loggerInfo).toHaveBeenCalledWith(expect.stringContaining("[FS] change"));
expect(mocks.dashboardLog).toHaveBeenCalledWith(expect.stringContaining("[FS] change"));
});
it("uses the configured dashboard port and exits on fatal server failure", async () => {
process.env.PORT = "4321";
const error = new Error("startup failed");
mocks.serverRun.mockRejectedValue(error);
const consoleError = vi.spyOn(console, "error").mockImplementation(() => undefined);
const exit = vi.spyOn(process, "exit").mockImplementation((() => undefined) as never);
await import("../src/index.js");
await vi.waitFor(() => expect(exit).toHaveBeenCalledWith(1));
expect(mocks.dashboardStart).toHaveBeenCalledWith(4321, process.cwd());
expect(consoleError).toHaveBeenCalledWith("[FATAL ERROR]", error);
});
});