新增 YAML 配置解析(Bun 内置 YAML)、SQLite 数据存储(bun:sqlite)、按 interval 分组并发拨测引擎、REST API(/api/summary、/api/targets、/api/targets/:id/history、/api/targets/:id/trend)、React 前端 Dashboard(统计卡片、目标表格、可展开详情面板、recharts 趋势图)。CLI 简化为仅接受配置文件路径。移除 /api/demo 路由和相关 demo 代码。保留 /health、静态资源服务和 SPA fallback。
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { checkExpect } from "../../../src/server/checker/fetcher";
|
|
|
|
describe("checkExpect", () => {
|
|
test("无 expect 配置时 matched 为 true", () => {
|
|
expect(checkExpect(200, "ok", 100, undefined)).toBe(true);
|
|
});
|
|
|
|
test("status 匹配", () => {
|
|
expect(checkExpect(200, "", 100, { status: [200, 201] })).toBe(true);
|
|
expect(checkExpect(201, "", 100, { status: [200, 201] })).toBe(true);
|
|
expect(checkExpect(404, "", 100, { status: [200, 201] })).toBe(false);
|
|
});
|
|
|
|
test("bodyContains 匹配", () => {
|
|
expect(checkExpect(200, "hello world", 100, { bodyContains: "hello" })).toBe(true);
|
|
expect(checkExpect(200, "hello world", 100, { bodyContains: "missing" })).toBe(false);
|
|
});
|
|
|
|
test("maxLatencyMs 匹配", () => {
|
|
expect(checkExpect(200, "", 100, { maxLatencyMs: 200 })).toBe(true);
|
|
expect(checkExpect(200, "", 300, { maxLatencyMs: 200 })).toBe(false);
|
|
expect(checkExpect(200, "", 200, { maxLatencyMs: 200 })).toBe(true);
|
|
});
|
|
|
|
test("多条 expect 全部通过", () => {
|
|
expect(
|
|
checkExpect(200, "healthy", 100, {
|
|
status: [200],
|
|
bodyContains: "healthy",
|
|
maxLatencyMs: 200,
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
test("多条 expect 部分失败", () => {
|
|
expect(
|
|
checkExpect(200, "healthy", 500, {
|
|
status: [200],
|
|
bodyContains: "healthy",
|
|
maxLatencyMs: 200,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
});
|