From 4295616cf356b9eea74d3ad7888514a3129338a2 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Sun, 24 Feb 2019 21:41:25 -0800 Subject: [PATCH] fix broken positional arguments in config; ensure positional args are unique; closes #3763 Signed-off-by: Christopher Hiller --- lib/cli/options.js | 6 ++++++ test/node-unit/cli/options.spec.js | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/cli/options.js b/lib/cli/options.js index 1e72dee034..95971fb75a 100644 --- a/lib/cli/options.js +++ b/lib/cli/options.js @@ -302,12 +302,15 @@ const loadOptions = (argv = []) => { if (rcConfig) { args.config = false; + args._ = args._.concat(rcConfig._ || []); } if (pkgConfig) { args.package = false; + args._ = args._.concat(pkgConfig._ || []); } if (optsConfig) { args.opts = false; + args._ = args._.concat(optsConfig._ || []); } args = parse( @@ -325,6 +328,9 @@ const loadOptions = (argv = []) => { delete args.spec; } + // make unique + args._ = Array.from(new Set(args._)); + return args; }; diff --git a/test/node-unit/cli/options.spec.js b/test/node-unit/cli/options.spec.js index eba791ddea..b849db5ab3 100644 --- a/test/node-unit/cli/options.spec.js +++ b/test/node-unit/cli/options.spec.js @@ -165,14 +165,13 @@ describe('options', function() { describe('when path to mocha.opts (`--opts `) is valid', function() { let result; - beforeEach(function() { const filepath = '/path/to/mocha.opts'; readFileSync = sandbox.stub(); // package.json readFileSync.onFirstCall().throws(); // mocha.opts - readFileSync.onSecondCall().returns('--retries 3'); + readFileSync.onSecondCall().returns('--retries 3 foobar.spec.js'); findConfig = sandbox.stub().returns('/some/.mocharc.json'); loadConfig = sandbox.stub().returns({}); findupSync = sandbox.stub().returns('/some/package.json'); @@ -191,7 +190,7 @@ describe('options', function() { 'to equal', Object.assign( { - _: [] + _: ['foobar.spec.js'] }, defaults, { @@ -353,7 +352,9 @@ describe('options', function() { const filepath = '/some/package.json'; readFileSync = sandbox.stub(); // package.json - readFileSync.onFirstCall().returns('{"mocha": {"retries": 3}}'); + readFileSync + .onFirstCall() + .returns('{"mocha": {"retries": 3, "_": ["foobar.spec.js"]}}'); // mocha.opts readFileSync.onSecondCall().throws(); findConfig = sandbox.stub().returns('/some/.mocharc.json'); @@ -374,7 +375,7 @@ describe('options', function() { 'to equal', Object.assign( { - _: [] + _: ['foobar.spec.js'] }, defaults, { @@ -443,8 +444,10 @@ describe('options', function() { readFileSync = sandbox.stub(); readFileSync .onFirstCall() - .returns('{"mocha": {"check-leaks": true}}'); - readFileSync.onSecondCall().returns('--retries 3'); + .returns( + '{"mocha": {"check-leaks": true, "_": ["foobar.spec.js"]}}' + ); + readFileSync.onSecondCall().returns('--retries 3 foobar.spec.js'); findConfig = sandbox.stub(); loadConfig = sandbox.stub(); findupSync = sandbox.stub().returns('/some/package.json'); @@ -463,7 +466,7 @@ describe('options', function() { expect( result, 'to equal', - Object.assign({_: []}, defaults, { + Object.assign({_: ['foobar.spec.js']}, defaults, { 'check-leaks': true, config: false, opts: false,