From 608b6077827bb05edfc7d4605b68cad8ee587f91 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Wed, 16 Aug 2017 04:37:19 +0100 Subject: [PATCH] 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 --- .travis.yml | 13 +++----- test/fixtures/merge/file3.json | 9 ++++++ .../nconf-hierarchical-defaults-merge.js | 20 ++++++++++++ test/hierarchy-test.js | 32 +++++++++++++++++++ 4 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 test/fixtures/merge/file3.json create mode 100644 test/fixtures/scripts/nconf-hierarchical-defaults-merge.js diff --git a/.travis.yml b/.travis.yml index 696701c..31d52fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,15 +3,9 @@ language: node_js node_js: - "0.10" - "0.12" - - "4.1" - - "5" - -before_install: - - travis_retry npm install npm -g - -before_install: - - travis_retry npm install -g npm@2.5.1 - - travis_retry npm install + - "4" + - "6" + - "7" script: - npm test @@ -23,6 +17,7 @@ after_script: matrix: allow_failures: - node_js: "0.10" + - node_js: "0.12" notifications: email: diff --git a/test/fixtures/merge/file3.json b/test/fixtures/merge/file3.json new file mode 100644 index 0000000..e519308 --- /dev/null +++ b/test/fixtures/merge/file3.json @@ -0,0 +1,9 @@ +{ + "candy": { + "something": "much better something for you", + "something18": "completely unique", + "something5": { + "second": 99 + } + } +} diff --git a/test/fixtures/scripts/nconf-hierarchical-defaults-merge.js b/test/fixtures/scripts/nconf-hierarchical-defaults-merge.js new file mode 100644 index 0000000..3e225d8 --- /dev/null +++ b/test/fixtures/scripts/nconf-hierarchical-defaults-merge.js @@ -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') +})); diff --git a/test/hierarchy-test.js b/test/hierarchy-test.js index 76566d5..d1c0030 100644 --- a/test/hierarchy-test.js +++ b/test/hierarchy-test.js @@ -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);