npm run test:stories (Vitest browser mode, Chromium, @storybook/addon-vitest) fails about one run in two in CI, and sometimes hangs.
What happens:
Failed to fetch dynamically imported module …?import&browserv=…, followed by Cannot connect to the iframe. Did you change the location or submitted a form?.PR #55 works around it: each attempt has a 6-minute timeout and the step retries once.
Already ruled out: lazy Vite dependency discovery. I tried optimizeDeps.entries pointed at the story globs, and CI still failed.
Suspects:
location, which reloads the shared iframe for the next file. Candidates: Interaction.stories, Dialog.stories, LabelsSettings.stories.browser.isolate, or fileParallelism: false for the stories project).@storybook/nextjs webpack-preset warning ("Failed to load preset builder-webpack5").Done when: 10 consecutive CI runs of test:stories pass on the first attempt, and the retry is removed.
#64 is merged. It runs story files one at a time, sets a root teardownTimeout, allows 10 minutes per attempt and retries once.
Running files one at a time does not fix the flake. On #64's own CI, the first attempt still failed one file (EnvBadge: "Failed to fetch dynamically imported module"), then the retry passed. An attempt takes about a minute.
The files that fail are usually ones added recently (EnvBadge, Pipeline, Toggle, Vote, Skeleton). That points at Vite optimising dependencies when a file's module graph is first requested, rather than at running files in parallel.
Next things to try:
optimizeDeps.include.vite optimize (a warmup pass) before the story run.@vitest/browser and Storybook versions in case it's a regression.The retry keeps CI usable in the meantime.
More data:
CI=true, nice'd, a production-node host), all 50 story files pass on the issue-detail branch. On CI the same branch fails.Colour.stories until the 10-minute timeout. Vite logged [optimizer] bundling dependencies... but never scanning.StatusIcon.stories with "Failed to fetch dynamically imported module" plus "Cannot connect to the iframe", and stopped after 35 of 50 files on an unhandled error.So this is a slow-runner race in Vite dependency optimisation, or in the browser iframe. It isn't a test bug, and running files serially doesn't help.
Interim merge policy: a story-test CI failure counts as non-blocking only when all of these hold:
Next fix to try: pre-warm the optimiser cache before the run (run a vitest browser pass on one tiny story, then the full run), or pin optimizeDeps.include to the exact dependency list Vite reports after a local run.
New data point from PR #59: on the retry, all 164 stories passed, then
timeout 360killed the process (exit 124). So part of the "hang" is vitest not exiting after a green run, probably because the browser provider or a Storybook/Vite server handle is left open, not a test that never finishes.Things to try:
teardownTimeout--pool=threadsAlso note: CI runners aren't the only constrained resource. The agent host is a production k8s node, so local
test:storiesruns should be rare.