Repository navigation
Conversation
… them `toBeCloseTo` changed each -Infinity operand to +Infinity and then returned a pass before it read the `.not` flag. So -Infinity was close to Infinity, and `.not` could not fail for an infinite pair. Two infinities are now close only when they are equal, and the result goes through the same `.not` inversion as every other pair.
|
Updated 11:30 PM PT - Oct 23rd, 2026
❌ @robobun, your commit d5f9969 has 1 failures in
🧪 To try this PR locally: bunx bun-pr 46674That installs a local version of the PR into your bun-46674 --bun |
|
Reproduced on a release build of main 5c6d4e2. These four assertions pass there, and Jest 30.5.2 fails all four: expect(-Infinity).toBeCloseTo(Infinity);
expect(Infinity).toBeCloseTo(-Infinity);
expect(Infinity).not.toBeCloseTo(Infinity);
expect(-Infinity).not.toBeCloseTo(-Infinity);The new test block shows the same: CI, build 131650 (the second run, finished): 181 of 182 jobs passed.
I will not push again to rerun CI. The remaining step is a retry of the failed Windows job. PR: #46674 |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Infinity comparison and regression coverage src/runtime/test_runner/expect/toBeCloseTo.rs, test/js/bun/test/expect.test.js |
Equal infinite values produce an actual difference of zero, and the result is subject to .not inversion. Tests cover finite values, infinities, NaN, precision inputs, .resolves, .rejects, and the reported difference for a negated comparison. |
Suggested reviewers: dylan-conway
Priority:
Merge Risk: 
Minimal · up to 26c2a
-
The infinity comparison change appears ready to merge after normal checks.
Pre-merge checks: 
4
-
Full details: Title check
-
Explanation
The title names the main change: toBeCloseTo now rejects -Infinity vs Infinity and applies .not to infinite pairs. This matches the raw summary, which says equal infinities are a zero-difference match that goes through the negation flag, and the objectives, which say infinite pairs are close only when equal and go through the usual .not inversion. The title is specific and short enough, though it is long at 88 characters.
Full details: Description check
-
Explanation
The description provides a detailed explanation of the problem, fix, scope, compatibility impact, and verification results. It does not use the exact template headings, but it contains the required information, including how the change was verified.
-
Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
| try { | ||
| expect(Infinity).not.toBeCloseTo(Infinity); | ||
| } catch (e) { | ||
| message = Bun.stripANSI(ANY(e).message); | ||
| } | ||
| expect(message).toEndWith("\nReceived difference: 0\n"); | ||
| }); | ||
| } |
There was a problem hiding this comment.
🟡 (optional) Bun maintainers get a message-shape test whose anchor "\nReceived difference: 0\n" at expect.test.js:3888 is the only guard on the new .not failure body for equal infinities. If message stays undefined because the matcher does not throw, toEndWith fails (expect.rs:1872 sets pass=false for a non-string receiver), so the test is not vacuous. But the assertion only checks the last line; a regression that prints "Received difference: 0" while "Expected difference" or "Expected precision" show "inf"/"NaN" (e.g. precision Infinity) still passes. Fix: assert the full stripped message (or at least every numeric line) with toBe/toMatchInlineSnapshot, and add the precision-Infinity variant so the whole new .not body is pinned.
Why this was flagged
The dismissal is sound on vacuity: run_string_affix_matcher at expect.rs:1872 computes pass = value.is_string(), so expect(undefined).toEndWith(...) throws, and throw_rendered at expect.rs:736 emits {signature}{args} with nothing after the template's trailing "\n", so the anchor is exact. What the test leaves unproven is the rest of the newly reachable .not body at toBeCloseTo.rs:79-80: for expect(Infinity).not.toBeCloseTo(Infinity, Infinity) the body prints "Expected precision: inf" and "Expected difference: < 0", and nothing in the suite pins those lines. The REVIEW.md rule that error messages are reviewed word-for-word and that assertions assert the strongest invariant (toBe over suffix checks) is what this test falls short of. The consequence is limited to test strength on the Bun lane; no production reader is affected beyond the message wording already covered by L1.
Verification: Triggering condition: any future regression in the .not failure body for an equal infinite pair other than its last line goes unnoticed by the suite. The only Bun-specific message test the PR adds is test/js/bun/test/expect.test.js:3879-3887, and its sole assertion is expect(message).toEndWith("\nReceived difference: 0\n") (line 3886).
There was a problem hiding this comment.
That is right: the test pins only the last line. I left it that way on purpose, for these reasons.
- The last line is the only part of this message that the PR decides. The failure arms and the template are the same as on main. The new failure prints the body that main already prints for an equal finite pair (
expect(1).not.toBeCloseTo(1)), withInfinityas the operands. - The assertion fails without the fix. On main nothing throws. With the
0.0for an equal infinite pair removed, this test fails, becauseInfinity - InfinityisNaN. - An exact match would assert text that the PR body lists under "Not changed here". The
.notbody has nonotin it. At precisionInfinitythe body isExpected precision: inf,Expected difference: < 0,Received difference: 0. That block reads badly, and I do not want a test that states it as the expected text. - No test on main pins any failure text of this matcher today.
The better place for an exact assertion is the change that gives .not.toBeCloseTo failures the body Jest prints (Expected: not Infinity). If a maintainer prefers the full text pinned in this PR, I will add it.
### What does this PR do? Replaces the matcher part of #32023. Every matcher repeated the same steps and kept two copies of its message, which had drifted. - A call is `Uncounted`, then `Matcher`. A built-in matcher returns `Passed`, which only a `Matcher` makes, so passing uncounted does not compile. That and a run-time test over all 95 matchers replace the `expect-call-counter` lint, which searched each matcher file for a token. Custom matchers and `expect.poll` still count by hand. - 53 matcher files become 11 (reverses the layout of #21810; overlaps #46789, #46729 and #48448). `src` is +3,009 / -6,769. - Deleted: the signature cache, the markup pass on every call, `PostMatchGuard`, `expect_throw!`, `throw2`, 8 `ensure_still_alive` calls before the value's last use. - New: `JSValue::try_for_each`. - Panic sites: 16 and a `debug_assert!` removed, 0 added. `unsafe` blocks: 5 removed, 1 added. **Bugs this fixes** - A `.not` or `.resolves` read on the same `expect()` while a matcher ran changed that call, in some matchers only. Those read the flags late. The call now copies them on entry (`expect.test.js`). - Panic in `.resolves`/`.rejects` called while another matcher started to wait. It skipped the pending check. Every call now checks (`expect-deferred.test.ts`). - `toBeCloseTo` passed for any two infinities, with or without `.not`. Same rule as Vitest and #46674 (`expect.test.js`). **Visible changes** - A modifier read during a call only affects later calls. Verdicts change in both directions. Vitest 4.1.9 lets such a read flip the mock matchers, as main did. - The nested call of the panic fix always waits, including `pass()`, `fail()` and argument errors. - Opposite infinities are not close. `.not` fails on equal ones. **Kept as is** - `.not.toThrow(matcher)` never asks the matcher. `toThrow` treats `expect.any(C)` as `instanceof C` and ignores `{ asymmetricMatch }` (all #48448). - `toThrow(expected)` throws a TypeError for a thrown symbol. - `toThrow` and `.not.toThrow` can both fail: no `message` (#48517), RegExp without `test`. - `toBeOneOf(generator)` cannot wait for an async matcher. - Sticky modifiers (#48073), signature quirks, `inf` in `toBeCloseTo`, which argument errors count. **Performance** | instructions per call, release | before | after | | --- | --- | --- | | `toBe` | 1,653 | 1,224 | | `resolves.toBe` | 2,504 | 2,134 | | custom matcher | 3,199 | 3,183 | | six forms of `toThrow` | 38,251 | 34,984 | | `toContain`, Set of 1,000 | 72,401 | 71,964 | | `toContainEqual` + `toBeOneOf`, Set of 1,000 | 612,437 | 616,435 (+0.65%) | | four failing matchers | 91,566 | 89,218 | | size: linux-x64 / darwin-aarch64 / windows-x64 (CI) | | -40.0 / -32.2 / -52.0 KB | ### How did you verify your code works? Final code, Linux x64: 27 test files under debug+ASAN, clippy, format and source lints. The tests for the three fixes fail on main. The assertion-count test (6 s) and "can both fail" pass on both. No existing assertion changed. A differential against main compared verdict, message, assertion count and getter/trap order in 5.2 million cells (matcher, value, arguments, chain, label, flavour, colour). 9,680 differ: - 80 infinities. - 8,940 that read a modifier mid-call. 1,428 now pass, 6,328 no longer do. - 660 whose snapshot number shifts after such a cell. Compared with main without that read, only the 80 differ. Snapshot files are byte-identical. Failing on both sides: `spyMatchers`, 1 test in `vitest-apis` and 6 in `snapshot.test.ts` (missing packages), and `error snapshots` (expects colours). CI only: other platforms, mordant, the full suite. Jest was not run.
Problem
expect(-Infinity).toBeCloseTo(Infinity)andexpect(Infinity).not.toBeCloseTo(Infinity)pass inbun test. Jest 30.5.2 and Vitest 4.1.9 fail both, also with the signs swapped.src/runtime/test_runner/expect/toBeCloseTo.rs:47-57changed each-Infinityoperand toInfinity, then returned a pass for an infinite pair before it read.not.Fix
.notinversion. No existing failure message changes.expect.closeToalready uses (bindings.cpp:600-604).toBeCloseTo()block intest/js/bun/test/expect.test.js. 10 of 29 tests fail on main, 0 with the fix. Alsoexpect-label,expect-assertions,expect-extend.toBeInstanceOf(another matcher).Background
.notis a flag on theExpectobject. A matcher invertspasswhen the flag is set.Infinity - InfinityisNaN, so an equal infinite pair needs its own case.expect.toBeCloseTo#2870 added this matcher with tests that listed[Infinity, -Infinity]as not close. finish implementing JSMockFunction prototype + lots of expect test organizing #3304 dropped them. The new block restores them in both polarities.expect.closeTo: that copy reads its precision throughtoInt32, so sharing also changesexpect.closeToverdicts. That is a separate change.Downsides
blackboardsh/cottontail,tests/js/bun-test-expect-conformance.test.ts:19.expect(Infinity).toBeCloseTo(Infinity)runs 699 -> 845 (one morepow). Text grows 768 bytes.Notes
Verdict against Jest. A grid of 14 values x 14 values x 9 precisions x 2 polarities, plus 36
.resolves/.rejectsrows (3564 rows, all with number operands and number precisions), run on release builds and on Jest 30.5.2 (node v26.3.0):.resolvesand.rejectsforms for each cell).Cost, measured. Release builds (
bun run build:release) of main 5c6d4e2 and of this PR. A gdb 16.3 script single-steps one warm call of the host functionBun__Bindgen__ExpectPrototype__toBeCloseToand counts instructions. Three runs per binary, all counts identical.perf,valgrindandbloatyare not installed in the container.expect(1.001).toBeCloseTo(1), instructions inside the host function: 103 (main) -> 101 (PR). Inclusive: 845 -> 843.expect(Infinity).toBeCloseTo(Infinity), inclusive instructions: 699 -> 845 (onepowcall added). The old code returned beforepowf. The new code computes the threshold for every pair, so the failure message can print it.nm -S). The release build now has two copies of the code that follows the infinity check (twopowcall sites and twothrow_renderedcall sites, main has one of each). Release binary text: 107635854 B -> 107636622 B (llvm-size, +768 B). The stripped file size does not change (107808480 B).throw!sites: 2 -> 2.Failure text. Seven inputs that already fail on main were probed with
NO_COLOR=1: 0 messages change. The new.notfailure for an equal infinite pair uses the existing.nottemplate and ends withReceived difference: 0. No new message containsNaN.Test validity.
bun test test/js/bun/test/expect.test.js -t "toBeCloseTo\(\)": 10 fail, 19 pass. All 10 are infinite-pair rows, the.resolves/.rejectstest, or the message test.bun bd test test/js/bun/test/expect.test.js: 456 pass, 2 todo, 0 fail.expect-label.test.ts(4 pass),expect-failure-message-angle-brackets.test.ts(2 pass),expect-assertions.test.ts(1 pass),expect-extend.test.js(29 pass).same_infinity ||, drop the0.0for an equal infinite pair, dropis_infinite(), dropreceived == expected.Not changed here.
expect.closeTo(the asymmetric matcher,src/jsc/bindings/bindings.cpp:583-611) is a separate copy of the rule. It was already right for infinite values. It reads its precision throughtoInt32, which is a different gap from Jest (expect(1.001).toEqual(expect.closeTo(1, Infinity))passes in Bun and fails in Jest). expect.closeTo: keep precision as a double instead of coercing via ToInt32 #34648 was about that..not.toBeCloseTofailure body keeps its wording, which has nonotin it. Jest printsExpected: not Infinityfor the new failure. Numbers in the difference lines still print asinf, notInfinity.toBeCloseTo.rs.toMatchObjectchange. A stale-PR sweep closed it with no review from a maintainer.[human-review] gate passed · iteration 0 · 2 files touched
fails on main (without fix)
passes on PR (with fix)
diff hotspot
gate history · 2 passed · 0 rejected · iteration 0
evidence per changed file