Add test for merging with defaults (#255)
* implementing a test for merging with defaults * bypassing strange common tests * trying to fix travis build in node 7 * adding node 8 to tests * removing node 8
This commit is contained in:
parent
0c5774fec7
commit
608b607782
4 changed files with 65 additions and 9 deletions
13
.travis.yml
13
.travis.yml
|
@ -3,15 +3,9 @@ language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "0.10"
|
- "0.10"
|
||||||
- "0.12"
|
- "0.12"
|
||||||
- "4.1"
|
- "4"
|
||||||
- "5"
|
- "6"
|
||||||
|
- "7"
|
||||||
before_install:
|
|
||||||
- travis_retry npm install npm -g
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- travis_retry npm install -g npm@2.5.1
|
|
||||||
- travis_retry npm install
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- npm test
|
- npm test
|
||||||
|
@ -23,6 +17,7 @@ after_script:
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- node_js: "0.10"
|
- node_js: "0.10"
|
||||||
|
- node_js: "0.12"
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email:
|
email:
|
||||||
|
|
9
test/fixtures/merge/file3.json
vendored
Normal file
9
test/fixtures/merge/file3.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"candy": {
|
||||||
|
"something": "much better something for you",
|
||||||
|
"something18": "completely unique",
|
||||||
|
"something5": {
|
||||||
|
"second": 99
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
test/fixtures/scripts/nconf-hierarchical-defaults-merge.js
vendored
Normal file
20
test/fixtures/scripts/nconf-hierarchical-defaults-merge.js
vendored
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
var path = require('path'),
|
||||||
|
nconf = require('../../../lib/nconf');
|
||||||
|
|
||||||
|
nconf
|
||||||
|
.file('localOverrides', path.join(__dirname, '..', 'merge', 'file3.json'))
|
||||||
|
.defaults({
|
||||||
|
"candy": {
|
||||||
|
"something": "a nice default",
|
||||||
|
"something1": true,
|
||||||
|
"something2": true,
|
||||||
|
"something5": {
|
||||||
|
"first": 1,
|
||||||
|
"second": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
process.stdout.write(JSON.stringify({
|
||||||
|
candy: nconf.get('candy')
|
||||||
|
}));
|
|
@ -108,6 +108,38 @@ vows.describe('nconf/hierarchy').addBatch({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"configured with .file(), .defaults() should deep merge objects": {
|
||||||
|
topic: function () {
|
||||||
|
var script = path.join(__dirname, 'fixtures', 'scripts', 'nconf-hierarchical-defaults-merge.js'),
|
||||||
|
that = this,
|
||||||
|
data = '',
|
||||||
|
child;
|
||||||
|
|
||||||
|
child = spawn('node', [script]);
|
||||||
|
|
||||||
|
child.stdout.on('data', function (d) {
|
||||||
|
data += d;
|
||||||
|
});
|
||||||
|
|
||||||
|
child.on('close', function() {
|
||||||
|
that.callback(null, data);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
"should merge nested objects ": function (err, data) {
|
||||||
|
assert.deepEqual(JSON.parse(data), {
|
||||||
|
candy: {
|
||||||
|
something: 'much better something for you',
|
||||||
|
something1: true,
|
||||||
|
something2: true,
|
||||||
|
something18: 'completely unique',
|
||||||
|
something5: {
|
||||||
|
first: 1,
|
||||||
|
second: 99
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).export(module);
|
}).export(module);
|
||||||
|
|
Loading…
Reference in a new issue