test: parallelize web fetch CLI checks (#122811)

Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Peter Steinberger
2026-08-12 14:11:49 -07:00
committed by GitHub
parent 5fda9d09f0
commit 27c6b97d6a
+32 -16
View File
@@ -1,24 +1,40 @@
// Bench Web Fetch tests cover the offline benchmark CLI contract.
import { spawnSync } from "node:child_process";
import { spawn } from "node:child_process";
import { describe, expect, it } from "vitest";
const SCRIPT_PATH = "scripts/bench-web-fetch.ts";
function runBenchWebFetch(...args: string[]) {
return spawnSync(process.execPath, ["--import", "tsx", SCRIPT_PATH, ...args], {
cwd: process.cwd(),
encoding: "utf8",
env: {
...process.env,
FIRECRAWL_API_KEY: "test-firecrawl-key-that-should-be-ignored",
NODE_NO_WARNINGS: "1",
return new Promise<{ status: number | null; stderr: string; stdout: string }>(
(resolve, reject) => {
const child = spawn(process.execPath, ["--import", "tsx", SCRIPT_PATH, ...args], {
cwd: process.cwd(),
env: {
...process.env,
FIRECRAWL_API_KEY: "test-firecrawl-key-that-should-be-ignored",
NODE_NO_WARNINGS: "1",
},
stdio: ["ignore", "pipe", "pipe"],
});
let stdout = "";
let stderr = "";
child.stdout.setEncoding("utf8");
child.stderr.setEncoding("utf8");
child.stdout.on("data", (chunk: string) => {
stdout += chunk;
});
child.stderr.on("data", (chunk: string) => {
stderr += chunk;
});
child.once("error", reject);
child.once("close", (status) => resolve({ status, stderr, stdout }));
},
});
);
}
describe("web fetch benchmark script", () => {
it("accepts the package-manager separator documented for pnpm scripts", () => {
const result = runBenchWebFetch(
it.concurrent("accepts the package-manager separator documented for pnpm scripts", async () => {
const result = await runBenchWebFetch(
"--",
"--case",
"tool-create",
@@ -42,8 +58,8 @@ describe("web fetch benchmark script", () => {
expect(report.cases[0]?.samplesMs).toHaveLength(1);
});
it("rejects duplicate singular flags without a stack trace", () => {
const result = runBenchWebFetch("--runs", "1", "--runs", "2");
it.concurrent("rejects duplicate singular flags without a stack trace", async () => {
const result = await runBenchWebFetch("--runs", "1", "--runs", "2");
expect(result.status).toBe(2);
expect(result.stdout).toBe("");
@@ -51,13 +67,13 @@ describe("web fetch benchmark script", () => {
expect(result.stderr).not.toContain("\n at ");
});
it.each([
it.concurrent.each([
["--runs", "1e3", "--runs must be a positive integer"],
["--warmup", "1e3", "--warmup must be a non-negative integer"],
["--runs", "9007199254740993", "--runs must be a positive integer"],
["--warmup", "9007199254740993", "--warmup must be a non-negative integer"],
])("rejects invalid benchmark count %s %s", (flag, value, expectedError) => {
const result = runBenchWebFetch(flag, value);
])("rejects invalid benchmark count %s %s", async (flag, value, expectedError) => {
const result = await runBenchWebFetch(flag, value);
expect(result.status).toBe(2);
expect(result.stdout).toBe("");