diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..0175d8220 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: + - "0.6" + - "0.8" + - "0.10" diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..c7e08fb3b --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +mocha = ../node_modules/.bin/mocha --reporter spec + +test: + cd client && $(mocha) + cd server && $(mocha) + +all: test + +.PHONY: test diff --git a/client/test/chest.js b/client/test/chest.js new file mode 100644 index 000000000..1102ccc42 --- /dev/null +++ b/client/test/chest.js @@ -0,0 +1,62 @@ +var requirejs = require('requirejs'), + should = require('should'), + sinon = require('sinon'); +var globals = new Object(); + +requirejs.config({nodeRequire: require, baseUrl: 'js/'}); + +requirejs(['lib/class', '../../shared/js/gametypes'], function(_Class, _Types) { + globals.Class = _Class; + globals.Types = _Types; + global.window = globals +}); + +describe('Chest', function() { + var Chest; + var self = this; + + beforeEach(function(done) { + + requirejs(['chest'], function(_Module) { + Chest = _Module; + self.chest = new Chest(1); + done(); + }); + }); + + + describe('#getSpriteName', function() { + it('should return "chest"', function() { + self.chest.getSpriteName().should.equal("chest"); + }); + }); + + describe('#isMoving', function() { + it('should return false', function() { + self.chest.isMoving().should.be.false + }); + }); + + describe('#onOpen', function() { + it('sets open_callback to the passed function', function() { + var func = function() {}; + self.chest.onOpen(func); + self.chest.open_callback.toString().should.equal(func.toString()); + }); + }); + + describe('#open', function() { + it('calls open_callback if set', function() { + var spy = sinon.spy(); + self.chest.onOpen(spy); + self.chest.open(); + spy.called.should.equal.true; + }); + + it('does not call open_callback if not set', function() { + var spy = sinon.spy(self.chest.open_callback); + self.chest.open(); + spy.called.should.equal.false; + }); + }); +}); diff --git a/package.json b/package.json index 16c9eebc0..a97d7766b 100644 --- a/package.json +++ b/package.json @@ -13,5 +13,12 @@ , "memcache": ">0" , "redis": ">0" , "connect": ">2" + , "mocha": ">1" + , "requirejs": ">2" + , "should": ">1" + , "sinon": ">1" + } + , "scripts": { + "test": "make test" } }