phase-7: code restructure
This commit is contained in:
committed by
saikiranvella
parent
c160e65bd6
commit
357b0c0f6e
@@ -1,23 +1,34 @@
|
||||
// Minimal test reporter: silent on pass, prints failures in full, ends with one summary line.
|
||||
export default async function* summaryReporter(source) {
|
||||
const failures = [];
|
||||
import type { TestEvent } from 'node:test/reporters';
|
||||
|
||||
interface Failure {
|
||||
name: string;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export default async function* summaryReporter(
|
||||
source: AsyncIterable<TestEvent>,
|
||||
): AsyncGenerator<string> {
|
||||
const failures: Failure[] = [];
|
||||
let passed = 0,
|
||||
failed = 0,
|
||||
totalMs = 0;
|
||||
|
||||
for await (const event of source) {
|
||||
// Skip file-level wrapper events (name ends in .js) — only count individual tests.
|
||||
if (event.data?.name?.endsWith('.js')) continue;
|
||||
// Skip file-level wrapper events (name ends in .ts) — only count individual tests.
|
||||
if ((event.data as { name?: string })?.name?.endsWith('.ts')) continue;
|
||||
|
||||
if (event.type === 'test:pass') {
|
||||
passed++;
|
||||
totalMs += event.data.details?.duration_ms ?? 0;
|
||||
totalMs += (event.data as { details?: { duration_ms?: number } }).details?.duration_ms ?? 0;
|
||||
} else if (event.type === 'test:fail') {
|
||||
failed++;
|
||||
totalMs += event.data.details?.duration_ms ?? 0;
|
||||
const err = event.data.details?.error;
|
||||
totalMs += (event.data as { details?: { duration_ms?: number } }).details?.duration_ms ?? 0;
|
||||
const err = (
|
||||
event.data as { details?: { error?: { cause?: { message?: string }; message?: string } } }
|
||||
).details?.error;
|
||||
failures.push({
|
||||
name: event.data.name,
|
||||
name: (event.data as { name?: string }).name ?? 'unknown',
|
||||
reason: err?.cause?.message ?? err?.message ?? 'unknown',
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user