test(cli): reduce repeated startup and filesystem setup

This commit is contained in:
morluto
2026-10-08 04:03:24 +08:00
parent 9c3479ed95
commit d88d6c1897
19 changed files with 409 additions and 677 deletions
+22 -25
View File
@@ -5,31 +5,28 @@ import { readJsonFile } from "../../../src/application/JsonFiles.js";
import { parseCliJsonInput } from "../../../src/cliJsonInput.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
describe("JSON file UTF-8 byte integrity", () => {
it.each([0x80, 0xe9, 0xff])(
"rejects invalid UTF-8 byte %s through both file input boundaries",
async (invalidByte) => {
const root = await createTestTempDirectory("rea-json-utf8-");
const path = join(root, "input.json");
await writeFile(
path,
Buffer.concat([
Buffer.from('{"message":"'),
Buffer.from([invalidByte]),
Buffer.from('"}'),
]),
);
const fileInput = await readJsonFile(path);
const cliInput = await parseCliJsonInput(path, "compare_web_captures");
expect(fileInput).toMatchObject({
ok: false,
error: { reason: "invalid-json" },
});
expect(cliInput).toMatchObject({
ok: false,
error: { input_reason: "invalid-json" },
});
},
);
it("rejects invalid UTF-8 through both file input boundaries", async () => {
const root = await createTestTempDirectory("rea-json-utf8-");
const path = join(root, "input.json");
await writeFile(
path,
Buffer.concat([
Buffer.from('{"message":"'),
Buffer.from([0x80]),
Buffer.from('"}'),
]),
);
const fileInput = await readJsonFile(path);
const cliInput = await parseCliJsonInput(path, "compare_web_captures");
expect(fileInput).toMatchObject({
ok: false,
error: { reason: "invalid-json" },
});
expect(cliInput).toMatchObject({
ok: false,
error: { input_reason: "invalid-json" },
});
});
it("preserves a legitimate UTF-8 replacement character", async () => {
const root = await createTestTempDirectory("rea-json-utf8-control-");
const path = join(root, "input.json");