mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
141 lines
4.9 KiB
TypeScript
141 lines
4.9 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { bunEnv, bunExe } from "harness";
|
|
import path from "path";
|
|
|
|
test("verify we print error messages passed to done callbacks", () => {
|
|
const { stdout, stderr } = Bun.spawnSync({
|
|
cmd: [bunExe(), "test", path.resolve(import.meta.dir, "test-error-done-callback-fixture.ts")],
|
|
env: { ...bunEnv, BUN_JSC_showPrivateScriptsInStackTraces: "0" },
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
let stdoutStr = stdout
|
|
.toString()
|
|
.replaceAll("\\", "/")
|
|
.replaceAll(import.meta.dir.replaceAll("\\", "/"), "<dir>")
|
|
.replace(/\d+(\.\d+)?ms/g, "<time>ms")
|
|
.replace(/\d+(\.\d+)?s/g, "<time>s")
|
|
.replaceAll(Bun.version_with_sha, "<version>")
|
|
.replaceAll("[<time>s]", "")
|
|
.replaceAll("[<time>ms]", "")
|
|
.split("\n")
|
|
.map(line => line.trim())
|
|
.join("\n");
|
|
let stderrStr = stderr
|
|
.toString()
|
|
.replaceAll("\\", "/")
|
|
.replaceAll(import.meta.dir.replaceAll("\\", "/"), "<dir>")
|
|
.replace(/\d+(\.\d+)?ms/g, "<time>ms")
|
|
.replace(/\d+(\.\d+)?s/g, "<time>s")
|
|
.replaceAll(Bun.version_with_sha, "<version>")
|
|
.replaceAll("[<time>s]", "")
|
|
.replaceAll("[<time>ms]", "")
|
|
.split("\n")
|
|
.map(line => line.trim())
|
|
.join("\n");
|
|
|
|
expect(stdoutStr).toMatchInlineSnapshot(`
|
|
"bun test <version>
|
|
"
|
|
`);
|
|
expect(stderrStr).toMatchInlineSnapshot(`
|
|
"
|
|
test/js/bun/test/test-error-done-callback-fixture.ts:
|
|
22 | 105,
|
|
23 | 115,
|
|
24 | );
|
|
25 |
|
|
26 | test("error done callback (sync)", done => {
|
|
27 | done(new Error(msg + "(sync)"));
|
|
^
|
|
error: you should see this(sync)
|
|
at <anonymous> (<dir>/test-error-done-callback-fixture.ts:27:8)
|
|
(fail) error done callback (sync)
|
|
27 | done(new Error(msg + "(sync)"));
|
|
28 | });
|
|
29 |
|
|
30 | test("error done callback (async with await)", async done => {
|
|
31 | await 1;
|
|
32 | done(new Error(msg + "(async with await)"));
|
|
^
|
|
error: you should see this(async with await)
|
|
at <anonymous> (<dir>/test-error-done-callback-fixture.ts:32:8)
|
|
(fail) error done callback (async with await)
|
|
32 | done(new Error(msg + "(async with await)"));
|
|
33 | });
|
|
34 |
|
|
35 | test("error done callback (async with Bun.sleep)", async done => {
|
|
36 | await Bun.sleep(0);
|
|
37 | done(new Error(msg + "(async with Bun.sleep)"));
|
|
^
|
|
error: you should see this(async with Bun.sleep)
|
|
at <anonymous> (<dir>/test-error-done-callback-fixture.ts:37:8)
|
|
(fail) error done callback (async with Bun.sleep)
|
|
37 | done(new Error(msg + "(async with Bun.sleep)"));
|
|
38 | });
|
|
39 |
|
|
40 | test("error done callback (async)", done => {
|
|
41 | Promise.resolve().then(() => {
|
|
42 | done(new Error(msg + "(async)"));
|
|
^
|
|
error: you should see this(async)
|
|
at <anonymous> (<dir>/test-error-done-callback-fixture.ts:42:10)
|
|
(fail) error done callback (async)
|
|
43 | });
|
|
44 | });
|
|
45 |
|
|
46 | test("error done callback (async, setTimeout)", done => {
|
|
47 | setTimeout(() => {
|
|
48 | done(new Error(msg + "(async, setTimeout)"));
|
|
^
|
|
error: you should see this(async, setTimeout)
|
|
at <anonymous> (<dir>/test-error-done-callback-fixture.ts:48:10)
|
|
(fail) error done callback (async, setTimeout)
|
|
49 | }, 0);
|
|
50 | });
|
|
51 |
|
|
52 | test("error done callback (async, setImmediate)", done => {
|
|
53 | setImmediate(() => {
|
|
54 | done(new Error(msg + "(async, setImmediate)"));
|
|
^
|
|
error: you should see this(async, setImmediate)
|
|
at <anonymous> (<dir>/test-error-done-callback-fixture.ts:54:10)
|
|
(fail) error done callback (async, setImmediate)
|
|
55 | });
|
|
56 | });
|
|
57 |
|
|
58 | test("error done callback (async, nextTick)", done => {
|
|
59 | process.nextTick(() => {
|
|
60 | done(new Error(msg + "(async, nextTick)"));
|
|
^
|
|
error: you should see this(async, nextTick)
|
|
at <anonymous> (<dir>/test-error-done-callback-fixture.ts:60:10)
|
|
(fail) error done callback (async, nextTick)
|
|
62 | });
|
|
63 |
|
|
64 | test("error done callback (async, setTimeout, Promise.resolve)", done => {
|
|
65 | setTimeout(() => {
|
|
66 | Promise.resolve().then(() => {
|
|
67 | done(new Error(msg + "(async, setTimeout, Promise.resolve)"));
|
|
^
|
|
error: you should see this(async, setTimeout, Promise.resolve)
|
|
at <anonymous> (<dir>/test-error-done-callback-fixture.ts:67:12)
|
|
(fail) error done callback (async, setTimeout, Promise.resolve)
|
|
70 | });
|
|
71 |
|
|
72 | test("error done callback (async, setImmediate, Promise.resolve)", done => {
|
|
73 | setImmediate(() => {
|
|
74 | Promise.resolve().then(() => {
|
|
75 | done(new Error(msg + "(async, setImmediate, Promise.resolve)"));
|
|
^
|
|
error: you should see this(async, setImmediate, Promise.resolve)
|
|
at <anonymous> (<dir>/test-error-done-callback-fixture.ts:75:12)
|
|
(fail) error done callback (async, setImmediate, Promise.resolve)
|
|
|
|
0 pass
|
|
9 fail
|
|
Ran 9 tests across 1 file.
|
|
"
|
|
`);
|
|
});
|