Organize test logs into separate directories by test suite and file

- wxWidgets logs: tests/logs/wxwidgets/<test-file>/
- KiCad logs: tests/logs/kicad/<test-file>/
- Global setup now cleans all log subdirectories recursively
- Added globalSetup to KiCad playwright config

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Viktor Vaczi 2025-12-27 16:35:40 +01:00
commit eedfe22654
6 changed files with 88 additions and 31 deletions

View file

@ -1,5 +1,6 @@
import { test as base } from '@playwright/test';
import { setupTestLogger, writeTestLogs, TestLogger, MAIN_CANVAS, waitForApp, tryLoadApp, getCanvasBox } from './test-utils';
import * as path from 'path';
import { setupTestLogger, writeTestLogs, TestLogger, MAIN_CANVAS, waitForApp, tryLoadApp, getCanvasBox, WXWIDGETS_LOGS_DIR, getTestFileName } from './test-utils';
// Extend base test with automatic logging
export const test = base.extend<{
@ -13,8 +14,10 @@ export const test = base.extend<{
await use(logger);
// Write logs after test completes
writeTestLogs(testName, logger);
// Write logs to wxwidgets/<test-file>/ directory
const testFileName = getTestFileName(testInfo.file);
const logsDir = path.join(WXWIDGETS_LOGS_DIR, testFileName);
writeTestLogs(testName, logger, logsDir);
logger.cleanup();
},
});

View file

@ -3,7 +3,9 @@ import * as fs from 'fs';
import * as path from 'path';
export const MAIN_CANVAS = '#canvas';
export const LOGS_DIR = path.join(__dirname, '..', '..', 'logs');
export const LOGS_BASE_DIR = path.join(__dirname, '..', '..', 'logs');
export const WXWIDGETS_LOGS_DIR = path.join(LOGS_BASE_DIR, 'wxwidgets');
export const KICAD_LOGS_DIR = path.join(LOGS_BASE_DIR, 'kicad');
export interface TestLogger {
consoleLogs: string[];
@ -12,9 +14,9 @@ export interface TestLogger {
}
// Ensure logs directory exists
export function ensureLogsDir() {
if (!fs.existsSync(LOGS_DIR)) {
fs.mkdirSync(LOGS_DIR, { recursive: true });
export function ensureLogsDir(dir: string = LOGS_BASE_DIR) {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
}
@ -48,8 +50,11 @@ export function setupTestLogger(page: Page): TestLogger {
}
// Write logs to files after test completion
export function writeTestLogs(testName: string, logger: TestLogger) {
ensureLogsDir();
export function writeTestLogs(testName: string, logger: TestLogger, logsDir: string) {
// Ensure logs directory exists
if (!fs.existsSync(logsDir)) {
fs.mkdirSync(logsDir, { recursive: true });
}
// Sanitize test name for filesystem
const safeTestName = testName
@ -58,17 +63,22 @@ export function writeTestLogs(testName: string, logger: TestLogger) {
.replace(/^-+|-+$/g, '');
// Always write console log file
const logFile = path.join(LOGS_DIR, `${safeTestName}.log`);
const logFile = path.join(logsDir, `${safeTestName}.log`);
fs.writeFileSync(logFile, logger.consoleLogs.join('\n'));
// Only write error file if there are errors (excluding favicon)
const realErrors = logger.errors.filter(e => !e.includes('favicon'));
if (realErrors.length > 0) {
const errorFile = path.join(LOGS_DIR, `${safeTestName}.errors.log`);
const errorFile = path.join(logsDir, `${safeTestName}.errors.log`);
fs.writeFileSync(errorFile, realErrors.join('\n\n'));
}
}
// Helper to get test file name without extension
export function getTestFileName(filePath: string): string {
return path.basename(filePath, '.spec.ts');
}
// Helper to wait for app initialization
export async function waitForApp(page: Page, timeout = 30000) {
await page.waitForSelector(MAIN_CANVAS, { state: 'visible', timeout });