Skip to content

Commit ee606f7

Browse files
committed
🤖 fix: hide storybook toggle when Chromatic detects UI tests
1 parent 055e107 commit ee606f7

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

.storybook/preview.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ import React from "react";
22
import type { Preview } from "@storybook/react-vite";
33
import { ThemeProvider, type ThemeMode } from "../src/browser/contexts/ThemeContext";
44
import { getStorageChangeEvent } from "@/common/constants/events";
5+
import isChromatic from "chromatic/isChromatic";
56
import { UI_THEME_KEY } from "@/common/constants/storage";
7+
import "../src/browser/styles/globals.css";
68

79
// Utility: detect e2e/test contexts where UI should be hidden (Chromatic, SB test-runner)
810
const isE2ETestEnv = () => {
9-
if (typeof window !== "undefined" && (window as any).CHROMATIC) return true;
10-
if (typeof navigator !== "undefined" && /StorybookTestRunner/i.test(navigator.userAgent)) return true;
11+
if (typeof window !== "undefined" && isChromatic()) {
12+
return true;
13+
}
14+
if (typeof navigator !== "undefined" && /StorybookTestRunner/i.test(navigator.userAgent)) {
15+
return true;
16+
}
1117
return false;
1218
};
13-
import "../src/browser/styles/globals.css";
1419

1520
const applyStorybookTheme = (mode: ThemeMode) => {
1621
if (typeof window === "undefined") {

bun.lock

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"lockfileVersion": 1,
3-
"configVersion": 0,
43
"workspaces": {
54
"": {
65
"name": "@coder/cmux",
@@ -79,6 +78,7 @@
7978
"@vitejs/plugin-react": "^4.0.0",
8079
"autoprefixer": "^10.4.21",
8180
"babel-plugin-react-compiler": "^1.0.0",
81+
"chromatic": "^13.3.4",
8282
"class-variance-authority": "^0.7.1",
8383
"clsx": "^2.1.1",
8484
"cmdk": "^1.0.0",
@@ -1297,6 +1297,8 @@
12971297

12981298
"chownr": ["chownr@2.0.0", "", {}, "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ=="],
12991299

1300+
"chromatic": ["chromatic@13.3.4", "", { "peerDependencies": { "@chromatic-com/cypress": "^0.*.* || ^1.0.0", "@chromatic-com/playwright": "^0.*.* || ^1.0.0" }, "optionalPeers": ["@chromatic-com/cypress", "@chromatic-com/playwright"], "bin": { "chroma": "dist/bin.js", "chromatic": "dist/bin.js", "chromatic-cli": "dist/bin.js" } }, "sha512-TR5rvyH0ESXobBB3bV8jc87AEAFQC7/n+Eb4XWhJz6hW3YNxIQPVjcbgLv+a4oKHEl1dUBueWSoIQsOVGTd+RQ=="],
1301+
13001302
"chromium-pickle-js": ["chromium-pickle-js@0.2.0", "", {}, "sha512-1R5Fho+jBq0DDydt+/vHWj5KJNJCKdARKOCwZUen84I5BreWoLqRLANH1U87eJy1tiASPtMnGqJJq0ZsLoRPOw=="],
13011303

13021304
"ci-info": ["ci-info@3.9.0", "", {}, "sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ=="],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
"@vitejs/plugin-react": "^4.0.0",
120120
"autoprefixer": "^10.4.21",
121121
"babel-plugin-react-compiler": "^1.0.0",
122+
"chromatic": "^13.3.4",
122123
"class-variance-authority": "^0.7.1",
123124
"clsx": "^2.1.1",
124125
"cmdk": "^1.0.0",

0 commit comments

Comments
 (0)