From 38571097939b6e053833ddadb974696a728a30b4 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 5 Sep 2014 17:04:15 +0100 Subject: [PATCH] add unit test suite --- package.json | 9 +++++++-- test/unit/controller/index.js | 35 +++++++++++++++++++++++++++++++++++ test/unit/run.js | 11 +++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 test/unit/controller/index.js create mode 100644 test/unit/run.js diff --git a/package.json b/package.json index f305b6e9..34ca0fb2 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "main": "index.js", "scripts": { "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" }, "repository": { @@ -29,7 +30,11 @@ "elasticsearch": ">=1.2.1" }, "dependencies": { - "ciao": "^0.3.4", "express": "^4.8.8" + }, + "devDependencies": { + "ciao": "^0.3.4", + "tape": "^2.13.4", + "tap-spec": "^0.2.0" } } diff --git a/test/unit/controller/index.js b/test/unit/controller/index.js new file mode 100644 index 00000000..42650322 --- /dev/null +++ b/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); + } +}; \ No newline at end of file diff --git a/test/unit/run.js b/test/unit/run.js new file mode 100644 index 00000000..36045ca9 --- /dev/null +++ b/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); +}); \ No newline at end of file