Browse Source

add unit test suite

pull/2/head
Peter Johnson 10 years ago
parent
commit
3857109793
  1. 9
      package.json
  2. 35
      test/unit/controller/index.js
  3. 11
      test/unit/run.js

9
package.json

@ -8,7 +8,8 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"start": "node index.js", "start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 0", "test": "npm run unit && npm run ciao",
"unit": "node test/unit/run.js | tap-spec",
"ciao": "node node_modules/ciao/bin/ciao -c test/ciao.json test/ciao" "ciao": "node node_modules/ciao/bin/ciao -c test/ciao.json test/ciao"
}, },
"repository": { "repository": {
@ -29,7 +30,11 @@
"elasticsearch": ">=1.2.1" "elasticsearch": ">=1.2.1"
}, },
"dependencies": { "dependencies": {
"ciao": "^0.3.4",
"express": "^4.8.8" "express": "^4.8.8"
},
"devDependencies": {
"ciao": "^0.3.4",
"tape": "^2.13.4",
"tap-spec": "^0.2.0"
} }
} }

35
test/unit/controller/index.js

@ -0,0 +1,35 @@
var controller = require('../../../controller/index');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('valid interface', function(t) {
t.equal(typeof controller, 'function', 'controller is a function');
t.end();
});
};
module.exports.tests.info = function(test, common) {
test('returns server info', function(t) {
var res = { json: function( json ){
t.equal(typeof json, 'object', 'returns json');
t.equal(typeof json.name, 'string', 'name');
t.equal(typeof json.version, 'object', 'version');
t.equal(typeof json.version.number, 'string', 'version number');
t.end();
}};
controller( null, res );
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape(name + ' / ' , testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};

11
test/unit/run.js

@ -0,0 +1,11 @@
var tape = require('tape');
var common = {};
var tests = [
require('./controller/index')
];
tests.map(function(t) {
t.all(tape, common);
});
Loading…
Cancel
Save