mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 05:42:43 +00:00
fix: bun test -t (#8845)
This commit is contained in:
@@ -40,7 +40,7 @@ pub const RegularExpression = opaque {
|
||||
|
||||
// Simple boolean matcher
|
||||
pub inline fn matches(this: *RegularExpression, str: bun.String) bool {
|
||||
return Yarr__RegularExpression__matches(this, str) > 0;
|
||||
return Yarr__RegularExpression__matches(this, str) >= 0;
|
||||
}
|
||||
|
||||
pub inline fn searchRev(this: *RegularExpression, str: bun.String) i32 {
|
||||
|
||||
@@ -1857,7 +1857,21 @@ fn eachBind(
|
||||
(description.toSlice(globalThis, allocator).cloneIfNeeded(allocator) catch unreachable).slice();
|
||||
const formattedLabel = formatLabel(globalThis, label, function_args, test_idx) catch return .zero;
|
||||
|
||||
if (each_data.is_test) {
|
||||
var is_skip = false;
|
||||
|
||||
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(formattedLabel) catch unreachable;
|
||||
const str = bun.String.fromBytes(buffer.toOwnedSliceLeaky());
|
||||
is_skip = !regex.matches(str);
|
||||
}
|
||||
|
||||
if (is_skip) {
|
||||
parent.skip_count += 1;
|
||||
function.unprotect();
|
||||
} else if (each_data.is_test) {
|
||||
function.protect();
|
||||
parent.tests.append(allocator, TestScope{
|
||||
.label = formattedLabel,
|
||||
|
||||
@@ -603,6 +603,52 @@ describe("bun test", () => {
|
||||
expect(stderr).toContain(`${numbers[0]} + ${numbers[1]} = ${numbers[2]}`);
|
||||
});
|
||||
});
|
||||
test("should allow tests run with test.each to be skipped", () => {
|
||||
const numbers = [
|
||||
[1, 2, 3],
|
||||
[1, 1, 2],
|
||||
[3, 4, 7],
|
||||
];
|
||||
|
||||
const stderr = runTest({
|
||||
args: ["-t", "$a"],
|
||||
input: `
|
||||
import { test, expect } from "bun:test";
|
||||
|
||||
test.each(${JSON.stringify(numbers)})("%i + %i = %i", (a, b, e) => {
|
||||
expect(a + b).toBe(e);
|
||||
});
|
||||
`,
|
||||
});
|
||||
numbers.forEach(numbers => {
|
||||
expect(stderr).not.toContain(`${numbers[0]} + ${numbers[1]} = ${numbers[2]}`);
|
||||
});
|
||||
});
|
||||
test("should allow tests run with test.each to be matched", () => {
|
||||
const numbers = [
|
||||
[1, 2, 3],
|
||||
[1, 1, 2],
|
||||
[3, 4, 7],
|
||||
];
|
||||
|
||||
const stderr = runTest({
|
||||
args: ["-t", "1 \\+"],
|
||||
input: `
|
||||
import { test, expect } from "bun:test";
|
||||
|
||||
test.each(${JSON.stringify(numbers)})("%i + %i = %i", (a, b, e) => {
|
||||
expect(a + b).toBe(e);
|
||||
});
|
||||
`,
|
||||
});
|
||||
numbers.forEach(numbers => {
|
||||
if (numbers[0] === 1) {
|
||||
expect(stderr).toContain(`${numbers[0]} + ${numbers[1]} = ${numbers[2]}`);
|
||||
} else {
|
||||
expect(stderr).not.toContain(`${numbers[0]} + ${numbers[1]} = ${numbers[2]}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
test("should run tests with describe.each", () => {
|
||||
const numbers = [
|
||||
[1, 2, 3],
|
||||
|
||||
Reference in New Issue
Block a user