-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`complete-test.js` correctly tests the modified `save()` method. It is an attempt at a more complete functional test of nconf.
- Loading branch information
Russell Frank
committed
May 2, 2012
1 parent
36e061c
commit 94bdb7d
Showing
4 changed files
with
164 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
.DS_Store | ||
config.json | ||
test/fixtures/*.json | ||
!test/fixtures/complete.json | ||
!test/fixtures/malformed.json | ||
node_modules/ | ||
node_modules/* | ||
npm-debug.log | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* complete-test.js: Complete test with multiple providers | ||
*/ | ||
|
||
var fs = require('fs'), | ||
path = require('path'), | ||
vows = require('vows'), | ||
assert = require('assert'), | ||
nconf = require('../lib/nconf'), | ||
data = require('./fixtures/data').data, | ||
helpers = require('./helpers'); | ||
|
||
var complete = helpers.fixture('complete.json'); | ||
var completeTest = helpers.fixture('complete-test.json'); | ||
|
||
vows.describe('nconf').addBatch({ | ||
"When using the nconf with multiple providers": { | ||
topic: function () { | ||
var that = this; | ||
helpers.cp(complete, completeTest, function () { | ||
nconf.env(); | ||
nconf.file({file: completeTest}); | ||
nconf.use('argv', {type: 'literal', store: data}); | ||
that.callback(); | ||
}); | ||
}, | ||
|
||
"env vars": { | ||
"are present": function () { | ||
Object.keys(process.env).forEach(function (key) { | ||
assert.equal(nconf.get(key), process.env[key]); | ||
}); | ||
} | ||
}, | ||
|
||
"json vars": { | ||
topic: function () { | ||
fs.readFile(complete, 'utf8', this.callback); | ||
}, | ||
|
||
"are present": function (err, data) { | ||
assert.isNull(err); | ||
data = JSON.parse(data); | ||
Object.keys(data).forEach(function (key) { | ||
assert.deepEqual(nconf.get(key), data[key]); | ||
}); | ||
} | ||
}, | ||
|
||
"literal vars": { | ||
"are present": function () { | ||
Object.keys(data).forEach(function (key) { | ||
assert.equal(nconf.get(key), data[key]); | ||
}); | ||
} | ||
}, | ||
|
||
"and saving *synchronously*": { | ||
topic: function () { | ||
nconf.set('weebls', 'stuff'); | ||
return nconf.save(); | ||
}, | ||
|
||
"correct return value": function (topic) { | ||
Object.keys(topic).forEach(function (key) { | ||
assert.deepEqual(topic[key], nconf.get(key)); | ||
}); | ||
}, | ||
|
||
"the file": { | ||
topic: function () { | ||
fs.readFile(completeTest, 'utf8', this.callback); | ||
}, | ||
|
||
"saved correctly": function (err, data) { | ||
data = JSON.parse(data); | ||
Object.keys(data).forEach(function (key) { | ||
assert.deepEqual(data[key], nconf.get(key)); | ||
}); | ||
assert.equal(nconf.get('weebls'), 'stuff'); | ||
} | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
// Threw this in it's own batch to make sure it's run separately from the | ||
// sync check | ||
"When using the nconf with multiple providers": { | ||
"and saving *asynchronously*": { | ||
topic: function () { | ||
nconf.set('weebls', 'crap'); | ||
nconf.save(this.callback); | ||
}, | ||
|
||
"correct return value": function (err, data) { | ||
assert.isNull(err); | ||
Object.keys(data).forEach(function (key) { | ||
assert.deepEqual(data[key], nconf.get(key)); | ||
}); | ||
}, | ||
|
||
"the file": { | ||
topic: function () { | ||
fs.readFile(completeTest, 'utf8', this.callback); | ||
}, | ||
|
||
"saved correctly": function (err, data) { | ||
assert.isNull(err); | ||
data = JSON.parse(data); | ||
Object.keys(data).forEach(function (key) { | ||
assert.deepEqual(nconf.get(key), data[key]); | ||
}); | ||
assert.equal(nconf.get('weebls'), 'crap'); | ||
} | ||
} | ||
}, | ||
|
||
teardown: function () { | ||
nconf.remove('file'); | ||
nconf.remove('memory'); | ||
nconf.remove('argv'); | ||
nconf.remove('env'); | ||
} | ||
} | ||
}).export(module); | ||
|
||
// vim: ts=2 shiftwidth=2 softtabstop=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"I've seen things": { | ||
"like": [ | ||
"carrots", | ||
"handbags", | ||
"cheese", | ||
"toilets", | ||
"russians", | ||
"planets", | ||
"hampsters", | ||
"weddings", | ||
"poets", | ||
"stalin", | ||
"kuala lumpur" | ||
] | ||
}, | ||
"host": "weebls-stuff.com", | ||
"port": 78304 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters