config: pass and filter JSON options to child

This commit is contained in:
Matthew Zipkin 2021-09-28 13:11:08 -04:00
parent 1216c77583
commit 3964a1785c
No known key found for this signature in database
GPG Key ID: E7E2984B6289C93A
2 changed files with 42 additions and 0 deletions

View File

@ -166,6 +166,7 @@ class Config {
_filter(name, this.args, child.args); _filter(name, this.args, child.args);
_filter(name, this.query, child.query); _filter(name, this.query, child.query);
_filter(name, this.hash, child.hash); _filter(name, this.hash, child.hash);
_filter(name, this.options, child.options);
return child; return child;
} }

41
test/bcfg-test.js Normal file
View File

@ -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');
});
});