Skip to content

feat(reporter): add filterMeta option to json reporter#10078

Merged
sheremet-va merged 5 commits intovitest-dev:mainfrom
nami8824:feat/json-reporter-filter-meta-field
Apr 9, 2026
Merged

feat(reporter): add filterMeta option to json reporter#10078
sheremet-va merged 5 commits intovitest-dev:mainfrom
nami8824:feat/json-reporter-filter-meta-field

Conversation

@nami8824
Copy link
Copy Markdown
Contributor

@nami8824 nami8824 commented Apr 6, 2026

Description

Resolves #8741

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.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

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:.

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 6, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 61de1eb
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69d5e93384610b0008ede436
😎 Deploy Preview https://deploy-preview-10078--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@AriPerkkio AriPerkkio changed the title feat(reporter/json): add filterMetaField option to json reporter feat(reporter): add filterMetaField option to json reporter Apr 6, 2026
AriPerkkio
AriPerkkio previously approved these changes Apr 6, 2026
Copy link
Copy Markdown
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

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

Looks good. Though I would rather name this just filterMeta. Thoughts @sheremet-va (#8741 (comment)) ?

location: t.location,
meta: t.meta,
meta: filterMetaField
? Object.fromEntries(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It pains me to see this tbh. I don't think it matters much since meta is usually pretty small, but 3 iterations over the same array is mental 🦀

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replaced with a single for...of loop.

Copy link
Copy Markdown
Member

@sheremet-va sheremet-va Apr 8, 2026

Choose a reason for hiding this comment

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

There are still two loops, you don't need Object.entries, you can use for in loop

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, changed to for...in loop.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, sorry for being pedantic, I would've accepted forof if PR started as such 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the note, I'll keep that in mind.


export interface JsonOptions {
outputFile?: string
filterMetaField?: (key: string, value: unknown) => boolean
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should support move return values (like filter does) - truthy/falsy

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed the return type to unknown and updated.

test: {
reporters: [
['json', {
filterMetaField: (key, value) => key !== 'internalField',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, my idea was just a proposal for a potential option. filterMeta sounds fine to me

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed to filterMeta.

@nami8824
Copy link
Copy Markdown
Contributor Author

nami8824 commented Apr 8, 2026

Addressed all review comments. Could you take another look?

@nami8824 nami8824 requested a review from sheremet-va April 8, 2026 05:44
@nami8824 nami8824 changed the title feat(reporter): add filterMetaField option to json reporter feat(reporter): add filterMeta option to json reporter Apr 8, 2026
sheremet-va
sheremet-va previously approved these changes Apr 8, 2026

export interface JsonOptions {
outputFile?: string
filterMeta?: (key: string, value: unknown) => unknown
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you mark this as @experimental, we can release it in the next fix

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added /** @experimental */ to the filterMeta option in JsonOptions.

sheremet-va
sheremet-va previously approved these changes Apr 9, 2026
@sheremet-va sheremet-va merged commit b77de96 into vitest-dev:main Apr 9, 2026
13 of 16 checks passed
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.

Excessive JSON reporter output when used together with Allure reporter

3 participants