- Replace __dirname with import.meta.url pattern for ES modules compatibility - Add fileURLToPath imports to all E2E test files - Fix duplicate require statements in setup-verification.spec.ts - Update playwright.config.ts to use relative path instead of __dirname This fixes the 'ReferenceError: __dirname is not defined in ES module scope' error when running Playwright tests in the ES modules environment.
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
/**
|
|
* Global Setup for Playwright E2E Tests
|
|
*
|
|
* This runs once before all test suites.
|
|
* Used for:
|
|
* - Database seeding
|
|
* - Test environment preparation
|
|
* - Creating test data
|
|
*/
|
|
|
|
import { execSync } from 'child_process';
|
|
import path from 'path';
|
|
import fs from 'fs';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
async function globalSetup() {
|
|
console.log('🚀 Starting E2E test setup...');
|
|
|
|
// Ensure test data directories exist
|
|
const testDataDir = path.join(__dirname, 'fixtures');
|
|
if (!fs.existsSync(testDataDir)) {
|
|
fs.mkdirSync(testDataDir, { recursive: true });
|
|
}
|
|
|
|
// Ensure screenshots directory exists
|
|
const screenshotsDir = path.join(__dirname, 'screenshots');
|
|
if (!fs.existsSync(screenshotsDir)) {
|
|
fs.mkdirSync(screenshotsDir, { recursive: true });
|
|
}
|
|
|
|
// Ensure baseline directory exists for visual regression
|
|
const baselineDir = path.join(screenshotsDir, 'baseline');
|
|
if (!fs.existsSync(baselineDir)) {
|
|
fs.mkdirSync(baselineDir, { recursive: true });
|
|
}
|
|
|
|
// Store test start time for cleanup tracking
|
|
const testStartTime = new Date().toISOString();
|
|
process.env.TEST_START_TIME = testStartTime;
|
|
|
|
console.log('✅ E2E test setup complete');
|
|
console.log(` Test started at: ${testStartTime}`);
|
|
}
|
|
|
|
export default globalSetup;
|