I used Mocha for the testing framework and Chai for the assertion library.
See http://actionherojs.com for ActionHero information.
- test
- actions
- status.test.js
- mocks
- api.js
- connection.js
- tasks
- init.js
- actions
describe('Status Test',function(){ | |
var action = require('../../actions/status').action | |
describe('Definition',function(){ | |
it('should have a name',function(){ | |
expect(action.name).to.equal('status') | |
}) | |
it('should have a description',function(){ | |
expect(action.description).to.equal('I will return some basic information about the API') | |
}) | |
it('should have inputs',function(){ | |
expect(action.inputs).to.be.an('object') | |
}) | |
it('should have blocked connection types',function(){ | |
expect(action.blockedConnectionTypes).to.be.instanceOf(Array) | |
}) | |
it('should have valid example output',function(){ | |
var out = action.outputExample | |
expect(out.status).to.equal('OK') | |
expect(out.uptime).to.equal(1234) | |
expect(Object.keys(out.stats).length).to.equal(0) | |
}) | |
}) | |
describe('Run',function(){ | |
var api = require('../mocks/api')() | |
, connectionMock = require('../mocks/connection')() | |
action.run(api,connectionMock,function(connection){ | |
console.log(connection) | |
it('should have an id',function(){ | |
expect(connection.response.id).to.equal('1234') | |
}) | |
it('should have a status',function(){ | |
expect(connection.response.status).to.equal('OK') | |
}) | |
it('should have a uptime',function(){ | |
expect(connection.response.uptime).to.be.greaterThan(0) | |
}) | |
it('should have stats',function(){ | |
expect(Object.keys(connection.response.stats).length).to.be.greaterThan(0) | |
}) | |
}) | |
}) | |
}) |
module.exports = function(){ | |
return { | |
response: {} | |
} | |
} |
module.exports = function(grunt){ | |
//config | |
grunt.initConfig({ | |
jshint: { | |
options: { | |
jshintrc: true, | |
reporter: require('jshint-stylish') | |
}, | |
server: ['actions/*.js','initializers/*.js','tasks/*.js','test/*.js'] | |
}, | |
mochaTest: { | |
test: { | |
options: { | |
reporter: 'spec' | |
}, | |
src: ['test/init.js','test/*.test.js','test/**/*.test.js'] | |
} | |
} | |
}) | |
//load tasks | |
grunt.loadNpmTasks('grunt-contrib-jshint') | |
grunt.loadNpmTasks('grunt-mocha-test') | |
//macros | |
grunt.registerTask('test',['jshint','mochaTest']) | |
} |
/* global expect: true */ | |
expect = require('chai').expect |
var action = {} | |
///////////////////////////////////////////////////////////////////// | |
// metadata | |
action.name = 'status' | |
action.description = 'I will return some basic information about the API' | |
action.inputs = { | |
'required' : [], | |
'optional' : [] | |
} | |
action.blockedConnectionTypes = [] | |
action.outputExample = { | |
status: 'OK', | |
uptime: 1234, | |
stats: {} | |
} | |
///////////////////////////////////////////////////////////////////// | |
// functional | |
action.run = function(api, connection, next){ | |
connection.response.id = api.id | |
connection.response.status = 'OK' | |
var now = new Date().getTime() | |
connection.response.uptime = now - api.bootTime | |
api.stats.getAll(function(err, stats){ | |
connection.response.stats = stats | |
api.tasks.details(function(err, details){ | |
connection.response.queues = details.queues | |
next(connection, true) | |
}) | |
}) | |
} | |
///////////////////////////////////////////////////////////////////// | |
// exports | |
exports.action = action |
describe('Status Test',function(){ | |
var action = require('../../actions/status').action | |
describe('Definition',function(){ | |
it('should have a name',function(){ | |
expect(action.name).to.equal('status') | |
}) | |
it('should have a description',function(){ | |
expect(action.description).to.equal('I will return some basic information about the API') | |
}) | |
it('should have inputs',function(){ | |
expect(action.inputs).to.be.an('object') | |
}) | |
it('should have blocked connection types',function(){ | |
expect(action.blockedConnectionTypes).to.be.instanceOf(Array) | |
}) | |
it('should have valid example output',function(){ | |
var out = action.outputExample | |
expect(out.status).to.equal('OK') | |
expect(out.uptime).to.equal(1234) | |
expect(Object.keys(out.stats).length).to.equal(0) | |
}) | |
}) | |
describe('Run',function(){ | |
var api = require('../mocks/api')() | |
, connectionMock = require('../mocks/connection')() | |
action.run(api,connectionMock,function(connection){ | |
it('should have an id',function(){ | |
expect(connection.response.id).to.equal('1234') | |
}) | |
it('should have a status',function(){ | |
expect(connection.response.status).to.equal('OK') | |
}) | |
it('should have a uptime',function(){ | |
expect(connection.response.uptime).to.be.greaterThan(0) | |
}) | |
it('should have stats',function(){ | |
expect(Object.keys(connection.response.stats).length).to.be.greaterThan(0) | |
}) | |
}) | |
}) | |
}) |
I used Mocha for the testing framework and Chai for the assertion library.
See http://actionherojs.com for ActionHero information.