2025-12-14 13:28:43 +01:00
|
|
|
import * as fs from 'fs';
|
|
|
|
|
import * as path from 'path';
|
|
|
|
|
|
2025-12-27 16:35:40 +01:00
|
|
|
/**
|
|
|
|
|
* Recursively clean all files in a directory (keeps directory structure).
|
|
|
|
|
*/
|
|
|
|
|
function cleanDirectory(dir: string): number {
|
|
|
|
|
let count = 0;
|
|
|
|
|
if (!fs.existsSync(dir)) return count;
|
|
|
|
|
|
|
|
|
|
for (const entry of fs.readdirSync(dir)) {
|
|
|
|
|
const fullPath = path.join(dir, entry);
|
|
|
|
|
const stat = fs.statSync(fullPath);
|
|
|
|
|
if (stat.isFile()) {
|
|
|
|
|
fs.unlinkSync(fullPath);
|
|
|
|
|
count++;
|
|
|
|
|
} else if (stat.isDirectory()) {
|
|
|
|
|
count += cleanDirectory(fullPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-14 13:28:43 +01:00
|
|
|
/**
|
|
|
|
|
* Global setup for Playwright tests.
|
2025-12-27 16:35:40 +01:00
|
|
|
* Cleans the logs directory (and subdirectories) before each test run.
|
2025-12-14 13:28:43 +01:00
|
|
|
*/
|
|
|
|
|
export default async function globalSetup() {
|
|
|
|
|
const logsDir = path.join(__dirname, 'logs');
|
2025-12-27 16:35:40 +01:00
|
|
|
const count = cleanDirectory(logsDir);
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
console.log(`[global-setup] Removed ${count} log files from ${logsDir}`);
|
2025-12-14 13:28:43 +01:00
|
|
|
}
|
|
|
|
|
}
|