Skip to content

Commit 26c6cae

Browse files
juergbaboneskull
authored andcommitted
options 'spec' and 'ignore': no splitting by comma
1 parent 2da50aa commit 26c6cae

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

lib/cli/options.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,19 @@ const configuration = Object.assign({}, YARGS_PARSER_CONFIG, {
5454

5555
/**
5656
* This is a really fancy way to:
57-
* - ensure unique values for `array`-type options
58-
* - use its array's last element for `boolean`/`number`/`string`- options given multiple times
57+
* - `array`-type options: ensure unique values and evtl. split comma-delimited lists
58+
* - `boolean`/`number`/`string`- options: use last element when given multiple times
5959
* This is passed as the `coerce` option to `yargs-parser`
6060
* @private
6161
* @ignore
6262
*/
63+
const globOptions = ['spec', 'ignore'];
6364
const coerceOpts = Object.assign(
6465
types.array.reduce(
6566
(acc, arg) =>
66-
Object.assign(acc, {[arg]: v => Array.from(new Set(list(v)))}),
67+
Object.assign(acc, {
68+
[arg]: v => Array.from(new Set(globOptions.includes(arg) ? v : list(v)))
69+
}),
6770
{}
6871
),
6972
types.boolean

test/node-unit/cli/options.spec.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,9 @@ describe('options', function() {
562562
readFileSync = sandbox.stub();
563563
readFileSync.onFirstCall().throws();
564564
findConfig = sandbox.stub().returns('/some/.mocharc.json');
565-
loadConfig = sandbox.stub().returns({spec: '*.spec.js'});
565+
loadConfig = sandbox
566+
.stub()
567+
.returns({spec: '{dirA,dirB}/**/*.spec.js'});
566568
findupSync = sandbox.stub();
567569
loadOptions = proxyLoadOptions({
568570
readFileSync,
@@ -573,10 +575,41 @@ describe('options', function() {
573575
result = loadOptions(['*.test.js']);
574576
});
575577

576-
it('should place both into the positional arguments array', function() {
577-
expect(result, 'to have property', '_', ['*.test.js', '*.spec.js']);
578+
it('should place both - unsplitted - into the positional arguments array', function() {
579+
expect(result, 'to have property', '_', [
580+
'*.test.js',
581+
'{dirA,dirB}/**/*.spec.js'
582+
]);
578583
});
579584
});
580585
});
586+
587+
describe('"ignore" handling', function() {
588+
let result;
589+
590+
beforeEach(function() {
591+
readFileSync = sandbox.stub();
592+
readFileSync.onFirstCall().throws();
593+
findConfig = sandbox.stub().returns('/some/.mocharc.json');
594+
loadConfig = sandbox
595+
.stub()
596+
.returns({ignore: '{dirA,dirB}/**/*.spec.js'});
597+
findupSync = sandbox.stub();
598+
loadOptions = proxyLoadOptions({
599+
readFileSync,
600+
findConfig,
601+
loadConfig,
602+
findupSync
603+
});
604+
result = loadOptions(['--ignore', '*.test.js']);
605+
});
606+
607+
it('should not split option values by comma', function() {
608+
expect(result, 'to have property', 'ignore', [
609+
'*.test.js',
610+
'{dirA,dirB}/**/*.spec.js'
611+
]);
612+
});
613+
});
581614
});
582615
});

0 commit comments

Comments
 (0)