Skip to content

Commit 70c7ee2

Browse files
authored
🤖 fix: mock Date.now() in Storybook for deterministic snapshots (#1033)
## Problem The `WithBashToolWaiting` story was flaky because the elapsed time display changed every run. The `BashToolCall` component calculates elapsed time using `Date.now()` for the current time, but stories use a fixed timestamp (`NOW = 1700000000000`, Nov 2023) for message timestamps. This meant the elapsed time showed something like `33000000s` (the difference between real `Date.now()` and the fixed timestamp), which changed every second. ## Solution Mock `Date.now()` globally in Storybook preview to return the same stable `NOW` timestamp used by all test fixtures. Now the elapsed time calculation is deterministic. _Generated with `mux`_
1 parent 45d9c5b commit 70c7ee2

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

.storybook/preview.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import type { Preview } from "@storybook/react-vite";
33
import { ThemeProvider, type ThemeMode } from "../src/browser/contexts/ThemeContext";
44
import "../src/browser/styles/globals.css";
55
import { TUTORIAL_STATE_KEY, type TutorialState } from "../src/common/constants/storage";
6+
import { NOW } from "../src/browser/stories/mockFactory";
7+
8+
// Mock Date.now() globally for deterministic snapshots
9+
// Components using Date.now() for elapsed time calculations need stable reference
10+
Date.now = () => NOW;
611

712
// Disable tutorials by default in Storybook to prevent them from interfering with stories
813
// Individual stories can override this by setting localStorage before rendering

0 commit comments

Comments
 (0)