Skip to content

Commit a957e8f

Browse files
committed
Fixed a bug where configurations did not actually support extends
1 parent 78d979d commit a957e8f

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
@@ -7,7 +7,10 @@
77
*/
88

99
const fs = require('fs');
10+
const path = require('path');
1011
const ansi = require('ansi-colors');
12+
const {cwd} = require('../utils');
13+
const applyExtends = require('yargs/lib/apply-extends');
1114
const yargsParser = require('yargs-parser');
1215
const {types, aliases} = require('./run-option-metadata');
1316
const {ONE_AND_DONE_ARGS} = require('./one-and-dones');
@@ -122,7 +125,19 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
122125

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

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)