Skip to content

Commit 7dd85f9

Browse files
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>
1 parent 50e7d5c commit 7dd85f9

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

src/bun.js/test/expect/toBeCloseTo.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ pub fn toBeCloseTo(this: *Expect, globalThis: *JSGlobalObject, callFrame: *CallF
55
const thisArguments = callFrame.arguments_old(2);
66
const arguments = thisArguments.ptr[0..thisArguments.len];
77

8+
incrementExpectCallCounter();
9+
810
if (arguments.len < 1) {
911
return globalThis.throwInvalidArguments("toBeCloseTo() requires at least 1 argument. Expected value must be a number", .{});
1012
}
@@ -83,6 +85,7 @@ const jsc = bun.jsc;
8385
const CallFrame = bun.jsc.CallFrame;
8486
const JSGlobalObject = bun.jsc.JSGlobalObject;
8587
const JSValue = bun.jsc.JSValue;
88+
const incrementExpectCallCounter = bun.jsc.Expect.incrementExpectCallCounter;
8689

8790
const Expect = bun.jsc.Expect.Expect;
8891
const getSignature = Expect.getSignature;

src/bun.js/test/expect/toBeValidDate.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub fn toBeValidDate(this: *Expect, globalThis: *JSGlobalObject, callFrame: *Cal
44
const thisValue = callFrame.this();
55
const value: JSValue = try this.getValue(globalThis, thisValue, "toBeValidDate", "");
66

7-
bun.jsc.Expect.active_test_expectation_counter.actual += 1;
7+
incrementExpectCallCounter();
88

99
const not = this.flags.not;
1010
var pass = (value.isDate() and !std.math.isNan(value.getUnixTimestamp()));
@@ -32,6 +32,7 @@ const jsc = bun.jsc;
3232
const CallFrame = bun.jsc.CallFrame;
3333
const JSGlobalObject = bun.jsc.JSGlobalObject;
3434
const JSValue = bun.jsc.JSValue;
35+
const incrementExpectCallCounter = bun.jsc.Expect.incrementExpectCallCounter;
3536

3637
const Expect = bun.jsc.Expect.Expect;
3738
const getSignature = Expect.getSignature;

src/bun.js/test/expect/toContainEqual.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn toContainEqual(
1212
return globalThis.throwInvalidArguments("toContainEqual() takes 1 argument", .{});
1313
}
1414

15-
bun.jsc.Expect.active_test_expectation_counter.actual += 1;
15+
incrementExpectCallCounter();
1616

1717
const expected = arguments[0];
1818
expected.ensureStillAlive();
@@ -108,6 +108,7 @@ const jsc = bun.jsc;
108108
const CallFrame = bun.jsc.CallFrame;
109109
const JSGlobalObject = bun.jsc.JSGlobalObject;
110110
const JSValue = bun.jsc.JSValue;
111+
const incrementExpectCallCounter = bun.jsc.Expect.incrementExpectCallCounter;
111112

112113
const Expect = bun.jsc.Expect.Expect;
113114
const getSignature = Expect.getSignature;

test/internal/ban-words.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { file, Glob } from "bun";
2+
import { readdirSync } from "fs";
23
import path from "path";
34

45
// prettier-ignore
@@ -134,3 +135,19 @@ describe("banned words", () => {
134135
});
135136
}
136137
});
138+
139+
describe("required words", () => {
140+
const expectDir = "src/bun.js/test/expect";
141+
const files = readdirSync(expectDir);
142+
for (const file of files) {
143+
if (!file.endsWith(".zig") || file.startsWith(".") || file === "toHaveReturnedTimes.zig") continue;
144+
test(file, async () => {
145+
const content = await Bun.file(path.join(expectDir, file)).text();
146+
if (!content.includes("incrementExpectCallCounter")) {
147+
throw new Error(
148+
`${expectDir}/${file} is missing string "incrementExpectCallCounter"\nAll expect() functions must call incrementExpectCallCounter()`,
149+
);
150+
}
151+
});
152+
}
153+
});

0 commit comments

Comments
 (0)