Files
Netcatty/scripts/run-tests.test.mjs
T
陈大猫 ad3d0cfeda refactor: streamline codebase, unify duplicated modules, and consolidate test suite (#4307)
* refactor: streamline codebase, unify duplicated modules, and consolidate tests

* fix(test): batch discovered test files into Windows-safe command lines
2026-11-23 11:00:14 +08:00

37 lines
1.4 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { batchTestFiles } from "./run-tests.mjs";
test("batchTestFiles splits large test suites safely under the Windows 32,767-char CreateProcessW limit", () => {
const files = Array.from(
{ length: 1400 },
(_, i) => `components/settings/tabs/ai/verySpecificFeatureModule${String(i).padStart(4, "0")}.test.tsx`,
);
const baseArgsLength = 200;
const batches = batchTestFiles(files, baseArgsLength, 20_000);
assert.ok(batches.length > 1, "expected multiple batches for 1,400 paths");
assert.deepEqual(batches.flat(), files, "all files must be preserved in order");
for (const batch of batches) {
const estimatedCmdLen =
baseArgsLength + batch.reduce((sum, f) => sum + f.length + 3, 0);
assert.ok(
estimatedCmdLen <= 20_000,
`batch exceeded budget: ${estimatedCmdLen}`,
);
}
});
test("batchTestFiles keeps a single batch when total command length fits within budget", () => {
const files = ["a.test.ts", "b.test.ts", "c.test.ts"];
const batches = batchTestFiles(files, 100, 20_000);
assert.deepEqual(batches, [files]);
});
test("batchTestFiles never drops or loops on a single path longer than the remaining budget", () => {
const longFile = `${"a".repeat(200)}.test.ts`;
const batches = batchTestFiles([longFile, "short.test.ts"], 150, 200);
assert.deepEqual(batches, [[longFile], ["short.test.ts"]]);
});