fix(reporters): report correct test run duration at the end (#8969) · vitest-dev/vitest@bc3a692
@@ -2,6 +2,7 @@ import type { File, Task, TestAnnotation } from '@vitest/runner'
22import type { SerializedError } from '@vitest/utils'
33import type { TestError, UserConsoleLog } from '../../types/general'
44import type { Vitest } from '../core'
5+import type { TestSpecification } from '../spec'
56import type { Reporter, TestRunEndReason } from '../types/reporter'
67import type { TestCase, TestCollection, TestModule, TestModuleState, TestResult, TestSuite, TestSuiteState } from './reported-tasks'
78import { performance } from 'node:perf_hooks'
@@ -57,7 +58,6 @@ export abstract class BaseReporter implements Reporter {
5758this.ctx = ctx
58595960this.ctx.logger.printBanner()
60-this.start = performance.now()
6161}
62626363log(...messages: any): void {
@@ -72,6 +72,11 @@ export abstract class BaseReporter implements Reporter {
7272return relative(this.ctx.config.root, path)
7373}
747475+onTestRunStart(_specifications: ReadonlyArray<TestSpecification>): void {
76+this.start = performance.now()
77+this._timeStart = formatTimeString(new Date())
78+}
79+7580onTestRunEnd(
7681testModules: ReadonlyArray<TestModule>,
7782unhandledErrors: ReadonlyArray<SerializedError>,
@@ -419,9 +424,6 @@ export abstract class BaseReporter implements Reporter {
419424for (const testModule of this.failedUnwatchedFiles) {
420425this.printTestModule(testModule)
421426}
422-423-this._timeStart = formatTimeString(new Date())
424-this.start = performance.now()
425427}
426428427429onUserConsoleLog(log: UserConsoleLog, taskState?: TestResult['state']): void {