Skip to content

Commit

Permalink
Fix yargs global pollution
Browse files Browse the repository at this point in the history
Yargs exports a global singleton by default. Using it directly will
most likely break testing apps using yargs themselves.
  • Loading branch information
inukshuk authored and boneskull committed Apr 9, 2019
1 parent 86cd699 commit f05a58f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/cli/cli.js
Expand Up @@ -11,7 +11,7 @@

const debug = require('debug')('mocha:cli:cli');
const symbols = require('log-symbols');
const yargs = require('yargs');
const yargs = require('yargs/yargs');
const path = require('path');
const {loadOptions, YARGS_PARSER_CONFIG} = require('./options');
const commands = require('./commands');
Expand All @@ -32,7 +32,7 @@ exports.main = (argv = process.argv.slice(2)) => {

Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?

yargs
yargs(argv)
.scriptName('mocha')
.command(commands.run)
.command(commands.init)
Expand Down
2 changes: 1 addition & 1 deletion test/node-unit/cli/run.spec.js
Expand Up @@ -7,7 +7,7 @@ describe('command', function() {
describe('run', function() {
describe('builder', function() {
const IGNORED_OPTIONS = new Set(['help', 'version']);
const options = builder(require('yargs')).getOptions();
const options = builder(require('yargs/yargs')().reset()).getOptions();
['number', 'string', 'boolean', 'array'].forEach(type => {
describe(`${type} type`, function() {
Array.from(new Set(options[type])).forEach(option => {
Expand Down

0 comments on commit f05a58f

Please sign in to comment.