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

JSON test report should include coverageMap #4276

Closed
6 tasks done
rlaferla opened this issue Oct 9, 2023 · 3 comments · Fixed by #6606
Closed
6 tasks done

JSON test report should include coverageMap #4276

rlaferla opened this issue Oct 9, 2023 · 3 comments · Fixed by #6606
Labels
enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority) pr welcome

Comments

@rlaferla
Copy link

rlaferla commented Oct 9, 2023

Describe the bug

vitest should include the coverage map in the coverage report but instead puts them in separate files.

The report should contain a key for the coverage map

e.g.

vitest run --coverage --outputFile=report.json --reporter=json

"coverageMap": {
  "/src/test.ts": {
    "path": "/src/test.ts",
    "statementMap": {
       "0": {
         "start": {
           "line": 1,
           "column": 0
         },
         "end": {
           "line": 1,
           "column": 44
         }
       }
    }
  }
}

Instead it puts the coverage map in a separate file:

coverage/coverage-final.json

Reproduction

If you run:

`% vitest run --coverage --outputFile=report.json --reporter=json

Both of these searches will not return any results:

% grep coverageMap report.json
% grep statementMap report.json

while this will return a result indicating that the json file is the coverage map.

% grep statementMap coverage/coverage-final.json

System Info

System:
    OS: macOS 14.0
    CPU: (8) arm64 Apple M2
    Memory: 685.72 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.5.1 - /usr/local/bin/npm
  Browsers:
    Brave Browser: 116.1.57.47
    Chrome: 117.0.5938.149
    Safari: 17.0
  npmPackages:
    @vitest/coverage-v8: ^0.34.6 => 0.34.6 
    vite: ^4.4.11 => 4.4.11 
    vitest: ^0.34.6 => 0.34.6

Used Package Manager

npm

Validations

@AriPerkkio
Copy link
Member

vitest should include the coverage map in the coverage report but instead puts them in separate files.

I'm not sure if I'm understanding this correctly. The vitest --reporter=json --outputFile=report.json will generate report.json that contains information about the test run. The vitest --coverage.enabled ---coverage.reporter=json will generate a coverage/coverage-final.json which contains information about the code coverage. Do you want coverage report to be included in the test report as well? If so, why? Do other tools do this?

@sheremet-va
Copy link
Member

Do other tools do this?

Looks like jest does, but we didn't implement it at the time (since there was no coverage yet):

// coverageMap?: CoverageMap | null | undefined

@AriPerkkio AriPerkkio changed the title vitest's coverage report should include the coverage map (not as a separate file) JSON test report should include coverageMap Oct 10, 2023
@AriPerkkio
Copy link
Member

I can't find any documentation from Jest on this, but it's there on the source code. I guess we can add this to be more compatible with Jest.

@sheremet-va sheremet-va added enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority) labels Oct 30, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority) pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants