From 83a8305bab7f1c3a2f43d4beea5a100df2ec0c6b Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Fri, 5 Apr 2019 23:22:14 +0200 Subject: [PATCH 1/2] 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 => { From 88eecd32284f374a18bc1455d6d75a8614d5cfe6 Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Fri, 5 Apr 2019 23:42:35 +0200 Subject: [PATCH 2/2] Do not pass argv twice --- lib/cli/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/cli.js b/lib/cli/cli.js index 2a075ca845..b51c2a1973 100755 --- a/lib/cli/cli.js +++ b/lib/cli/cli.js @@ -32,7 +32,7 @@ exports.main = (argv = process.argv.slice(2)) => { Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit? - yargs(argv) + yargs() .scriptName('mocha') .command(commands.run) .command(commands.init)