Skip to content

Commit 8da6ee1

Browse files
authored
Merge pull request #19523 from mozilla/feat/include-test-time-functional-reporter
chore(functional-tests): Add test duration to ci reporter
2 parents 61ba593 + 90d8f71 commit 8da6ee1

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

packages/functional-tests/lib/ci-reporter.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,29 @@ import {
1313
TestResult,
1414
} from '@playwright/test/reporter';
1515

16+
/**
17+
* Converts milliseconds to human-readable format
18+
* If the time is less than 1 second, it shows milliseconds
19+
* If the time is less than 1 minute, it shows seconds
20+
* And if over 1 minute, it shows minutes and seconds
21+
* @param ms
22+
*/
23+
const formatTime = (ms: number) => {
24+
// protect against bad input so we don't crash the reporter
25+
if (ms === undefined || ms === null || isNaN(ms) || ms < 0) {
26+
return 'unknown';
27+
}
28+
if (ms < 1000) {
29+
return `${ms}ms`;
30+
}
31+
const seconds = Math.floor(ms / 1000);
32+
if (seconds < 60) {
33+
return `${seconds}s`;
34+
}
35+
const minutes = Math.floor(seconds / 60);
36+
return `${minutes}m${seconds % 60}s`;
37+
};
38+
1639
class CIReporter implements Reporter {
1740
private fixmeCount = 0;
1841
private passCount = 0;
@@ -48,7 +71,7 @@ class CIReporter implements Reporter {
4871
console.log(
4972
`${status} ${path.relative(process.cwd(), test.location.file)}: ${
5073
test.title
51-
}`
74+
} (${formatTime(result.duration)})`
5275
);
5376
if (test.outcome() === 'unexpected') {
5477
console.log(result.error?.stack);

0 commit comments

Comments
 (0)