test setup
This commit is contained in:
@@ -1,77 +1,25 @@
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
/**
|
||||
* Playwright configuration for website smoke tests
|
||||
* Playwright configuration for fully containerized e2e testing
|
||||
*
|
||||
* Purpose: Verify all website pages load without runtime errors
|
||||
* Scope: Page rendering, console errors, React hydration
|
||||
* Scope: Page rendering, console errors, React hydration, API integration
|
||||
*
|
||||
* Critical Detection:
|
||||
* - Console errors during page load
|
||||
* - React hydration mismatches
|
||||
* - Navigation failures
|
||||
* - Missing content
|
||||
* - API connectivity issues
|
||||
*
|
||||
* IMPORTANT: This test requires Docker to run against real TypeORM/PostgreSQL
|
||||
* Architecture: Everything runs in Docker
|
||||
* - Website: containerized Next.js (port 3100)
|
||||
* - API: containerized NestJS (port 3101)
|
||||
* - Database: containerized PostgreSQL (port 5434)
|
||||
* - Playwright: containerized test runner
|
||||
*/
|
||||
|
||||
// Enforce Docker usage
|
||||
function validateDockerEnvironment(): void {
|
||||
// Skip validation if explicitly requested (for CI or advanced users)
|
||||
if (process.env.PLAYWRIGHT_SKIP_DOCKER_CHECK === 'true') {
|
||||
console.warn('⚠️ Skipping Docker validation - assuming services are running');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Check if Docker is running
|
||||
execSync('docker info', { stdio: 'pipe' });
|
||||
|
||||
// Check if the required Docker services are running
|
||||
const services = execSync('docker ps --format "{{.Names}}"', { encoding: 'utf8' });
|
||||
|
||||
// Look for services that match our test pattern
|
||||
const testServices = services.split('\n').filter(s => s.includes('gridpilot-test'));
|
||||
|
||||
if (testServices.length === 0) {
|
||||
console.error('❌ No test Docker services found running');
|
||||
console.error('💡 Please run: docker-compose -f docker-compose.test.yml up -d');
|
||||
console.error(' This will start:');
|
||||
console.error(' - PostgreSQL database');
|
||||
console.error(' - API server with TypeORM/PostgreSQL');
|
||||
console.error(' - Website server');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Check for specific required services (website runs locally, not in Docker)
|
||||
const hasApi = testServices.some(s => s.includes('api'));
|
||||
const hasDb = testServices.some(s => s.includes('db'));
|
||||
|
||||
if (!hasApi || !hasDb) {
|
||||
console.error('❌ Missing required Docker services');
|
||||
console.error(' Found:', testServices.join(', '));
|
||||
console.error(' Required: api, db');
|
||||
console.error('💡 Please run: docker-compose -f docker-compose.test.yml up -d');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('✅ Docker environment validated');
|
||||
} catch (error) {
|
||||
console.error('❌ Docker is not available or not running');
|
||||
console.error('💡 Please ensure Docker is installed and running, then run:');
|
||||
console.error(' docker-compose -f docker-compose.test.yml up -d');
|
||||
console.error('');
|
||||
console.error(' Or skip this check with: PLAYWRIGHT_SKIP_DOCKER_CHECK=true npx playwright test');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Run validation before config (unless in CI or explicitly skipped)
|
||||
if (!process.env.CI && !process.env.PLAYWRIGHT_SKIP_DOCKER_CHECK) {
|
||||
validateDockerEnvironment();
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
testDir: './tests/e2e/website',
|
||||
testMatch: ['**/website-pages.test.ts'],
|
||||
@@ -87,9 +35,9 @@ export default defineConfig({
|
||||
// Timeout: Pages should load quickly
|
||||
timeout: 30_000,
|
||||
|
||||
// Base URL for the website (local dev server)
|
||||
// Base URL for the website (containerized)
|
||||
use: {
|
||||
baseURL: process.env.PLAYWRIGHT_BASE_URL || 'http://localhost:3000', // Local website dev server
|
||||
baseURL: process.env.PLAYWRIGHT_BASE_URL || 'http://website:3000',
|
||||
screenshot: 'only-on-failure',
|
||||
video: 'retain-on-failure',
|
||||
trace: 'retain-on-failure',
|
||||
@@ -101,21 +49,11 @@ export default defineConfig({
|
||||
['html', { open: 'never' }]
|
||||
],
|
||||
|
||||
// No retry - smoke tests must pass on first run
|
||||
// No retry - e2e tests must pass on first run
|
||||
retries: 0,
|
||||
|
||||
// Web server configuration
|
||||
// Start local Next.js dev server that connects to Docker API
|
||||
webServer: {
|
||||
command: 'npm run dev -w @gridpilot/website',
|
||||
url: 'http://localhost:3000',
|
||||
timeout: 120_000,
|
||||
reuseExistingServer: !process.env.CI,
|
||||
env: {
|
||||
NEXT_PUBLIC_API_BASE_URL: 'http://localhost:3101',
|
||||
API_BASE_URL: 'http://localhost:3101',
|
||||
},
|
||||
},
|
||||
// No webServer - everything runs in Docker
|
||||
webServer: undefined,
|
||||
|
||||
// Browser projects
|
||||
projects: [
|
||||
|
||||
Reference in New Issue
Block a user