Skip to content

Commit 48706cf

Browse files
committed
Add start time for test modules
1 parent e5e1ff3 commit 48706cf

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default tseslint.config(
3535
'**/node_modules',
3636
'lib/buildtools/bin',
3737
'lib/buildtools/src/build/__test_mocks__',
38+
'lib/vitest-reporter/build',
3839
'src/**/samples/**',
3940
'src/bundles/scrabble/src/words.json', // Don't lint this because its way too big
4041
'src/java/**',

lib/vitest-reporter/build/test-reporter.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/vitest-reporter/src/test-reporter.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function* formatTestCase(testCase: TestCase) {
77
const diagnostics = testCase.diagnostic();
88
const durationStr = diagnostics ? `${diagnostics.duration.toFixed(0)}ms` : '';
99

10-
yield `${passed ? '✅' : '❌'} ${testCase.name} ${durationStr}\n`;
10+
yield `${passed ? '✅' : '❌'} ${testCase.name} <code>${durationStr}</code>\n`;
1111
}
1212

1313
function* formatTestSuite(suite: TestSuite): Generator<string> {
@@ -48,6 +48,7 @@ function getTestCount(item: TestModule | TestSuite | TestCase): number {
4848
export default class GithubActionsSummaryReporter implements Reporter {
4949
private writeStream: fs.WriteStream | null = null;
5050
private vitest: Vitest | null = null;
51+
private startTimes: Record<string, number> = {};
5152

5253
onInit(vitest: Vitest) {
5354
this.vitest = vitest;
@@ -57,6 +58,10 @@ export default class GithubActionsSummaryReporter implements Reporter {
5758
}
5859
}
5960

61+
onTestModuleStart(module: TestModule) {
62+
this.startTimes[module.id] = performance.now();
63+
}
64+
6065
onTestRunEnd(modules: readonly TestModule[]) {
6166
if (!this.writeStream) return;
6267

@@ -81,12 +86,16 @@ export default class GithubActionsSummaryReporter implements Reporter {
8186
const diagnostics = testModule.diagnostic();
8287
const totalDuration = diagnostics.duration.toFixed(0);
8388

89+
const startTime = new Date(this.startTimes[testModule.id]);
90+
const hours = startTime.getHours().toString().padStart(2, '0');
91+
const minutes = startTime.getMinutes().toString().padStart(2, '0');
92+
const seconds = startTime.getSeconds().toString().padStart(2, '0');
93+
8494
this.writeStream.write('\n\n');
85-
this.writeStream.write(`<h4>Summary for <code>${file.filepath}</code></h4>\n`);
95+
this.writeStream.write(`<h4>Summary for <code>${relpath}</code></h4>\n`);
8696
this.writeStream.write('<table>\n');
87-
this.writeStream.write(formatRow('Test Files', ''));
8897
this.writeStream.write(formatRow('Tests', testCount.toString()));
89-
this.writeStream.write(formatRow('Start at', ''));
98+
this.writeStream.write(formatRow('Start at', `${hours}:${minutes}:${seconds}`));
9099
this.writeStream.write(formatRow('Duration', `${totalDuration}ms`));
91100
this.writeStream.write('</table>');
92101
}

0 commit comments

Comments
 (0)