feat: ValueMatcher 支持 primitive 原始值简写,等价于 { equals: value }
This commit is contained in:
@@ -62,6 +62,28 @@ describe("config contract", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
test("导出 schema 支持 ValueMatcher primitive 简写且拒绝数组对象简写", () => {
|
||||
const ajv = new Ajv({
|
||||
allErrors: true,
|
||||
coerceTypes: false,
|
||||
removeAdditional: false,
|
||||
strict: true,
|
||||
useDefaults: false,
|
||||
});
|
||||
const validate = ajv.compile(createProbeConfigJsonSchema(createDefaultCheckerRegistry()));
|
||||
const target = (durationMs: unknown) => ({
|
||||
targets: [{ expect: { durationMs }, http: { url: "https://example.com" }, id: "api", type: "http" }],
|
||||
});
|
||||
|
||||
expect(validate(target(5000))).toBe(true);
|
||||
expect(validate(target("5000"))).toBe(true);
|
||||
expect(validate(target(null))).toBe(true);
|
||||
expect(validate(target([1, 2]))).toBe(false);
|
||||
expect(validate(target({ foo: "bar" }))).toBe(false);
|
||||
expect(validate(target({ equals: [1, 2] }))).toBe(true);
|
||||
expect(validate(target({ equals: { status: "ok" } }))).toBe(true);
|
||||
});
|
||||
|
||||
test("Ajv 错误转换为中文结构化 issue", () => {
|
||||
const result = validateProbeConfigContract(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user