Skip to content

Commit 840f23a

Browse files
committed
Try to fix the duration string again
1 parent 14db79b commit 840f23a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ import fs from 'fs';
22
import pathlib from 'path';
33
import type { Reporter, RunnerTestFile, TestCase, TestModule, TestSuite } from 'vitest/node';
44

5+
function getIcon(passed: boolean) {
6+
return passed ? '✅' : '❌';
7+
}
8+
59
function* formatTestCase(testCase: TestCase) {
610
const passed = testCase.ok();
711
const diagnostics = testCase.diagnostic();
8-
const durationStr = typeof diagnostics?.duration === 'number'
9-
? ` <code>${diagnostics.duration.toFixed(0)}ms</code>`
12+
const durationStr = !Number.isNaN(diagnostics?.duration)
13+
? ` <code>${diagnostics!.duration.toFixed(0)}ms</code>`
1014
: '';
1115

12-
yield `${passed ? '✅' : '❌'} ${testCase.name}${durationStr}`;
16+
yield `${getIcon(passed)} ${testCase.name}${durationStr}`;
1317

1418
if (diagnostics?.slow) {
1519
yield ' ⚠️';
@@ -37,10 +41,6 @@ function* formatTestSuite(suite: TestSuite): Generator<string> {
3741
yield '</ul>\n';
3842
}
3943

40-
function getIcon(passed: boolean) {
41-
return passed ? '✅' : '❌';
42-
}
43-
4444
function formatRow(...items: string[]) {
4545
const tds = items.map(item => `<td>${item}</td>`);
4646
return `<tr>${tds.join('')}</tr>\n`;

0 commit comments

Comments
 (0)