Local Testing Workflow
This guide covers the local development testing workflow for fast iteration and debugging.
Quick Start
Section titled “Quick Start”# Terminal 1: Start your main appnpm run dev
# Terminal 2: Start Storybooknpm run storybook
# Terminal 3: Start unit tests in watch modenpm 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:runningTesting Scripts Overview
Section titled “Testing Scripts Overview”Unit Tests (Fast)
Section titled “Unit Tests (Fast)”| Command | Description | Use Case |
|---|---|---|
npm run test:unit:watch | Watch mode for unit tests | Development |
npm run test:unit | Run unit tests once | CI/verification |
npm run test:ui | Interactive test UI | Debugging |
npm run test:coverage | Run with coverage | Local verification |
npm run test | Run all tests once | Quick verification |
Storybook Tests (Comprehensive)
Section titled “Storybook Tests (Comprehensive)”| Command | Description | Use Case |
|---|---|---|
npm run test:storybook | Interactive mode with Storybook UI | Development |
npm run test-storybook | Run once (headless) | CI/verification |
npm run test:storybook:watch | Watch mode for stories | Storybook development |
npm run test:storybook:running | Test against live server | Manual testing |
Combined Workflows
Section titled “Combined Workflows”| Command | Description | Use Case |
|---|---|---|
npm run test:all | Unit + Storybook tests | Full verification |
npm run test:dev | Alias for unit watch mode | Development |
Development Workflows
Section titled “Development Workflows”1. Component Development Flow
Section titled “1. Component Development Flow”# Terminal 1: Start your main appnpm run dev
# Terminal 2: Start Storybooknpm run storybook
# Terminal 3: Start tests in watch modenpm run test:dev
# Terminal 4: Run Storybook tests (when needed)npm run test:storybook:running2. Test-Driven Development
Section titled “2. Test-Driven Development”# Run specific test file while developingnpm run test:file src/components/tooltip/tooltip.spec.tsx
# Or test by patternnpm run test -- --testNamePattern="tooltip"3. Pre-Commit Workflow
Section titled “3. Pre-Commit Workflow”# Quick verification before committingnpm run test:unit && npm run lint
# Full test suitenpm run test:all4. Debugging Failing Tests
Section titled “4. Debugging Failing Tests”# Use the interactive UI for debuggingnpm run test:ui
# Run with verbose outputnpm run test:file src/path/to/failing.spec.tsLocal vs CI Testing
Section titled “Local vs CI Testing”Local Development (Fast Iteration)
Section titled “Local Development (Fast Iteration)”- Unit Tests: Run in Node.js with jsdom (fast)
- Storybook: Build static + serve locally
- Focus: Quick feedback, debugging, component development
CI Testing (Production-Like)
Section titled “CI Testing (Production-Like)”- Unit Tests: Docker Alpine container
- Storybook: Docker Playwright container
- Focus: Production environment simulation, comprehensive coverage
File Structure
Section titled “File Structure”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 utilitiesTest Types & When to Use
Section titled “Test Types & When to Use”Unit Tests (.spec.ts/.spec.tsx)
Section titled “Unit Tests (.spec.ts/.spec.tsx)”✅ Use for:
- Pure functions
- Component logic
- Data transformations
- Edge cases
- Fast feedback loops
# Watch specific component testsnpm run test -- src/components/tooltipStorybook Tests (.stories.tsx)
Section titled “Storybook Tests (.stories.tsx)”✅ Use for:
- Visual regression
- Accessibility testing
- Component interactions
- Integration scenarios
- Cross-browser testing
# Test specific storynpm run test:storybook -- --testNamePattern="Tooltip"Debugging Tips
Section titled “Debugging Tips”Unit Test Debugging
Section titled “Unit Test Debugging”// Add debug info to failing testsimport { 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();});Storybook Test Debugging
Section titled “Storybook Test Debugging”# Run Storybook tests with browser visiblenpm run test:storybook -- --no-headless
# Debug specific accessibility failuresnpm run test:storybook -- --testNamePattern="a11y" --verboseVS Code Integration
Section titled “VS Code Integration”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" } ]}Performance Optimization
Section titled “Performance Optimization”Speed Up Unit Tests
Section titled “Speed Up Unit Tests”# Skip coverage for faster feedbacknpm run test:dev
# Run only changed filesnpm run test:changed
# Test specific patternsnpm run test -- --testNamePattern="utils"Speed Up Storybook Tests
Section titled “Speed Up Storybook Tests”# Keep Storybook dev server running# Terminal 1:npm run storybook
# Terminal 2:npm run test:storybook:watchCommon Issues & Solutions
Section titled “Common Issues & Solutions””Playwright not found” (Only for Storybook testing)
Section titled “”Playwright not found” (Only for Storybook testing)”npx playwright installNote: This is only needed if you want to run Storybook accessibility tests locally. Unit tests don’t require Playwright.
”Port 6006 already in use"
Section titled “”Port 6006 already in use"”# Kill existing Storybookpkill -f "storybook"# Or use different portnpm run storybook -- --port 6007"Tests timing out"
Section titled “"Tests timing out"”# Increase timeout for slow testsnpm run test -- --testTimeout=10000"Coverage reports not generated”
Section titled “"Coverage reports not generated””# Clean and regeneraterm -rf coverage/npm run test:coverageIntegration with Git Hooks
Section titled “Integration with Git Hooks”Add to .husky/pre-commit:
#!/usr/bin/env sh. "$(dirname -- "$0")/_/husky.sh"
# Run quick tests before commitnpm run test:unit && npm run lintBest Practices
Section titled “Best Practices”- Use watch mode during development for instant feedback
- Start with unit tests for component logic
- Add Storybook tests for interactions and accessibility
- Run full test suite before pushing
- Debug with test UI when tests fail
- Keep tests close to code for easy maintenance