fix toBeCloseTo missing incrementExpectCallCounter (#21871)

Fixes #11367. Also enforces that all expect functions must use
incrementExpectCallCounter and migrates two from incrementing
active_test_expectation_counter manually

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
pfg
2025-08-14 17:02:58 -07:00
committed by GitHub
parent 50e7d5c26e
commit 7dd85f9dd4
4 changed files with 24 additions and 2 deletions

View File

@@ -5,6 +5,8 @@ pub fn toBeCloseTo(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallF
const thisArguments = callFrame.arguments_old(2);
const arguments = thisArguments.ptr[0..thisArguments.len];
incrementExpectCallCounter();
if (arguments.len < 1) {
return globalThis.throwInvalidArguments("toBeCloseTo() requires at least 1 argument. Expected value must be a number", .{});
}
@@ -83,6 +85,7 @@ const jsc = bun.jsc;
const CallFrame = bun.jsc.CallFrame;
const JSGlobalObject = bun.jsc.JSGlobalObject;
const JSValue = bun.jsc.JSValue;
const incrementExpectCallCounter = bun.jsc.Expect.incrementExpectCallCounter;
const Expect = bun.jsc.Expect.Expect;
const getSignature = Expect.getSignature;

View File

@@ -4,7 +4,7 @@ pub fn toBeValidDate(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Cal
const thisValue = callFrame.this();
const value: JSValue = try this.getValue(globalThis, thisValue, "toBeValidDate", "");
bun.jsc.Expect.active_test_expectation_counter.actual += 1;
incrementExpectCallCounter();
const not = this.flags.not;
var pass = (value.isDate() and !std.math.isNan(value.getUnixTimestamp()));
@@ -32,6 +32,7 @@ const jsc = bun.jsc;
const CallFrame = bun.jsc.CallFrame;
const JSGlobalObject = bun.jsc.JSGlobalObject;
const JSValue = bun.jsc.JSValue;
const incrementExpectCallCounter = bun.jsc.Expect.incrementExpectCallCounter;
const Expect = bun.jsc.Expect.Expect;
const getSignature = Expect.getSignature;

View File

@@ -12,7 +12,7 @@ pub fn toContainEqual(
return globalThis.throwInvalidArguments("toContainEqual() takes 1 argument", .{});
}
bun.jsc.Expect.active_test_expectation_counter.actual += 1;
incrementExpectCallCounter();
const expected = arguments[0];
expected.ensureStillAlive();
@@ -108,6 +108,7 @@ const jsc = bun.jsc;
const CallFrame = bun.jsc.CallFrame;
const JSGlobalObject = bun.jsc.JSGlobalObject;
const JSValue = bun.jsc.JSValue;
const incrementExpectCallCounter = bun.jsc.Expect.incrementExpectCallCounter;
const Expect = bun.jsc.Expect.Expect;
const getSignature = Expect.getSignature;

View File

@@ -1,4 +1,5 @@
import { file, Glob } from "bun";
import { readdirSync } from "fs";
import path from "path";
// prettier-ignore
@@ -134,3 +135,19 @@ describe("banned words", () => {
});
}
});
describe("required words", () => {
const expectDir = "src/bun.js/test/expect";
const files = readdirSync(expectDir);
for (const file of files) {
if (!file.endsWith(".zig") || file.startsWith(".") || file === "toHaveReturnedTimes.zig") continue;
test(file, async () => {
const content = await Bun.file(path.join(expectDir, file)).text();
if (!content.includes("incrementExpectCallCounter")) {
throw new Error(
`${expectDir}/${file} is missing string "incrementExpectCallCounter"\nAll expect() functions must call incrementExpectCallCounter()`,
);
}
});
}
});