aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/test/jest.zig
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-08-06 06:13:39 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-06 06:13:39 -0700
commitcd0774cd89f44ae3880ae5d3840787012d9df603 (patch)
treeb1285dd26a5134b227f56afcc58c8e2b519fd3a1 /src/bun.js/test/jest.zig
parentcf8650937aa03b7410c24675868eec36b7e2f390 (diff)
downloadbun-cd0774cd89f44ae3880ae5d3840787012d9df603.tar.gz
bun-cd0774cd89f44ae3880ae5d3840787012d9df603.tar.zst
bun-cd0774cd89f44ae3880ae5d3840787012d9df603.zip
Implement --test-name-pattern (#3998)
* Fix end not being emitted all the time * stuff * Implement -t * Undo js_printer changes * Undo http changes * Update InternalModuleRegistryConstants.h * Delete unrelated test --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/test/jest.zig')
-rw-r--r--src/bun.js/test/jest.zig35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig
index 39116054e..aacf671ce 100644
--- a/src/bun.js/test/jest.zig
+++ b/src/bun.js/test/jest.zig
@@ -34,6 +34,7 @@ const FeatureFlags = @import("root").bun.FeatureFlags;
const ArrayBuffer = @import("../base.zig").ArrayBuffer;
const Properties = @import("../base.zig").Properties;
const getAllocator = @import("../base.zig").getAllocator;
+const RegularExpression = bun.RegularExpression;
const ZigString = JSC.ZigString;
const JSInternalPromise = JSC.JSInternalPromise;
@@ -96,6 +97,10 @@ pub const TestRunner = struct {
afterAll: std.ArrayListUnmanaged(JSC.JSValue) = .{},
} = .{},
+ // Used for --test-name-pattern to reduce allocations
+ filter_regex: ?*RegularExpression,
+ filter_buffer: MutableString,
+
pub const Drainer = JSC.AnyTask.New(TestRunner, drain);
pub fn onTestTimeout(timer: *bun.uws.Timer) callconv(.C) void {
@@ -1441,6 +1446,17 @@ pub const Result = union(TestRunner.Test.Status) {
}
};
+fn appendParentLabel(
+ buffer: *bun.MutableString,
+ parent: *DescribeScope,
+) !void {
+ if (parent.parent) |par| {
+ try appendParentLabel(buffer, par);
+ }
+ try buffer.append(parent.label);
+ try buffer.append(" ");
+}
+
inline fn createScope(
globalThis: *JSGlobalObject,
callframe: *CallFrame,
@@ -1516,11 +1532,26 @@ inline fn createScope(
return .zero;
}
- const is_skip = tag == .skip or
+ var is_skip = tag == .skip or
(tag == .todo and (function == .zero or !Jest.runner.?.run_todo)) or
(tag != .only and Jest.runner.?.only and parent.tag != .only);
+ var tag_to_use = tag;
if (is_test) {
+ if (!is_skip) {
+ if (Jest.runner.?.filter_regex) |regex| {
+ var buffer: bun.MutableString = Jest.runner.?.filter_buffer;
+ buffer.reset();
+ appendParentLabel(&buffer, parent) catch @panic("Bun ran out of memory while filtering tests");
+ buffer.append(label) catch unreachable;
+ var str = bun.String.fromBytes(buffer.toOwnedSliceLeaky());
+ is_skip = !regex.matches(str);
+ if (is_skip) {
+ tag_to_use = .skip;
+ }
+ }
+ }
+
if (is_skip) {
parent.skip_count += 1;
function.unprotect();
@@ -1531,7 +1562,7 @@ inline fn createScope(
parent.tests.append(allocator, TestScope{
.label = label,
.parent = parent,
- .tag = tag,
+ .tag = tag_to_use,
.callback = if (is_skip) .zero else function,
.timeout_millis = timeout_ms,
}) catch unreachable;