diff --git a/config/config.global.js b/config/config.global.js index 3364bbd663..4e2ec250ca 100644 --- a/config/config.global.js +++ b/config/config.global.js @@ -1,7 +1,7 @@ /*jshint node: true*/ /** * @author lattmann / https://github.com/lattmann - * @author pemijer / https://github.com/pmeijer + * @author pmeijer / https://github.com/pmeijer */ var config = { diff --git a/config/config.malformed.js b/config/config.malformed.js new file mode 100644 index 0000000000..19982daa79 --- /dev/null +++ b/config/config.malformed.js @@ -0,0 +1,14 @@ +/*jshint node: true*/ +/** + * @author lattmann / https://github.com/lattmann + */ + +var config = require('./config.global'); + +config.server = {}; + + +config.mongo = {}; + + +module.exports = config; \ No newline at end of file diff --git a/config/config.test.js b/config/config.test.js index 821dcb1ab3..27fbd47fce 100644 --- a/config/config.test.js +++ b/config/config.test.js @@ -1,7 +1,7 @@ /*jshint node: true*/ /** * @author lattmann / https://github.com/lattmann - * @author pemijer / https://github.com/pmeijer + * @author pmeijer / https://github.com/pmeijer */ var config = require('./config.global'); diff --git a/test/config/config.spec.js b/test/config/config.spec.js index 394b0dae87..c9168f60b9 100644 --- a/test/config/config.spec.js +++ b/test/config/config.spec.js @@ -4,9 +4,12 @@ */ describe('configuration', function () { + 'use strict'; var should = require('chai').should(), oldNodeEnv = process.env.NODE_ENV, + path = require('path'), + configPath = path.join(__dirname, '..', '..', 'config', 'index.js'), configGlobal = require('../../config/config.global.js'), configTest = require('../../config/config.test.js'); @@ -14,6 +17,23 @@ describe('configuration', function () { }); + beforeEach(function () { + // clear the cached files + var key, + i, + modulesToUnload = []; + + for (key in require.cache) { + if (key.indexOf(configPath) > -1) { + modulesToUnload.push(key); + } + } + + for (i = 0; i < modulesToUnload.length; i += 1) { + delete require.cache[modulesToUnload[i]]; + } + }); + after(function () { process.env.NODE_ENV = oldNodeEnv; }); @@ -34,4 +54,22 @@ describe('configuration', function () { config.should.deep.equal(configTest); }); + it('should be serializable', function () { + var config; + process.env.NODE_ENV = 'test'; + config = require('../../config'); + + config.should.deep.equal(JSON.parse(JSON.stringify(config))); + }); + + it('should throw if configuration is malformed', function () { + var config; + process.env.NODE_ENV = 'malformed'; + + (function () { + config = require('../../config'); + }).should.throw(Error); + + }); + }); \ No newline at end of file