Describe the bug
I have multiple CSS/JS themes in my real Storybook/HTML repo, which I manage in .storybook/main.js via .env variables, enabling me to determine if Storybook is running in local DEV mode or PRODUCTION.
This works when running Storybook UI. CSS/JS loads correctly, irrespective of environment.
However, I noticed that Vitest does not load the CSS/JS for Storybook, so the a11y tests are running purely on "naked" HTML components - I tested this by setting headless: false in vitest.config.js.
NOTE: I have a temporary workaround for now, which does not use .env files, or main.js... but I have setup a simplified repro Storybook to demonstrate the actual problem - see below.
Reproduction link
https://github.com/basher/storybook-html-vitest-a11y
Reproduction steps
- Uncomment the
previewHead() function in main.js.
- Comment out the inline
<script> in preview-head.html.
npm run storybook - the CSS loads OK in the UI.
- Set
headless: false in vitest.config.js.
npm run test-storybook - the CSS does NOT load. The rendered <button> is unstyled.
System
│ Storybook Environment Info:
│
│ System:
│ OS: Windows 10 10.0.19045
│ CPU: (4) x64 Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz
│ Binaries:
│ Node: 22.19.0 - C:\Program Files\nodejs\node.EXE
│ Yarn: 1.22.22 - C:\Users\kev\AppData\Roaming\npm\yarn.CMD
│ npm: 10.9.3 - C:\Program Files\nodejs\npm.CMD <----- active
│ Browsers:
│ Chrome: 147.0.7727.117
│ Edge: Chromium (140.0.3485.94)
│ Firefox: 150.0.1 - C:\Program Files (x86)\Mozilla Firefox\firefox.exe
│ npmPackages:
│ @storybook/addon-a11y: ^10.3.5 => 10.3.5
│ @storybook/addon-docs: ^10.3.5 => 10.3.5
│ @storybook/addon-vitest: ^10.3.5 => 10.3.5
│ @storybook/html-vite: ^10.3.5 => 10.3.5
│ storybook: ^10.3.5 => 10.3.5
Additional context
No response
Describe the bug
I have multiple CSS/JS themes in my real Storybook/HTML repo, which I manage in
.storybook/main.jsvia.envvariables, enabling me to determine if Storybook is running in local DEV mode or PRODUCTION.This works when running Storybook UI. CSS/JS loads correctly, irrespective of environment.
However, I noticed that Vitest does not load the CSS/JS for Storybook, so the a11y tests are running purely on "naked" HTML components - I tested this by setting
headless: falseinvitest.config.js.Reproduction link
https://github.com/basher/storybook-html-vitest-a11y
Reproduction steps
previewHead()function inmain.js.<script>inpreview-head.html.npm run storybook- the CSS loads OK in the UI.headless: falseinvitest.config.js.npm run test-storybook- the CSS does NOT load. The rendered<button>is unstyled.System
Additional context
No response