Skip to content

Conversation

kotAPI
Copy link
Collaborator

@kotAPI kotAPI commented Sep 7, 2025

Summary

  • add npm script and basic smoke test runner for Storybook stories
  • run Storybook build and smoke tests in CI using Playwright

Testing

Summary by CodeRabbit

  • Chores

    • Added a CI workflow to build Storybook and run smoke tests on pull requests and the main branch.
    • Faster, more reliable runs via Node setup and browser dependency installation with caching.
  • Tests

    • Added a lightweight Storybook smoke test that renders stories and exercises a basic UI interaction to catch runtime errors.
    • Added a script to run Storybook smoke tests locally against the built static output.

Copy link
Contributor

coderabbitai bot commented Sep 7, 2025

Walkthrough

Adds a GitHub Actions workflow to build and smoke-test Storybook on PRs and main pushes, adds a Storybook test-runner that renders each story and clicks the first button in the canvas, and adds an npm script to run the Storybook test-runner against the generated index JSON.

Changes

Cohort / File(s) Summary
CI Workflow
.github/workflows/storybook.yml
New workflow "Storybook Build and Test" triggered on pull_request and pushes to main: checkout, setup Node 18 with npm cache, npm ci, npx playwright install --with-deps chromium, npm run build-storybook, npm run test-storybook; permissions: contents: read.
Storybook Test Runner
.storybook/test-runner.js
Adds exported run({ canvasElement }) async function that lazily imports within and userEvent from @storybook/testing-library, scopes to canvasElement, finds the first button via queryAllByRole('button'), and clicks it if present (renders each story and exercises a minimal interaction).
Package Scripts
package.json
Adds script test-storybooknpx @storybook/test-runner --index-json ./storybook-static/index.json.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant GH as GitHub Actions
  participant Job as storybook job
  Dev->>GH: Push to main / Open PR
  GH->>Job: Trigger workflow
  Job->>Job: actions/checkout@v4
  Job->>Job: actions/setup-node@v3 (Node 18, npm cache)
  Job->>Job: npm ci
  Job->>Job: npx playwright install --with-deps chromium
  Job->>Job: npm run build-storybook
  Job->>Job: npm run test-storybook
  Note over Job: Runs `npx @storybook/test-runner --index-json ./storybook-static/index.json`\nPermissions: contents: read
Loading
sequenceDiagram
  autonumber
  participant SB as Storybook Test Runner
  participant Canvas as canvasElement
  participant DOM as Story DOM
  SB->>Canvas: within(canvasElement)
  SB->>DOM: queryAllByRole('button')
  alt Button found
    SB->>DOM: userEvent.click(first button)
  else No button
    SB->>SB: Complete without action
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “Run Storybook build and smoke tests in CI” accurately captures the primary change of adding a CI workflow to build Storybook and execute smoke tests, is concise, and avoids unnecessary detail or noise. It clearly informs reviewers of the main intent without listing individual files or using vague language.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

Hop hop, I test each tale tonight,
Buttons nudged with careful might.
CI hums and lights go green,
Stories safe on every screen.
A rabbit cheers—merge in sight. 🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kotapi/add-ci-for-storybook-build-and-smoke-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

@kotAPI kotAPI linked an issue Sep 7, 2025 that may be closed by this pull request
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
package.json (1)

68-77: Unify Storybook to v8

Mismatched v7 and v8 packages detected (e.g. @storybook/[email protected], @storybook/[email protected] vs @storybook/[email protected]). Align all Storybook deps to v8 and add the test runner:

-    "@storybook/addon-a11y": "^7.6.17",
-    "@storybook/addon-essentials": "7.6.17",
-    "@storybook/addon-interactions": "8.0.9",
-    "@storybook/addon-links": "8.6.12",
-    "@storybook/blocks": "8.1.10",
-    "@storybook/react": "7.6.17",
-    "@storybook/react-webpack5": "7.6.17",
+    "@storybook/addon-a11y": "^8.6.12",
+    "@storybook/addon-essentials": "^8.6.12",
+    "@storybook/addon-interactions": "^8.6.12",
+    "@storybook/addon-links": "^8.6.12",
+    "@storybook/blocks": "^8.6.12",
+    "@storybook/react": "^8.6.12",
+    "@storybook/react-webpack5": "^8.6.12",
+    "@storybook/test-runner": "^0.20.0",
-    "storybook": "^8.6.11",
+    "storybook": "^8.6.12",
♻️ Duplicate comments (1)
.storybook/test-runner.js (1)

