Permalink
Browse files

Converting to use lab

  • Loading branch information...
1 parent f7a8e30 commit cffb5527bf342abff15792785d69a119a1a8b844 @geek geek committed Mar 19, 2013
Showing with 111 additions and 109 deletions.
  1. +1 −1 .gitignore
  2. +7 −9 Makefile
  3. +3 −7 package.json
  4. +44 −40 test/index.js
  5. +56 −52 test/tv.js
View
@@ -15,4 +15,4 @@ config.json
*/*/._*
coverage.*
lib-cov
-
+complexity.md
View
@@ -1,12 +1,10 @@
-REPORTER = dot
-
test:
- @NODE_ENV=test ./node_modules/.bin/mocha --recursive --reporter $(REPORTER) --ignore-leaks --timeout 3000
-
-test-cov:
- @NODE_ENV=test ./node_modules/.bin/mocha --require blanket --recursive --ignore-leaks --timeout 3000 -R travis-cov
-
+ @./node_modules/.bin/lab
+test-cov:
+ @./node_modules/.bin/lab -r threshold -t 100
test-cov-html:
- @NODE_ENV=test ./node_modules/.bin/mocha --require blanket --recursive --ignore-leaks --timeout 3000 -R html-cov > coverage.html
+ @./node_modules/.bin/lab -r html -o coverage.html
+complexity:
+ @./node_modules/.bin/cr -o complexity.md -f markdown lib
-.PHONY: test test-cov test-cov-html
+.PHONY: test test-cov test-cov-html complexity
View
@@ -29,15 +29,11 @@
},
"devDependencies": {
"hapi": "0.15.x",
- "mocha": "1.x.x",
- "chai": "1.x.x",
- "blanket": "1.0.x",
- "travis-cov": "0.2.x"
+ "lab": "0.0.x",
+ "complexity-report": "0.x.x"
},
"scripts": {
- "test": "make test && make test-cov",
- "blanket": { "pattern": "//^((?!\/node_modules\/)(?!\/test\/).)*$/ig", "onlyCwd": true, "data-cover-flags": { "branchTracking": true } },
- "travis-cov": { "threshold": 100 }
+ "test": "make test-cov"
},
"licenses": [
{
View
@@ -1,6 +1,6 @@
// Load modules
-var Chai = require('chai');
+var Lab = require('lab');
var Hapi = require('hapi');
var Ws = require('ws');
@@ -12,69 +12,73 @@ var internals = {};
// Test shortcuts
-var expect = Chai.expect;
+var expect = Lab.expect;
+var before = Lab.before;
+var after = Lab.after;
+var describe = Lab.experiment;
+var it = Lab.test;
-describe('Tv', function () {
+describe('Tv', function () {
var server = null;
- before(function (done) {
-
- var options = {
- websocketPort: 3007
+ before(function (done) {
+
+ var options = {
+ websocketPort: 3007
};
server = new Hapi.Server();
- server.route({
- method: 'GET',
- path: '/',
- handler: function () {
+ server.route({
+ method: 'GET',
+ path: '/',
+ handler: function () {
- return this.reply('1');
- }
+ return this.reply('1');
+ }
});
- server.plugin.allow({ ext: true }).require('../', options, function (err) {
+ server.plugin.allow({ ext: true }).require('../', options, function (err) {
expect(err).to.not.exist;
- done();
- });
+ done();
+ });
});
- it('returns the console html', function (done) {
+ it('returns the console html', function (done) {
- server.inject({ method: 'GET', url: '/debug/console' }, function (res) {
+ server.inject({ method: 'GET', url: '/debug/console' }, function (res) {
expect(res.result).to.contain('<!DOCTYPE html>');
- done();
- });
- });
+ done();
+ });
+ });
- it('reports a request event', function (done) {
+ it('reports a request event', function (done) {
var ws = new Ws('ws://localhost:3007');
- ws.on('open', function () {
-
+ ws.on('open', function () {
+
ws.send('*');
-
- setTimeout(function () {
-
- server.inject({ method: 'GET', url: '/?debug=123' }, function (res) {
-
- expect(res.result).to.equal('1');
- });
- }, 100);
- });
-
- ws.once('message', function (data, flags) {
-
- expect(JSON.parse(data).data.agent).to.equal('shot');
- done();
- });
- });
+
+ setTimeout(function () {
+
+ server.inject({ method: 'GET', url: '/?debug=123' }, function (res) {
+
+ expect(res.result).to.equal('1');
+ });
+ }, 100);
+ });
+
+ ws.once('message', function (data, flags) {
+
+ expect(JSON.parse(data).data.agent).to.equal('shot');
+ done();
+ });
+ });
});
View
@@ -1,6 +1,6 @@
// Load modules
-var Chai = require('chai');
+var Lab = require('lab');
var Ws = require('ws');
var Tv = require('../lib/tv');
@@ -12,142 +12,146 @@ var internals = {};
// Test shortcuts
-var expect = Chai.expect;
+var expect = Lab.expect;
+var before = Lab.before;
+var after = Lab.after;
+var describe = Lab.experiment;
+var it = Lab.test;
-describe('Tv', function () {
+describe('Tv', function () {
- describe('#constructor', function () {
+ describe('#constructor', function () {
- it('cannot be constructed without new', function (done) {
+ it('cannot be constructed without new', function (done) {
- var fn = function () {
+ var fn = function () {
- var tv = Tv();
+ var tv = Tv();
};
expect(fn).to.throw(Error);
- done();
+ done();
});
- it('can be constructed with new', function (done) {
+ it('can be constructed with new', function (done) {
- var fn = function () {
+ var fn = function () {
- var tv = new Tv({ websocketPort: 3001 });
+ var tv = new Tv({ websocketPort: 3001 });
};
expect(fn).to.not.throw(Error);
- done();
+ done();
});
- it('uses the tv defaults when no config is passed in', function (done) {
+ it('uses the tv defaults when no config is passed in', function (done) {
var tv = new Tv();
expect(tv.settings.host).to.equal('0.0.0.0');
expect(tv.settings.websocketPort).to.equal(3000);
- done();
+ done();
});
- it('uses the passed in config', function (done) {
+ it('uses the passed in config', function (done) {
var tv = new Tv({ host: 'localhost', websocketPort: 3002 });
expect(tv.settings.host).to.equal('localhost');
expect(tv.settings.websocketPort).to.equal(3002);
- done();
+ done();
});
- it('adds message to subscribers list when receiving message', function (done) {
+ it('adds message to subscribers list when receiving message', function (done) {
var config = { host: 'localhost', websocketPort: 3010 }
var tv = new Tv(config);
var ws = new Ws("ws://" + config.host + ':' + config.websocketPort);
ws.readyState = Ws.OPEN;
- ws.on('open', function () {
+ ws.on('open', function () {
ws.send("test1");
- setTimeout(function () {
+ setTimeout(function () {
expect(tv._subscribers["test1"]).to.exist;
- done();
- }, 100);
- });
- });
+ done();
+ }, 100);
+ });
+ });
});
- describe('#report', function () {
+ describe('#report', function () {
- it('sends the data to all subscribers when session is null', function (done) {
+ it('sends the data to all subscribers when session is null', function (done) {
var tv = new Tv({ websocketPort: 3003 });
- tv._subscribers['*'] = [{
+ tv._subscribers['*'] = [{
readyState: Ws.OPEN,
- send: function (message) {
+ send: function (message) {
expect(message).to.exist;
expect(message).to.equal('"test"');
- done();
- }
+ done();
+ }
}];
- tv.report('test');
+ tv.report('test');
});
- it('only sends a message to the appropriate subscribers', function (done) {
+ it('only sends a message to the appropriate subscribers', function (done) {
var tv = new Tv({ websocketPort: 3004 });
- tv._subscribers['*'] = [{
+ tv._subscribers['*'] = [{
readyState: Ws.OPEN,
- send: function (message) {
+ send: function (message) {
- expect(message).to.not.exist;
- }
+ expect(message).to.not.exist;
+ }
}];
- tv._subscribers['test'] = [{
+ tv._subscribers['test'] = [{
readyState: Ws.OPEN,
- send: function (message) {
+ send: function (message) {
expect(message).to.exist;
expect(message).to.equal('"test"');
- done();
- }
+ done();
+ }
}];
- tv.report('test', 'test');
+ tv.report('test', 'test');
});
- it('only sends a message when the websocket exists', function (done) {
+ it('only sends a message when the websocket exists', function (done) {
var tv = new Tv({ websocketPort: 3005 });
- tv._subscribers['*'] = [{
+ tv._subscribers['*'] = [{
readyState: 'none',
- send: function (message) {
+ send: function (message) {
- expect(message).to.not.exist;
- }
+ expect(message).to.not.exist;
+ }
}];
tv.report('test');
- done();
- });
+ done();
+ });
});
- describe('#getMarkup', function () {
+ describe('#getMarkup', function () {
- it('includes the hostname and port in the source', function (done) {
+ it('includes the hostname and port in the source', function (done) {
var tv = new Tv({ host: 'localhost', websocketPort: 3006 });
var html = tv.getMarkup();
expect(html).to.contain('localhost');
expect(html).to.contain('3006');
- done();
- });
- });
+ done();
+ });
+ });
});

0 comments on commit cffb552

Please sign in to comment.