updated tests to verify that Provider.load respects hierarchy
This commit is contained in:
parent
a216336290
commit
fdb73f007b
4 changed files with 47 additions and 16 deletions
|
@ -18,7 +18,8 @@
|
|||
"pkginfo": "0.2.x"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vows": "0.6.x"
|
||||
"vows": "0.6.x",
|
||||
"eyes": "0.1.7"
|
||||
},
|
||||
"main": "./lib/nconf",
|
||||
"scripts": { "test": "vows test/*-test.js test/**/*-test.js --spec" },
|
||||
|
|
4
test/fixtures/merge/file1.json
vendored
4
test/fixtures/merge/file1.json
vendored
|
@ -1,7 +1,11 @@
|
|||
{
|
||||
"apples": true,
|
||||
"bananas": true,
|
||||
"foo": {
|
||||
"bar": "boo"
|
||||
},
|
||||
"candy": {
|
||||
"something": "file1",
|
||||
"something1": true,
|
||||
"something2": true
|
||||
}
|
||||
|
|
1
test/fixtures/merge/file2.json
vendored
1
test/fixtures/merge/file2.json
vendored
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"candy": {
|
||||
"something": "file2",
|
||||
"something3": true,
|
||||
"something4": true
|
||||
},
|
||||
|
|
|
@ -11,7 +11,8 @@ var assert = require('assert'),
|
|||
spawn = require('child_process').spawn,
|
||||
vows = require('vows'),
|
||||
helpers = require('./helpers'),
|
||||
nconf = require('../lib/nconf');
|
||||
nconf = require('../lib/nconf'),
|
||||
eyes = require('eyes');
|
||||
|
||||
var fixturesDir = path.join(__dirname, 'fixtures'),
|
||||
mergeFixtures = path.join(fixturesDir, 'merge'),
|
||||
|
@ -72,23 +73,47 @@ vows.describe('nconf/provider').addBatch({
|
|||
provider.load();
|
||||
provider.merge(override);
|
||||
helpers.assertMerged(null, provider.stores.file.store);
|
||||
assert.equal(provider.stores.file.store.candy.something, 'file1');
|
||||
}
|
||||
},
|
||||
"when sources are passed in": {
|
||||
topic: new nconf.Provider({
|
||||
sources: {
|
||||
user: {
|
||||
type: 'file',
|
||||
file: files[0]
|
||||
},
|
||||
global: {
|
||||
type: 'file',
|
||||
file: files[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When using nconf": {
|
||||
"an instance of 'nconf.Provider'": {
|
||||
"the load() method": {
|
||||
"when sources are passed in": {
|
||||
topic: new nconf.Provider({
|
||||
sources: {
|
||||
user: {
|
||||
type: 'file',
|
||||
file: files[0]
|
||||
},
|
||||
global: {
|
||||
type: 'file',
|
||||
file: files[1]
|
||||
}
|
||||
}
|
||||
}),
|
||||
"should respect the hierarchy ": function (provider) {
|
||||
var merged = provider.load();
|
||||
|
||||
helpers.assertMerged(null, merged);
|
||||
assert.equal(merged.candy.something, 'file1');
|
||||
console.log(provider.sources);
|
||||
}
|
||||
},
|
||||
"when multiple stores are used": {
|
||||
topic: new nconf.Provider().overrides({foo: {bar: 'baz'}})
|
||||
.add('file1', {type: 'file', file: files[0]})
|
||||
.add('file2', {type: 'file', file: files[1]}),
|
||||
"should respect the hierarchy": function(provider) {
|
||||
var merged = provider.load();
|
||||
|
||||
helpers.assertMerged(null, merged);
|
||||
assert.equal(merged.foo.bar, 'baz');
|
||||
assert.equal(merged.candy.something, 'file1');
|
||||
}
|
||||
}),
|
||||
"should have the result merged in": function (provider) {
|
||||
helpers.assertMerged(null, provider.load());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue