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

Add "fileTemplate" to complement "addFileAttribute" #202

Closed
ceefour opened this issue Mar 16, 2022 · 6 comments · Fixed by #209
Closed

Add "fileTemplate" to complement "addFileAttribute" #202

ceefour opened this issue Mar 16, 2022 · 6 comments · Fixed by #209

Comments

@ceefour
Copy link

ceefour commented Mar 16, 2022

In a monorepo, the package is not at the root of git repository.

Meaning, addFileAttribute becomes inaccurate.

Please add fileTemplate so that we can use like:

fileTemplate: 'packages/qc-api/{filepath}',

which will be correct path relative to repository root.

@palmerj3
Copy link
Collaborator

addFileAttribute and anything that uses the filepath template variable is populated by the location of the test file relative to the project root.

The way your issue is written I am not seeing an obvious problem that needs solving.

Please elaborate and create a github repo that reproduces this issue and clearly articulates what the expected result is.

Thank you

@ceefour
Copy link
Author

ceefour commented Mar 17, 2022

The issue is in a monorepo, project root != repository root.

In my case:

  • repository root: /

  • project root: /packages/qc-api

    which contains: jest.config.js, package.json, etc.

So when I have a test file /packages/qc-api/src/fusionauth.spec.ts this gets saved in the junit file as src/fusionauth.spec.ts which, from the point of repository root, the file /src/fusionauth.spec.ts doesn't exist.

This is to support integration with GitLab Unit test reports in a monorepo.

I have to signify monorepo as it works just fine if project root is the same as repository root.

@palmerj3
Copy link
Collaborator

I see now I understand. Thanks for taking the time to explain!

Right now I think I can safely say we don't have anything built in to jest-junit to easily help with this situation.

Feel free to submit a PR adding this functionality and I will review it. Or you could also have a posttest npm script that decorates the junit.xml file that jest-junit creates and prepends the rest of the path.

@marvinroger
Copy link
Contributor

I have the exact same use case, here's a PR: #209

@ceefour
Copy link
Author

ceefour commented Apr 20, 2022

Super thank you @marvinroger 😎

@jjoselv
Copy link

jjoselv commented Jul 20, 2023

Maybe we can expand this with #256, so we have a way to resolve to the package dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants