Files
bun.sh/test/js/bun/util/reportError.test.ts
2025-04-23 23:21:22 -07:00

68 lines
1.2 KiB
TypeScript

import { spawnSync } from "bun";
import { expect, test } from "bun:test";
import { bunEnv, bunExe } from "harness";
import { join } from "path";
test("reportError", () => {
const cwd = import.meta.dir;
const { stderr } = spawnSync({
cmd: [bunExe(), join(import.meta.dir, "reportError.ts")],
cwd,
env: {
...bunEnv,
// this is default enabled in debug, affects output.
BUN_JSC_showPrivateScriptsInStackTraces: "0",
},
});
let output = stderr.toString().replaceAll(cwd, "").replaceAll("\\", "/");
// remove bun version from output
output = output.split("\n").slice(0, -2).join("\n");
expect(output.replaceAll("\\", "/").replaceAll("/reportError.ts", "[file]")).toMatchInlineSnapshot(
`
"1 | reportError(new Error("reportError Test!"));
^
error: reportError Test!
at [file]:1:13
at loadAndEvaluateModule (2:1)
error: true
true
error: false
false
error: null
null
error: 123
123
error: Infinity
Infinity
error: NaN
NaN
error: NaN
NaN
error
error
Uint8Array(1) [ 0 ]
error
Uint8Array(0) []
error
ArrayBuffer(0) []
error
ArrayBuffer(1) [ 0 ]
error: string
string
error
[]
error
[ 123, null ]
error
{}
error
[
{}
]
"
`,
);
});