7-7: Past concern addressed: no more multi-match throw

Switch to queryAllByRole resolves the earlier false failures when multiple buttons exist. Nice.

🧹 Nitpick comments (2)
.storybook/test-runner.js (1)

7-11: Reduce flakiness: use userEvent.setup with relaxed pointer events and add step context

Avoids failures on covered elements and gives clearer test output.

-export const run = async ({ canvasElement }) => {
+export const run = async ({ step, canvasElement }) => {
   const canvas = within(canvasElement);
   const [button] = canvas.queryAllByRole('button');
   if (button) {
-    await userEvent.click(button);
+    const ue = userEvent.setup({ pointerEventsCheck: 0 });
+    await (step ? step('click first button', async () => ue.click(button)) : ue.click(button));
   }
 };
.github/workflows/storybook.yml (1)

21-23: Playwright install is fine; consider caching to speed up CI (optional)

Cache browsers between runs to cut minutes off CI.

# Example:
- name: Cache Playwright
  uses: actions/cache@v4
  with:
    path: ~/.cache/ms-playwright
    key: ${{ runner.os }}-playwright-${{ hashFiles('package-lock.json') }}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 142c0cb and 8803f37.

📒 Files selected for processing (3)
  • .github/workflows/storybook.yml (1 hunks)
  • .storybook/test-runner.js (1 hunks)
  • package.json (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.7)
.github/workflows/storybook.yml

16-16: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: storybook
  • GitHub Check: build

Comment on lines +16 to +19
- uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use setup-node v4 and current LTS

Node 18 reached EOL in April 2025; move to Node 20 (or 22) and the latest action.

-      - uses: actions/setup-node@v3
+      - uses: actions/setup-node@v4
         with:
-          node-version: '18'
+          node-version: '20'
           cache: 'npm'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
🧰 Tools
🪛 actionlint (1.7.7)

16-16: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🤖 Prompt for AI Agents
.github/workflows/storybook.yml around lines 16 to 19 currently pins
actions/setup-node@v3 and node-version: '18'; update the workflow to use
actions/setup-node@v4 and bump the node-version to a current LTS (e.g., '20' or
'22') in those lines, keeping the cache setting as needed (cache: 'npm'); ensure
any other steps relying on Node 18 are compatible or adjusted accordingly.

package.json Outdated
"sb": "storybook dev -p 6006",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"test-storybook": "storybook test --index-json ./storybook-static/index.json",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Make Storybook tests hermetic (avoid registry hits) and resilient in CI

  • Run the local CLI and disable telemetry/update checks to prevent the 403 registry fetch during CI.

Apply:

-    "test-storybook": "storybook test --index-json ./storybook-static/index.json",
+    "test-storybook": "STORYBOOK_DISABLE_TELEMETRY=1 NO_UPDATE_NOTIFIER=1 storybook test --index-json ./storybook-static/index.json",
+    "pretest-storybook": "npm run build-storybook",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"test-storybook": "storybook test --index-json ./storybook-static/index.json",
"scripts": {
// … other scripts …
"test-storybook": "STORYBOOK_DISABLE_TELEMETRY=1 NO_UPDATE_NOTIFIER=1 storybook test --index-json ./storybook-static/index.json",
"pretest-storybook": "npm run build-storybook",
// … other scripts …
}
🤖 Prompt for AI Agents
In package.json around line 17, the "test-storybook" script invokes the global
Storybook CLI which can hit registries in CI; change it to run the local CLI
binary and disable telemetry/update checks to avoid network calls. Update the
script to call the local binary (./node_modules/.bin/storybook or use npm run
resolution via npx --no-install) and prefix it with environment variables to
suppress updates/telemetry (e.g., NO_UPDATE_NOTIFIER=1 and
STORYBOOK_DISABLE_TELEMETRY=1 or the Storybook-specific env var your version
supports) so the command becomes hermetic and CI-resilient.

Copy link
Contributor

Coverage

This report compares the PR with the base branch. “Δ” shows how the PR affects each metric.

Metric PR Δ
Statements 89.67% +0.00%
Branches 66.03% +0.00%
Functions 73.06% +0.00%
Lines 88.55% +0.00%

Coverage improved or stayed the same. Great job!

Run npm run coverage locally for detailed reports and target untested areas to raise these numbers.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
.github/workflows/storybook.yml (1)

16-19: Upgrade to setup-node@v4 and current LTS Node (20/22) to fix actionlint and EOL.

Node 18 is EOL (April 2025) and actionlint flags v3 as too old. Move to v4 and LTS Node.

-      - uses: actions/setup-node@v3
+      - uses: actions/setup-node@v4
         with:
-          node-version: '18'
+          node-version: '20'
           cache: 'npm'
🧹 Nitpick comments (6)
.github/workflows/storybook.yml (6)

12-14: Set job-level env to disable Storybook telemetry/update checks and harden CI.

Reduces network calls (helps the prior 403) and standardizes CI behavior.

   storybook:
     runs-on: ubuntu-latest
+    env:
+      CI: 'true'
+      STORYBOOK_DISABLE_TELEMETRY: '1'
+      NO_UPDATE_NOTIFIER: '1'

22-23: Prefer the official Playwright action for installs and system deps.

It handles browser caching and OS deps more robustly than raw npx.

-      - name: Install Playwright
-        run: npx playwright install --with-deps chromium
+      - name: Install Playwright
+        uses: microsoft/playwright-github-action@v1
+        with:
+          install-deps: true
+          # browsers: 'chromium' # uncomment to restrict

13-14: Add a timeout to prevent hung CI.

Guardrails for network stalls during install/build.

   storybook:
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-latest
+    timeout-minutes: 30

24-27: Upload artifacts on failure for faster triage (static build, logs).

Keeps storybook-static and test output for inspection.

       - name: Build Storybook
         run: npm run build-storybook
       - name: Storybook smoke tests
         run: npm run test-storybook
+      - name: Upload Storybook static (on failure)
+        if: failure()
+        uses: actions/upload-artifact@v4
+        with:
+          name: storybook-static
+          path: storybook-static
+          if-no-files-found: ignore
+      - name: Upload test results (always)
+        if: always()
+        uses: actions/upload-artifact@v4
+        with:
+          name: storybook-tests
+          path: |
+            ./**/playwright-report/**
+            ./**/test-results/**
+          if-no-files-found: ignore

16-21: Optional: pin npm registry if a custom .npmrc could cause 403s.

If your org enforces a private registry for scoped packages, explicitly set npmjs registry for CI.

-      - uses: actions/setup-node@v4
+      - uses: actions/setup-node@v4
         with:
           node-version: '20'
           cache: 'npm'
+          registry-url: 'https://registry.npmjs.org'

24-25: Optional: increase memory for Storybook build to avoid OOM on large catalogs.

-      - name: Build Storybook
-        run: npm run build-storybook
+      - name: Build Storybook
+        run: NODE_OPTIONS="--max-old-space-size=4096" npm run build-storybook
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 85dce38 and 9a09a88.

📒 Files selected for processing (3)
  • .github/workflows/storybook.yml (1 hunks)
  • .storybook/test-runner.js (1 hunks)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .storybook/test-runner.js
  • package.json
🧰 Additional context used
🪛 actionlint (1.7.7)
.github/workflows/storybook.yml

16-16: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build
  • GitHub Check: coverage
  • GitHub Check: storybook
🔇 Additional comments (1)
.github/workflows/storybook.yml (1)

8-10: Minimal permissions look good.

You added contents: read, addressing the prior security bot warning. No further perms needed for this job.

@kotAPI
Copy link
Collaborator Author

kotAPI commented Sep 13, 2025

@coderabbitai

> @radui/[email protected] test-storybook
> npx @storybook/test-runner --index-json ./storybook-static/index.json

npm warn exec The following package was not found and will be installed: @storybook/[email protected]
npm warn deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
[test-storybook] It seems that your Storybook instance is not running at: http://127.0.0.1:6006./ Are you sure it's running?

If you're not running Storybook on the default 6006 port or want to run the tests against any custom URL, you can pass the --url flag like so:

yarn test-storybook --url http://127.0.0.1:9009/

Any idea why this is failing?

Copy link
Contributor

coderabbitai bot commented Sep 13, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@kotAPI The issue is that the Storybook test runner is trying to connect to a running Storybook server instead of using the static build. Let me investigate the current setup to identify the root cause.


🏁 Script executed:

#!/bin/bash
# Check if the storybook-static directory and index.json exist
echo "=== Checking storybook-static directory ==="
ls -la storybook-static/ 2>/dev/null || echo "storybook-static directory not found"

echo -e "\n=== Checking if index.json exists ==="
if [ -f "storybook-static/index.json" ]; then
    echo "index.json exists"
    echo "Size: $(stat -f%z storybook-static/index.json 2>/dev/null || stat -c%s storybook-static/index.json)"
    echo "First few lines:"
    head -5 storybook-static/index.json
else
    echo "index.json does not exist"
fi

echo -e "\n=== Checking package.json scripts ==="
jq '.scripts | with_entries(select(.key | contains("storybook")))' package.json

echo -e "\n=== Checking Storybook configuration ==="
ls -la .storybook/

Length of output: 700


@kotAPI The issue is that the storybook-static directory doesn't exist, which means the Storybook build hasn't been run yet. The test runner is looking for the index.json file in that directory to run tests against the static build.

Let me check the CI workflow and test the build process:


🏁 Script executed:

#!/bin/bash
# Check the CI workflow to see the execution order
echo "=== Checking CI workflow ==="
cat .github/workflows/storybook.yml

echo -e "\n=== Testing the build-storybook command ==="
npm run build-storybook

echo -e "\n=== Checking if storybook-static was created ==="
if [ -d "storybook-static" ]; then
    echo "storybook-static directory created successfully"
    ls -la storybook-static/ | head -10
    
    if [ -f "storybook-static/index.json" ]; then
        echo -e "\nindex.json exists, size: $(stat -c%s storybook-static/index.json)"
        echo "First few lines:"
        head -5 storybook-static/index.json
    else
        echo "index.json not found in storybook-static"
    fi
else
    echo "storybook-static directory was not created"
fi

Length of output: 839


@kotAPI Now I see the root issue! The storybook command is not found, which means the Storybook CLI is not installed. Let me check what Storybook packages you have and fix this:


🏁 Script executed:

#!/bin/bash
# Check what Storybook packages are installed
echo "=== Checking Storybook dependencies ==="
npm list | grep storybook || echo "No storybook packages found in npm list"

echo -e "\n=== Checking package.json for storybook dependencies ==="
jq '.dependencies, .devDependencies' package.json | grep -i storybook || echo "No storybook packages found in package.json"

echo -e "\n=== Testing with npx storybook build ==="
npx storybook build

echo -e "\n=== Checking if build succeeded ==="
if [ -d "storybook-static" ]; then
    echo "Build successful! storybook-static directory created"
    ls -la storybook-static/ | head -5
    
    if [ -f "storybook-static/index.json" ]; then
        echo -e "\nindex.json created successfully"
        echo "Size: $(stat -c%s storybook-static/index.json)"
    fi
else
    echo "Build failed - no storybook-static directory"
fi

Length of output: 8705


@kotAPI I found the issue! The problem is that the dependencies haven't been installed. The error shows many UNMET DEPENDENCY errors, including the Storybook packages that are required. Let me install the dependencies and test the complete workflow:


🏁 Script executed:

#!/bin/bash
echo "=== Installing dependencies ==="
npm ci

echo -e "\n=== Testing build-storybook after dependency installation ==="
npm run build-storybook

echo -e "\n=== Checking if build succeeded ==="
if [ -d "storybook-static" ] && [ "$(ls -A storybook-static)" ]; then
    echo "Build successful! storybook-static directory created with content"
    echo "Files created:"
    ls -la storybook-static/ | head -10
    
    if [ -f "storybook-static/index.json" ]; then
        echo -e "\nindex.json exists - size: $(stat -c%s storybook-static/index.json)"
        echo "First few lines:"
        head -3 storybook-static/index.json
    fi
else
    echo "Build failed or storybook-static is empty"
fi

echo -e "\n=== Now testing the test-storybook command ==="
npm run test-storybook

Length of output: 87331


@kotAPI Perfect! The build is now working correctly after installing dependencies with npm ci. The issue is that the Storybook test runner is still trying to connect to a running server despite the --index-json flag.

Let me check the test runner configuration:


🏁 Script executed:

#!/bin/bash
echo "=== Examining test-runner.js configuration ==="
cat .storybook/test-runner.js

echo -e "\n=== Checking test-runner version compatibility ==="
# Let's see if there's a configuration issue or if we need to use a different approach
# The issue might be that the test runner needs the --url flag to point to the static build

echo -e "\n=== Testing with explicit static build serving ==="
# Try serving the static build locally and pointing the test runner to it
echo "Starting a simple HTTP server for storybook-static..."
cd storybook-static && python3 -m http.server 6006 &
SERVER_PID=$!
sleep 2

echo "Testing if the server is running..."
curl -s -o /dev/null -w "%{http_code}" http://localhost:6006/ || echo "Server not responding"

# Kill the server
kill $SERVER_PID 2>/dev/null || true
cd ..

echo -e "\n=== Alternative approach: Using --url flag with file protocol ==="
# The test runner might need the --url flag even with --index-json
echo "Checking if we can use file:// protocol..."
pwd
ls -la storybook-static/index.html

Unrecoverable error: Request timed out after 300000ms (requestId=160654d9-cce6-43b4-a574-21ef07fc6c41)


@kotAPI The issue is clear now. The Storybook test runner's --index-json flag doesn't work in true "static" mode - it still expects a running server. Here's the solution:

The Problem

The --index-json flag tells the test runner which stories to test, but it still needs a running Storybook server to load and execute the stories.

The Solution

You need to either:

  1. Option 1: Serve the static build (Recommended for CI)
  2. Option 2: Run against a dev server

Let me provide you with the corrected approach:

Fix the package.json scripts:

{
  "scripts": {
    "storybook": "storybook dev -p 6006",
    "build-storybook": "storybook build",
    "serve-storybook": "npx http-server storybook-static -p 6006 -s",
    "test-storybook": "npx @storybook/test-runner",
    "test-storybook:ci": "npx concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"npx http-server storybook-static -p 6006 -s\" \"npx wait-on http://127.0.0.1:6006 && npx @storybook/test-runner\""
  }
}

Update the CI workflow:

name: Storybook Build and Test

on:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  storybook:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v3
        with:
          node-version: '18'
          cache: 'npm'
      - name: Install dependencies
        run: npm ci
      - name: Install Playwright
        run: npx playwright install --with-deps chromium
      - name: Build Storybook
        run: npm run build-storybook
      - name: Install additional packages for CI
        run: npm install --no-save concurrently http-server wait-on
      - name: Storybook smoke tests
        run: npm run test-storybook:ci

The key changes:

  1. Remove the --index-json flag from the test script
  2. Use concurrently to serve the static build and run tests simultaneously
  3. Use wait-on to ensure the server is ready before running tests
  4. Install the required packages (concurrently, http-server, wait-on) in CI

This approach:

  • ✅ Works with static builds (no need for storybook dev)
  • ✅ Runs tests against the actual built output
  • ✅ Automatically manages the server lifecycle
  • ✅ Is reliable in CI environments

Would you like me to create a shell script to test this approach before you update your files?

@kotAPI
Copy link
Collaborator Author

kotAPI commented Sep 13, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain
@kotAPI The issue is clear now. The Storybook test runner's --index-json flag doesn't work in true "static" mode - it still expects a running server. Here's the solution:

The Problem

The --index-json flag tells the test runner which stories to test, but it still needs a running Storybook server to load and execute the stories.

The Solution

You need to either:

  1. Option 1: Serve the static build (Recommended for CI)
  2. Option 2: Run against a dev server

Let me provide you with the corrected approach:

Fix the package.json scripts:

{
  "scripts": {
    "storybook": "storybook dev -p 6006",
    "build-storybook": "storybook build",
    "serve-storybook": "npx http-server storybook-static -p 6006 -s",
    "test-storybook": "npx @storybook/test-runner",
    "test-storybook:ci": "npx concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"npx http-server storybook-static -p 6006 -s\" \"npx wait-on http://127.0.0.1:6006 && npx @storybook/test-runner\""
  }
}

Update the CI workflow:

name: Storybook Build and Test

on:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  storybook:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v3
        with:
          node-version: '18'
          cache: 'npm'
      - name: Install dependencies
        run: npm ci
      - name: Install Playwright
        run: npx playwright install --with-deps chromium
      - name: Build Storybook
        run: npm run build-storybook
      - name: Install additional packages for CI
        run: npm install --no-save concurrently http-server wait-on
      - name: Storybook smoke tests
        run: npm run test-storybook:ci

The key changes:

  1. Remove the --index-json flag from the test script
  2. Use concurrently to serve the static build and run tests simultaneously
  3. Use wait-on to ensure the server is ready before running tests
  4. Install the required packages (concurrently, http-server, wait-on) in CI

This approach:

  • ✅ Works with static builds (no need for storybook dev)
  • ✅ Runs tests against the actual built output
  • ✅ Automatically manages the server lifecycle
  • ✅ Is reliable in CI environments

Would you like me to create a shell script to test this approach before you update your files?

@coderabbitai , give me a prompt for AI agents

Copy link
Contributor

coderabbitai bot commented Sep 13, 2025

Tip

For best results, initiate chat on the files or code changes.

@kotAPI Here's a comprehensive prompt you can use with AI agents for similar CI/testing troubleshooting scenarios:


AI Agent Prompt for CI/Testing Issue Resolution

You are an expert DevOps engineer and CI/CD specialist. I need help troubleshooting and fixing a CI pipeline issue.

**Context:**
I'm working on a [TECHNOLOGY STACK] project with [TESTING FRAMEWORK] and experiencing failures in my CI pipeline.

**Current Issue:**
[DESCRIBE THE SPECIFIC ERROR/FAILURE]

**What I've tried:**
[LIST ANY ATTEMPTS MADE]

**Requirements for your response:**
1. **Systematic Analysis**: Examine the error message and identify the root cause
2. **Step-by-step Debugging**: Provide commands to investigate the issue further if needed
3. **Multiple Solutions**: Offer at least 2-3 different approaches (quick fix, proper fix, alternative approach)
4. **CI-Specific Considerations**: Account for CI environment constraints (no interactive processes, limited resources, etc.)
5. **Prevention**: Suggest how to prevent similar issues in the future
6. **Code Examples**: Provide complete, copy-pasteable configuration files and scripts
7. **Testing Strategy**: Include ways to verify the fix works locally before pushing to CI

**My current setup:**
- CI Platform: [GitHub Actions/GitLab CI/etc.]
- Node.js version: [VERSION]
- Testing framework: [FRAMEWORK]
- Build tools: [LIST TOOLS]

Please be thorough but concise, and prioritize solutions that work reliably in automated CI environments.

For your specific Storybook case, the filled version would be:

You are an expert DevOps engineer and CI/CD specialist. I need help troubleshooting and fixing a CI pipeline issue.

**Context:**
I'm working on a React component library with Storybook and experiencing failures when trying to run automated smoke tests in GitHub Actions.

**Current Issue:**
The Storybook test runner fails with "It seems that your Storybook instance is not running at: http://127.0.0.1:6006" despite using the --index-json flag to test against a static build.

**Requirements for your response:**
[Same as above]

**My current setup:**
- CI Platform: GitHub Actions
- Node.js version: 18
- Testing framework: @storybook/test-runner with Playwright
- Build tools: Storybook CLI, npm

Please be thorough but concise, and prioritize solutions that work reliably in automated CI environments.

This prompt structure works well because it:

  • Sets clear expectations for the AI's expertise level
  • Provides structured context
  • Asks for multiple solution approaches
  • Emphasizes CI-specific requirements
  • Requests actionable, testable solutions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TEST] Repo: Storybook smoke test CI
1 participant