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

Fix yargs global pollution #3863

Merged
merged 2 commits into from
Apr 9, 2019

Conversation

inukshuk
Copy link
Contributor

@inukshuk inukshuk commented Apr 5, 2019

Description of the Change

Yargs exports a global singleton by default. Using it directly will break testing apps using yargs themselves.

Alternate Designs

I followed the best-practice example in yargs' documentation. One test had to be adjusted slightly, using a separate yargs instance which has been reset: this is what yargs does internally and required, because run.builder() calls .positional() which cannot be called on the outer yargs instance.

Benefits

Makes mocha compatible with other projects depending on yargs.

Possible Drawbacks

If we need access to mocha's yargs instance, we'll have to expose it ourselves, instead of relying on the global one.

I think this should be a bug fix (patch release).

Yargs exports a global singleton by default. Using it directly will
most likely break testing apps using yargs themselves.
@jsf-clabot
Copy link

jsf-clabot commented Apr 5, 2019

CLA assistant check
All committers have signed the CLA.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) to 91.675% when pulling 88eecd3 on inukshuk:fix-yargs-global-pollution into b079d24 on mochajs:master.

@plroebuck plroebuck requested a review from boneskull April 9, 2019 07:02
Copy link
Contributor

@boneskull boneskull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. totally missed that yargs messed w/ the global state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants