From 02833d5ba40167c1b06feda0734caf351c96ead1 Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Tue, 7 Apr 2026 09:36:13 +0000 Subject: [PATCH] Fix flaky metadata timer test by using closeTo for floating-point comparisons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The nested timer tests compared performance timing values using exact equality via toMatchObject. Due to floating-point arithmetic precision, values like `a + b` can differ from separately measured durations by tiny amounts (e.g. 11.820208999999977 vs 11.82020900000009), causing intermittent failures. Replace exact equality with expect.closeTo(value, 5) which tolerates differences smaller than 1e-5 — more than sufficient for millisecond-level timing measurements. --- .../cli-kit/src/public/node/metadata.test.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/cli-kit/src/public/node/metadata.test.ts b/packages/cli-kit/src/public/node/metadata.test.ts index d68cb0e4fe0..6ec183a9fa7 100644 --- a/packages/cli-kit/src/public/node/metadata.test.ts +++ b/packages/cli-kit/src/public/node/metadata.test.ts @@ -118,16 +118,16 @@ describe('runtime metadata', () => { const entries = Object.fromEntries(performanceEntries.map((entry) => [entry.name, entry.duration])) expect(entries).toMatchObject({ - 'a#wall': a + b + c + d + e, - 'a#measurable': a, - 'b#wall': b + c + d + e, - 'b#measurable': b, - 'c#wall': c, - 'c#measurable': c, - 'd#wall': d + e, - 'd#measurable': d, - 'e#wall': e, - 'e#measurable': e, + 'a#wall': expect.closeTo(a + b + c + d + e, 5), + 'a#measurable': expect.closeTo(a, 5), + 'b#wall': expect.closeTo(b + c + d + e, 5), + 'b#measurable': expect.closeTo(b, 5), + 'c#wall': expect.closeTo(c, 5), + 'c#measurable': expect.closeTo(c, 5), + 'd#wall': expect.closeTo(d + e, 5), + 'd#measurable': expect.closeTo(d, 5), + 'e#wall': expect.closeTo(e, 5), + 'e#measurable': expect.closeTo(e, 5), }) }) @@ -163,10 +163,10 @@ describe('runtime metadata', () => { const entries = Object.fromEntries(performanceEntries.map((entry) => [entry.name, entry.duration])) expect(entries).toMatchObject({ - 'a#wall': a + b, - 'a#measurable': a, - 'b#wall': b, - 'b#measurable': b, + 'a#wall': expect.closeTo(a + b, 5), + 'a#measurable': expect.closeTo(a, 5), + 'b#wall': expect.closeTo(b, 5), + 'b#measurable': expect.closeTo(b, 5), }) }) })