Files
leptos-shadcn-ui/playwright.config.ts
Peter Hanssens c3759fb019 feat: Complete Phase 2 Infrastructure Implementation
🏗️ MAJOR MILESTONE: Phase 2 Infrastructure Complete

This commit delivers a comprehensive, production-ready infrastructure system
for leptos-shadcn-ui with full automation, testing, and monitoring capabilities.

## 🎯 Infrastructure Components Delivered

### 1. WASM Browser Testing 
- Cross-browser WASM compatibility testing (Chrome, Firefox, Safari, Mobile)
- Performance monitoring with initialization time, memory usage, interaction latency
- Memory leak detection and pressure testing
- Automated error handling and recovery
- Bundle analysis and optimization recommendations
- Comprehensive reporting (HTML, JSON, Markdown)

### 2. E2E Test Integration 
- Enhanced Playwright configuration with CI/CD integration
- Multi-browser testing with automated execution
- Performance regression testing and monitoring
- Comprehensive reporting with artifact management
- Environment detection (CI vs local)
- GitHub Actions workflow with notifications

### 3. Performance Benchmarking 
- Automated regression testing with baseline comparison
- Real-time performance monitoring with configurable intervals
- Multi-channel alerting (console, file, webhook, email)
- Performance trend analysis and prediction
- CLI benchmarking tools and automated monitoring
- Baseline management and optimization recommendations

### 4. Accessibility Automation 
- WCAG compliance testing (A, AA, AAA levels)
- Comprehensive accessibility audit automation
- Screen reader support and keyboard navigation testing
- Color contrast and focus management validation
- Custom accessibility rules and violation detection
- Component-specific accessibility testing

## 🚀 Key Features

- **Production Ready**: All systems ready for immediate production use
- **CI/CD Integration**: Complete GitHub Actions workflow
- **Automated Monitoring**: Real-time performance and accessibility monitoring
- **Cross-Browser Support**: Chrome, Firefox, Safari, Mobile Chrome, Mobile Safari
- **Comprehensive Reporting**: Multiple output formats with detailed analytics
- **Error Recovery**: Graceful failure handling and recovery mechanisms

## 📁 Files Added/Modified

### New Infrastructure Files
- tests/e2e/wasm-browser-testing.spec.ts
- tests/e2e/wasm-performance-monitor.ts
- tests/e2e/wasm-test-config.ts
- tests/e2e/e2e-test-runner.ts
- tests/e2e/accessibility-automation.ts
- tests/e2e/accessibility-enhanced.spec.ts
- performance-audit/src/regression_testing.rs
- performance-audit/src/automated_monitoring.rs
- performance-audit/src/bin/performance-benchmark.rs
- scripts/run-wasm-tests.sh
- scripts/run-performance-benchmarks.sh
- scripts/run-accessibility-audit.sh
- .github/workflows/e2e-tests.yml
- playwright.config.ts

### Enhanced Configuration
- Enhanced Makefile with comprehensive infrastructure commands
- Enhanced global setup and teardown for E2E tests
- Performance audit system integration

### Documentation
- docs/infrastructure/PHASE2_INFRASTRUCTURE_GUIDE.md
- docs/infrastructure/INFRASTRUCTURE_SETUP_GUIDE.md
- docs/infrastructure/PHASE2_COMPLETION_SUMMARY.md
- docs/testing/WASM_TESTING_GUIDE.md

## 🎯 Usage

### Quick Start
```bash
# Run all infrastructure tests
make test

# Run WASM browser tests
make test-wasm

# Run E2E tests
make test-e2e-enhanced

# Run performance benchmarks
make benchmark

# Run accessibility audit
make accessibility-audit
```

### Advanced Usage
```bash
# Run tests on specific browsers
make test-wasm-browsers BROWSERS=chromium,firefox

# Run with specific WCAG level
make accessibility-audit-wcag LEVEL=AAA

# Run performance regression tests
make regression-test

# Start automated monitoring
make performance-monitor
```

## 📊 Performance Metrics

- **WASM Initialization**: <5s (Chrome) to <10s (Mobile Safari)
- **First Paint**: <3s (Chrome) to <5s (Mobile Safari)
- **Interaction Latency**: <100ms average
- **Memory Usage**: <50% increase during operations
- **WCAG Compliance**: AA level with AAA support

## 🎉 Impact

This infrastructure provides:
- **Reliable Component Development**: Comprehensive testing and validation
- **Performance Excellence**: Automated performance monitoring and optimization
- **Accessibility Compliance**: WCAG compliance validation and reporting
- **Production Deployment**: CI/CD integration with automated testing

## 🚀 Next Steps

Ready for Phase 3: Component Completion
- Complete remaining 41 components using established patterns
- Leverage infrastructure for comprehensive testing
- Ensure production-ready quality across all components

**Status**:  PHASE 2 COMPLETE - READY FOR PRODUCTION

Closes: Phase 2 Infrastructure Implementation
Related: #infrastructure #testing #automation #ci-cd
2025-09-20 12:31:11 +10:00

264 lines
6.4 KiB
TypeScript

