Clearer error handling for this test

This commit is contained in:
Jarred Sumner
2024-03-08 04:31:36 -08:00
parent 05d3d3ecf6
commit cd72100e90

View File

@@ -5,14 +5,33 @@ import { join } from "node:path";
it("should log to console correctly", async () => {
const { stdout, stderr, exited } = spawn({
cmd: [bunExe(), join(import.meta.dir, "console-log.js")],
stdin: null,
stdin: "inherit",
stdout: "pipe",
stderr: "pipe",
env: bunEnv,
});
expect(await exited).toBe(0);
expect((await new Response(stderr).text()).replaceAll("\r\n", "\n")).toBe("uh oh\n");
expect((await new Response(stdout).text()).replaceAll("\r\n", "\n")).toBe(
(await new Response(file(join(import.meta.dir, "console-log.expected.txt"))).text()).replaceAll("\r\n", "\n"),
const exitCode = await exited;
const err = (await new Response(stderr).text()).replaceAll("\r\n", "\n");
const out = (await new Response(stdout).text()).replaceAll("\r\n", "\n");
const expected = (await new Response(file(join(import.meta.dir, "console-log.expected.txt"))).text()).replaceAll(
"\r\n",
"\n",
);
const errMatch = err === "uh oh\n";
const outmatch = out === expected;
if (errMatch && outmatch && exitCode === 0) {
expect().pass();
return;
}
console.error(err);
console.log("Length of output:", out.length);
console.log("Length of expected:", expected.length);
console.log("Exit code:", exitCode);
expect(out).toBe(expected);
expect(err).toBe("uh oh\n");
expect(exitCode).toBe(0);
});