istanbuljs / nyc

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

nyc not working with mocha and ts-node #1473

Open NikolayMakhonin opened 2 years ago

NikolayMakhonin commented 2 years ago

Link to bug demonstration repository

https://github.com/NikolayMakhonin/mocha-ts-nyc-error

Expected Behavior

Work without error and with correct paths to the files

Observed Behavior

Incorrect file paths and error:

C:\projects\mocha-ts-nyc-error\coverage\lcov-report\1\file:\C:\projects\mocha-ts-nyc-error\src\1

Troubleshooting steps

npm i
npm test

you should see this:

C:\projects\mocha-ts-nyc-error>npm test

> mocha-ts-nyc-error@1.0.0 test C:\projects\mocha-ts-nyc-error
> nyc --reporter lcov mocha -r ts-node/register ./src/qwe.test.ts

  test
OK
OK
    √ test

  1 passing (7ms)

Path contains invalid characters: C:\projects\mocha-ts-nyc-error\coverage\lcov-report\1\file:\C:\projects\mocha-ts-nyc-error\src\1
 ELIFECYCLE  Test failed. See above for more details.

Environment Information

  System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i7-3610QM CPU @ 2.30GHz
    Memory: 5.27 GB / 15.89 GB
  Binaries:
    Node: 14.19.3 - E:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.14.17 - E:\Program Files\nodejs\npm.CMD
  npmPackages:
    nyc: ^15.1.0 => 15.1.0
    ts-node: ^10.8.1 => 10.8.1
    typescript: ^4.7.4 => 4.7.4
dzhuang commented 2 years ago

This is caused by ts-node recent update. see https://github.com/TypeStrong/ts-node/pull/1771 as reported by https://github.com/TypeStrong/ts-node/issues/1790. Downgrade ts-node to 10.8.0 result the issue for me.

NikolayMakhonin commented 2 years ago

Yes, it working with ts-node@10.8.0, but not working with ts-node@10.8.1

pmconne commented 2 years ago

I just confirmed the fix in ts-node 10.8.2 resolves the issue for me.