nyc
nyc copied to clipboard
The --cwd option breaks instrumentation on Windows
Link to bug demonstration repository
https://github.com/elliot-nelson/nyc-bug-demo
Expected Behavior
Running nyc --cwd spec jasmine should instrument the specs run, and produce a coverage report:
1 spec, 0 failures
Finished in 0.023 seconds
Randomized with seed 40333 (jasmine --random=true --seed=40333)
---------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
index-spec.js | 100 | 100 | 100 | 100 |
---------------|---------|----------|---------|---------|-------------------
Observed Behavior
Adding the --cwd option removes all instrumentation:
1 spec, 0 failures
Finished in 0.017 seconds
Randomized with seed 50629 (jasmine --random=true --seed=50629)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Troubleshooting steps
- [ ] Issue occurs only on Windows (the --cwd flag works as expected on MacOS/Linux)
- [ ] Issue does not occur in Windows using [email protected] (--cwd flag works as expected)
- [ ] Suspecting the issue is with jasmine, I tried modifying the the
"spec_dir"setting inspec/support/jasmine.json- this didn't work (jasmine is running the right files, those files just aren't instrumented).
Environment Information
npx: installed 1 in 1.869s
System:
OS: Windows Server 2012 6.3.9600
CPU: (2) x64 Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz
Memory: 5.63 GB / 8.00 GB
Binaries:
Node: 8.15.0 - c:\nodejs\node.EXE
npm: 6.4.1 - c:\nodejs\npm.CMD
npmPackages:
nyc: ^15.0.1 => 15.0.1
Note: I did see https://github.com/istanbuljs/nyc/issues/1234, but the solution to that report doesn't seem to have fixed this problem. (The problem occurs even without any nycrc file, without adding any other flags like report-dir, etc.)
@elliot-nelson This is https://github.com/istanbuljs/test-exclude/issues/43, potentially being fixed by https://github.com/istanbuljs/test-exclude/pull/44
@addaleax It seems related but I wonder if this will fix my situation where there are no uppercase files? I'm willing to test it out later today though, it looks like I could copy the fix into my local node modules.
@elliot-nelson I think it’s also about the comment I just left on the fix about using path.resolve() instead of path.join() :)
I'm new to programming, so I know my statements could be completely off, but I am experiencing an issue using the cwd option too, like @elliot-nelson.
I was using [email protected] in my NodeJS project and I had placed the nyc package in a location other than my project's root folder. When I attempted to use the cwd option to specify the project's root folder, I got the same empty coverage report like @elliot-nelson showed. I only got valid results if I actually moved the nyc package to my project's root folder.
If I downgraded to [email protected], as @elliot-nelson mentioned, I began getting a valid coverage report even with the nyc package in a folder other than the project's root folder and using the cwd option to specify the project's root folder.
I'm not sure if this is helpful at all to this particular thread, but I thought I would mention it, as the content here did help me to find out that I wasn't going crazy after and I was actually using the cwd option correctly after all. 😃 Thanks!
@ryancabanas , you've solved my issue. I've [email protected] working on my Mac, but it wasn’t working on Windows. Downgrading [email protected] works fine for both.