From f05a58f5616b7b184e905231ab25c6162bc268f4 Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Fri, 5 Apr 2019 23:22:14 +0200 Subject: [PATCH] Fix yargs global pollution Yargs exports a global singleton by default. Using it directly will most likely break testing apps using yargs themselves. --- lib/cli/cli.js | 4 ++-- test/node-unit/cli/run.spec.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cli/cli.js b/lib/cli/cli.js index c17d68a99d..2a075ca845 100755 --- a/lib/cli/cli.js +++ b/lib/cli/cli.js @@ -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'); @@ -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) diff --git a/test/node-unit/cli/run.spec.js b/test/node-unit/cli/run.spec.js index 6dfe5aaa4f..ed93b09129 100644 --- a/test/node-unit/cli/run.spec.js +++ b/test/node-unit/cli/run.spec.js @@ -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 => {