Skip to content

fix(reporter): task.meta should be available in custom reporter's errors #8115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

AriPerkkio
Copy link
Member

Description

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Comment on lines +244 to +255
class Custom extends DefaultReporter {
getFullName(test: RunnerTask, separator?: string): string {
return `${separator}{ name: ${test.name}, meta: ${test.meta.custom} } (Custom getFullName here)`
}
}

const { stderr } = await runVitest({
root: 'fixtures/metadata',
reporters: new Custom(),
})

expect(stderr).toMatch('FAIL > { name: fails, meta: Failing test added this } (Custom getFullName here')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lafeuil from #8018 👋

Is this the kind of use case you are trying to achieve?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is exactly that 👍

@@ -249,6 +249,10 @@ export abstract class BaseReporter implements Reporter {
return getTestName(test, separator)
}

protected getFullName(test: Task, separator?: string): string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I don't like here is the use of Task since it's an experimental API, but to have the reported entity, we would have to rewrite the reporter which is probably outside of the scope of this PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is inline with protected getTestName(test: Task, separator?: string) above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but the previous one was there before the new API

@sheremet-va sheremet-va merged commit 27df68a into vitest-dev:main Jun 11, 2025
14 checks passed
@AriPerkkio AriPerkkio deleted the fix/access-test-metadata-in-reporter-errors branch June 11, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The test name can differ in the base reporter in the task errors
3 participants