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

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).

inukshuk added 2 commits Apr 5, 2019
Yargs exports a global singleton by default. Using it directly will
most likely break testing apps using yargs themselves.
@jsf-clabot

This comment has been minimized.

Copy link

commented Apr 5, 2019

CLA assistant check
All committers have signed the CLA.

@coveralls

This comment has been minimized.

Copy link

commented Apr 5, 2019

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 Apr 9, 2019
Copy link
Member

left a comment

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

@boneskull boneskull merged commit 5121211 into mochajs:master Apr 9, 2019
4 of 5 checks passed
4 of 5 checks passed
coverage/coveralls Coverage decreased (-0.03%) to 91.675%
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
deploy/netlify Deploy preview ready!
Details
licence/cla Contributor License Agreement is signed.
Details
@boneskull boneskull added this to the next milestone Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.