aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-05-23 00:40:41 -0700
committerGravatar GitHub <noreply@github.com> 2023-05-23 00:40:41 -0700
commit1e3476ee08a572b961833ca0f84ee651e643ef9b (patch)
tree84f42e3cc7bb21dd942de92bfbe94c48a078ed26
parent5b38c55c3db018a94505f61cd785f0dd40f442ac (diff)
downloadbun-1e3476ee08a572b961833ca0f84ee651e643ef9b.tar.gz
bun-1e3476ee08a572b961833ca0f84ee651e643ef9b.tar.zst
bun-1e3476ee08a572b961833ca0f84ee651e643ef9b.zip
[bun:test] Fix async/done-based test.todo (#3015)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
-rw-r--r--src/bun.js/test/jest.zig33
-rw-r--r--test/js/bun/test/test-test.test.ts10
-rw-r--r--test/js/bun/test/todo-test-fixture.js18
3 files changed, 51 insertions, 10 deletions
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(" <d>^<r> <red>this test is marked as todo but passes.<r> <d>Remove `.todo` or check that test is correct.<r>", .{});
- 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(" <d>^<r> <red>this test is marked as todo but passes.<r> <d>Remove `.todo` or check that test is correct.<r>", .{});
+ 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;
+ }
};
diff --git a/test/js/bun/test/test-test.test.ts b/test/js/bun/test/test-test.test.ts
index e7e8e7e34..5d45ef48e 100644
--- a/test/js/bun/test/test-test.test.ts
+++ b/test/js/bun/test/test-test.test.ts
@@ -2772,11 +2772,15 @@ it("test.todo", () => {
env: bunEnv,
cwd: realpathSync(dirname(path)),
});
-
const err = stderr!.toString();
expect(err).toContain("this test is marked as todo but passes");
- expect(err).toContain("2 todo");
- expect(err).toContain("1 fail");
+ expect(err).toContain("this async error is shown");
+ expect(err).toContain("this async error with an await is shown");
+ expect(err).toContain("this error is shown");
+ expect(err).toContain("4 todo");
+ expect(err).toContain("0 pass");
+ expect(err).toContain("3 fail");
+ expect(exitCode).toBe(1);
});
it("test.todo doesnt cause exit code 1", () => {
diff --git a/test/js/bun/test/todo-test-fixture.js b/test/js/bun/test/todo-test-fixture.js
index 9bb2fdfca..e5768700d 100644
--- a/test/js/bun/test/todo-test-fixture.js
+++ b/test/js/bun/test/todo-test-fixture.js
@@ -1,4 +1,4 @@
-import { test } from "bun:test";
+import { test, describe } from "bun:test";
test.todo("todo 1");
test.todo("todo 2", () => {
@@ -7,3 +7,19 @@ test.todo("todo 2", () => {
test.todo("todo 3", () => {
// passes
});
+
+describe("async", () => {
+ test.todo("todo with error", async () => {
+ throw new Error("this async error is shown");
+ });
+
+ test.todo("todo with error and await", async () => {
+ await 1;
+ throw new Error("this async error with an await is shown");
+ });
+
+ test.todo("passing todo", async () => {});
+ test.todo("passing todo with an await", async () => {
+ await 1;
+ });
+});