Files
engine/e2e/global-setup.ts
luzhuang c50e4f2a18 Migrate e2e testing from Cypress to Playwright (#2746)
* refactor: migrate e2e testing from Cypress to Playwright
2025-07-08 14:38:49 +08:00

68 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import * as fs from "fs-extra";
import * as path from "path";
// Wait for server to be ready
async function waitForServer(url: string, timeout: number = 120000): Promise<void> {
const startTime = Date.now();
console.log(`⏳ Waiting for server at ${url}...`);
while (Date.now() - startTime < timeout) {
try {
const response = await fetch(url);
if (response.ok) {
console.log(`✅ Server is ready at ${url}`);
return;
}
} catch (error) {
// Server not ready yet, continue waiting
}
// Wait 1 second before next attempt
await new Promise((resolve) => setTimeout(resolve, 100));
}
throw new Error(`❌ Server at ${url} did not start within ${timeout}ms`);
}
export default async function globalSetup() {
console.log("🚀 Galacean Engine E2E Test Setup");
console.log("📁 Cleaning downloads directory...");
// Clean downloads directory before tests
const downloadsPath = path.join(process.cwd(), "e2e/downloads");
if (fs.existsSync(downloadsPath)) {
const files = fs.readdirSync(downloadsPath);
fs.emptyDirSync(downloadsPath);
console.log(` ✅ Cleaned ${files.length} files from e2e/downloads`);
} else {
console.log(" Downloads directory is empty");
}
// Count test cases from config
let testCount = 0;
try {
const configPath = path.join(process.cwd(), "e2e/config.ts");
if (fs.existsSync(configPath)) {
const { E2E_CONFIG } = require(configPath);
testCount = Object.values(E2E_CONFIG).reduce((total: number, category: any) => {
return total + Object.keys(category).length;
}, 0) as number;
console.log(`🧪 Found ${testCount} test cases`);
}
} catch (error) {
console.log("⚠️ Could not read test configuration");
}
// Check baseline images
const baselineDir = path.join(process.cwd(), "e2e/fixtures/originImage");
if (fs.existsSync(baselineDir)) {
const baselineFiles = fs.readdirSync(baselineDir).filter((f) => f.endsWith(".jpg"));
console.log(`📸 Found ${baselineFiles.length} baseline images`);
}
// Wait for server to be ready
await waitForServer("http://localhost:5175");
console.log("🎬 Ready to run visual regression tests!\n");
}