istanbuljs / nyc

the Istanbul command line interface
https://istanbul.js.org/
ISC License
5.6k stars 359 forks source link

nyc generates inconsistent file delimiters #1575

Open david-kirkland opened 2 months ago

david-kirkland commented 2 months ago

Link to bug demonstration repository

https://github.com/david-kirkland/ng18-code-coverage/tree/bug-nyc-file-paths

Branch = bug-nyc-file-paths

Expected Behavior

The generated coverage JSON has consistent file path delimiters.

Observed Behavior

The generated coverage JSON has inconsistent file path delimiters.

Sometimes it uses a forward slash and sometimes it uses a double backslash. This becomes a problem when attempting to merge reports as coverage is not calculated cumulatively when the file paths do not match between reports.

image image

Troubleshooting steps

You will see in the repo that I am attempting to merge component and e2e test coverage reports (via npm run test:coverage), both generated by Cypress. I am not saying the file path delimiters differ for component and e2e tests. I'm saying the generated JSON coverage will use different file path delimiters for the same file when re-running the same test type (component or e2e) without any other changes. For example, run npm run test:component and sometimes you will get...

image

Re-run npm run test:component without making any changes and the next time you might get...

image

Note: I am on a company-issued Windows 10 Enterprise machine.

Environment Information

  System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 13th Gen Intel(R) Core(TM) i7-1365U
    Memory: 13.74 GB / 31.64 GB
  Binaries:
    Node: 22.4.1 - ~\AppData\Local\fnm_multishells\11776_1721413704500\node.EXE
    npm: 10.8.1 - ~\AppData\Local\fnm_multishells\11776_1721413704500\npm.CMD
  npmPackages:
    @jsdevtools/coverage-istanbul-loader: 3.0.5 => 3.0.5
    istanbul-lib-coverage: 3.2.2 => 3.2.2
    nyc: 17.0.0 => 17.0.0
    source-map-support: ^0.5.21 => 0.5.21
    ts-node: ^10.9.2 => 10.9.2
    typescript: 5.5.3 => 5.5.3
pawelgur commented 1 day ago

Having same issue on vite+vue+cypress+jest project: nyc@15.1.0, istanbul-lib-coverage@3.2, jest@29.7.0, vite@5.4.3

Worked around by manually normalizing paths in json coverage data files before running nyc report.