mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Ensure test with errors before JS execution exit with code 1 (#15321)
This commit is contained in:
@@ -1599,13 +1599,13 @@ pub const TestCommand = struct {
|
||||
|
||||
if (files.len > 1) {
|
||||
for (files[0 .. files.len - 1]) |file_name| {
|
||||
TestCommand.run(reporter, vm, file_name.slice(), allocator, false) catch {};
|
||||
TestCommand.run(reporter, vm, file_name.slice(), allocator, false) catch |err| handleTopLevelTestErrorBeforeJavaScriptStart(err);
|
||||
reporter.jest.default_timeout_override = std.math.maxInt(u32);
|
||||
Global.mimalloc_cleanup(false);
|
||||
}
|
||||
}
|
||||
|
||||
TestCommand.run(reporter, vm, files[files.len - 1].slice(), allocator, true) catch {};
|
||||
TestCommand.run(reporter, vm, files[files.len - 1].slice(), allocator, true) catch |err| handleTopLevelTestErrorBeforeJavaScriptStart(err);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1769,3 +1769,12 @@ pub const TestCommand = struct {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fn handleTopLevelTestErrorBeforeJavaScriptStart(err: anyerror) noreturn {
|
||||
if (comptime Environment.isDebug) {
|
||||
if (err != error.ModuleNotFound) {
|
||||
Output.debugWarn("Unhandled error: {s}\n", .{@errorName(err)});
|
||||
}
|
||||
}
|
||||
Global.exit(1);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,16 @@ import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
|
||||
describe("bun test", () => {
|
||||
test("running a non-existent absolute file path is a 1 exit code", () => {
|
||||
const spawn = Bun.spawnSync({
|
||||
cmd: [bunExe(), "test", join(import.meta.dirname, "non-existent.test.ts")],
|
||||
env: bunEnv,
|
||||
stdin: "ignore",
|
||||
stdout: "inherit",
|
||||
stderr: "inherit",
|
||||
});
|
||||
expect(spawn.exitCode).toBe(1);
|
||||
});
|
||||
test("can provide no arguments", () => {
|
||||
const stderr = runTest({
|
||||
args: [],
|
||||
|
||||
Reference in New Issue
Block a user