Skip to content

Commit

Permalink
options 'spec' and 'ignore': no splitting by comma
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba authored and boneskull committed Jun 10, 2020
1 parent 2da50aa commit 26c6cae
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lib/cli/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,19 @@ const configuration = Object.assign({}, YARGS_PARSER_CONFIG, {

/**
* This is a really fancy way to:
* - ensure unique values for `array`-type options
* - use its array's last element for `boolean`/`number`/`string`- options given multiple times
* - `array`-type options: ensure unique values and evtl. split comma-delimited lists
* - `boolean`/`number`/`string`- options: use last element when given multiple times
* This is passed as the `coerce` option to `yargs-parser`
* @private
* @ignore
*/
const globOptions = ['spec', 'ignore'];
const coerceOpts = Object.assign(
types.array.reduce(
(acc, arg) =>
Object.assign(acc, {[arg]: v => Array.from(new Set(list(v)))}),
Object.assign(acc, {
[arg]: v => Array.from(new Set(globOptions.includes(arg) ? v : list(v)))
}),
{}
),
types.boolean
Expand Down
39 changes: 36 additions & 3 deletions test/node-unit/cli/options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,9 @@ describe('options', function() {
readFileSync = sandbox.stub();
readFileSync.onFirstCall().throws();
findConfig = sandbox.stub().returns('/some/.mocharc.json');
loadConfig = sandbox.stub().returns({spec: '*.spec.js'});
loadConfig = sandbox
.stub()
.returns({spec: '{dirA,dirB}/**/*.spec.js'});
findupSync = sandbox.stub();
loadOptions = proxyLoadOptions({
readFileSync,
Expand All @@ -573,10 +575,41 @@ describe('options', function() {
result = loadOptions(['*.test.js']);
});

it('should place both into the positional arguments array', function() {
expect(result, 'to have property', '_', ['*.test.js', '*.spec.js']);
it('should place both - unsplitted - into the positional arguments array', function() {
expect(result, 'to have property', '_', [
'*.test.js',
'{dirA,dirB}/**/*.spec.js'
]);
});
});
});

describe('"ignore" handling', function() {
let result;

beforeEach(function() {
readFileSync = sandbox.stub();
readFileSync.onFirstCall().throws();
findConfig = sandbox.stub().returns('/some/.mocharc.json');
loadConfig = sandbox
.stub()
.returns({ignore: '{dirA,dirB}/**/*.spec.js'});
findupSync = sandbox.stub();
loadOptions = proxyLoadOptions({
readFileSync,
findConfig,
loadConfig,
findupSync
});
result = loadOptions(['--ignore', '*.test.js']);
});

it('should not split option values by comma', function() {
expect(result, 'to have property', 'ignore', [
'*.test.js',
'{dirA,dirB}/**/*.spec.js'
]);
});
});
});
});

0 comments on commit 26c6cae

Please sign in to comment.