Skip to content

Instantly share code, notes, and snippets.

@minhphong306
Created March 25, 2026 14:05
Show Gist options
  • Select an option

  • Save minhphong306/40e36fb92724ed19f90a41f5cbfa7686 to your computer and use it in GitHub Desktop.

Select an option

Save minhphong306/40e36fb92724ed19f90a41f5cbfa7686 to your computer and use it in GitHub Desktop.
import {
FullConfig,
FullResult,
Reporter,
Suite,
TestCase,
TestResult
} from '@playwright/test/reporter';
type TestInfo = {
title: string;
duration: number;
};
class CustomReporter implements Reporter {
private passed: TestInfo[] = [];
private failed: TestInfo[] = [];
private timedOut: TestInfo[] = [];
private flaky: TestInfo[] = [];
onTestEnd(test: TestCase, result: TestResult) {
const info: TestInfo = {
title: test.title,
duration: result.duration
};
switch (result.status) {
case 'passed':
if (test.outcome() === 'flaky') {
this.flaky.push(info);
} else {
this.passed.push(info);
}
break;
case 'failed':
this.failed.push(info);
break;
case 'timedOut':
this.timedOut.push(info);
break;
}
}
onEnd(result: FullResult) {
const total =
this.passed.length +
this.failed.length +
this.timedOut.length +
this.flaky.length;
const percent = (count: number): string =>
total === 0 ? '0' : ((count / total) * 100).toFixed(2);
const printGroup = (title: string, data: TestInfo[], pct: string) => {
console.log(`${title} (${pct}%):`);
data.forEach(t =>
console.log(`- ${t.title} (${t.duration}ms)`)
);
console.log('');
};
console.log(`Tổng số test: ${total}\n`);
printGroup('Passed', this.passed, percent(this.passed.length));
printGroup('Failed cases', this.failed, percent(this.failed.length));
printGroup('Timeout', this.timedOut, percent(this.timedOut.length));
printGroup('Flaky', this.flaky, percent(this.flaky.length));
}
}
export default CustomReporter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment