Skip to content

Commit 425cd95

Browse files
test: sample the #3459 Loading-reset scenario on a fake clock
Same shape as the other three: a real 200ms flight sampled every 25ms of wall time, asserting the frame still showing at each sample. Co-authored-by: Cursor <[email protected]>
1 parent 273125c commit 425cd95

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎packages/signals/tests/loading-reset-collects-forwarded-3459.test.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ import {
66
createSignal,
77
flush
88
} from "../src/index.js";
9+
import { afterEach, beforeEach, vi } from "vitest";
910

1011
const delay = <T = void>(ms: number, value?: T) => new Promise<T>(r => setTimeout(r, ms, value));
1112

13+
// Fake timers: the scenario samples a 200 ms flight every 25 ms and asserts
14+
// the frames it must still be showing — a wall-clock window on a loaded
15+
// runner. `delay` stays the timer both the flight and the click use; the
16+
// sampling loop advances the clock instead of waiting on it.
17+
beforeEach(() => vi.useFakeTimers());
18+
afterEach(() => vi.useRealTimers());
19+
1220
// #3459: `Loading on={a()}` over `fast = createMemo(async () => a())` and
1321
// `slow = createMemo(() => delay(200, b()))`. `setB(1); await 50; setA(1)`.
1422
// The `on` reset takes the hold off the lane (#3375: fallback-caught async
@@ -70,14 +78,15 @@ async function scenario(shape: "two-effects" | "one-effect") {
7078
setA(1);
7179
};
7280
});
73-
await delay(250);
81+
flush(); // starts slow's first flight before the clock moves
82+
await vi.advanceTimersByTimeAsync(250);
7483
flush();
7584
log.push(`initial: ${snap()}`);
7685
void click();
7786
for (let t = 0; t <= 300; t += 25) {
7887
flush();
7988
log.push(`t=${t}: ${snap()}`);
80-
await delay(25);
89+
await vi.advanceTimersByTimeAsync(25);
8190
}
8291
return log;
8392
}

0 commit comments

Comments
 (0)