Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nyc incorrectly uses --reporter argument passed to wrapped command when called with --all #922

Closed
frgtn opened this issue Sep 24, 2018 · 5 comments

Comments

@frgtn
Copy link

frgtn commented Sep 24, 2018

Link to bug demonstration repository.

See README in the below repository on how to reproduce the issue

https://github.com/frgtn/nyc-all-minimal-example

Expected Behavior

nyc should ignore arguments passed to the wrapped command, eg. --reporter:

nyc --all mocha --reporter my-custom-mocha-reporter test/*.js

Should produce a coverage report

Observed Behavior

nyc crashes with the following error. From traceback it appears that nyc is trying to use mocha reporter as an istanbul reporter.

/nyc-all-minimal-example/node_modules/mocha/lib/reporters/base.js:302
  runner.on('start', function() {
         ^

TypeError: runner.on is not a function
    at MochaJUnitReporter.Base (/nyc-all-minimal-example/node_modules/mocha/lib/reporters/base.js:302:10)
    at new MochaJUnitReporter (/nyc-all-minimal-example/node_modules/mocha-junit-reporter/index.js:110:8)
    at Object.create (/nyc-all-minimal-example/node_modules/nyc/node_modules/istanbul-reports/index.js:17:16)
    at reporter.forEach (/nyc-all-minimal-example/node_modules/nyc/index.js:451:24)
    at Array.forEach (<anonymous>)
    at NYC.report (/nyc-all-minimal-example/node_modules/nyc/index.js:450:17)
    at report (/nyc-all-minimal-example/node_modules/nyc/bin/nyc.js:89:7)
    at /nyc-all-minimal-example/node_modules/nyc/bin/nyc.js:76:25
    at ChildProcess.<anonymous> (/nyc-all-minimal-example/node_modules/nyc/node_modules/foreground-child/index.js:52:5)
    at emitTwo (events.js:126:13)

Workaround

Calling nyc with --all -- mocha ... (note the added --) seems to be a workaround for the issue.

Forensic information

Operating System: Ubuntu Linux 18.04
Environment Information: node v8.10.0, npm 6.1.0

@coreyfarrell
Copy link
Member

Adding -- would be the safest way to handle this situation (and probably the only way at this time). I think this is something that will need support from yargs. Potentially yargs/yargs-parser#130 once it is reviewed and concerns are addressed.

@stale stale bot added the wontfix label Jan 5, 2019
@JaKXz
Copy link
Member

JaKXz commented Jan 24, 2019

Is this still an issue with the latest nyc?

@istanbuljs istanbuljs deleted a comment from stale bot Jan 24, 2019
@JaKXz JaKXz removed the wontfix label Jan 24, 2019
@frgtn
Copy link
Author

frgtn commented Jan 24, 2019

Yes it is still an issue, updated the minimal example with latest nyc.

@JaKXz JaKXz added the bug label Jan 24, 2019
@coreyfarrell
Copy link
Member

This was partially fixed by yargs/yargs-parser#130. The next release of NYC will include the updated version of yargs-parser. You can monitor #972 for updates about the next release.

There is a second issue. Specifically --all expects an argument (true or false). So the following two commands will work in the next version of nyc:

nyc --all=true mocha --reporter=mocha-junit-reporter test*.js
nyc --all true mocha --reporter=mocha-junit-reporter test*.js

The following will not work because mocha is interpreted as the argument to the --all flag:

nyc --all mocha --reporter=mocha-junit-reporter test*.js

I'm not sure if yargs-parser has an option to deal with this. Even if it does that would be a potentially breaking change (ignoring argument to --all would break things if someone else is using --all true). So my advice is to use --, this is explicit and prevents any potential confusion by the command-line parser.

@stale
Copy link

stale bot commented Mar 27, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 27, 2019
@stale stale bot closed this as completed Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants