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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple output-files / Allow extension of existing reporters #1068

Closed
4 tasks done
steve-py96 opened this issue Apr 1, 2022 · 12 comments
Closed
4 tasks done

Multiple output-files / Allow extension of existing reporters #1068

steve-py96 opened this issue Apr 1, 2022 · 12 comments
Labels
enhancement New feature or request

Comments

@steve-py96
Copy link
Contributor

Clear and concise description of the problem

Before going to the problem I have to... Thank for this awesome lib, you're doing an insanely great job 馃憤馃徔

The problem:
I have the case where I need the json and junit reporter at once (one dataset goes into some documentary, the other to gitlab), when using both they merge their results into the specified outputFile. Since I cannot access the default reporter classes (https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/node/reporters/json.ts f.e.) to overwrite some stuff I'd need to create a custom one by merging junit & json reporters which seems kinda cubersome.

(sidenote: if the FR is not declined I'd try to contribute to this ofc, if I may :P)

Suggested solution

If outputFile would accept a Record in a format like { [reporter]: outputFilePath } (besides the string, the simple solution should ofc remain for the simple cases :D) the reporters could be run in parallel (would result in code like this.ctx.config.outputFile.json || this.ctx.config.outputFile or typeof this.ctx.config.outputFile === 'string' ? this.ctx.config.outputFile : this.ctx.config.outputFile.json or sth).

Alternative

By exposing the default reporters somehow they could be overwritten (would result in code like class MyCustomReporter extends JsonReporter { ... } where the ctx could be overwritten at a certain point).

Additional context

No response

Validations

@sheremet-va
Copy link
Member

I like the suggested solution, if you can make it work 馃

@ericjgagnon
Copy link
Contributor

I'm in the process of creating a Jetbrains run/debug configuration plugin for Vitest that would require me to create a custom reporter to emit messages in a format that the plugin framework understands.

@sheremet-va would you be open to me creating a PR for @steve-py96 alternative solution? I'd love to bring first class support for Vitest to Jetbrains IDEs.

@AriPerkkio
Copy link
Member

If outputFile would accept a Record in a format like { [reporter]: outputFilePath } (besides the string [...]

How could we use this with custom reporters? Currently the reporters option only allows class declarations, e.g. new SonarReporter().

Maybe it should allow package names of custom reporters as keys there. Vitest should then check if it's built in one - if not, import the given package and initialize it. Something similar as built-in ones have here:

export const ReportersMap = {
'default': DefaultReporter,
'verbose': VerboseReporter,
'dot': DotReporter,
'json': JsonReporter,
'tap': TapReporter,
'tap-flat': TapFlatReporter,
'junit': JUnitReporter,
}

This id could then also be used when declaring reporters from CLI, e.g. vitest run --reporters vitest-sonar-reporter. Currently this CLI API only allows built-in ones.

Maybe this first PR should only address the built-in reporters. I'm happy to help extending this functionality to cover custom 3rd party reporters.

@AriPerkkio
Copy link
Member

Right, the custom reporters would actually work with the suggested changes. Simply with outputFile: { 'my-custom-reporter': 'some/path.xml' }, and in code this.ctx.config.outputFile['my-custom-reporter'].
I think I was mixing this with reporters configuration. 馃槃

@steve-py96
Copy link
Contributor Author

@AriPerkkio was thinking about the CLI too tho, the --outputFile arg only allows 1 path after all... It'd make sense to limit this feature to a config but also it'd make sense to allow multiple outputFile args and attach them in proper order to the provided reporters f.e., idk what to prefer

@sheremet-va
Copy link
Member

sheremet-va commented Apr 2, 2022

@AriPerkkio was thinking about the CLI too tho, the --outputFile arg only allows 1 path after all... It'd make sense to limit this feature to a config but also it'd make sense to allow multiple outputFile args and attach them in proper order to the provided reporters f.e., idk what to prefer

We can use dot-nested options: https://github.com/cacjs/cac#dot-nested-options

@sheremet-va
Copy link
Member

sheremet-va commented Apr 2, 2022

@sheremet-va would you be open to me creating a PR for @steve-py96 alternative solution? I'd love to bring first class support for Vitest to Jetbrains IDEs.

Yeah, I think it's ok if we export default reporter for extending it's functionality, from vitest/node

@steve-py96
Copy link
Contributor Author

Didn't check the used CLI lib, neat stuff 馃憣馃徔
Adding that to the documentation later

@sheremet-va sheremet-va added the enhancement New feature or request label Apr 2, 2022
@ericjgagnon
Copy link
Contributor

@AriPerkkio @sheremet-va I have something working, similar to what @AriPerkkio mentioned:

Maybe it should allow package names of custom reporters as keys there. Vitest should then check if it's built in one - if not, import the given package and initialize it. Something similar as built-in ones have here...

To clarify this is for the CLI. The only issue I'm having at the moment is where to put tests for the added functionality? I don't really see any tests related to the CLI part of the vitest package. Do either of you have a preference? I want to make sure I have the go ahead and a test in place before putting in a PR.

@sheremet-va
Copy link
Member

What do you mean? Don't we already have PR for this feature? I was waiting for @steve-py96 to make last changes before merging.

@ericjgagnon
Copy link
Contributor

@sheremet-va there has definitely been a mixup, potentially by me. I'm going to open a separate enhancement request to describe my scenario in detail.

@steve-py96
Copy link
Contributor Author

@sheremet-va sorry it was done already! I somehow managed to not push :(, it is up now

@antfu antfu closed this as completed in a63cfa2 Apr 7, 2022
chaii3 pushed a commit to chaii3/vitest that referenced this issue May 13, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants