1
0

feat: ValueMatcher 支持 primitive 原始值简写,等价于 { equals: value }

This commit is contained in:
2026-05-19 17:07:47 +08:00
parent 8d8549d07f
commit 12cd05b04e
37 changed files with 1836 additions and 1022 deletions

View File

@@ -1,12 +1,12 @@
import { isPlainObject } from "es-toolkit";
import type { ExpectResult, KeyValueExpect, ValueMatcher } from "../../expect/types";
import type { ExpectResult, KeyValueExpect, ValueMatcherInput } from "../../expect/types";
import { mismatchFailure } from "../../expect/failure";
import { checkKeyValueExpect } from "../../expect/key-value";
import { checkValueMatcher } from "../../expect/matcher";
export function checkRowCount(actual: number, matcher: ValueMatcher): ExpectResult {
export function checkRowCount(actual: number, matcher: ValueMatcherInput): ExpectResult {
return checkValueMatcher(actual, matcher, {
message: `rowCount ${actual} 不满足条件`,
path: "rowCount",

View File

@@ -1,10 +1,10 @@
import type { ContentRules, KeyValueExpect, ValueMatcher } from "../../expect/types";
import type { ContentRules, KeyValueExpect, ValueMatcherInput } from "../../expect/types";
import type { ResolvedTargetBase } from "../../types";
export interface DbExpectConfig {
durationMs?: ValueMatcher;
durationMs?: ValueMatcherInput;
result?: ContentRules;
rowCount?: ValueMatcher;
rowCount?: ValueMatcherInput;
rows?: KeyValueExpect[];
}

View File

@@ -3,6 +3,7 @@ import { isPlainObject, isString } from "es-toolkit";
import type { ConfigValidationIssue } from "../../schema/issues";
import type { CheckerValidationInput } from "../types";
import { normalizeExpectMatchers } from "../../expect/normalize";
import { validateContentRules, validateKeyValueExpect, validateValueMatcher } from "../../expect/validate-matcher";
import { issue, joinPath } from "../../schema/issues";
@@ -44,6 +45,8 @@ function validateDbExpect(target: Record<string, unknown>, path: string): Config
const issues: ConfigValidationIssue[] = [];
const expectPath = joinPath(path, "expect");
normalizeExpectMatchers(expect, ["durationMs", "rowCount"]);
if (expect["durationMs"] !== undefined) {
issues.push(...validateValueMatcher(expect["durationMs"], joinPath(expectPath, "durationMs"), targetName));
}