Files
SnowLuma/.pnpm-store/v11/files/e9/1ccb99464fdbcfb7e7e287f63c07fdda06b8d8983a61a7b334ed2549907d61c9b170a7392a69f1b00bef5dba013653a6b4d0f8896599a9d3534b91ef4c6ac0
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

35 lines
1.3 KiB
Plaintext

import { expect, test } from "vitest";
import * as z from "../../index.js";
// Verifies that the compile-mode setup file is wired up correctly. Vitest's `isolate: true` resets module state per test file, so the counter only sees this file's compile attempts. We construct + parse a few schemas here to produce signal, then assert the post-processor saw them.
//
// When run under the default project (without the setup file), the counter is absent and the test self-skips.
interface CompileStats {
attempts: number;
successes: number;
fallbacks: number;
}
test("compile-mode post-processor is installed and compiles supported schemas", () => {
const stats = (globalThis as any).__zodCompileStats as CompileStats | undefined;
if (!stats) return; // Default project — compile mode disabled.
const before = { ...stats };
// Trigger compile via a handful of supported shapes
const cases: Array<[z.ZodType, unknown]> = [
[z.string(), "hi"],
[z.number(), 1],
[z.object({ name: z.string() }), { name: "ok" }],
[z.array(z.number()), [1, 2, 3]],
[z.union([z.string(), z.number()]), "x"],
];
for (const [schema, input] of cases) {
schema.safeParse(input);
}
expect(stats.attempts - before.attempts).toBeGreaterThanOrEqual(cases.length);
expect(stats.successes - before.successes).toBeGreaterThanOrEqual(cases.length);
});