Files
coredns-web-ui/e2e/harness/reporter.ts
T
bryanpedini 57a005c19f test(e2e): add playwright harness and test stack
- test(e2e): add playwright harness and test stack
- test(e2e): add core flow
- fix(ui): preserve same-origin browser form submissions
- fix(ui): offer reload inside stale edit dialogs
- test(e2e): add persona session and accessibility suites
- test(e2e): preserve per-run artifacts and clean pulled images
- test(e2e): verify import and audit state across navigation
- test(e2e): tighten verification helpers and persona checks
- test(e2e): bound response body reads of the browser observer
- test: recover review compatibility assertions
- test: stabilize audit and user flow assertions
2026-11-19 15:46:12 +01:00

62 lines
2.2 KiB
TypeScript

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2026 Bryan Joshua Pedini
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import type { FullConfig, Reporter, TestCase, TestError, TestResult, TestStep } from '@playwright/test/reporter';
import { loadPersistedSecrets, redactText } from './secrets';
const TEXTUAL = /^(text\/|application\/(json|xml|x-ndjson))|markdown/;
function secretsDirectory(): string | null {
const project = process.env.E2E_PROJECT;
if (!project) return null;
return path.join(os.tmpdir(), `${project}-run`, 'secrets');
}
export default class RedactingReporter implements Reporter {
private outputDirs: string[] = [];
printsToStdio(): boolean {
return false;
}
onBegin(config: FullConfig): void {
this.outputDirs = config.projects.map((p) => path.resolve(p.outputDir));
}
onTestEnd(_test: TestCase, result: TestResult): void {
const dir = secretsDirectory();
const secrets = dir ? loadPersistedSecrets(dir) : [];
const r = (s: string) => redactText(s, secrets);
const fixError = (e: TestError | undefined) => {
if (!e) return;
if (e.message) e.message = r(e.message);
if (e.stack) e.stack = r(e.stack);
if (e.value) e.value = r(e.value);
if (e.snippet) e.snippet = r(e.snippet);
if (e.cause) fixError(e.cause);
};
result.errors.forEach(fixError);
fixError(result.error);
const fixStep = (s: TestStep) => {
fixError(s.error);
s.title = r(s.title);
s.steps.forEach(fixStep);
};
result.steps.forEach(fixStep);
result.stdout = result.stdout.map((c) => (typeof c === 'string' ? r(c) : Buffer.from(r(c.toString('utf8')))));
result.stderr = result.stderr.map((c) => (typeof c === 'string' ? r(c) : Buffer.from(r(c.toString('utf8')))));
for (const a of result.attachments) {
if (!TEXTUAL.test(a.contentType)) continue;
if (a.body) a.body = Buffer.from(r(a.body.toString('utf8')));
if (a.path && this.outputDirs.some((d) => path.resolve(a.path as string).startsWith(d + path.sep)) && fs.existsSync(a.path)) {
const text = fs.readFileSync(a.path, 'utf8');
const red = r(text);
if (red !== text) fs.writeFileSync(a.path, red);
}
}
}
}