Merge PR #6 from 'pinheadmz/filter-options'
This commit is contained in:
commit
2e88341820
|
@ -166,6 +166,7 @@ class Config {
|
|||
_filter(name, this.args, child.args);
|
||||
_filter(name, this.query, child.query);
|
||||
_filter(name, this.hash, child.hash);
|
||||
_filter(name, this.options, child.options);
|
||||
|
||||
return child;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
'use strict';
|
||||
|
||||
const assert = require('bsert');
|
||||
const Config = require('../lib/config');
|
||||
|
||||
describe('bcfg', function() {
|
||||
it('should filter options', () => {
|
||||
const options = {
|
||||
testString: 'hello',
|
||||
childTestString: 'goodbye'
|
||||
};
|
||||
|
||||
const parent = new Config('bcfg');
|
||||
parent.inject(options);
|
||||
parent.load(options);
|
||||
|
||||
assert.strictEqual(parent.str('test-string'), 'hello');
|
||||
|
||||
const child = parent.filter('child');
|
||||
|
||||
assert.strictEqual(child.str('test-string'), 'goodbye');
|
||||
});
|
||||
|
||||
it('should filter argv', () => {
|
||||
const parent = new Config('bcfg');
|
||||
|
||||
// process.argv
|
||||
parent.parseArg([
|
||||
'node',
|
||||
'bcfg',
|
||||
'--test-string=hello',
|
||||
'--child-test-string=goodbye'
|
||||
]);
|
||||
|
||||
assert.strictEqual(parent.str('test-string'), 'hello');
|
||||
|
||||
const child = parent.filter('child');
|
||||
|
||||
assert.strictEqual(child.str('test-string'), 'goodbye');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue