Skip to content

OnTestCaseReady's timing not firing as Expected #8108

@VinayBerry

Description

@VinayBerry

Describe the bug

I'm attempting to implement a custom Vitest Reporter but when I try to listen for the onTestCaseReady event I would expect it to occur before anything from my test occurs. However it seems to be logs from userConsole appear to show before the onTestCaseReady.

import {Reporter, Vitest, TestCase} from 'vitest/node'

export default class MyReporter implements Reporter {
  constructor() {
    console.log('MyReporter loaded!');
  }

  onInit(ctx: Vitest) {
    console.log(`[onInit] at ${new Date().toISOString()}`)
  }

  onUserConsoleLog(log: any){
    console.log(log.content)
  }

  onTestRunStart() {
    console.log(`[onTestRunStart] at ${new Date().toISOString()}`)
  }

  onTestCaseReady(testCase: TestCase) {
    console.log(`[onTestCaseReady] ${testCase.name} at ${new Date().toISOString()}`)
  }
  onTestCaseResult(testCase: TestCase) {
    console.log(`[onTestCaseResult] ${testCase.name} at ${new Date().toISOString()}`)
  }

  onTestRunEnd() {
    console.log(`[onTestRunEnd] at ${new Date().toISOString()}`)
  }
}

Reproduction

mini-repro.zip

In this mini example the onTestCaseReady occurs after the beforeEach and test logs:

[onInit] at 2025-06-05T21:59:14.603Z
[onTestRunStart] at 2025-06-05T21:59:14.605Z
[beforeEach] minimal test at 2025-06-05T21:59:14.796Z

[TEST FUNCTION] start at 2025-06-05T21:59:14.797Z

[TEST FUNCTION] end at 2025-06-05T21:59:15.298Z

[onTestCaseReady] minimal test at 2025-06-05T21:59:15.300Z
[onTestCaseResult] minimal test at 2025-06-05T21:59:15.300Z
[onTestRunEnd] at 2025-06-05T21:59:15.314Z

I would expect to see:

[onInit] at 2025-06-05T21:59:14.603Z
[onTestRunStart] at 2025-06-05T21:59:14.605Z
[beforeEach] minimal test at 2025-06-05T21:59:14.796Z
----> [onTestCaseReady] minimal test at 2025-06-05T21:59:15.300Z

[TEST FUNCTION] start at 2025-06-05T21:59:14.797Z

[TEST FUNCTION] end at 2025-06-05T21:59:15.298Z

[onTestCaseResult] minimal test at 2025-06-05T21:59:15.300Z
[onTestRunEnd] at 2025-06-05T21:59:15.314Z

System Info

System:
    OS: macOS 15.4.1
    CPU: (16) arm64 Apple M4 Max
    Memory: 3.78 GB / 48.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.15.0 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.9.2 - /usr/local/bin/npm
  Browsers:
    Chrome: 137.0.7151.57
    Edge: 137.0.3296.62
    Safari: 18.4
  npmPackages:
    vitest: ^3.1.4 => 3.1.4

Used Package Manager

yarn

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: reportersIssues and PRs related to Vitest reportersp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions