Skip to content

Commit 105d1aa

Browse files
committed
Fixed a bug where configurations did not actually support extends
1 parent 30d5b66 commit 105d1aa

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

lib/cli/options.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
*/
99

1010
const fs = require('fs');
11+
const path = require('path');
1112
const ansi = require('ansi-colors');
13+
const {cwd} = require('../utils');
14+
const applyExtends = require('yargs/lib/apply-extends');
1215
const yargsParser = require('yargs-parser');
1316
const {types, aliases} = require('./run-option-metadata');
1417
const {ONE_AND_DONE_ARGS} = require('./one-and-dones');
@@ -123,7 +126,19 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
123126

124127
const result = yargsParser.detailed(args, {
125128
configuration,
126-
configObjects,
129+
configObjects: configObjects.map(configObject => {
130+
// '_configPath' gets set by config.loadConfig()
131+
const config = configObject || {};
132+
const configPath =
133+
typeof config._configPath === 'string'
134+
? path.dirname(config._configPath)
135+
: cwd();
136+
137+
// Remove the internal property
138+
delete config._configPath;
139+
140+
return applyExtends(config, configPath, true);
141+
}),
127142
default: defaultValues,
128143
coerce: coerceOpts,
129144
narg: nargOpts,
@@ -157,7 +172,12 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
157172
const loadRc = (args = {}) => {
158173
if (args.config !== false) {
159174
const config = args.config || findConfig();
160-
return config ? loadConfig(config) : {};
175+
const configObject = config ? loadConfig(config) : {};
176+
177+
// Set _configPath for use by parse()
178+
configObject._configPath = config;
179+
180+
return configObject;
161181
}
162182
};
163183

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"require": ["foo", "bar"],
3+
"bail": true,
4+
"reporter": "dot",
5+
"slow": 60
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./modifiers.json"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "./base.json",
3+
"reporter": "html",
4+
"slow": 30
5+
}

test/integration/options.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
var path = require('path');
4+
var loadOptions = require('../../lib/cli/options').loadOptions;
5+
6+
describe('options', function() {
7+
it('Should support extended options', function() {
8+
var configDir = path.join(
9+
__dirname,
10+
'fixtures',
11+
'config',
12+
'mocharc-extended'
13+
);
14+
var extended = loadOptions([
15+
'--config',
16+
path.join(configDir, 'extends.json')
17+
]);
18+
expect(extended.require, 'to equal', ['foo', 'bar']);
19+
expect(extended.bail, 'to equal', true);
20+
expect(extended.reporter, 'to equal', 'html');
21+
expect(extended.slow, 'to equal', 30);
22+
});
23+
});

0 commit comments

Comments
 (0)