Skip to content

Commit

Permalink
#205 add test for malformed configuration structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zsolt Lattmann committed Mar 9, 2015
1 parent 452d23b commit 3ed14a4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/config.global.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
14 changes: 14 additions & 0 deletions config/config.malformed.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion config/config.test.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
38 changes: 38 additions & 0 deletions test/config/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,36 @@
*/

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');

before(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;
});
Expand All @@ -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);

});

});

0 comments on commit 3ed14a4

Please sign in to comment.