import { defineConfig, devices } from '@playwright/test';
/**
* Enhanced Playwright Configuration for leptos-shadcn-ui
*
* This configuration provides comprehensive E2E testing with CI/CD integration,
* performance monitoring, and cross-browser compatibility testing.
*/
// Environment-based configuration
const isCI = !!process.env.CI;
const isDebug = !!process.env.DEBUG;
const isHeadless = process.env.HEADLESS !== 'false';
// Performance thresholds
const PERFORMANCE_THRESHOLDS = {
maxInitializationTime: parseInt(process.env.MAX_INIT_TIME || '5000'),
maxFirstPaint: parseInt(process.env.MAX_FIRST_PAINT || '3000'),
maxFirstContentfulPaint: parseInt(process.env.MAX_FCP || '4000'),
maxInteractionLatency: parseInt(process.env.MAX_INTERACTION_LATENCY || '100'),
};
// Browser-specific configurations
const browserConfigs = {
chromium: {
timeout: 30000,
retries: isCI ? 2 : 0,
headless: isHeadless,
},
firefox: {
timeout: 35000,
retries: isCI ? 2 : 0,
headless: isHeadless,
},
webkit: {
timeout: 40000,
retries: isCI ? 3 : 0,
headless: isHeadless,
},
'Mobile Chrome': {
timeout: 45000,
retries: isCI ? 2 : 0,
headless: isHeadless,
},
'Mobile Safari': {
timeout: 50000,
retries: isCI ? 3 : 0,
headless: isHeadless,
},
};
export default defineConfig({
testDir: './tests/e2e',
/* Run tests in files in parallel */
fullyParallel: !isDebug,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: isCI,
/* Retry on CI only */
retries: isCI ? 2 : 0,
/* Opt out of parallel tests on CI or debug mode. */
workers: isCI ? 1 : isDebug ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [
// HTML reporter for local development
['html', {
open: isDebug ? 'always' : 'never',
outputFolder: 'test-results/html-report'
}],
// JSON reporter for CI/CD integration
['json', {
outputFile: 'test-results/results.json'
}],
// JUnit reporter for CI/CD systems
['junit', {
outputFile: 'test-results/results.xml'
}],
// Line reporter for CI
...(isCI ? [['line']] : []),
// List reporter for debug mode
...(isDebug ? [['list']] : []),
],
/* Shared settings for all the projects below. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.BASE_URL || 'http://localhost:8082',
/* Collect trace when retrying the failed test. */
trace: isCI ? 'on-first-retry' : 'retain-on-failure',
/* Take screenshot on failure */
screenshot: 'only-on-failure',
/* Record video on failure */
video: isCI ? 'retain-on-failure' : 'retain-on-failure',
/* Global test timeout */
actionTimeout: 10000,
navigationTimeout: 30000,
/* Ignore HTTPS errors */
ignoreHTTPSErrors: true,
/* Extra HTTP headers */
extraHTTPHeaders: {
'Accept-Language': 'en-US,en;q=0.9',
},
/* Viewport size */
viewport: { width: 1280, height: 720 },
/* User agent */
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
},
/* Configure projects for major browsers */
projects: [
// Desktop browsers
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
...browserConfigs.chromium,
},
},
{
name: 'firefox',
use: {
...devices['Desktop Firefox'],
...browserConfigs.firefox,
},
},
{
name: 'webkit',
use: {
...devices['Desktop Safari'],
...browserConfigs.webkit,
},
},
// Mobile browsers
{
name: 'Mobile Chrome',
use: {
...devices['Pixel 5'],
...browserConfigs['Mobile Chrome'],
},
},
{
name: 'Mobile Safari',
use: {
...devices['iPhone 12'],
...browserConfigs['Mobile Safari'],
},
},
// Test-specific projects
{
name: 'accessibility-tests',
testMatch: '**/accessibility*.spec.ts',
use: {
...devices['Desktop Chrome'],
...browserConfigs.chromium,
},
},
{
name: 'performance-tests',
testMatch: '**/performance*.spec.ts',
use: {
...devices['Desktop Chrome'],
...browserConfigs.chromium,
},
},
{
name: 'wasm-tests',
testMatch: '**/wasm*.spec.ts',
use: {
...devices['Desktop Chrome'],
...browserConfigs.chromium,
},
},
],
/* Run your local dev server before starting the tests */
webServer: [
{
command: 'cd examples/leptos && trunk serve --port 8082',
port: 8082,
reuseExistingServer: !isCI,
timeout: 120 * 1000,
stdout: 'pipe',
stderr: 'pipe',
},
// Additional server for WASM tests
{
command: 'cd minimal-wasm-test && python3 -m http.server 8083',
port: 8083,
reuseExistingServer: !isCI,
timeout: 30 * 1000,
stdout: 'pipe',
stderr: 'pipe',
},
],
/* Global setup and teardown */
globalSetup: require.resolve('./tests/e2e/global-setup.ts'),
globalTeardown: require.resolve('./tests/e2e/global-teardown.ts'),
/* Test timeout */
timeout: 30 * 1000,
expect: {
timeout: 5 * 1000,
},
/* Output directory for test artifacts */
outputDir: 'test-results/',
/* Global test timeout */
globalTimeout: isCI ? 60 * 60 * 1000 : 30 * 60 * 1000, // 1 hour in CI, 30 minutes locally
/* Maximum number of test failures */
maxFailures: isCI ? 10 : undefined,
/* Update snapshots */
updateSnapshots: process.env.UPDATE_SNAPSHOTS === 'true',
/* Ignore test files */
testIgnore: [
'**/node_modules/**',
'**/dist/**',
'**/build/**',
'**/.git/**',
],
/* Test match patterns */
testMatch: [
'**/*.spec.ts',
'**/*.test.ts',
],
/* Metadata for test results */
metadata: {
testEnvironment: isCI ? 'ci' : 'local',
browserVersions: {
chromium: process.env.CHROMIUM_VERSION || 'latest',
firefox: process.env.FIREFOX_VERSION || 'latest',
webkit: process.env.WEBKIT_VERSION || 'latest',
},
performanceThresholds: PERFORMANCE_THRESHOLDS,
},
});
// Export configuration for use in other files
export { PERFORMANCE_THRESHOLDS, browserConfigs };