From 4155a2365fc5a1ab15159dc31072220a57e8099f Mon Sep 17 00:00:00 2001 From: Zolotoi Date: Fri, 16 Oct 2026 15:22:37 -0300 Subject: [PATCH] test: freeze the clock in the reveal reset-key test The test compared animation delays measured from the real clock, with no tolerance. Once the queue sits at maxWaveLagMs both delays are 240 ms up to floating-point rounding, so it failed at random (240 vs 240.0000000000001 on CI). The clock is now frozen for the test, and the comparison allows a thousandth of a millisecond, far below the 36 ms a reused slot would cost. --- tests/react.test.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/react.test.tsx b/tests/react.test.tsx index dbc3aed..c420e40 100644 --- a/tests/react.test.tsx +++ b/tests/react.test.tsx @@ -2,7 +2,7 @@ import { act, render, cleanup } from '@testing-library/react' import { StrictMode, createRef } from 'react' import { renderToStaticMarkup } from 'react-dom/server' -import { afterEach, describe, expect, it } from 'vitest' +import { afterEach, describe, expect, it, onTestFinished, vi } from 'vitest' import { Reveal, RevealProvider, @@ -625,6 +625,10 @@ describe('settings that change at runtime', () => { describe('RevealProvider resetKey', () => { it('starts a new message on a fresh queue, even for a paragraph mounted with the new key', () => { + // Delays are measured from the clock at each render. Frozen, they compare slot positions + // rather than how much real time happened to pass between two renders. + const now = vi.spyOn(performance, 'now').mockReturnValue(1000) + onTestFinished(() => now.mockRestore()) const message = (key: number, id: string, text: string) => ( @@ -645,7 +649,9 @@ describe('RevealProvider resetKey', () => { const before = delays() rerender(message(2, 'new', 'a new answer, and more')) const after = delays().slice(before.length) - expect(parseFloat(after[0])).toBeGreaterThanOrEqual(parseFloat(before.at(-1)!)) + // A slot handed out again would come at least one stagger (36 ms) earlier; the tolerance + // only absorbs floating-point rounding once the queue is held at maxWaveLagMs. + expect(parseFloat(after[0])).toBeGreaterThanOrEqual(parseFloat(before.at(-1)!) - 0.001) }) it('takes its slots once under StrictMode, which mounts every paragraph twice', () => {