aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-10-01 01:46:34 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-10-01 01:46:34 -0700
commitc57b32fa0cdeaf7f1490bd6af9c5248a92c71ea0 (patch)
tree4d8c21838025da446f9f79326dd54e911f9c15a1
parent43c22b44118695407d87cc102be067eceee786fc (diff)
downloadbun-c57b32fa0cdeaf7f1490bd6af9c5248a92c71ea0.tar.gz
bun-c57b32fa0cdeaf7f1490bd6af9c5248a92c71ea0.tar.zst
bun-c57b32fa0cdeaf7f1490bd6af9c5248a92c71ea0.zip
[bun:test] When there are lots of tests, print the failures at the bottom so you can see them easier
-rw-r--r--src/cli/test_command.zig26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig
index a70c4c4e0..d8d243983 100644
--- a/src/cli/test_command.zig
+++ b/src/cli/test_command.zig
@@ -51,6 +51,8 @@ pub const CommandLineReporter = struct {
summary: Summary = Summary{},
prev_file: u64 = 0,
+ failures_to_repeat_buf: std.ArrayListUnmanaged(u8) = .{},
+
pub const Summary = struct {
pass: u32 = 0,
expectations: u32 = 0,
@@ -135,18 +137,23 @@ pub const CommandLineReporter = struct {
}
pub fn handleTestFail(cb: *TestRunner.Callback, id: Test.ID, _: string, label: string, expectations: u32, parent: ?*Jest.DescribeScope) void {
var writer_: std.fs.File.Writer = Output.errorWriter();
- var buffered_writer = std.io.bufferedWriter(writer_);
- var writer = buffered_writer.writer();
- defer buffered_writer.flush() catch unreachable;
-
var this: *CommandLineReporter = @fieldParentPtr(CommandLineReporter, "callback", cb);
+ // when the tests fail, we want to repeat the failures at the end
+ // so that you can see them better when there are lots of tests that ran
+ const initial_length = this.failures_to_repeat_buf.items.len;
+ var writer = this.failures_to_repeat_buf.writer(bun.default_allocator);
+
if (Output.enable_ansi_colors_stderr)
writer.print(comptime Output.prettyFmt("<r><red>✗<r>", true), .{}) catch unreachable
else
writer.print(comptime Output.prettyFmt("<r><red>✗<r>", false), .{}) catch unreachable;
printTestLine(label, parent, writer);
+
+ writer_.writeAll(this.failures_to_repeat_buf.items[initial_length..]) catch unreachable;
+ Output.flush();
+
// this.updateDots();
this.summary.fail += 1;
this.summary.expectations += expectations;
@@ -340,7 +347,15 @@ pub const TestCommand = struct {
runAllTests(reporter, vm, test_files, ctx.allocator);
}
- Output.pretty("\n", .{});
+ if (reporter.summary.pass > 20 and reporter.summary.fail > 0) {
+ Output.prettyError("\n<r><d>{d} tests failed<r>:\n", .{reporter.summary.fail});
+
+ Output.flush();
+
+ var error_writer = Output.errorWriter();
+ error_writer.writeAll(reporter.failures_to_repeat_buf.items) catch unreachable;
+ }
+
Output.flush();
Output.prettyError("\n", .{});
@@ -374,7 +389,6 @@ pub const TestCommand = struct {
});
Output.printStartEnd(ctx.start_time, std.time.nanoTimestamp());
Output.prettyError("\n", .{});
-
Output.flush();
if (reporter.summary.fail > 0) {