-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Labels
feat: reportersIssues and PRs related to Vitest reportersIssues and PRs related to Vitest reportersp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Description
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
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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
feat: reportersIssues and PRs related to Vitest reportersIssues and PRs related to Vitest reportersp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)