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'

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

58595960

this.ctx.logger.printBanner()

60-

this.start = performance.now()

6161

}

62626363

log(...messages: any): void {

@@ -72,6 +72,11 @@ export abstract class BaseReporter implements Reporter {

7272

return 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+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

}

426428427429

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