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

adding ability to change reported root dir file path #153

Closed
AdaskoTheBeAsT opened this issue Jan 31, 2024 · 8 comments · Fixed by #154
Closed

adding ability to change reported root dir file path #153

AdaskoTheBeAsT opened this issue Jan 31, 2024 · 8 comments · Fixed by #154
Labels
enhancement New feature or request

Comments

@AdaskoTheBeAsT
Copy link

Could you please add ability to define root dir file path similar to
https://github.com/sh33dafi/jest-sonar#readme

it is important in monorepos where frontend is not in main folder but in subfolder and sonar is not able to process result file in such case due to invalid file path

@AriPerkkio
Copy link
Owner

Could you provide some more information for this. Maybe an example of file structure, vitest.config.ts and what is expected to be on the report.

@AriPerkkio AriPerkkio added the enhancement New feature or request label Jan 31, 2024
@AdaskoTheBeAsT
Copy link
Author

ok imagine that solution folder contains subfolder frontend in which ui project is located
image

due to fact that azure devops uses sonarqube/sonarcloud step and those steps works on root folder - reports are not properly consumed when given source files are not accessible by reported path
in that case report looks like this

image

it would be really nice if by using some additional parameter I can define root folder with value ".." which in report it will be changed to

image

and then sonarqube/sonarcloud using that path will properly find source code and consume that test report

@AriPerkkio
Copy link
Owner

Thanks for the additional information. This feature request makes sense. I think I've run into that same exact problem myself couple of years ago with different test runner and reporter integration. Sonarqube can be tricky with relative paths.

To solve this I'm thinking about adding a new configuration option that users could use to modify the path properties. Some users could use this to append additional directories there (like in this one), and some could even use it to remove directories from the path.

In your case the configuration would look something like this:

test: {
    reporters: 'vitest-sonar-reporter',
    sonarReporterOptions: {
        onWriteFilePath(path: string) {
            // path is "apps/ui/src/app/app.spec.tsx"
            return `frontend/${path}`;
        }
    }
}

@AdaskoTheBeAsT
Copy link
Author

hi @AriPerkkio
thanks a lot taking a look into this - this will solve the problem with monorepo and sonarqube

in this case I could use

import * as path from 'path';
...

test: {
    reporters: 'vitest-sonar-reporter',
    sonarReporterOptions: {
        onWriteFilePath(reportPath: string) {
            // path is "apps/ui/src/app/app.spec.tsx"
            return path.relative("..", reportPath);
        }
    }
}

@AriPerkkio
Copy link
Owner

Yes, exactly like that.

I'll try to implement this in a week or so.

@AriPerkkio
Copy link
Owner

AriPerkkio commented Feb 4, 2024

Looks like support from Vitest's side is needed first: vitest-dev/vitest#5042. Currently custom test.<custom-name> entry is passed to worker threads and it fails to serialize inline functions. With a proper custom reporter options support this will not be a problem.

@AriPerkkio
Copy link
Owner

This is now included in 1.1.0 release.

@AdaskoTheBeAsT
Copy link
Author

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants