Skip to content
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

feat(reporter): add support for function type to classname option in the junit reporter #6839

Merged
merged 8 commits into from
Nov 18, 2024

Conversation

jpleclerc
Copy link
Contributor

@jpleclerc jpleclerc commented Nov 1, 2024

Description

This PR adds support for a function for the classname option for the junit reporter.
It is currently possible to specify a static string as the classname of the junit reporter but it is not flexible enough in some case.

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

@jpleclerc jpleclerc changed the title feat(reporter): added support function type support to classname option in the junit reporter feat(reporter): add support function type support to classname option in the junit reporter Nov 1, 2024
@jpleclerc jpleclerc changed the title feat(reporter): add support function type support to classname option in the junit reporter feat(reporter): add support for function type to classname option in the junit reporter Nov 1, 2024
@hi-ogawa
Copy link
Contributor

hi-ogawa commented Nov 2, 2024

Hey, thanks for the PR. Can you explain your specific use case? While exposing Task gives flexibility, that comes with increased API surface and potential breaking change in the future, so we might need to discuss a bit.

As an alternative, would it work for you if we support classNameTemplate like jest's reporter? https://github.com/jest-community/jest-junit?tab=readme-ov-file#configuration They have functions too https://github.com/jest-community/jest-junit?tab=readme-ov-file#example-5, but it looks like the argument is normalized first, so internal is not exposed.

Btw, what we support right now for options.classname is probably weird/useless #3808 as it looks like OP introduced to just hide classname #3691

@jpleclerc
Copy link
Contributor Author

jpleclerc commented Nov 2, 2024

We ended up having test cases with duplicated class names in our project and our CI/CD reporting UI couldn't handle duplicates. For that reason we need a more flexible way to generate classnames in order to make them more unique.

Exposing Task definitly felt a bit wrong. I just looked at jest's classNameTemplate and definitly feels cleaner. I'll make the change to mimic that behavior.

Current classname option feels useless indeed, can't see a use for that.

@AriPerkkio
Copy link
Member

@jpleclerc what properties of Task would you like to use here to create those unique names? Instead of exposing whole Task, we could expose some specific parts that are easier to maintain.

@jpleclerc
Copy link
Contributor Author

@AriPerkkio In our case the file name and path is enough. I think the jest-junit project got it right. I'm thinking of supporting at least the following:

  • suitename
  • filepath
  • filename

- classnameTemplate can take a function or a string
- the string can be parameterized

Change-Id: I6a79ed8f89e23e518c8d18f6fe49a210edaa247a
Copy link

netlify bot commented Nov 4, 2024

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit f2ee2f7
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/673692a5a63a530008382e16
😎 Deploy Preview https://deploy-preview-6839--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 site configuration.

… classnameTemplate

Change-Id: I03a3d47d26aa36ca5c14cf790a19629d151b7c61
hi-ogawa
hi-ogawa previously approved these changes Nov 4, 2024
Copy link
Contributor

@hi-ogawa hi-ogawa 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!
I think we can deprecate (and remove later) classname as it's useless and easy to move to classnameTemplate as a constant.

packages/vitest/src/node/reporters/junit.ts Show resolved Hide resolved
hi-ogawa
hi-ogawa previously approved these changes Nov 4, 2024
Copy link
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! We should also update documentation. Maybe something about classnameTemplate after this section:

The outputted XML contains nested `testsuites` and `testcase` tags. You can use the reporter options to configure these attributes:
```ts
export default defineConfig({
test: {
reporters: [
['junit', { suiteName: 'custom suite name', classname: 'custom-classname' }]
]
},
})
```

Change-Id: I1caa6e359998071ced9839ad27d121d25e8b8d99
AriPerkkio
AriPerkkio previously approved these changes Nov 7, 2024
@sheremet-va sheremet-va added this to the 2.2.0 milestone Nov 8, 2024
docs/guide/reporters.md Outdated Show resolved Hide resolved
packages/vitest/src/node/reporters/junit.ts Outdated Show resolved Hide resolved
packages/vitest/src/node/reporters/junit.ts Outdated Show resolved Hide resolved
… fixed typo.

Change-Id: Ie77e0955011fa42d2a8ef42c074327589d780739
Change-Id: I6d4e936a6cabaacf31a82036acf22f9af401bdb0
docs/guide/reporters.md Outdated Show resolved Hide resolved
@sheremet-va sheremet-va merged commit dc238e9 into vitest-dev:main Nov 18, 2024
16 of 17 checks passed
@sheremet-va sheremet-va modified the milestones: 2.2.0, 3.0.0 Dec 5, 2024
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.

4 participants