Skip to content

Local Testing Workflow

This guide covers the local development testing workflow for fast iteration and debugging.

Terminal window
# Terminal 1: Start your main app
npm run dev
# Terminal 2: Start Storybook
npm run storybook
# Terminal 3: Start unit tests in watch mode
npm run test:dev
# Optional: Install Playwright browsers (only needed for Storybook testing)
npx playwright install
# Terminal 4: Test Storybook against running server (requires Playwright)
npm run test:storybook:running
CommandDescriptionUse Case
npm run test:unit:watchWatch mode for unit testsDevelopment
npm run test:unitRun unit tests onceCI/verification
npm run test:uiInteractive test UIDebugging
npm run test:coverageRun with coverageLocal verification
npm run testRun all tests onceQuick verification
CommandDescriptionUse Case
npm run test:storybookInteractive mode with Storybook UIDevelopment
npm run test-storybookRun once (headless)CI/verification
npm run test:storybook:watchWatch mode for storiesStorybook development
npm run test:storybook:runningTest against live serverManual testing
CommandDescriptionUse Case
npm run test:allUnit + Storybook testsFull verification
npm run test:devAlias for unit watch modeDevelopment
Terminal window
# Terminal 1: Start your main app
npm run dev
# Terminal 2: Start Storybook
npm run storybook
# Terminal 3: Start tests in watch mode
npm run test:dev
# Terminal 4: Run Storybook tests (when needed)
npm run test:storybook:running
Terminal window
# Run specific test file while developing
npm run test:file src/components/tooltip/tooltip.spec.tsx
# Or test by pattern
npm run test -- --testNamePattern="tooltip"
Terminal window
# Quick verification before committing
npm run test:unit && npm run lint
# Full test suite
npm run test:all
Terminal window
# Use the interactive UI for debugging
npm run test:ui
# Run with verbose output
npm run test:file src/path/to/failing.spec.ts
  • Unit Tests: Run in Node.js with jsdom (fast)
  • Storybook: Build static + serve locally
  • Focus: Quick feedback, debugging, component development
  • Unit Tests: Docker Alpine container
  • Storybook: Docker Playwright container
  • Focus: Production environment simulation, comprehensive coverage
src/
├── components/
│ └── tooltip/
│ ├── tooltip.tsx # Component
│ ├── tooltip.spec.tsx # Unit tests
│ └── tooltip.stories.tsx # Storybook tests
├── utils/
│ └── format/
│ ├── formatDate.ts # Utility
│ └── formatDate.spec.ts # Unit tests
└── test/
└── test-utils.tsx # Shared test utilities

Use for:

  • Pure functions
  • Component logic
  • Data transformations
  • Edge cases
  • Fast feedback loops
Terminal window
# Watch specific component tests
npm run test -- src/components/tooltip

Use for:

  • Visual regression
  • Accessibility testing
  • Component interactions
  • Integration scenarios
  • Cross-browser testing
Terminal window
# Test specific story
npm run test:storybook -- --testNamePattern="Tooltip"
// Add debug info to failing tests
import { screen, debug } from '@testing-library/solid';
it('should render correctly', () => {
render(() => <Tooltip content="Test" />);
// Debug the DOM when tests fail
debug();
expect(screen.getByText('Test')).toBeInTheDocument();
});
Terminal window
# Run Storybook tests with browser visible
npm run test:storybook -- --no-headless
# Debug specific accessibility failures
npm run test:storybook -- --testNamePattern="a11y" --verbose

Add to your .vscode/launch.json:

{
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Unit Tests",
"program": "${workspaceFolder}/node_modules/vitest/vitest.mjs",
"args": ["run", "--reporter=verbose"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
Terminal window
# Skip coverage for faster feedback
npm run test:dev
# Run only changed files
npm run test:changed
# Test specific patterns
npm run test -- --testNamePattern="utils"
Terminal window
# Keep Storybook dev server running
# Terminal 1:
npm run storybook
# Terminal 2:
npm run test:storybook:watch

”Playwright not found” (Only for Storybook testing)

Section titled “”Playwright not found” (Only for Storybook testing)”
Terminal window
npx playwright install

Note: This is only needed if you want to run Storybook accessibility tests locally. Unit tests don’t require Playwright.

Terminal window
# Kill existing Storybook
pkill -f "storybook"
# Or use different port
npm run storybook -- --port 6007
Terminal window
# Increase timeout for slow tests
npm run test -- --testTimeout=10000
Terminal window
# Clean and regenerate
rm -rf coverage/
npm run test:coverage

Add to .husky/pre-commit:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
# Run quick tests before commit
npm run test:unit && npm run lint
  1. Use watch mode during development for instant feedback
  2. Start with unit tests for component logic
  3. Add Storybook tests for interactions and accessibility
  4. Run full test suite before pushing
  5. Debug with test UI when tests fail
  6. Keep tests close to code for easy maintenance