mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 12:29:07 +00:00
Clearer error handling for this test
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user