Storybook test-runner "Cannot connect to Storybook at http://127.0.0.1:6006" in CI
The test-runner tried to open the Storybook URL and the connection was refused or returned nothing usable. Either nothing is listening on that port, or Storybook is served on a different host/port than the runner expects.
What this error means
The runner fails with "Cannot connect to Storybook at http://127.0.0.1:6006" or "connect ECONNREFUSED 127.0.0.1:6006".
Cannot connect to Storybook at http://127.0.0.1:6006.
connect ECONNREFUSED 127.0.0.1:6006Common causes
Storybook served on a different port
The static server or storybook dev uses a port other than 6006, but the runner defaults to 6006.
The server exited before the runner connected
A background Storybook process crashed or was not kept alive, so the port is closed when the runner tries.
How to fix it
Align the served port with the runner URL
- Serve Storybook on a known port.
- Pass the same URL to the runner with
--url. - Confirm the server stays up for the test duration.
npx http-server storybook-static --port 6006 --silent &
npx wait-on tcp:127.0.0.1:6006
npx test-storybook --url http://127.0.0.1:6006Bind the server to the address the runner uses
If the runner uses 127.0.0.1, do not serve only on localhost/IPv6; bind explicitly so the address matches.
npx http-server storybook-static -a 127.0.0.1 --port 6006How to prevent it
- Serve and test on the same explicit host and port.
- Keep the Storybook server alive for the whole test run with
concurrently. - Wait for the port before starting the runner.