-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathslowStepReporter.ts
More file actions
48 lines (44 loc) · 1.12 KB
/
slowStepReporter.ts
File metadata and controls
48 lines (44 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import type {
Reporter,
TestCase,
TestResult,
TestStep,
} from '@playwright/test/reporter';
class SlowStepReporter implements Reporter {
private steps: Array<{
count: number;
name: string;
location: string | undefined;
duration: number;
}> = [];
onStepEnd(test: TestCase, result: TestResult, step: TestStep) {
if (step.category === 'test.step') {
const stepToReport = {
count: 1,
name: step.titlePath().join('->'),
location: `${step.location?.file}:${step.location?.line}`,
duration: step.duration,
};
const alreadyReported = this.steps.find(
(s) => s.name === stepToReport.name
);
if (alreadyReported) {
alreadyReported.count++;
} else {
this.steps.push(stepToReport);
}
}
}
onEnd() {
console.warn('TOP-10 slowest steps');
console.table(
// Slowest first
this.steps
.sort((a, b) => b.duration - a.duration)
// TOP-10 slowest steps
.slice(0, 10)
);
}
}
export default SlowStepReporter;