nyc: Regression: Linux: (edge case) nyc returns 0% coverage if Node.js binary has permissions to bind to ports < 1024 via setcap
To reproduce
- Install the simple test app.
git clone https://github.com/aral/simple-demonstration-of-nyc-bug-1281 bug-1281 cd bug-1281 npm i
- Ensure Node.js does not have permissions to access privileged ports:
sudo setcap 'cap_net_bind_service=-ep' `which node`
npm run coverage
succeeds (100%)- Get permissions for Node to bind to ports < 1024:
sudo setcap 'cap_net_bind_service=+ep' `which node`
npm run coverage
fails (0%)
Run the second step again to return to being able to use nyc properly.
It appears that using setcap
to set permissions has side-effects. e.g., see this: Linux capabilities (setcap) seems to disable LD_LIBRARY_PATH.
What should happen
Coverage should be 100% at Step 5.
What actually happens
Coverage is 0% at Step 5.
Regression
Works with nyc@14.1.1 (with both Tape 4.11.0 and Tape 5.0.0). The issue occurs on nyc@15.0.1.
<strike>To reproduce
- Check out the git repo at https://source.ind.ie/site.js/app (branch: hugo)
- Run
./install
- Run
npm run coverage
What happens (nyc version 15.0.0)
Incorrectly reports 0% coverage:
> @small-tech/site.js@12.11.0 coverage /home/aral/small-tech/site.js/app
> QUIET=true nyc tape test/*.js | tap-nyc
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
total: 143
passing: 143
duration: 680ms
What happens (nyc version 14.1.1)
Works correctly:
> @small-tech/site.js@12.11.0 coverage /home/aral/small-tech/site.js/app
> QUIET=true nyc tape test/*.js | tap-nyc
-----------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------------------|----------|----------|----------|----------|-------------------|
All files | 36.68 | 24.61 | 36.76 | 37.5 | |
app | 56.76 | 39.44 | 63.08 | 58.5 | |
index.js | 56.76 | 39.44 | 63.08 | 58.5 |... 97,898,899,900 |
app/bin/commands | 12.24 | 0 | 0 | 12.24 | |
serve.js | 12.24 | 0 | 0 | 12.24 |... 50,353,357,359 |
app/bin/lib | 15.69 | 12.5 | 5.13 | 15.67 | |
RsyncWatcher.js | 7.69 | 0 | 0 | 7.95 |... 91,192,193,195 |
cli.js | 100 | 100 | 100 | 100 | |
console-timestamp.js | 14.29 | 100 | 0 | 14.29 | 4,5,9,10,11,12 |
ensure.js | 8.79 | 0 | 0 | 8.99 |... 97,199,202,203 |
runtime.js | 100 | 75 | 100 | 100 | 16 |
status.js | 14.29 | 0 | 0 | 14.29 |... 35,36,37,39,42 |
sync.js | 9.8 | 0 | 0 | 9.8 |... 15,119,120,126 |
app/lib | 53.23 | 44.44 | 38.89 | 57.89 | |
Stats.js | 50 | 44 | 35.29 | 54.72 |... 18,120,122,124 |
clr.js | 100 | 50 | 100 | 100 | 6 |
errors.js | 100 | 100 | 100 | 100 | |
-----------------------|----------|----------|----------|----------|-------------------|
total: 143
passing: 143
duration: 1.7s
Environment Information
System:
OS: Linux 5.3 Pop!_OS 19.10
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Memory: 1.15 GB / 15.35 GB
Binaries:
Node: 12.14.1 - ~/.nvm/versions/node/v12.14.1/bin/node
Yarn: 1.21.1 - /usr/bin/yarn
npm: 6.13.7 - ~/.nvm/versions/node/v12.14.1/bin/npm
npmPackages:
nyc: ^14.1.1 => 14.1.1
</strike>About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 16 (6 by maintainers)
Alright. @ljharb @aral For my case it’s not working with
esm
, but withbabel-register
(though slower).My updated
.nycrc
:According to the docs
esm
should work 😕 https://github.com/istanbuljs/nyc#require-additional-modulesI think those issues maybe be related:
In that case it’s unlikely to be a regression in tape itself; please let me know if there’s anything actionable on tape’s side.
@ljharb Thank you very much for your input.
No, I get
tape
^4.9.0
throughstylelint-test-rule-tape
https://github.com/stylelint/stylelint-test-rule-tape/blob/6279a6512269720e737aa06490a6bf8f4d27fa31/package.json#L26