aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/test/jest.zig
diff options
context:
space:
mode:
authorGravatar Igor Shapiro <shapigor@gmail.com> 2023-10-17 01:33:02 +0200
committerGravatar GitHub <noreply@github.com> 2023-10-16 16:33:02 -0700
commit01e04e3341e8bf19f1b08cb2238663b2fdb48c54 (patch)
tree00f983d80bcde4b1c2a52df33891a251a5965328 /src/bun.js/test/jest.zig
parent0853e19f53bfeb636971423a62214e0519b10729 (diff)
downloadbun-01e04e3341e8bf19f1b08cb2238663b2fdb48c54.tar.gz
bun-01e04e3341e8bf19f1b08cb2238663b2fdb48c54.tar.zst
bun-01e04e3341e8bf19f1b08cb2238663b2fdb48c54.zip
fix(test): when tests run with --only the nested describe blocks `.on… (#5616)
Diffstat (limited to 'src/bun.js/test/jest.zig')
-rw-r--r--src/bun.js/test/jest.zig35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig
index 3617d5961..283f369ff 100644
--- a/src/bun.js/test/jest.zig
+++ b/src/bun.js/test/jest.zig
@@ -793,14 +793,25 @@ pub const DescribeScope = struct {
current_test_id: TestRunner.Test.ID = 0,
value: JSValue = .zero,
done: bool = false,
- is_skip: bool = false,
skip_count: u32 = 0,
tag: Tag = .pass,
- pub fn isAllSkipped(this: *const DescribeScope) bool {
- if (this.is_skip) return true;
- const total = this.tests.items.len;
- return total > 0 and @as(usize, this.skip_count) >= total;
+ fn isWithinOnlyScope(this: *const DescribeScope) bool {
+ if (this.tag == .only) return true;
+ if (this.parent != null) return this.parent.?.isWithinOnlyScope();
+ return false;
+ }
+
+ fn isWithinSkipScope(this: *const DescribeScope) bool {
+ if (this.tag == .skip) return true;
+ if (this.parent != null) return this.parent.?.isWithinSkipScope();
+ return false;
+ }
+
+ pub fn shouldEvaluateScope(this: *const DescribeScope) bool {
+ if (this.isWithinSkipScope()) return false;
+ if (Jest.runner.?.only and this.isWithinOnlyScope()) return true;
+ return true;
}
pub fn push(new: *DescribeScope) void {
@@ -1114,7 +1125,7 @@ pub const DescribeScope = struct {
var i: TestRunner.Test.ID = 0;
- if (!this.isAllSkipped()) {
+ if (this.shouldEvaluateScope()) {
if (this.runCallback(globalObject, .beforeAll)) |_| {
while (i < end) {
Jest.runner.?.reportFailure(i + this.test_id_start, source.path.text, tests[i].label, 0, 0, this);
@@ -1168,7 +1179,7 @@ pub const DescribeScope = struct {
return;
}
- if (!this.isAllSkipped()) {
+ if (this.shouldEvaluateScope()) {
// Run the afterAll callbacks, in reverse order
// unless there were no tests for this scope
if (this.execCallback(globalThis, .afterAll)) |err| {
@@ -1267,8 +1278,8 @@ pub const TestRunnerTask = struct {
var test_: TestScope = this.describe.tests.items[test_id];
describe.current_test_id = test_id;
- if (test_.func == .zero or (describe.is_skip and test_.tag != .only)) {
- var tag = if (describe.is_skip) describe.tag else test_.tag;
+ if (test_.func == .zero or !describe.shouldEvaluateScope()) {
+ var tag = if (!describe.shouldEvaluateScope()) describe.tag else test_.tag;
switch (tag) {
.todo => {
this.processTestResult(globalThis, .{ .todo = {} }, test_, test_id, describe);
@@ -1609,8 +1620,7 @@ inline fn createScope(
.label = label,
.parent = parent,
.file_id = parent.file_id,
- .tag = if (parent.is_skip) parent.tag else tag,
- .is_skip = is_skip or parent.is_skip,
+ .tag = tag,
};
return scope.run(globalThis, function, &.{});
@@ -1983,8 +1993,7 @@ fn eachBind(
.label = formattedLabel,
.parent = parent,
.file_id = parent.file_id,
- .tag = if (parent.is_skip) parent.tag else .pass,
- .is_skip = parent.is_skip,
+ .tag = .pass,
};
const ret = scope.run(globalThis, function, function_args);