istanbuljs / nyc

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

nyc on Windows shows 0 coverage #1381

Open osher opened 3 years ago

osher commented 3 years ago

Link to bug demonstration repository

https://github.com/mariszin/nyc-coverage-0-sample

(Taken from #1076...)

Expected Behavior

After tests, nyc should show 100% coverage

Observed Behavior

When running tests on Windows, the coverage is 0. Not even after upgrading to nyc@15

C:\ws\nyc-coverage-0-sample>nyc mocha

  HelloWorld
    √ should return hello world with no arguments
    √ should return passed argument

  2 passing (6ms)

---------------|----------|----------|----------|----------|-------------------|
File           |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
---------------|----------|----------|----------|----------|-------------------|
All files      |        0 |        0 |        0 |        0 |                   |
 helloWorld.js |        0 |        0 |        0 |        0 |         1,2,3,5,9 |
---------------|----------|----------|----------|----------|-------------------|

C:\ws\nyc-coverage-0-sample>npm ls nyc
nyc-coverage-0@1.0.0 C:\nyc-coverage-0-sample
`-- nyc@14.1.1

C:\ws\nyc-coverage-0-sample>npm i nyc@15 --save-dev
npm WARN nyc-coverage-0@1.0.0 No description                                                                                                                                          bel\helper-module-transforms-1c5a7680 (356ms)
npm WARN nyc-coverage-0@1.0.0 No repository field.

+ nyc@15.1.0
added 65 packages from 26 contributors, removed 29 packages and updated 25 packages in 11.652s

25 packages are looking for funding
  run `npm fund` for details

C:\ws\nyc-coverage-0-sample>nyc mocha

  HelloWorld
    √ should return hello world with no arguments
    √ should return passed argument

  2 passing (7ms)

---------------|---------|----------|---------|---------|-------------------
File           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------|---------|----------|---------|---------|-------------------
All files      |       0 |        0 |       0 |       0 |
 helloWorld.js |       0 |        0 |       0 |       0 | 1-9
---------------|---------|----------|---------|---------|-------------------

Troubleshooting steps

Environment Information

C:\ws\nyc-coverage-0-sample>npx envinfo@latest --preset nyc
'npx' is not recognized as an internal or external command,
operable program or batch file.

C:\ws\nyc-coverage-0-sample>npm i -g envinfo
C:\Program Files (x86)\Nodist\bin\envinfo -> C:\Program Files (x86)\Nodist\bin\node_modules\envinfo\dist\cli.js                                                                       node_modules\.staging
+ envinfo@7.7.3
added 1 package from 1 contributor in 0.862s

C:\ws\nyc-coverage-0-sample>envinfo --preset nyc

  System:
    OS: Windows 10 10.0.19041
    CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
    Memory: 2.95 GB / 15.85 GB
  Binaries:
    Node: 12.18.4 - C:\Program Files (x86)\Nodist\bin\node.EXE
    npm: 6.14.6 - C:\Program Files (x86)\Nodist\bin\npm.EXE
  npmPackages:
    nyc: ^15.1.0 => 15.1.0
osher commented 3 years ago

yea, I know it's frustrating, I saw how the other issue fell in the abyss. but I would like to help with that - and I'm ready for a lot:

Osher

osher commented 3 years ago

I'm still standing, yea yea yea...

osher commented 3 years ago

Oh, aaai - I'm still alive, yeeoo

PhakornKiong commented 3 years ago

I was not able to reproduce the error by cloning and running it on my own machine.

I've tried both v14 and v15, it is working as intended.

nyc mocha

  HelloWorld
    √ should return hello world with no arguments
    √ should return passed argument

  2 passing (15ms)

---------------|---------|----------|---------|---------|-------------------
File           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------|---------|----------|---------|---------|-------------------
All files      |     100 |      100 |     100 |     100 |
 helloWorld.js |     100 |      100 |     100 |     100 |
---------------|---------|----------|---------|---------|-------------------
  System:
    OS: Windows 10 10.0.21286
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 5.58 GB / 15.86 GB
  Binaries:
    Node: 15.0.1 - E:\CodeProgram\Node\node.EXE
    npm: 7.5.2 - E:\CodeProgram\Node\npm.CMD
  npmPackages:
    nyc: ^14.0.0 => 14.0.0 
osher commented 3 years ago

WTF. I also just cloned a project where it worked on windows. It tried on v15.1, v15.1 and v14 and they all worked, the culprit is not there.

I'll find the differences and update, but will be able to do it next week.

osher commented 3 years ago

bullseye! 🎯 I manage to find a reproduction scenario. @Darkripper214 - lets hope it's the only one.

First - disclaimer

when I posted the issue I edited out parts from the paths because I did not think it makes a difference. But evidently, it did, because one of the edited out path folders was a symlink (junction).

I use a symlink because the ops guys destroyed my name when creating my ldap username. By the time I got to open a ticket to fix that - they could fix everything except for the original underlying LDAP username - and sadly, that happens a lot with my consultation customers. So I hide it with a symlink, and since I did not want my name in the bug description - I edited it out.

Anyway - see for yourself:

reproduction scenario

C:\git clone https://github.com/mariszin/nyc-coverage-0-sample 
//... bla bla bla...
C:\cd nyc-coverage-0-sample
C:\nyc-coverage-0-sample>npm i
// ... bla bla bla ...
C:\nyc-coverage-0-sample>nyc mocha

  HelloWorld
    √ should return hello world with no arguments
    √ should return passed argument

  2 passing (14ms)

---------------|---------|----------|---------|---------|-------------------
File           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------|---------|----------|---------|---------|-------------------
All files      |     100 |      100 |     100 |     100 |
 helloWorld.js |     100 |      100 |     100 |     100 |
---------------|---------|----------|---------|---------|-------------------

C:\nyc-coverage-0-sample>cd ..
C:\>mklink /J nyc-coverage-0-sample-symlink nyc-coverage-0-sample
Junction created for nyc-coverage-0-sample-symlink <<===>> nyc-coverage-0-sample
C:\>cd nyc-coverage-0-sample-symlink
C:\nyc-coverage-0-sample-symlink>nyc mocha

  HelloWorld
    √ should return hello world with no arguments
    √ should return passed argument

  2 passing (14ms)

---------------|---------|----------|---------|---------|-------------------
File           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------|---------|----------|---------|---------|-------------------
All files      |       0 |        0 |       0 |       0 |
 helloWorld.js |       0 |        0 |       0 |       0 | 1-9
---------------|---------|----------|---------|---------|-------------------

C:\nyc-coverage-0-sample-symlink>

This leads me to suspect that when symlinks are involved nyc may be watching the wrong paths

osher commented 3 years ago

@Darkripper214 - whats the procedure here, should I update the bug description above to make it easier for future readers that land on the issue from something they googled? I mean, is that something you do here, or you prefer to preserve the narrative?

osher commented 3 years ago

ha. I've got it.

follow up here: https://github.com/istanbuljs/test-exclude/issues/46

osher commented 3 years ago

actually, we may not need to wait for the PR on test-exclude if we pass it from nyc side a path already resolved through fs.realpath. LMK what you think.

osher commented 3 years ago

@Darkripper214 - sup?

osher commented 3 years ago

Summary: I found the culprit, it's in test-exclude. We can wait for them, or we can pass them an already resolved path. @Darkripper214 - what do you think?|

osher commented 3 years ago

omg. sorry for the noise. I thought I was getting maintainers in the autocomplete when I type"@".

@coreyfarrell, you look a frequent committer on both projects - are you a maintainer of this project? Can we have your opinion?

osher commented 3 years ago

so. what's the move?

GerHobbelt commented 3 years ago

Same problem here. This time, SUBST-based. See https://github.com/istanbuljs/test-exclude/issues/46#issuecomment-873377302

osher commented 3 years ago

any decision?

andyleejordan commented 3 years ago

I hope that nyc gets fixed for Windows and updated, I'd like to use it, but right now it's not usable on Windows at all.