diff options
author | 2023-05-23 22:33:32 -0700 | |
---|---|---|
committer | 2023-05-23 22:33:32 -0700 | |
commit | c3d402ce47e273b60e3a37164a6ba2be6e1eee5d (patch) | |
tree | 5e780162de9c723aba5126fd3276df51d9048c18 /src/cli.zig | |
parent | d9bdfcf1317f0ea14453cb2023daa07830d446d8 (diff) | |
download | bun-c3d402ce47e273b60e3a37164a6ba2be6e1eee5d.tar.gz bun-c3d402ce47e273b60e3a37164a6ba2be6e1eee5d.tar.zst bun-c3d402ce47e273b60e3a37164a6ba2be6e1eee5d.zip |
Implement `bun test --timeout` (#3040)
You can change the default per-test timeout in `bun test`:
> bun test --timeout 10
The default timeout is 5000.
Diffstat (limited to 'src/cli.zig')
-rw-r--r-- | src/cli.zig | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/cli.zig b/src/cli.zig index be8f9fe76..606e0a3cc 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -211,6 +211,7 @@ pub const Arguments = struct { // TODO: update test completions const test_only_params = [_]ParamType{ + clap.parseParam("--timeout <NUMBER> Set the per-test timeout in milliseconds, default is 5000.") catch unreachable, clap.parseParam("--update-snapshots Update snapshot files") catch unreachable, clap.parseParam("--rerun-each <NUMBER> Re-run each test file <NUMBER> times, helps catch certain bugs") catch unreachable, }; @@ -371,6 +372,14 @@ pub const Arguments = struct { } if (cmd == .TestCommand) { + if (args.option("--timeout")) |timeout_ms| { + if (timeout_ms.len > 0) { + ctx.test_options.default_timeout_ms = std.fmt.parseInt(u32, timeout_ms, 10) catch { + Output.prettyErrorln("<r><red>error<r>: Invalid timeout: \"{s}\"", .{timeout_ms}); + Global.exit(1); + }; + } + } ctx.test_options.update_snapshots = args.flag("--update-snapshots"); if (args.option("--rerun-each")) |repeat_count| { if (repeat_count.len > 0) { @@ -904,6 +913,7 @@ pub const Command = struct { }; pub const TestOptions = struct { + default_timeout_ms: u32 = 5 * std.time.ms_per_s, update_snapshots: bool = false, repeat_count: u32 = 0, }; |