- 引入 typed target 判别联合,支持 http 与 command 两种 checker - expect 重构为有序规则数组,按配置顺序快速失败并生成结构化 failure - 新增 command runner,支持 exec + args 本地命令执行 - 引入全局并发限制 maxConcurrentChecks 和 size 解析 (KB/MB/GB) - HTTP/command 各自独立 expect pipeline,应用领域默认成功语义 - SQLite schema、API、Dashboard 全链路调整为 checker 通用契约 - 补充完整测试覆盖(192 tests),更新 README 与示例配置
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { truncateActual, mismatchFailure, errorFailure } from "../../../../src/server/checker/expect/failure";
|
|
|
|
describe("truncateActual", () => {
|
|
test("短字符串不截断", () => {
|
|
expect(truncateActual("hello")).toBe("hello");
|
|
});
|
|
|
|
test("恰好等于限制长度不截断", () => {
|
|
const str = "a".repeat(200);
|
|
expect(truncateActual(str)).toBe(str);
|
|
});
|
|
|
|
test("超过限制长度截断并加省略号", () => {
|
|
const str = "a".repeat(300);
|
|
const result = truncateActual(str) as string;
|
|
expect(result.length).toBe(203);
|
|
expect(result.endsWith("...")).toBe(true);
|
|
expect(result.startsWith("a".repeat(200))).toBe(true);
|
|
});
|
|
|
|
test("自定义最大长度", () => {
|
|
const str = "abcdefghij";
|
|
const result = truncateActual(str, 5) as string;
|
|
expect(result).toBe("abcde...");
|
|
});
|
|
|
|
test("null 不截断", () => {
|
|
expect(truncateActual(null)).toBe(null);
|
|
});
|
|
|
|
test("undefined 不截断", () => {
|
|
expect(truncateActual(undefined)).toBe(undefined);
|
|
});
|
|
|
|
test("数字转换为字符串后判断", () => {
|
|
expect(truncateActual(42)).toBe(42);
|
|
expect(truncateActual(123456789, 3) as string).toBe("123...");
|
|
});
|
|
});
|
|
|
|
describe("mismatchFailure", () => {
|
|
test("返回正确的 mismatch 结构", () => {
|
|
const f = mismatchFailure("status", "status", [200], 500, "status mismatch");
|
|
expect(f).toEqual({
|
|
kind: "mismatch",
|
|
phase: "status",
|
|
path: "status",
|
|
expected: [200],
|
|
actual: 500,
|
|
message: "status mismatch",
|
|
});
|
|
});
|
|
|
|
test("自动截断过长的 actual", () => {
|
|
const longStr = "x".repeat(300);
|
|
const f = mismatchFailure("body", "body[0]", "short", longStr, "too long");
|
|
expect((f.actual as string).endsWith("...")).toBe(true);
|
|
expect((f.actual as string).length).toBe(203);
|
|
});
|
|
});
|
|
|
|
describe("errorFailure", () => {
|
|
test("返回正确的 error 结构", () => {
|
|
const f = errorFailure("body", "body[0].json($.x)", "body is not valid JSON");
|
|
expect(f).toEqual({
|
|
kind: "error",
|
|
phase: "body",
|
|
path: "body[0].json($.x)",
|
|
message: "body is not valid JSON",
|
|
});
|
|
});
|
|
|
|
test("不含 expected 和 actual 字段", () => {
|
|
const f = errorFailure("headers", "headers.x", "header missing");
|
|
expect(f).not.toHaveProperty("expected");
|
|
expect(f).not.toHaveProperty("actual");
|
|
});
|
|
});
|