mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-13 03:02:49 +00:00
updated package.json
This commit is contained in:
32
node_modules/nconf/test/common-test.js
generated
vendored
Normal file
32
node_modules/nconf/test/common-test.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* common.js: Tests for common utility function in nconf.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
helpers = require('./helpers'),
|
||||
nconf = require('../lib/nconf');
|
||||
|
||||
var mergeDir = path.join(__dirname, 'fixtures', 'merge'),
|
||||
files = fs.readdirSync(mergeDir).map(function (f) { return path.join(mergeDir, f) });
|
||||
|
||||
vows.describe('nconf/common').addBatch({
|
||||
"Using nconf.common module": {
|
||||
"the loadFiles() method": {
|
||||
topic: function () {
|
||||
nconf.loadFiles(files, this.callback);
|
||||
},
|
||||
"should merge the files correctly": helpers.assertMerged
|
||||
},
|
||||
"the loadFilesSync() method": {
|
||||
"should merge the files correctly": function () {
|
||||
helpers.assertMerged(null, nconf.loadFilesSync(files));
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
126
node_modules/nconf/test/complete-test.js
generated
vendored
Normal file
126
node_modules/nconf/test/complete-test.js
generated
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* complete-test.js: Complete test for multiple stores.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
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 completeTest = helpers.fixture('complete-test.json'),
|
||||
complete = helpers.fixture('complete.json');
|
||||
|
||||
vows.describe('nconf/multiple-stores').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();
|
||||
});
|
||||
},
|
||||
"should have the correct `stores`": function () {
|
||||
assert.isObject(nconf.stores.env);
|
||||
assert.isObject(nconf.stores.argv);
|
||||
assert.isObject(nconf.stores.file);
|
||||
},
|
||||
"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.deepEqual(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');
|
||||
}
|
||||
}
|
||||
},
|
||||
teardown: function () {
|
||||
// remove the file so that we can test saving it async
|
||||
fs.unlinkSync(completeTest);
|
||||
}
|
||||
}
|
||||
}).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 () {
|
||||
fs.unlinkSync(completeTest);
|
||||
nconf.remove('file');
|
||||
nconf.remove('memory');
|
||||
nconf.remove('argv');
|
||||
nconf.remove('env');
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
19
node_modules/nconf/test/fixtures/bom.json
generated
vendored
Normal file
19
node_modules/nconf/test/fixtures/bom.json
generated
vendored
Normal file
@@ -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
|
||||
}
|
||||
19
node_modules/nconf/test/fixtures/complete.json
generated
vendored
Normal file
19
node_modules/nconf/test/fixtures/complete.json
generated
vendored
Normal file
@@ -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
|
||||
}
|
||||
30
node_modules/nconf/test/fixtures/data.js
generated
vendored
Normal file
30
node_modules/nconf/test/fixtures/data.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* data.js: Simple data fixture for configuration test.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
exports.data = {
|
||||
isNull: null,
|
||||
literal: 'bazz',
|
||||
arr: ['one', 2, true, { value: 'foo' }],
|
||||
obj: {
|
||||
host: 'localhost',
|
||||
port: 5984,
|
||||
array: ['one', 2, true, { foo: 'bar' }],
|
||||
auth: {
|
||||
username: 'admin',
|
||||
password: 'password'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.merge = {
|
||||
prop1: 1,
|
||||
prop2: [1, 2, 3],
|
||||
prop3: {
|
||||
foo: 'bar',
|
||||
bar: 'foo'
|
||||
}
|
||||
};
|
||||
5
node_modules/nconf/test/fixtures/hierarchy/global.json
generated
vendored
Normal file
5
node_modules/nconf/test/fixtures/hierarchy/global.json
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"title": "My generic title",
|
||||
"color": "red",
|
||||
"movie": "Kill Bill"
|
||||
}
|
||||
3
node_modules/nconf/test/fixtures/hierarchy/hierarchical.json
generated
vendored
Normal file
3
node_modules/nconf/test/fixtures/hierarchy/hierarchical.json
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"test": "empty"
|
||||
}
|
||||
4
node_modules/nconf/test/fixtures/hierarchy/user.json
generated
vendored
Normal file
4
node_modules/nconf/test/fixtures/hierarchy/user.json
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"title": "My specific title",
|
||||
"color": "green"
|
||||
}
|
||||
3
node_modules/nconf/test/fixtures/malformed.json
generated
vendored
Normal file
3
node_modules/nconf/test/fixtures/malformed.json
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"literal": "bazz",
|
||||
}
|
||||
19
node_modules/nconf/test/fixtures/merge/file1.json
generated
vendored
Normal file
19
node_modules/nconf/test/fixtures/merge/file1.json
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"apples": true,
|
||||
"bananas": true,
|
||||
"foo": {
|
||||
"bar": "boo"
|
||||
},
|
||||
"candy": {
|
||||
"something": "file1",
|
||||
"something1": true,
|
||||
"something2": true,
|
||||
"something5": {
|
||||
"first": 1,
|
||||
"second": 2
|
||||
}
|
||||
},
|
||||
"unicorn": {
|
||||
"exists": true
|
||||
}
|
||||
}
|
||||
10
node_modules/nconf/test/fixtures/merge/file2.json
generated
vendored
Normal file
10
node_modules/nconf/test/fixtures/merge/file2.json
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"candy": {
|
||||
"something": "file2",
|
||||
"something3": true,
|
||||
"something4": true
|
||||
},
|
||||
"dates": true,
|
||||
"elderberries": true,
|
||||
"unicorn": null
|
||||
}
|
||||
19
node_modules/nconf/test/fixtures/no-bom.json
generated
vendored
Normal file
19
node_modules/nconf/test/fixtures/no-bom.json
generated
vendored
Normal file
@@ -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
|
||||
}
|
||||
10
node_modules/nconf/test/fixtures/scripts/nconf-argv.js
generated
vendored
Normal file
10
node_modules/nconf/test/fixtures/scripts/nconf-argv.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* default-argv.js: Test fixture for using optimist defaults with nconf.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var nconf = require('../../../lib/nconf').argv().env();
|
||||
|
||||
process.stdout.write(nconf.get('something'));
|
||||
16
node_modules/nconf/test/fixtures/scripts/nconf-change-argv.js
generated
vendored
Normal file
16
node_modules/nconf/test/fixtures/scripts/nconf-change-argv.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* nconf-change-argv.js: Test fixture for changing argv on the fly
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var nconf = require('../../../lib/nconf').argv();
|
||||
|
||||
//
|
||||
// Remove 'badValue', 'evenWorse' and 'OHNOEZ'
|
||||
//
|
||||
process.argv.splice(3, 3);
|
||||
nconf.stores['argv'].loadArgv();
|
||||
process.stdout.write(nconf.get('something'));
|
||||
|
||||
10
node_modules/nconf/test/fixtures/scripts/nconf-env.js
generated
vendored
Normal file
10
node_modules/nconf/test/fixtures/scripts/nconf-env.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* nconf-env.js: Test fixture for using process.env defaults with nconf.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var nconf = require('../../../lib/nconf').env();
|
||||
|
||||
process.stdout.write(nconf.get('SOMETHING'));
|
||||
17
node_modules/nconf/test/fixtures/scripts/nconf-hierarchical-file-argv.js
generated
vendored
Normal file
17
node_modules/nconf/test/fixtures/scripts/nconf-hierarchical-file-argv.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* nconf-hierarchical-file-argv.js: Test fixture for using optimist defaults and a file store with nconf.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
* (C) 2011, Sander Tolsma
|
||||
*
|
||||
*/
|
||||
|
||||
var path = require('path'),
|
||||
nconf = require('../../../lib/nconf');
|
||||
|
||||
nconf.argv();
|
||||
nconf.add('file', {
|
||||
file: path.join(__dirname, '../hierarchy/hierarchical.json')
|
||||
});
|
||||
|
||||
process.stdout.write(nconf.get('something') || 'undefined');
|
||||
18
node_modules/nconf/test/fixtures/scripts/nconf-hierarchical-load-merge.js
generated
vendored
Normal file
18
node_modules/nconf/test/fixtures/scripts/nconf-hierarchical-load-merge.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* nconf-hierarchical-load-merge.js: Test fixture for loading and merging nested objects across stores.
|
||||
*
|
||||
* (C) 2012, Nodejitsu Inc.
|
||||
* (C) 2012, Michael Hart
|
||||
*
|
||||
*/
|
||||
|
||||
var path = require('path'),
|
||||
nconf = require('../../../lib/nconf');
|
||||
|
||||
nconf.argv()
|
||||
.file(path.join(__dirname, '..', 'merge', 'file1.json'));
|
||||
|
||||
process.stdout.write(JSON.stringify({
|
||||
apples: nconf.get('apples'),
|
||||
candy: nconf.get('candy')
|
||||
}));
|
||||
32
node_modules/nconf/test/fixtures/scripts/nconf-hierarchical-load-save.js
generated
vendored
Normal file
32
node_modules/nconf/test/fixtures/scripts/nconf-hierarchical-load-save.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* nconf-hierarchical-load-save.js: Test fixture for using optimist, envvars and a file store with nconf.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
nconf = require('../../../lib/nconf');
|
||||
|
||||
//
|
||||
// Setup nconf to use (in-order):
|
||||
// 1. Command-line arguments
|
||||
// 2. Environment variables
|
||||
// 3. A file located at 'path/to/config.json'
|
||||
//
|
||||
nconf.argv()
|
||||
.env()
|
||||
.file({ file: path.join(__dirname, '..', 'load-save.json') });
|
||||
|
||||
//
|
||||
// Set a few variables on `nconf`.
|
||||
//
|
||||
nconf.set('database:host', '127.0.0.1');
|
||||
nconf.set('database:port', 5984);
|
||||
|
||||
process.stdout.write(nconf.get('foo'));
|
||||
//
|
||||
// Save the configuration object to disk
|
||||
//
|
||||
nconf.save();
|
||||
11
node_modules/nconf/test/fixtures/scripts/nconf-nested-env.js
generated
vendored
Normal file
11
node_modules/nconf/test/fixtures/scripts/nconf-nested-env.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* nconf-nested-env.js: Test fixture for env with nested keys.
|
||||
*
|
||||
* (C) 2012, Nodejitsu Inc.
|
||||
* (C) 2012, Michael Hart
|
||||
*
|
||||
*/
|
||||
|
||||
var nconf = require('../../../lib/nconf').env('_');
|
||||
|
||||
process.stdout.write(nconf.get('SOME:THING'));
|
||||
12
node_modules/nconf/test/fixtures/scripts/provider-argv.js
generated
vendored
Normal file
12
node_modules/nconf/test/fixtures/scripts/provider-argv.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* provider-argv.js: Test fixture for using optimist defaults with nconf.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var nconf = require('../../../lib/nconf');
|
||||
|
||||
var provider = new (nconf.Provider)().argv();
|
||||
|
||||
process.stdout.write(provider.get('something'));
|
||||
12
node_modules/nconf/test/fixtures/scripts/provider-env.js
generated
vendored
Normal file
12
node_modules/nconf/test/fixtures/scripts/provider-env.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* provider-argv.js: Test fixture for using process.env defaults with nconf.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var nconf = require('../../../lib/nconf');
|
||||
|
||||
var provider = new (nconf.Provider)().env();
|
||||
|
||||
process.stdout.write(provider.get('SOMETHING'));
|
||||
68
node_modules/nconf/test/helpers.js
generated
vendored
Normal file
68
node_modules/nconf/test/helpers.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* helpers.js: Test helpers for nconf.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
spawn = require('child_process').spawn,
|
||||
util = require('util'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
nconf = require('../lib/nconf');
|
||||
|
||||
exports.assertMerged = function (err, merged) {
|
||||
merged = merged instanceof nconf.Provider
|
||||
? merged.store.store
|
||||
: merged;
|
||||
|
||||
assert.isNull(err);
|
||||
assert.isObject(merged);
|
||||
assert.isTrue(merged.apples);
|
||||
assert.isTrue(merged.bananas);
|
||||
assert.isObject(merged.candy);
|
||||
assert.isTrue(merged.candy.something1);
|
||||
assert.isTrue(merged.candy.something2);
|
||||
assert.isTrue(merged.candy.something3);
|
||||
assert.isTrue(merged.candy.something4);
|
||||
assert.isTrue(merged.dates);
|
||||
assert.isTrue(merged.elderberries);
|
||||
};
|
||||
|
||||
exports.assertSystemConf = function (options) {
|
||||
return {
|
||||
topic: function () {
|
||||
var env = null;
|
||||
|
||||
if (options.env) {
|
||||
env = {}
|
||||
Object.keys(process.env).forEach(function (key) {
|
||||
env[key] = process.env[key];
|
||||
});
|
||||
|
||||
Object.keys(options.env).forEach(function (key) {
|
||||
env[key] = options.env[key];
|
||||
});
|
||||
}
|
||||
|
||||
var child = spawn('node', [options.script].concat(options.argv), { env: env });
|
||||
child.stdout.once('data', this.callback.bind(this, null));
|
||||
},
|
||||
"should respond with the value passed into the script": function (_, data) {
|
||||
assert.equal(data.toString(), 'foobar');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// copy a file
|
||||
exports.cp = function (from, to, callback) {
|
||||
fs.readFile(from, function (err, data) {
|
||||
if (err) return callback(err);
|
||||
fs.writeFile(to, data, callback);
|
||||
});
|
||||
};
|
||||
|
||||
exports.fixture = function (file) {
|
||||
return path.join(__dirname, 'fixtures', file);
|
||||
};
|
||||
113
node_modules/nconf/test/hierarchy-test.js
generated
vendored
Normal file
113
node_modules/nconf/test/hierarchy-test.js
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* hierarchy-test.js: Basic tests for hierarchical file stores.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
spawn = require('child_process').spawn,
|
||||
vows = require('vows'),
|
||||
nconf = require('../lib/nconf');
|
||||
|
||||
var configDir = path.join(__dirname, 'fixtures', 'hierarchy'),
|
||||
globalConfig = path.join(configDir, 'global.json'),
|
||||
userConfig = path.join(configDir, 'user.json');
|
||||
|
||||
vows.describe('nconf/hierarchy').addBatch({
|
||||
"When using nconf": {
|
||||
"configured with two file stores": {
|
||||
topic: function () {
|
||||
nconf.add('user', { type: 'file', file: userConfig });
|
||||
nconf.add('global', { type: 'file', file: globalConfig });
|
||||
nconf.load();
|
||||
return nconf;
|
||||
},
|
||||
"should have the appropriate keys present": function () {
|
||||
assert.equal(nconf.get('title'), 'My specific title');
|
||||
assert.equal(nconf.get('color'), 'green');
|
||||
assert.equal(nconf.get('movie'), 'Kill Bill');
|
||||
}
|
||||
},
|
||||
"configured with two file stores using `file`": {
|
||||
topic: function () {
|
||||
nconf.file('user', userConfig);
|
||||
nconf.file('global', globalConfig);
|
||||
nconf.load();
|
||||
return nconf;
|
||||
},
|
||||
"should have the appropriate keys present": function () {
|
||||
assert.equal(nconf.get('title'), 'My specific title');
|
||||
assert.equal(nconf.get('color'), 'green');
|
||||
assert.equal(nconf.get('movie'), 'Kill Bill');
|
||||
}
|
||||
},
|
||||
"configured with .argv(), .env() and .file()": {
|
||||
topic: function () {
|
||||
var configFile = path.join(__dirname, 'fixtures', 'load-save.json'),
|
||||
script = path.join(__dirname, 'fixtures', 'scripts', 'nconf-hierarchical-load-save.js'),
|
||||
argv = ['--foo', 'foo', '--bar', 'bar'],
|
||||
that = this,
|
||||
data = '',
|
||||
child;
|
||||
|
||||
try { fs.unlinkSync(configFile) }
|
||||
catch (ex) { }
|
||||
|
||||
child = spawn('node', [script].concat(argv));
|
||||
|
||||
child.stdout.on('data', function (d) {
|
||||
data += d;
|
||||
});
|
||||
|
||||
child.on('exit', function () {
|
||||
fs.readFile(configFile, 'utf8', that.callback.bind(null, null, data));
|
||||
});
|
||||
},
|
||||
"should not persist information passed in to process.env and process.argv to disk ": function (_, data, _, ondisk){
|
||||
assert.equal(data, 'foo');
|
||||
assert.deepEqual(JSON.parse(ondisk), {
|
||||
database: {
|
||||
host: '127.0.0.1',
|
||||
port: 5984
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
"configured with .argv(), .file() and invoked with nested command line options": {
|
||||
topic: function () {
|
||||
var script = path.join(__dirname, 'fixtures', 'scripts', 'nconf-hierarchical-load-merge.js'),
|
||||
argv = ['--candy:something', 'foo', '--candy:something5:second', 'bar'],
|
||||
that = this,
|
||||
data = '',
|
||||
child;
|
||||
|
||||
child = spawn('node', [script].concat(argv));
|
||||
|
||||
child.stdout.on('data', function (d) {
|
||||
data += d;
|
||||
});
|
||||
|
||||
child.on('exit', function() {
|
||||
that.callback(null, data);
|
||||
});
|
||||
},
|
||||
"should merge nested objects ": function (err, data) {
|
||||
assert.deepEqual(JSON.parse(data), {
|
||||
apples: true,
|
||||
candy: {
|
||||
something: 'foo',
|
||||
something1: true,
|
||||
something2: true,
|
||||
something5: {
|
||||
first: 1,
|
||||
second: 'bar'
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
38
node_modules/nconf/test/mocks/mock-store.js
generated
vendored
Normal file
38
node_modules/nconf/test/mocks/mock-store.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* mock-store.js: Mock store for ensuring certain operations are actually called.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var util = require('util'),
|
||||
events = require('events'),
|
||||
nconf = require('../../lib/nconf');
|
||||
|
||||
var Mock = nconf.Mock = function () {
|
||||
events.EventEmitter.call(this);
|
||||
this.type = 'mock';
|
||||
};
|
||||
|
||||
// Inherit from Memory store.
|
||||
util.inherits(Mock, events.EventEmitter);
|
||||
|
||||
//
|
||||
// ### function save (value, callback)
|
||||
// #### @value {Object} _Ignored_ Left here for consistency
|
||||
// #### @callback {function} Continuation to respond to when complete.
|
||||
// Waits `1000ms` and then calls the callback and emits the `save` event.
|
||||
//
|
||||
Mock.prototype.save = function (value, callback) {
|
||||
if (!callback && typeof value === 'function') {
|
||||
callback = value;
|
||||
value = null;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
setTimeout(function () {
|
||||
self.emit('save');
|
||||
callback();
|
||||
}, 1000);
|
||||
};
|
||||
132
node_modules/nconf/test/nconf-test.js
generated
vendored
Normal file
132
node_modules/nconf/test/nconf-test.js
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* file-store-test.js: Tests for the nconf File store.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
nconf = require('../lib/nconf'),
|
||||
data = require('./fixtures/data').data;
|
||||
|
||||
vows.describe('nconf').addBatch({
|
||||
"When using the nconf": {
|
||||
"should have the correct methods set": function () {
|
||||
assert.isFunction(nconf.key);
|
||||
assert.isFunction(nconf.path);
|
||||
assert.isFunction(nconf.use);
|
||||
assert.isFunction(nconf.get);
|
||||
assert.isFunction(nconf.set);
|
||||
assert.isFunction(nconf.clear);
|
||||
assert.isFunction(nconf.load);
|
||||
assert.isFunction(nconf.save);
|
||||
assert.isFunction(nconf.reset);
|
||||
},
|
||||
"the use() method": {
|
||||
"should instaniate the correct store": function () {
|
||||
nconf.use('memory');
|
||||
nconf.load();
|
||||
assert.instanceOf(nconf.stores['memory'], nconf.Memory);
|
||||
}
|
||||
},
|
||||
"it should": {
|
||||
topic: function () {
|
||||
fs.readFile(path.join(__dirname, '..', 'package.json'), this.callback);
|
||||
},
|
||||
"have the correct version set": function (err, data) {
|
||||
assert.isNull(err);
|
||||
data = JSON.parse(data.toString());
|
||||
assert.equal(nconf.version, data.version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When using the nconf": {
|
||||
"with the memory store": {
|
||||
"the set() method": {
|
||||
"should respond with true": function () {
|
||||
assert.isTrue(nconf.set('foo:bar:bazz', 'buzz'));
|
||||
}
|
||||
},
|
||||
"the get() method": {
|
||||
"without a callback": {
|
||||
"should respond with the correct value": function () {
|
||||
assert.equal(nconf.get('foo:bar:bazz'), 'buzz');
|
||||
}
|
||||
},
|
||||
"with a callback": {
|
||||
topic: function () {
|
||||
nconf.get('foo:bar:bazz', this.callback);
|
||||
},
|
||||
"should respond with the correct value": function (err, value) {
|
||||
assert.equal(value, 'buzz');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When using the nconf": {
|
||||
"with the memory store": {
|
||||
"the get() method": {
|
||||
"should respond allow access to the root": function () {
|
||||
assert(nconf.get(null));
|
||||
assert(nconf.get(undefined));
|
||||
assert(nconf.get());
|
||||
}
|
||||
},
|
||||
"the set() method": {
|
||||
"should respond allow access to the root and complain about non-objects": function () {
|
||||
assert(!nconf.set(null, null));
|
||||
assert(!nconf.set(null, undefined));
|
||||
assert(!nconf.set(null));
|
||||
assert(!nconf.set(null, ''));
|
||||
assert(!nconf.set(null, 1));
|
||||
var original = nconf.get();
|
||||
assert(nconf.set(null, nconf.get()));
|
||||
assert.notEqual(nconf.get(), original);
|
||||
assert.deepEqual(nconf.get(), original)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When using nconf": {
|
||||
"with the memory store": {
|
||||
"the clear() method": {
|
||||
"should respond with the true": function () {
|
||||
assert.equal(nconf.get('foo:bar:bazz'), 'buzz');
|
||||
assert.isTrue(nconf.clear('foo:bar:bazz'));
|
||||
assert.isTrue(typeof nconf.get('foo:bar:bazz') === 'undefined');
|
||||
}
|
||||
},
|
||||
"the load() method": {
|
||||
"without a callback": {
|
||||
"should respond with the merged store": function () {
|
||||
assert.deepEqual(nconf.load(), {
|
||||
title: 'My specific title',
|
||||
color: 'green',
|
||||
movie: 'Kill Bill'
|
||||
});
|
||||
}
|
||||
},
|
||||
"with a callback": {
|
||||
topic: function () {
|
||||
nconf.load(this.callback.bind(null, null));
|
||||
},
|
||||
"should respond with the merged store": function (ign, err, store) {
|
||||
assert.isNull(err);
|
||||
assert.deepEqual(store, {
|
||||
title: 'My specific title',
|
||||
color: 'green',
|
||||
movie: 'Kill Bill'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
39
node_modules/nconf/test/provider-save-test.js
generated
vendored
Normal file
39
node_modules/nconf/test/provider-save-test.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* provider-save-test.js: Ensures consistency for Provider `save` operations.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
vows = require('vows'),
|
||||
nconf = require('../lib/nconf');
|
||||
|
||||
//
|
||||
// Expose `nconf.Mock`
|
||||
//
|
||||
require('./mocks/mock-store');
|
||||
|
||||
vows.describe('nconf/provider/save').addBatch({
|
||||
"When using nconf": {
|
||||
"an instance of 'nconf.Provider'": {
|
||||
"with a Mock store": {
|
||||
topic: function () {
|
||||
return nconf.use('mock');
|
||||
},
|
||||
"the save() method": {
|
||||
topic: function () {
|
||||
var mock = nconf.stores.mock,
|
||||
that = this;
|
||||
|
||||
mock.on('save', function () { that.saved = true });
|
||||
nconf.save(this.callback);
|
||||
},
|
||||
"should actually save before responding": function () {
|
||||
assert.isTrue(this.saved);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
170
node_modules/nconf/test/provider-test.js
generated
vendored
Normal file
170
node_modules/nconf/test/provider-test.js
generated
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* provider-test.js: Tests for the nconf Provider object.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
spawn = require('child_process').spawn,
|
||||
vows = require('vows'),
|
||||
helpers = require('./helpers'),
|
||||
nconf = require('../lib/nconf');
|
||||
|
||||
var fixturesDir = path.join(__dirname, 'fixtures'),
|
||||
mergeFixtures = path.join(fixturesDir, 'merge'),
|
||||
files = [path.join(mergeFixtures, 'file1.json'), path.join(mergeFixtures, 'file2.json')],
|
||||
override = JSON.parse(fs.readFileSync(files[0]), 'utf8');
|
||||
|
||||
function assertProvider(test) {
|
||||
return {
|
||||
topic: new nconf.Provider(),
|
||||
"should use the correct File store": test
|
||||
};
|
||||
}
|
||||
|
||||
vows.describe('nconf/provider').addBatch({
|
||||
"When using nconf": {
|
||||
"an instance of 'nconf.Provider'": {
|
||||
"calling the use() method with the same store type and different options": {
|
||||
topic: new nconf.Provider().use('file', { file: files[0] }),
|
||||
"should use a new instance of the store type": function (provider) {
|
||||
var old = provider.stores['file'];
|
||||
|
||||
assert.equal(provider.stores.file.file, files[0]);
|
||||
provider.use('file', { file: files[1] });
|
||||
|
||||
assert.notStrictEqual(old, provider.stores.file);
|
||||
assert.equal(provider.stores.file.file, files[1]);
|
||||
}
|
||||
},
|
||||
"when 'argv' is true": helpers.assertSystemConf({
|
||||
script: path.join(fixturesDir, 'scripts', 'provider-argv.js'),
|
||||
argv: ['--something', 'foobar']
|
||||
}),
|
||||
"when 'env' is true": helpers.assertSystemConf({
|
||||
script: path.join(fixturesDir, 'scripts', 'provider-env.js'),
|
||||
env: { SOMETHING: 'foobar' }
|
||||
})
|
||||
},
|
||||
"the default nconf provider": {
|
||||
"when 'argv' is set to true": helpers.assertSystemConf({
|
||||
script: path.join(fixturesDir, 'scripts', 'nconf-argv.js'),
|
||||
argv: ['--something', 'foobar'],
|
||||
env: { SOMETHING: true }
|
||||
}),
|
||||
"when 'env' is set to true": helpers.assertSystemConf({
|
||||
script: path.join(fixturesDir, 'scripts', 'nconf-env.js'),
|
||||
env: { SOMETHING: 'foobar' }
|
||||
}),
|
||||
"when 'argv' is set to true and process.argv is modified": helpers.assertSystemConf({
|
||||
script: path.join(fixturesDir, 'scripts', 'nconf-change-argv.js'),
|
||||
argv: ['--something', 'badValue', 'evenWorse', 'OHNOEZ', 'foobar']
|
||||
}),
|
||||
"when hierarchical 'argv' get": helpers.assertSystemConf({
|
||||
script: path.join(fixturesDir, 'scripts', 'nconf-hierarchical-file-argv.js'),
|
||||
argv: ['--something', 'foobar'],
|
||||
env: { SOMETHING: true }
|
||||
}),
|
||||
"when 'env' is set to true with a nested separator": helpers.assertSystemConf({
|
||||
script: path.join(fixturesDir, 'scripts', 'nconf-nested-env.js'),
|
||||
env: { SOME_THING: 'foobar' }
|
||||
})
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When using nconf": {
|
||||
"an instance of 'nconf.Provider'": {
|
||||
"the merge() method": {
|
||||
topic: new nconf.Provider().use('file', { file: files[1] }),
|
||||
"should have the result merged in": function (provider) {
|
||||
provider.load();
|
||||
provider.merge(override);
|
||||
helpers.assertMerged(null, provider.stores.file.store);
|
||||
assert.equal(provider.stores.file.store.candy.something, 'file1');
|
||||
},
|
||||
"should merge Objects over null": function (provider) {
|
||||
provider.load();
|
||||
provider.merge(override);
|
||||
assert.equal(provider.stores.file.store.unicorn.exists, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).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');
|
||||
}
|
||||
},
|
||||
"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');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When using nconf": {
|
||||
"an instance of 'nconf.Provider'": {
|
||||
"the .file() method": {
|
||||
"with a single filepath": assertProvider(function (provider) {
|
||||
provider.file(helpers.fixture('store.json'));
|
||||
assert.isObject(provider.stores.file);
|
||||
}),
|
||||
"with a name and a filepath": assertProvider(function (provider) {
|
||||
provider.file('custom', helpers.fixture('store.json'));
|
||||
assert.isObject(provider.stores.custom);
|
||||
}),
|
||||
"with a single object": assertProvider(function (provider) {
|
||||
provider.file({
|
||||
dir: helpers.fixture(''),
|
||||
file: 'store.json',
|
||||
search: true
|
||||
});
|
||||
|
||||
assert.isObject(provider.stores.file);
|
||||
assert.equal(provider.stores.file.file, helpers.fixture('store.json'));
|
||||
}),
|
||||
"with a name and an object": assertProvider(function (provider) {
|
||||
provider.file('custom', {
|
||||
dir: helpers.fixture(''),
|
||||
file: 'store.json',
|
||||
search: true
|
||||
});
|
||||
|
||||
assert.isObject(provider.stores.custom);
|
||||
assert.equal(provider.stores.custom.file, helpers.fixture('store.json'));
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
22
node_modules/nconf/test/stores/argv-test.js
generated
vendored
Normal file
22
node_modules/nconf/test/stores/argv-test.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* argv-test.js: Tests for the nconf argv store.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
helpers = require('../helpers'),
|
||||
nconf = require('../../lib/nconf');
|
||||
|
||||
vows.describe('nconf/stores/argv').addBatch({
|
||||
"An instance of nconf.Argv": {
|
||||
topic: new nconf.Argv(),
|
||||
"should have the correct methods defined": function (argv) {
|
||||
assert.isFunction(argv.loadSync);
|
||||
assert.isFunction(argv.loadArgv);
|
||||
assert.isFalse(argv.options);
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
24
node_modules/nconf/test/stores/env-test.js
generated
vendored
Normal file
24
node_modules/nconf/test/stores/env-test.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* env-test.js: Tests for the nconf env store.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
helpers = require('../helpers'),
|
||||
nconf = require('../../lib/nconf');
|
||||
|
||||
vows.describe('nconf/stores/env').addBatch({
|
||||
"An instance of nconf.Env": {
|
||||
topic: new nconf.Env(),
|
||||
"should have the correct methods defined": function (env) {
|
||||
assert.isFunction(env.loadSync);
|
||||
assert.isFunction(env.loadEnv);
|
||||
assert.isArray(env.whitelist);
|
||||
assert.lengthOf(env.whitelist, 0);
|
||||
assert.equal(env.separator, '');
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
226
node_modules/nconf/test/stores/file-store-test.js
generated
vendored
Normal file
226
node_modules/nconf/test/stores/file-store-test.js
generated
vendored
Normal file
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* file-store-test.js: Tests for the nconf File store.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
nconf = require('../../lib/nconf'),
|
||||
data = require('../fixtures/data').data,
|
||||
store;
|
||||
|
||||
vows.describe('nconf/stores/file').addBatch({
|
||||
"When using the nconf file store": {
|
||||
"with a valid JSON file": {
|
||||
topic: function () {
|
||||
var filePath = path.join(__dirname, '..', 'fixtures', 'store.json');
|
||||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
|
||||
this.store = store = new nconf.File({ file: filePath });
|
||||
return null;
|
||||
},
|
||||
"the load() method": {
|
||||
topic: function () {
|
||||
this.store.load(this.callback);
|
||||
},
|
||||
"should load the data correctly": function (err, data) {
|
||||
assert.isNull(err);
|
||||
assert.deepEqual(data, this.store.store);
|
||||
}
|
||||
}
|
||||
},
|
||||
"with a malformed JSON file": {
|
||||
topic: function () {
|
||||
var filePath = path.join(__dirname, '..', 'fixtures', 'malformed.json');
|
||||
this.store = new nconf.File({ file: filePath });
|
||||
return null;
|
||||
},
|
||||
"the load() method with a malformed JSON config file": {
|
||||
topic: function () {
|
||||
this.store.load(this.callback.bind(null, null));
|
||||
},
|
||||
"should respond with an error and indicate file name": function (_, err) {
|
||||
assert.isTrue(!!err);
|
||||
assert.match(err, /malformed\.json/);
|
||||
}
|
||||
}
|
||||
},
|
||||
"with a valid UTF8 JSON file that contains a BOM": {
|
||||
topic: function () {
|
||||
var filePath = path.join(__dirname, '..', 'fixtures', 'bom.json');
|
||||
this.store = store = new nconf.File({ file: filePath });
|
||||
return null;
|
||||
},
|
||||
"the load() method": {
|
||||
topic: function () {
|
||||
this.store.load(this.callback);
|
||||
},
|
||||
"should load the data correctly": function (err, data) {
|
||||
assert.isNull(err);
|
||||
assert.deepEqual(data, this.store.store);
|
||||
}
|
||||
},
|
||||
"the loadSync() method": {
|
||||
topic: function () {
|
||||
var data = this.store.loadSync();
|
||||
return data;
|
||||
},
|
||||
"should load the data correctly": function (result) {
|
||||
assert.deepEqual(result, this.store.store);
|
||||
}
|
||||
}
|
||||
},
|
||||
"with a valid UTF8 JSON file that contains no BOM": {
|
||||
topic: function () {
|
||||
var filePath = path.join(__dirname, '..', 'fixtures', 'no-bom.json');
|
||||
this.store = store = new nconf.File({ file: filePath });
|
||||
return null;
|
||||
},
|
||||
"the load() method": {
|
||||
topic: function () {
|
||||
this.store.load(this.callback);
|
||||
},
|
||||
"should load the data correctly": function (err, data) {
|
||||
assert.isNull(err);
|
||||
assert.deepEqual(data, this.store.store);
|
||||
}
|
||||
},
|
||||
"the loadSync() method": {
|
||||
topic: function () {
|
||||
var data = this.store.loadSync();
|
||||
return data;
|
||||
},
|
||||
"should load the data correctly": function (result) {
|
||||
assert.deepEqual(result, this.store.store);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When using the nconf file store": {
|
||||
topic: function () {
|
||||
var tmpPath = path.join(__dirname, '..', 'fixtures', 'tmp.json'),
|
||||
tmpStore = new nconf.File({ file: tmpPath });
|
||||
return tmpStore;
|
||||
},
|
||||
"the save() method": {
|
||||
topic: function (tmpStore) {
|
||||
var that = this;
|
||||
|
||||
Object.keys(data).forEach(function (key) {
|
||||
tmpStore.set(key, data[key]);
|
||||
});
|
||||
|
||||
tmpStore.save(function () {
|
||||
fs.readFile(tmpStore.file, function (err, d) {
|
||||
fs.unlinkSync(tmpStore.file);
|
||||
|
||||
return err
|
||||
? that.callback(err)
|
||||
: that.callback(err, JSON.parse(d.toString()));
|
||||
});
|
||||
});
|
||||
},
|
||||
"should save the data correctly": function (err, read) {
|
||||
assert.isNull(err);
|
||||
assert.deepEqual(read, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When using the nconf file store": {
|
||||
topic: function () {
|
||||
var tmpPath = path.join(__dirname, '..', 'fixtures', 'tmp.json'),
|
||||
tmpStore = new nconf.File({ file: tmpPath });
|
||||
return tmpStore;
|
||||
},
|
||||
"the saveSync() method": {
|
||||
topic: function (tmpStore) {
|
||||
var that = this;
|
||||
|
||||
Object.keys(data).forEach(function (key) {
|
||||
tmpStore.set(key, data[key]);
|
||||
});
|
||||
|
||||
var saved = tmpStore.saveSync();
|
||||
|
||||
fs.readFile(tmpStore.file, function (err, d) {
|
||||
fs.unlinkSync(tmpStore.file);
|
||||
|
||||
return err
|
||||
? that.callback(err)
|
||||
: that.callback(err, JSON.parse(d.toString()), saved);
|
||||
});
|
||||
},
|
||||
"should save the data correctly": function (err, read, saved) {
|
||||
assert.isNull(err);
|
||||
assert.deepEqual(read, data);
|
||||
assert.deepEqual(read, saved);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When using the nconf file store": {
|
||||
"the set() method": {
|
||||
"should respond with true": function () {
|
||||
assert.isTrue(store.set('foo:bar:bazz', 'buzz'));
|
||||
assert.isTrue(store.set('falsy:number', 0));
|
||||
assert.isTrue(store.set('falsy:string', ''));
|
||||
assert.isTrue(store.set('falsy:boolean', false));
|
||||
assert.isTrue(store.set('falsy:object', null));
|
||||
}
|
||||
},
|
||||
"the get() method": {
|
||||
"should respond with the correct value": function () {
|
||||
assert.equal(store.get('foo:bar:bazz'), 'buzz');
|
||||
assert.equal(store.get('falsy:number'), 0);
|
||||
assert.equal(store.get('falsy:string'), '');
|
||||
assert.equal(store.get('falsy:boolean'), false);
|
||||
assert.equal(store.get('falsy:object'), null);
|
||||
}
|
||||
},
|
||||
"the clear() method": {
|
||||
"should respond with the true": function () {
|
||||
assert.equal(store.get('foo:bar:bazz'), 'buzz');
|
||||
assert.isTrue(store.clear('foo:bar:bazz'));
|
||||
assert.isTrue(typeof store.get('foo:bar:bazz') === 'undefined');
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When using the nconf file store": {
|
||||
"the search() method": {
|
||||
"when the target file exists higher in the directory tree": {
|
||||
topic: function () {
|
||||
var filePath = this.filePath = path.join(process.env.HOME, '.nconf');
|
||||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
|
||||
return new (nconf.File)({
|
||||
file: '.nconf'
|
||||
})
|
||||
},
|
||||
"should update the file appropriately": function (store) {
|
||||
store.search();
|
||||
assert.equal(store.file, this.filePath);
|
||||
fs.unlinkSync(this.filePath);
|
||||
}
|
||||
},
|
||||
"when the target file doesn't exist higher in the directory tree": {
|
||||
topic: function () {
|
||||
var filePath = this.filePath = path.join(__dirname, '..', 'fixtures', 'search-store.json');
|
||||
return new (nconf.File)({
|
||||
dir: path.dirname(filePath),
|
||||
file: 'search-store.json'
|
||||
})
|
||||
},
|
||||
"should update the file appropriately": function (store) {
|
||||
store.search();
|
||||
assert.equal(store.file, this.filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
|
||||
31
node_modules/nconf/test/stores/literal-test.js
generated
vendored
Normal file
31
node_modules/nconf/test/stores/literal-test.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* literal-test.js: Tests for the nconf literal store.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
helpers = require('../helpers'),
|
||||
nconf = require('../../lib/nconf');
|
||||
|
||||
vows.describe('nconf/stores/literal').addBatch({
|
||||
"An instance of nconf.Literal": {
|
||||
topic: new nconf.Literal({
|
||||
foo: 'bar',
|
||||
one: 2
|
||||
}),
|
||||
"should have the correct methods defined": function (literal) {
|
||||
assert.equal(literal.type, 'literal');
|
||||
assert.isFunction(literal.get);
|
||||
assert.isFunction(literal.set);
|
||||
assert.isFunction(literal.merge);
|
||||
assert.isFunction(literal.loadSync);
|
||||
},
|
||||
"should have the correct values in the store": function (literal) {
|
||||
assert.equal(literal.store.foo, 'bar');
|
||||
assert.equal(literal.store.one, 2);
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
108
node_modules/nconf/test/stores/memory-store-test.js
generated
vendored
Normal file
108
node_modules/nconf/test/stores/memory-store-test.js
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* memory-store-test.js: Tests for the nconf Memory store.
|
||||
*
|
||||
* (C) 2011, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
nconf = require('../../lib/nconf'),
|
||||
merge = require('../fixtures/data').merge;
|
||||
|
||||
vows.describe('nconf/stores/memory').addBatch({
|
||||
"When using the nconf memory store": {
|
||||
topic: new nconf.Memory(),
|
||||
"the set() method": {
|
||||
"should respond with true": function (store) {
|
||||
assert.isTrue(store.set('foo:bar:bazz', 'buzz'));
|
||||
assert.isTrue(store.set('falsy:number', 0));
|
||||
assert.isTrue(store.set('falsy:string:empty', ''));
|
||||
assert.isTrue(store.set('falsy:string:value', 'value'));
|
||||
assert.isTrue(store.set('falsy:boolean', false));
|
||||
assert.isTrue(store.set('falsy:object', null));
|
||||
}
|
||||
},
|
||||
"the get() method": {
|
||||
"should respond with the correct value": function (store) {
|
||||
assert.equal(store.get('foo:bar:bazz'), 'buzz');
|
||||
assert.equal(store.get('falsy:number'), 0);
|
||||
assert.equal(store.get('falsy:string:empty'), '');
|
||||
assert.equal(store.get('falsy:string:value'), 'value');
|
||||
assert.equal(store.get('falsy:boolean'), false);
|
||||
assert.equal(store.get('falsy:object'), null);
|
||||
},
|
||||
"should not fail when retrieving non-existent keys": {
|
||||
"at the root level": function (store) {
|
||||
assert.doesNotThrow(function() {
|
||||
assert.equal(store.get('this:key:does:not:exist'), undefined);
|
||||
}, TypeError);
|
||||
},
|
||||
"within numbers": function (store) {
|
||||
assert.doesNotThrow(function() {
|
||||
assert.equal(store.get('falsy:number:not:exist'), undefined);
|
||||
}, TypeError);
|
||||
},
|
||||
"within booleans": function (store) {
|
||||
assert.doesNotThrow(function() {
|
||||
assert.equal(store.get('falsy:boolean:not:exist'), undefined);
|
||||
}, TypeError);
|
||||
},
|
||||
"within objects": function (store) {
|
||||
assert.doesNotThrow(function() {
|
||||
assert.equal(store.get('falsy:object:not:exist'), undefined);
|
||||
}, TypeError);
|
||||
},
|
||||
"within empty strings": function (store) {
|
||||
assert.doesNotThrow(function() {
|
||||
assert.equal(store.get('falsy:string:empty:not:exist'), undefined);
|
||||
}, TypeError);
|
||||
},
|
||||
"within non-empty strings": function (store) {
|
||||
assert.doesNotThrow(function() {
|
||||
assert.equal(store.get('falsy:string:value:not:exist'), undefined);
|
||||
}, TypeError);
|
||||
}
|
||||
}
|
||||
},
|
||||
"the clear() method": {
|
||||
"should respond with the true": function (store) {
|
||||
assert.equal(store.get('foo:bar:bazz'), 'buzz');
|
||||
assert.isTrue(store.clear('foo:bar:bazz'));
|
||||
assert.isTrue(typeof store.get('foo:bar:bazz') === 'undefined');
|
||||
}
|
||||
},
|
||||
"the merge() method": {
|
||||
"when overriding an existing literal value": function (store) {
|
||||
store.set('merge:literal', 'string-value');
|
||||
store.merge('merge:literal', merge);
|
||||
assert.deepEqual(store.get('merge:literal'), merge);
|
||||
},
|
||||
"when overriding an existing Array value": function (store) {
|
||||
store.set('merge:array', [1,2,3,4]);
|
||||
store.merge('merge:array', merge);
|
||||
assert.deepEqual(store.get('merge:literal'), merge);
|
||||
},
|
||||
"when merging into an existing Object value": function (store) {
|
||||
store.set('merge:object', {
|
||||
prop1: 2,
|
||||
prop2: 'prop2',
|
||||
prop3: {
|
||||
bazz: 'bazz'
|
||||
},
|
||||
prop4: ['foo', 'bar']
|
||||
});
|
||||
store.merge('merge:object', merge);
|
||||
|
||||
assert.equal(store.get('merge:object:prop1'), 1);
|
||||
assert.equal(store.get('merge:object:prop2').length, 3);
|
||||
assert.deepEqual(store.get('merge:object:prop3'), {
|
||||
foo: 'bar',
|
||||
bar: 'foo',
|
||||
bazz: 'bazz'
|
||||
});
|
||||
assert.equal(store.get('merge:object:prop4').length, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
Reference in New Issue
Block a user