38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
// Minimal test reporter: silent on pass, prints failures in full, ends with one summary line.
|
|
export default async function* summaryReporter(source) {
|
|
const failures = [];
|
|
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;
|
|
|
|
if (event.type === 'test:pass') {
|
|
passed++;
|
|
totalMs += event.data.details?.duration_ms ?? 0;
|
|
} else if (event.type === 'test:fail') {
|
|
failed++;
|
|
totalMs += event.data.details?.duration_ms ?? 0;
|
|
const err = event.data.details?.error;
|
|
failures.push({
|
|
name: event.data.name,
|
|
reason: err?.cause?.message ?? err?.message ?? 'unknown',
|
|
});
|
|
}
|
|
}
|
|
|
|
if (failures.length) {
|
|
yield '\nFailed tests:\n';
|
|
for (const f of failures) yield ` ❌ ${f.name}\n ${f.reason}\n`;
|
|
yield '\n';
|
|
}
|
|
|
|
const status = failed === 0 ? '✅' : '❌';
|
|
const time = (totalMs / 1000).toFixed(2);
|
|
yield `${status} ${passed + failed} tests: ${passed} passed`;
|
|
if (failed) yield `, ${failed} failed`;
|
|
yield ` (${time}s)\n`;
|
|
}
|