Test Validation
React Kickstart's QA automation includes comprehensive test validation to ensure that generated projects not only build correctly but also have passing, meaningful tests that validate the application functionality.
Quality Assurance: Test validation goes beyond build verification to ensure generated tests actually work and provide value to developers.
๐ฏ Validation Scope
The test validation system ensures multiple layers of quality:
โ What Gets Validated
Build Validation
- Project builds successfully (
npm run build
) - No compilation errors or warnings
- All dependencies resolve correctly
- TypeScript compilation (when enabled)
Test Validation ๐
- Test scripts execute without errors
- All generated tests pass
- Test frameworks work correctly (Jest/Vitest)
- State management integration tests
- Component rendering tests
- API integration tests (when applicable)
Framework Integration
- Font mocking works for Next.js projects
- Module resolution works correctly
- Asset handling in test environment
- Environment configuration is proper
Linting Validation
- ESLint configuration works (when enabled)
- Code follows style guidelines
- No linting errors in generated code
๐งช Test Categories
Component Unit Tests:
// Example generated test for Counter component
import { render, screen, fireEvent } from '@testing-library/react'
import Counter from '../Counter'
describe('Counter Component', () => {
it('renders with initial count of 0', () => {
render(<Counter />)
expect(screen.getByText('Count: 0')).toBeInTheDocument()
})
it('increments count when increment button is clicked', () => {
render(<Counter />)
const incrementButton = screen.getByText('+')
fireEvent.click(incrementButton)
expect(screen.getByText('Count: 1')).toBeInTheDocument()
})
it('decrements count when decrement button is clicked', () => {
render(<Counter />)
const decrementButton = screen.getByText('-')
fireEvent.click(decrementButton)
expect(screen.getByText('Count: -1')).toBeInTheDocument()
})
})
Validation Checks:
- โ Tests render components without errors
- โ User interactions work correctly
- โ Component state updates properly
- โ Props are handled correctly
๐ Validation Process
Project Generation
Generate test project with specific configuration:
# Example: Generate Vite + TypeScript + Redux + Tailwind project
node bin/react-kickstart.js qa-test-project --yes \
--framework vite \
--typescript \
--state redux \
--styling tailwind \
--testing vitest
Dependency Installation
Install all project dependencies:
cd qa-test-project
npm install
Test Execution
Run the complete test suite:
# Run all tests
npm run test
# Run tests with coverage
npm run test:coverage
# Run linting (if enabled)
npm run lint
Result Analysis
Analyze test results and generate validation report:
// Test validation analysis
const testResults = {
framework: 'vite',
testRunner: 'vitest',
totalTests: 12,
passingTests: 12,
failingTests: 0,
coverage: {
statements: 95.2,
branches: 89.1,
functions: 100,
lines: 94.8
},
performance: {
testDuration: 2.3,
slowestTest: 'API integration test (450ms)'
}
}
Quality Metrics
Evaluate against quality thresholds:
const qualityThresholds = {
testPassRate: 100, // All tests must pass
minCoverage: 80, // Minimum 80% coverage
maxTestDuration: 30, // Tests should complete in 30s
maxSlowTest: 2000, // No single test > 2s
lintingErrors: 0 // Zero linting errors
}
๐ Test Validation Results
Validation Report Structure
{
"testValidation": {
"passed": true,
"summary": {
"totalTests": 15,
"passingTests": 15,
"failingTests": 0,
"testDuration": 2847,
"coverage": {
"statements": 92.5,
"branches": 87.3,
"functions": 95.8,
"lines": 91.2
}
},
"details": {
"unitTests": {
"passed": 8,
"failed": 0,
"tests": [
"Counter component renders correctly",
"Button handles click events",
"Form validation works"
]
},
"integrationTests": {
"passed": 4,
"failed": 0,
"tests": [
"Redux store integration",
"API client integration",
"Router navigation"
]
},
"frameworkTests": {
"passed": 3,
"failed": 0,
"tests": [
"Vite configuration works",
"TypeScript compilation",
"Asset handling"
]
}
},
"performance": {
"fastestTest": "Button component (12ms)",
"slowestTest": "API integration (456ms)",
"averageTestTime": "189ms"
},
"issues": []
}
}
Common Test Issues
Test Environment: Many test failures are due to environment configuration issues rather than actual code problems.
Dependency Issues:
{
"issue": "Missing test dependencies",
"description": "@testing-library/jest-dom not configured",
"solution": "Add to test setup file",
"impact": "Assertions fail unexpectedly"
}
Configuration Issues:
{
"issue": "Jest/Vitest configuration conflict",
"description": "Transform configuration incorrect",
"solution": "Update test configuration for framework",
"impact": "Tests fail to run"
}
Mocking Issues:
{
"issue": "Next.js font mocking missing",
"description": "next/font/google not mocked",
"solution": "Add font mocking to test setup",
"impact": "Next.js tests fail"
}
๐ ๏ธ Test Generation Strategy
Automatic Test Generation
React Kickstart generates meaningful tests based on the selected features:
Generated Component Tests:
// Auto-generated based on components created
describe('App Component', () => {
it('renders welcome message', () => {
render(<App />)
expect(screen.getByText(/welcome to react kickstart/i)).toBeInTheDocument()
})
it('renders navigation when routing enabled', () => {
render(<App />)
expect(screen.getByRole('navigation')).toBeInTheDocument()
})
it('applies correct styling classes', () => {
render(<App />)
const container = screen.getByTestId('app-container')
expect(container).toHaveClass('min-h-screen', 'bg-gray-100')
})
})
Test Quality Standards
Generated tests must meet these criteria:
- โ Meaningful Assertions - Tests verify actual functionality
- โ Proper Setup/Teardown - Clean test environment
- โ Error Scenarios - Test both success and failure cases
- โ Performance Aware - Tests complete quickly
- โ Maintainable - Clear, readable test code
- โ Framework Appropriate - Use correct testing patterns
๐ Continuous Validation
CI/CD Integration
# GitHub Actions workflow for test validation
name: Test Validation
on: [push, pull_request]
jobs:
test-validation:
runs-on: ubuntu-latest
strategy:
matrix:
config:
- { framework: 'vite', state: 'redux', testing: 'vitest' }
- { framework: 'nextjs', state: 'zustand', testing: 'jest' }
- { framework: 'vite', state: 'none', testing: 'vitest' }
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
- name: Generate Test Project
run: |
node bin/react-kickstart.js test-${{ matrix.config.framework }} --yes \
--framework ${{ matrix.config.framework }} \
--state ${{ matrix.config.state }} \
--testing ${{ matrix.config.testing }}
- name: Install Dependencies
run: |
cd test-${{ matrix.config.framework }}
npm ci
- name: Run Tests
run: |
cd test-${{ matrix.config.framework }}
npm run test
- name: Validate Test Results
run: |
cd test-${{ matrix.config.framework }}
# Ensure all tests passed
npm run test -- --reporter=json > test-results.json
PASSED=$(jq '.numPassedTests' test-results.json)
FAILED=$(jq '.numFailedTests' test-results.json)
if [ "$FAILED" -gt 0 ]; then
echo "โ $FAILED tests failed"
exit 1
fi
echo "โ
All $PASSED tests passed"
Quality Metrics Tracking
// Track test quality metrics over time
const testMetrics = {
timestamp: new Date().toISOString(),
configuration: userChoices,
results: {
testPassRate: 100,
coveragePercent: 92.5,
testDuration: 2847,
generatedTestCount: 15,
qualityScore: calculateQualityScore({
passRate: 100,
coverage: 92.5,
performance: 2847,
maintainability: 95
})
}
}
function calculateQualityScore(metrics) {
const weights = {
passRate: 0.4, // 40% - tests must pass
coverage: 0.3, // 30% - good coverage
performance: 0.2, // 20% - reasonable speed
maintainability: 0.1 // 10% - code quality
}
return (
metrics.passRate * weights.passRate +
metrics.coverage * weights.coverage +
(metrics.performance < 5000 ? 100 : 50) * weights.performance +
metrics.maintainability * weights.maintainability
)
}
๐ Next Steps
Explore Related Documentation:
- QA Overview โ - Understanding the QA system architecture
- Reading QA Reports โ - Analyzing test results and reports
- Contributing โ - How to contribute to React Kickstart
Test-Driven Quality: Test validation ensures that React Kickstart not only generates working code but also provides developers with meaningful, passing tests from day one.