From 1e3476ee08a572b961833ca0f84ee651e643ef9b Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Tue, 23 May 2023 00:40:41 -0700 Subject: [bun:test] Fix async/done-based test.todo (#3015) Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> --- src/bun.js/test/jest.zig | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src/bun.js') diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index 10cd581ad..8b06caa0f 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -546,6 +546,7 @@ pub const TestRunner = struct { fail, skip, todo, + fail_because_todo_passed, }; }; }; @@ -3551,11 +3552,6 @@ pub const TestScope = struct { return .{ .fail = active_test_expectation_counter.actual }; } - if (this.is_todo) { - Output.prettyErrorln(" ^ this test is marked as todo but passes. Remove `.todo` or check that test is correct.", .{}); - return .{ .fail = active_test_expectation_counter.actual }; - } - return .{ .pass = active_test_expectation_counter.actual }; } @@ -4208,7 +4204,7 @@ pub const TestRunnerTask = struct { } fn processTestResult(this: *TestRunnerTask, globalThis: *JSC.JSGlobalObject, result: Result, test_: TestScope, test_id: u32, describe: *DescribeScope) void { - switch (result) { + switch (result.forceTODO(test_.is_todo)) { .pass => |count| Jest.runner.?.reportPass( test_id, this.source_file_path, @@ -4233,6 +4229,20 @@ pub const TestRunnerTask = struct { ), .skip => Jest.runner.?.reportSkip(test_id, this.source_file_path, test_.label, describe), .todo => Jest.runner.?.reportTodo(test_id, this.source_file_path, test_.label, describe), + .fail_because_todo_passed => |count| { + Output.prettyErrorln(" ^ this test is marked as todo but passes. Remove `.todo` or check that test is correct.", .{}); + Jest.runner.?.reportFailure( + test_id, + this.source_file_path, + test_.label, + count, + if (test_elapsed_timer) |timer| + timer.read() + else + 0, + describe, + ); + }, .pending => @panic("Unexpected pending test"), } describe.onTestComplete(globalThis, test_id, result == .skip); @@ -4268,4 +4278,15 @@ pub const Result = union(TestRunner.Test.Status) { pending: void, skip: void, todo: void, + fail_because_todo_passed: u32, + + pub fn forceTODO(this: Result, is_todo: bool) Result { + if (is_todo and this == .pass) + return .{ .fail_because_todo_passed = this.pass }; + + if (is_todo and this == .fail) { + return .{ .todo = {} }; + } + return this; + } }; -- cgit v1.2.3