aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Alex Lam S.L <alexlamsl@gmail.com> 2023-07-18 14:54:24 +0300
committerGravatar GitHub <noreply@github.com> 2023-07-18 04:54:24 -0700
commit179035702156bd7fa9f17bc7db1be2000219f787 (patch)
tree05873629066ba00f2c7fcf2c0fc9b9c1a5d15c12 /src
parent105919d7ae9681d9be18401b032128bf826a39d3 (diff)
downloadbun-179035702156bd7fa9f17bc7db1be2000219f787.tar.gz
bun-179035702156bd7fa9f17bc7db1be2000219f787.tar.zst
bun-179035702156bd7fa9f17bc7db1be2000219f787.zip
[jest] execute lifecycle hooks on empty blocks (#3663)
fixes #3494
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/test/jest.zig34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig
index 429b79bcc..39116054e 100644
--- a/src/bun.js/test/jest.zig
+++ b/src/bun.js/test/jest.zig
@@ -777,7 +777,9 @@ pub const DescribeScope = struct {
tag: Tag = .pass,
pub fn isAllSkipped(this: *const DescribeScope) bool {
- return this.is_skip or @as(usize, this.skip_count) >= this.tests.items.len;
+ if (this.is_skip) return true;
+ const total = this.tests.items.len;
+ return total > 0 and @as(usize, this.skip_count) >= total;
}
pub fn push(new: *DescribeScope) void {
@@ -1080,13 +1082,8 @@ pub const DescribeScope = struct {
const end = @as(TestRunner.Test.ID, @truncate(tests.len));
this.pending_tests = std.DynamicBitSetUnmanaged.initFull(allocator, end) catch unreachable;
- if (end == 0) {
- // TODO: print the describe label when there are no tests
- return;
- }
-
// Step 2. Update the runner with the count of how many tests we have for this block
- this.test_id_start = Jest.runner.?.addTestCount(end);
+ if (end > 0) this.test_id_start = Jest.runner.?.addTestCount(end);
const source: logger.Source = Jest.runner.?.files.items(.source)[file];
@@ -1102,6 +1099,19 @@ pub const DescribeScope = struct {
this.pending_tests.deinit(allocator);
return;
}
+ if (end == 0) {
+ var runner = allocator.create(TestRunnerTask) catch unreachable;
+ runner.* = .{
+ .test_id = std.math.maxInt(TestRunner.Test.ID),
+ .describe = this,
+ .globalThis = globalObject,
+ .source_file_path = source.path.text,
+ };
+ runner.ref.ref(globalObject.bunVM());
+
+ Jest.runner.?.enqueue(runner);
+ return;
+ }
}
while (i < end) : (i += 1) {
@@ -1121,7 +1131,7 @@ pub const DescribeScope = struct {
pub fn onTestComplete(this: *DescribeScope, globalThis: *JSC.JSGlobalObject, test_id: TestRunner.Test.ID, skipped: bool) void {
// invalidate it
this.current_test_id = std.math.maxInt(TestRunner.Test.ID);
- this.pending_tests.unset(test_id);
+ if (test_id != std.math.maxInt(TestRunner.Test.ID)) this.pending_tests.unset(test_id);
if (!skipped) {
if (this.runCallback(globalThis, .afterEach)) |err| {
@@ -1221,6 +1231,14 @@ pub const TestRunnerTask = struct {
jsc_vm.last_reported_error_for_dedupe = .zero;
const test_id = this.test_id;
+
+ if (test_id == std.math.maxInt(TestRunner.Test.ID)) {
+ describe.onTestComplete(globalThis, test_id, true);
+ Jest.runner.?.runNextTest();
+ this.deinit();
+ return false;
+ }
+
var test_: TestScope = this.describe.tests.items[test_id];
describe.current_test_id = test_id;