32 lines
1.4 KiB
TypeScript
32 lines
1.4 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { spawnSync } from "node:child_process";
|
|
import { dirname, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const scriptPath = resolve(here, "generate-spec.ts");
|
|
|
|
/**
|
|
* Smoke test: the script exits 0 in write mode, then `--check` mode confirms
|
|
* the file is in sync. We do not exercise the network or invoke the heavy
|
|
* Hono import here — these tests run alongside vitest's default include.
|
|
*
|
|
* This file deliberately lives under scripts/ so the package's vitest config
|
|
* (which only globs src/**) skips it during regular `pnpm test`. It is kept
|
|
* here as documentation + smoke for manual / CI invocation:
|
|
*
|
|
* pnpm exec vitest run packages/api-client-ts/scripts/generate-spec.test.ts
|
|
*/
|
|
describe("generate-spec script", () => {
|
|
it("compiles via tsx --check without throwing", () => {
|
|
// Just verify the script is importable / syntactically valid by running --help-equivalent.
|
|
// We invoke the file with --check, which only succeeds when openapi.json already exists;
|
|
// when it doesn't, the script exits with code 1 (missing) or 2 (drift). Either is a "ran" signal.
|
|
const result = spawnSync("pnpm", ["exec", "tsx", scriptPath, "--check"], {
|
|
cwd: resolve(here, ".."),
|
|
encoding: "utf8",
|
|
});
|
|
expect([0, 1, 2]).toContain(result.status ?? -1);
|
|
});
|
|
});
|