Skip to content

Commit bc3a692

Browse files
authored
fix(reporters): report correct test run duration at the end (#8969)
1 parent 4f2776e commit bc3a692

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/vitest/src/node/reporters/base.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { File, Task, TestAnnotation } from '@vitest/runner'
22
import type { SerializedError } from '@vitest/utils'
33
import type { TestError, UserConsoleLog } from '../../types/general'
44
import type { Vitest } from '../core'
5+
import type { TestSpecification } from '../spec'
56
import type { Reporter, TestRunEndReason } from '../types/reporter'
67
import type { TestCase, TestCollection, TestModule, TestModuleState, TestResult, TestSuite, TestSuiteState } from './reported-tasks'
78
import { performance } from 'node:perf_hooks'
@@ -57,7 +58,6 @@ export abstract class BaseReporter implements Reporter {
5758
this.ctx = ctx
5859

5960
this.ctx.logger.printBanner()
60-
this.start = performance.now()
6161
}
6262

6363
log(...messages: any): void {
@@ -72,6 +72,11 @@ export abstract class BaseReporter implements Reporter {
7272
return relative(this.ctx.config.root, path)
7373
}
7474

75+
onTestRunStart(_specifications: ReadonlyArray<TestSpecification>): void {
76+
this.start = performance.now()
77+
this._timeStart = formatTimeString(new Date())
78+
}
79+
7580
onTestRunEnd(
7681
testModules: ReadonlyArray<TestModule>,
7782
unhandledErrors: ReadonlyArray<SerializedError>,
@@ -419,9 +424,6 @@ export abstract class BaseReporter implements Reporter {
419424
for (const testModule of this.failedUnwatchedFiles) {
420425
this.printTestModule(testModule)
421426
}
422-
423-
this._timeStart = formatTimeString(new Date())
424-
this.start = performance.now()
425427
}
426428

427429
onUserConsoleLog(log: UserConsoleLog, taskState?: TestResult['state']): void {

packages/vitest/src/node/reporters/default.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class DefaultReporter extends BaseReporter {
4242
}
4343
}
4444

45+
super.onTestRunStart(specifications)
4546
this.summary?.onTestRunStart(specifications)
4647
}
4748

0 commit comments

Comments
 (0)