Skip to content

Commit 2914907

Browse files
hassoncsChris Hasson
andauthored
Fix Storybook flakes caused by Math.random() (#892)
Now we use seedrandom so it doesn't change! Co-authored-by: Chris Hasson <[email protected]>
1 parent ed4ec40 commit 2914907

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@roo-code/types": "workspace:^",
3333
"@tailwindcss/vite": "^4.0.0",
3434
"@tanstack/react-query": "^5.68.0",
35+
"@types/seedrandom": "^3.0.8",
3536
"@vscode/codicons": "^0.0.36",
3637
"@vscode/webview-ui-toolkit": "^1.4.0",
3738
"axios": "^1.7.4",
@@ -66,6 +67,7 @@
6667
"remark-gfm": "^4.0.1",
6768
"remark-math": "^6.0.0",
6869
"remove-markdown": "^0.6.0",
70+
"seedrandom": "^3.0.5",
6971
"shell-quote": "^1.8.2",
7072
"shiki": "^3.2.1",
7173
"source-map": "^0.7.4",
@@ -103,9 +105,9 @@
103105
"jest": "^29.7.0",
104106
"jest-environment-jsdom": "^29.7.0",
105107
"jest-simple-dot-reporter": "^1.0.5",
108+
"jsdom": "^26.0.0",
106109
"storybook": "^8.4.7",
107110
"ts-jest": "^29.2.5",
108-
"jsdom": "^26.0.0",
109111
"typescript": "5.8.3",
110112
"vite": "6.3.5",
111113
"vitest": "^3.2.3"

webview-ui/src/utils/timeline/mockData.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { ClineMessage } from "@roo-code/types"
2+
import seedrandom from "seedrandom"
23

34
// Fixed base timestamp for consistent snapshots (January 1, 2024, 12:00:00 UTC)
45
const BASE_TIMESTAMP = 1704110400000
6+
const rng = seedrandom("TimelineData")
57

68
export function generateSampleTimelineData(): ClineMessage[] {
79
const messages: ClineMessage[] = []
@@ -47,9 +49,9 @@ export function generateSampleTimelineData(): ClineMessage[] {
4749

4850
for (let cycle = 0; cycle < 8; cycle++) {
4951
messageTemplates.forEach((template, i) => {
50-
const randomText = template.texts[Math.floor(Math.random() * template.texts.length)]
52+
const randomText = template.texts[Math.floor(rng() * template.texts.length)]
5153
messages.push({
52-
ts: BASE_TIMESTAMP + (cycle * 8 + i) * (1000 + Math.random() * 3000),
54+
ts: BASE_TIMESTAMP + (cycle * 8 + i) * (1000 + rng() * 3000),
5355
type: template.type as "ask" | "say",
5456
...(template.ask && { ask: template.ask as any }),
5557
...(template.say && { say: template.say as any }),

0 commit comments

Comments
 (0)