sh33dafi / jest-sonar

A jest reporter that generates sonar reports
MIT License
49 stars 11 forks source link

Respect <rootDir> in outputDirectory #36

Closed gmiklich closed 1 year ago

gmiklich commented 3 years ago

Is your feature request related to a problem? Please describe. Other reporters, such as jest-junit allow for adding the key "" to the outputDirectory path. It will then replace it for you depending on the root directory values (which can be overridden in monorepos). Not being able to do so results in having to specify the reporter and the output directory in each sub-project's jest config.

Describe the solution you'd like Add a method to replace the rootDir with the actual path (like in the link to jest-junit that was supplied above). Invoke that method when retrieving a filename around here.

Describe alternatives you've considered I've found a workaround by configuring the coverageDirectory to have the string. If I don't supply an outputDirectory for jest-sonar, it will default to that coverage directory value. Someone may want the result to be in a different directory than the coverage, so it's not 100% ideal, but it works for now.

sh33dafi commented 3 years ago

Can you please elaborate your question a little bit it's not clear to me what you want to achieve

gmiklich commented 3 years ago

Sure, I'll try to be more specific. I have an angular monorepo that consists of a few libraries and a few apps. When I configure my jest.preset.js file, I can use syntax like this:

'jest-junit',
      {
        outputDirectory: '<rootDir>/unit-test-results',
        suiteNameTemplate: '{filepath}/{title}',
        classNameTemplate: '{classname}.{title}',
      }

That will allow the output to be under each individual app's/library's folder structure. That type of syntax even works for the coverageDirectory (for example: coverageDirectory: '<rootDir>/sonar-reports').

However, if I try that syntax to configure the outputDirectory for jest-sonar, it complains about not being able to find a "<rootDir>/whatever" path. So it does not replace the <rootDir>, and instead takes it as a literal string/part of the path.

Does that help?

sh33dafi commented 3 years ago

That is clear, will add that as a feature

marr commented 2 years ago

This would be great. I was wondering where my reports were going, and they were in an actual directory called <rootDir>.

tiagodj commented 2 years ago

Any update on this? I just noticed this bug as well. Btw thanks for creating this, very useful! :)

sh33dafi commented 2 years ago

I still need to pick it up, I hope to tackle this next week.

swcm-mnestler commented 1 year ago

Just ran into the same using 0.2.12, I'm open to providing a PR for this feature if you're willing.

sh33dafi commented 1 year ago

Just ran into the same using 0.2.12, I'm open to providing a PR for this feature if you're willing.

Feel free to open a PR

swcm-mnestler commented 1 year ago

@sh33dafi Feel free to open a PR

Created #58

github-actions[bot] commented 1 year ago

Locked due to an inactive of 90 days