Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/bun.js/test/Collection.zig
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ pub fn step(buntest_strong: bun_test.BunTestPtr, globalThis: *jsc.JSGlobalObject
this.active_scope = new_scope;
group.log("collection:runOne set scope to {s}", .{this.active_scope.base.name orelse "undefined"});

BunTest.runTestCallback(buntest_strong, globalThis, callback.get(), false, .{
.collection = .{
.active_scope = previous_scope,
},
}, .epoch);
if (BunTest.runTestCallback(buntest_strong, globalThis, callback.get(), false, .{
.collection = .{ .active_scope = previous_scope },
}, .epoch)) |cfg_data| {
// the result is available immediately; queue
buntest.addResult(cfg_data);
}

return .{ .waiting = .{} };
}
Expand Down
6 changes: 5 additions & 1 deletion src/bun.js/test/Execution.zig
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,11 @@ fn stepSequenceOne(buntest_strong: bun_test.BunTestPtr, globalThis: *jsc.JSGloba
};
groupLog.log("runSequence queued callback: {}", .{callback_data});

BunTest.runTestCallback(buntest_strong, globalThis, cb.get(), next_item.has_done_parameter, callback_data, next_item.timespec);
if (BunTest.runTestCallback(buntest_strong, globalThis, cb.get(), next_item.has_done_parameter, callback_data, next_item.timespec) != null) {
// the result is available immediately; advance the sequence and run again.
this.advanceSequence(sequence, group);
return null; // run again
}
return .{ .execute = .{ .timeout = next_item.timespec } };
} else {
switch (next_item.base.mode) {
Expand Down
11 changes: 5 additions & 6 deletions src/bun.js/test/bun_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,8 @@ pub const BunTest = struct {
}
}

/// if sync, the result is queued and appended later
pub fn runTestCallback(this_strong: BunTestPtr, globalThis: *jsc.JSGlobalObject, cfg_callback: jsc.JSValue, cfg_done_parameter: bool, cfg_data: BunTest.RefDataValue, timeout: bun.timespec) void {
/// if sync, the result is returned. if async, null is returned.
pub fn runTestCallback(this_strong: BunTestPtr, globalThis: *jsc.JSGlobalObject, cfg_callback: jsc.JSValue, cfg_done_parameter: bool, cfg_data: BunTest.RefDataValue, timeout: bun.timespec) ?RefDataValue {
group.begin(@src());
defer group.end();
const this = this_strong.get();
Expand Down Expand Up @@ -586,20 +586,19 @@ pub const BunTest = struct {
const this_ref: *RefData = if (dcb_ref) |dcb_ref_value| dcb_ref_value.dupe() else ref(this_strong, cfg_data);
result.?.then(globalThis, this_ref, bunTestThen, bunTestCatch);
drain(globalThis);
return;
return null;
}

if (dcb_ref) |_| {
// completed asynchronously
group.log("callTestCallback -> wait for done callback", .{});
drain(globalThis);
return;
return null;
}

group.log("callTestCallback -> sync", .{});
drain(globalThis);
this.addResult(cfg_data);
return;
return cfg_data;
}

/// called from the uncaught exception handler, or if a test callback rejects or throws an error
Expand Down
15 changes: 15 additions & 0 deletions test/js/bun/test/concurrent_immediate.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
beforeEach(() => {
console.log("beforeEach");
});
afterEach(() => {
console.log("afterEach");
});
test.concurrent("test 1", () => {
console.log("start test 1");
});
test.concurrent("test 2", () => {
console.log("start test 2");
});
test.concurrent("test 3", () => {
console.log("start test 3");
});
59 changes: 59 additions & 0 deletions test/js/bun/test/concurrent_immediate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { expect, test } from "bun:test";
import { bunEnv, bunExe, normalizeBunSnapshot } from "harness";

test("describe/test", async () => {
const result = await Bun.spawn({
cmd: [bunExe(), "test", import.meta.dir + "/concurrent_immediate.fixture.ts"],
stdout: "pipe",
stderr: "pipe",
env: bunEnv,
});
const exitCode = await result.exited;
const stdout = await result.stdout.text();
const stderr = await result.stderr.text();
expect(exitCode).toBe(0);
expect(normalizeBunSnapshot(stdout)).toMatchInlineSnapshot(`
"bun test <version> (<revision>)
beforeEach
start test 1
afterEach
beforeEach
start test 2
afterEach
beforeEach
start test 3
afterEach"
`);
});

test("describe/test", async () => {
const result = await Bun.spawn({
cmd: [bunExe(), "test", import.meta.dir + "/concurrent_immediate_error.fixture.ts"],
stdout: "pipe",
stderr: "pipe",
env: bunEnv,
});
const exitCode = await result.exited;
const stdout = await result.stdout.text();
const stderr = await result.stderr.text();
expect(exitCode).toBe(1);
expect(normalizeBunSnapshot(stderr)).toMatchInlineSnapshot(`
"test/js/bun/test/concurrent_immediate_error.fixture.ts:
(pass) test 1
6 | });
7 | test.concurrent("test 1", () => {
8 | console.log("start test 1");
9 | });
10 | test.concurrent("test 2", () => {
11 | throw new Error("test 2 error");
^
error: test 2 error
at <anonymous> (file:NN:NN)
(fail) test 2
(pass) test 3

2 pass
1 fail
Ran 3 tests across 1 file."
`);
});
15 changes: 15 additions & 0 deletions test/js/bun/test/concurrent_immediate_error.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
beforeEach(() => {
console.log("beforeEach");
});
afterEach(() => {
console.log("afterEach");
});
test.concurrent("test 1", () => {
console.log("start test 1");
});
test.concurrent("test 2", () => {
throw new Error("test 2 error");
});
test.concurrent("test 3", () => {
console.log("start test 3");
});