mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 22:01:47 +00:00
Support multiple --full-test-name arguments
Extends --full-test-name to accept multiple values, allowing users to run several specific tests in a single command without regex overhead. Features: - Multiple --full-test-name arguments: --full-test-name "test1" --full-test-name "test2" - OR logic: matches any of the provided test names - Proper error messages for single vs multiple names - Comprehensive test coverage for all scenarios Usage examples: bun test --full-test-name "auth login test" --full-test-name "user profile test" bun test --full-test-name "test1" --full-test-name "test2" --full-test-name "test3" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -106,7 +106,7 @@ pub const TestRunner = struct {
|
||||
filter_buffer: MutableString,
|
||||
|
||||
// Used for --full-test-name filtering
|
||||
full_name_filter: ?[]const u8,
|
||||
full_name_filters: []const string,
|
||||
|
||||
unhandled_errors_between_tests: u32 = 0,
|
||||
summary: Summary = Summary{},
|
||||
@@ -139,7 +139,7 @@ pub const TestRunner = struct {
|
||||
}
|
||||
|
||||
pub fn hasTestFilter(this: *const TestRunner) bool {
|
||||
return this.filter_regex != null or this.full_name_filter != null;
|
||||
return this.filter_regex != null or this.full_name_filters.len > 0;
|
||||
}
|
||||
|
||||
pub fn setTimeout(
|
||||
@@ -2005,16 +2005,24 @@ inline fn createScope(
|
||||
is_skip = true;
|
||||
tag_to_use = .skipped_because_label;
|
||||
}
|
||||
} else if (runner.full_name_filter) |full_name| {
|
||||
} else if (runner.full_name_filters.len > 0) {
|
||||
var buffer: bun.MutableString = runner.filter_buffer;
|
||||
buffer.reset();
|
||||
appendParentLabel(&buffer, parent) catch @panic("Bun ran out of memory while filtering tests");
|
||||
buffer.append(label) catch unreachable;
|
||||
const full_test_name = buffer.slice();
|
||||
// Add leading space to filter to match the format from appendParentLabel
|
||||
|
||||
// Check if the test name matches any of the provided filters
|
||||
var matches = false;
|
||||
var expected_name_buffer: [1024]u8 = undefined;
|
||||
const expected_name = std.fmt.bufPrint(&expected_name_buffer, " {s}", .{full_name}) catch full_name;
|
||||
if (!bun.strings.eql(full_test_name, expected_name)) {
|
||||
for (runner.full_name_filters) |full_name| {
|
||||
const expected_name = std.fmt.bufPrint(&expected_name_buffer, " {s}", .{full_name}) catch continue;
|
||||
if (bun.strings.eql(full_test_name, expected_name)) {
|
||||
matches = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!matches) {
|
||||
is_skip = true;
|
||||
tag_to_use = .skipped_because_label;
|
||||
}
|
||||
@@ -2393,16 +2401,24 @@ fn eachBind(globalThis: *JSGlobalObject, callframe: *CallFrame) bun.JSError!JSVa
|
||||
if (is_skip) {
|
||||
tag_to_use = .skipped_because_label;
|
||||
}
|
||||
} else if (Jest.runner.?.full_name_filter) |full_name| {
|
||||
} else if (Jest.runner.?.full_name_filters.len > 0) {
|
||||
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(formattedLabel) catch unreachable;
|
||||
const full_test_name = buffer.slice();
|
||||
// Add leading space to filter to match the format from appendParentLabel
|
||||
|
||||
// Check if the test name matches any of the provided filters
|
||||
var matches = false;
|
||||
var expected_name_buffer: [1024]u8 = undefined;
|
||||
const expected_name = std.fmt.bufPrint(&expected_name_buffer, " {s}", .{full_name}) catch full_name;
|
||||
is_skip = !bun.strings.eql(full_test_name, expected_name);
|
||||
for (Jest.runner.?.full_name_filters) |full_name| {
|
||||
const expected_name = std.fmt.bufPrint(&expected_name_buffer, " {s}", .{full_name}) catch continue;
|
||||
if (bun.strings.eql(full_test_name, expected_name)) {
|
||||
matches = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
is_skip = !matches;
|
||||
if (is_skip) {
|
||||
tag_to_use = .skipped_because_label;
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ pub const Command = struct {
|
||||
coverage: TestCommand.CodeCoverageOptions = .{},
|
||||
test_filter_pattern: ?[]const u8 = null,
|
||||
test_filter_regex: ?*RegularExpression = null,
|
||||
test_full_name_filter: ?[]const u8 = null,
|
||||
test_full_name_filter: []const string = &.{},
|
||||
|
||||
file_reporter: ?TestCommand.FileReporter = null,
|
||||
reporter_outfile: ?[]const u8 = null,
|
||||
|
||||
@@ -196,7 +196,7 @@ pub const test_only_params = [_]ParamType{
|
||||
clap.parseParam("--coverage-dir <STR> Directory for coverage files. Defaults to 'coverage'.") catch unreachable,
|
||||
clap.parseParam("--bail <NUMBER>? Exit the test suite after <NUMBER> failures. If you do not specify a number, it defaults to 1.") catch unreachable,
|
||||
clap.parseParam("-t, --test-name-pattern <STR> Run only tests with a name that matches the given regex.") catch unreachable,
|
||||
clap.parseParam("--full-test-name <STR> Run only tests with the exact full test name (space separated, no regex).") catch unreachable,
|
||||
clap.parseParam("--full-test-name <STR>... Run only tests matching any of the exact full test names (space separated, no regex).") catch unreachable,
|
||||
clap.parseParam("--reporter <STR> Specify the test reporter. Currently --reporter=junit is the only supported format.") catch unreachable,
|
||||
clap.parseParam("--reporter-outfile <STR> The output file used for the format from --reporter.") catch unreachable,
|
||||
};
|
||||
@@ -485,12 +485,12 @@ pub fn parse(allocator: std.mem.Allocator, ctx: Command.Context, comptime cmd: C
|
||||
};
|
||||
ctx.test_options.test_filter_regex = regex;
|
||||
}
|
||||
if (args.option("--full-test-name")) |fullTestName| {
|
||||
if (args.options("--full-test-name").len > 0) {
|
||||
if (ctx.test_options.test_filter_regex != null) {
|
||||
Output.prettyErrorln("<r><red>error<r>: --full-test-name and --test-name-pattern cannot be used together", .{});
|
||||
Global.exit(1);
|
||||
}
|
||||
ctx.test_options.test_full_name_filter = fullTestName;
|
||||
ctx.test_options.test_full_name_filter = args.options("--full-test-name");
|
||||
}
|
||||
ctx.test_options.update_snapshots = args.flag("--update-snapshots");
|
||||
ctx.test_options.run_todo = args.flag("--todo");
|
||||
|
||||
@@ -1325,7 +1325,7 @@ pub const TestCommand = struct {
|
||||
.bail = ctx.test_options.bail,
|
||||
.filter_regex = ctx.test_options.test_filter_regex,
|
||||
.filter_buffer = bun.MutableString.init(ctx.allocator, 0) catch unreachable,
|
||||
.full_name_filter = ctx.test_options.test_full_name_filter,
|
||||
.full_name_filters = ctx.test_options.test_full_name_filter,
|
||||
.snapshots = Snapshots{
|
||||
.allocator = ctx.allocator,
|
||||
.update_snapshots = ctx.test_options.update_snapshots,
|
||||
@@ -1702,9 +1702,10 @@ pub const TestCommand = struct {
|
||||
summary.skipped_because_label,
|
||||
if (summary.skipped_because_label == 1) "" else "s",
|
||||
});
|
||||
} else if (ctx.test_options.test_full_name_filter) |full_name| {
|
||||
Output.prettyError("<red>error<r><d>:<r> test name <b>{}<r> matched 0 tests. Searched {d} file{s} (skipping {d} test{s}) ", .{
|
||||
bun.fmt.quote(full_name),
|
||||
} else if (ctx.test_options.test_full_name_filter.len > 0) {
|
||||
const names_text = if (ctx.test_options.test_full_name_filter.len == 1) "test name" else "test names";
|
||||
Output.prettyError("<red>error<r><d>:<r> {s} matched 0 tests. Searched {d} file{s} (skipping {d} test{s}) ", .{
|
||||
names_text,
|
||||
summary.files,
|
||||
if (summary.files == 1) "" else "s",
|
||||
summary.skipped_because_label,
|
||||
|
||||
Reference in New Issue
Block a user