From 2b5270622109277732d076509fefc35c492a096d Mon Sep 17 00:00:00 2001 From: Ammar Date: Tue, 9 Dec 2025 09:10:30 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20fix:=20mock=20Date.now()=20in=20?= =?UTF-8?q?Storybook=20for=20deterministic=20snapshots?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The BashToolCall component calculates elapsed time using Date.now(), but stories use a fixed timestamp (NOW) from the past. This caused the elapsed time display to be flaky, showing different values each run (the real time minus the fixed timestamp). Mock Date.now() globally in Storybook preview to return the same stable NOW timestamp used by all test fixtures. _Generated with mux_ --- .storybook/preview.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx index 9c7acb8c15..a7289ef90d 100644 --- a/.storybook/preview.tsx +++ b/.storybook/preview.tsx @@ -3,6 +3,11 @@ import type { Preview } from "@storybook/react-vite"; import { ThemeProvider, type ThemeMode } from "../src/browser/contexts/ThemeContext"; import "../src/browser/styles/globals.css"; import { TUTORIAL_STATE_KEY, type TutorialState } from "../src/common/constants/storage"; +import { NOW } from "../src/browser/stories/mockFactory"; + +// Mock Date.now() globally for deterministic snapshots +// Components using Date.now() for elapsed time calculations need stable reference +Date.now = () => NOW; // Disable tutorials by default in Storybook to prevent them from interfering with stories // Individual stories can override this by setting localStorage before rendering