From 9bc8e7c83ea579fe7642c850bab206927e724e67 Mon Sep 17 00:00:00 2001 From: pfg Date: Thu, 14 Aug 2025 15:57:51 -0700 Subject: [PATCH 1/2] fix toBeCloseTo missing incrementExpectCallCounter --- src/bun.js/test/expect/toBeCloseTo.zig | 3 +++ src/bun.js/test/expect/toBeValidDate.zig | 3 ++- src/bun.js/test/expect/toContainEqual.zig | 3 ++- test/internal/ban-words.test.ts | 17 +++++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/bun.js/test/expect/toBeCloseTo.zig b/src/bun.js/test/expect/toBeCloseTo.zig index 60fa1496d4dde7..705a889d0896d2 100644 --- a/src/bun.js/test/expect/toBeCloseTo.zig +++ b/src/bun.js/test/expect/toBeCloseTo.zig @@ -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", .{}); } @@ -86,3 +88,4 @@ const JSValue = bun.jsc.JSValue; const Expect = bun.jsc.Expect.Expect; const getSignature = Expect.getSignature; +const incrementExpectCallCounter = bun.jsc.Expect.incrementExpectCallCounter; diff --git a/src/bun.js/test/expect/toBeValidDate.zig b/src/bun.js/test/expect/toBeValidDate.zig index 560e025f992850..f44a702406b60c 100644 --- a/src/bun.js/test/expect/toBeValidDate.zig +++ b/src/bun.js/test/expect/toBeValidDate.zig @@ -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())); @@ -35,3 +35,4 @@ const JSValue = bun.jsc.JSValue; const Expect = bun.jsc.Expect.Expect; const getSignature = Expect.getSignature; +const incrementExpectCallCounter = bun.jsc.Expect.incrementExpectCallCounter; diff --git a/src/bun.js/test/expect/toContainEqual.zig b/src/bun.js/test/expect/toContainEqual.zig index 4cf2f487584199..8a618e364fe8e8 100644 --- a/src/bun.js/test/expect/toContainEqual.zig +++ b/src/bun.js/test/expect/toContainEqual.zig @@ -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(); @@ -111,3 +111,4 @@ const JSValue = bun.jsc.JSValue; const Expect = bun.jsc.Expect.Expect; const getSignature = Expect.getSignature; +const incrementExpectCallCounter = bun.jsc.Expect.incrementExpectCallCounter; diff --git a/test/internal/ban-words.test.ts b/test/internal/ban-words.test.ts index 8660778656ab5a..bc5c90fc012ce4 100644 --- a/test/internal/ban-words.test.ts +++ b/test/internal/ban-words.test.ts @@ -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()`, + ); + } + }); + } +}); From 010b423afafc74b10c15e822f84ed46e3f907adc Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 14 Aug 2025 23:04:13 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- src/bun.js/test/expect/toBeCloseTo.zig | 2 +- src/bun.js/test/expect/toBeValidDate.zig | 2 +- src/bun.js/test/expect/toContainEqual.zig | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bun.js/test/expect/toBeCloseTo.zig b/src/bun.js/test/expect/toBeCloseTo.zig index 705a889d0896d2..143b3dd63640aa 100644 --- a/src/bun.js/test/expect/toBeCloseTo.zig +++ b/src/bun.js/test/expect/toBeCloseTo.zig @@ -85,7 +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; -const incrementExpectCallCounter = bun.jsc.Expect.incrementExpectCallCounter; diff --git a/src/bun.js/test/expect/toBeValidDate.zig b/src/bun.js/test/expect/toBeValidDate.zig index f44a702406b60c..f1495377fec94d 100644 --- a/src/bun.js/test/expect/toBeValidDate.zig +++ b/src/bun.js/test/expect/toBeValidDate.zig @@ -32,7 +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; -const incrementExpectCallCounter = bun.jsc.Expect.incrementExpectCallCounter; diff --git a/src/bun.js/test/expect/toContainEqual.zig b/src/bun.js/test/expect/toContainEqual.zig index 8a618e364fe8e8..2b1b6537b62db8 100644 --- a/src/bun.js/test/expect/toContainEqual.zig +++ b/src/bun.js/test/expect/toContainEqual.zig @@ -108,7 +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; -const incrementExpectCallCounter = bun.jsc.Expect.incrementExpectCallCounter;