Comparing version 0.2.3 to 0.2.4
var request = require('request') | ||
, convert = require('../services/converter'); | ||
, convert = require('../services/converter') | ||
module.exports = function(e, opts) { | ||
return request.post( | ||
{ | ||
url: 'http://localhost:' + this.port | ||
, json: { | ||
event: e | ||
, statusCode: 0 | ||
, ttl: convert.minutesToMilliseconds(opts.ttl) | ||
} | ||
var reqBody = { | ||
url: 'http://localhost:' + this.port, | ||
json: { | ||
event: e, | ||
statusCode: 0, | ||
ttl: convert.minutesToMilliseconds(opts.ttl) | ||
} | ||
, function(err, res, body) { | ||
opts && opts.callback && opts.callback(err, res, body); | ||
}); | ||
}; | ||
} | ||
return request.post(reqBody, function(err, res, body) { | ||
opts && opts.callback && opts.callback(err, res, body) | ||
}) | ||
} |
@@ -1,9 +0,9 @@ | ||
var request = require('request'); | ||
var request = require('request') | ||
module.exports = function(opts) { | ||
return request.del( | ||
{ url: 'http://localhost:' + this.port } | ||
, function(err, res, body) { | ||
opts && opts.callback && opts.callback(err, res, body); | ||
}); | ||
}; | ||
var reqBody = { url: 'http://localhost:' + this.port } | ||
return request.del(reqBody, function(err, res, body) { | ||
opts && opts.callback && opts.callback(err, res, body) | ||
}) | ||
} |
var request = require('request') | ||
, convert = require('../services/converter'); | ||
, convert = require('../services/converter') | ||
module.exports = function(e, opts) { | ||
return request.post( | ||
{ | ||
url: 'http://localhost:' + this.port | ||
, json: { | ||
event: e | ||
, statusCode: 1 | ||
, ttl: convert.minutesToMilliseconds(opts.ttl) | ||
} | ||
var reqBody = { | ||
url: 'http://localhost:' + this.port, | ||
json: { | ||
event: e, | ||
statusCode: 1, | ||
ttl: convert.minutesToMilliseconds(opts.ttl) | ||
} | ||
, function(err, res, body) { | ||
opts && opts.callback && opts.callback(err, res, body); | ||
}); | ||
}; | ||
} | ||
return request.post(reqBody, function(err, res, body) { | ||
opts && opts.callback && opts.callback(err, res, body) | ||
}) | ||
} |
@@ -1,2 +0,2 @@ | ||
var request = require('request'); | ||
var request = require('request') | ||
@@ -7,30 +7,28 @@ module.exports = function(e, opts) { | ||
, interval | ||
, onHandler; | ||
, onHandler | ||
opts = opts || {}; | ||
opts = opts || {} | ||
onHandler = function() { | ||
var requestObj | ||
, callback; | ||
var reqBody | ||
, callback | ||
requestObj = { | ||
url: 'http://localhost:' + self.port | ||
, json: { | ||
event: e | ||
} | ||
}; | ||
reqBody = { | ||
url: 'http://localhost:' + self.port, | ||
json: { event: e } | ||
} | ||
callback = (opts && opts.callback) || function(err, res, body) { | ||
if (body && body.flinched) { | ||
state.blocking = false; | ||
clearInterval(interval); | ||
process.exit(body.statusCode); | ||
state.blocking = false | ||
clearInterval(interval) | ||
process.exit(body.statusCode) | ||
} | ||
}; | ||
} | ||
request.get(requestObj, callback); | ||
}; | ||
request.get(reqBody, callback) | ||
} | ||
interval = setInterval(onHandler, (opts.intervalTime || 1000)); | ||
return state; | ||
}; | ||
interval = setInterval(onHandler, (opts.intervalTime || 1000)) | ||
return state | ||
} |
var http = require('http') | ||
, events = require('../services/event_manager') | ||
, notify = require('../services/notifier'); | ||
, notify = require('../services/notifier') | ||
exports.requestHandler = function(req, res) { | ||
var body = ''; | ||
var body = '' | ||
req.on('data', function(chunk) { | ||
body += chunk.toString(); | ||
}); | ||
body += chunk.toString() | ||
}) | ||
req.on('end', function() { | ||
var event; | ||
body = body ? JSON.parse(body) : {}; | ||
var event | ||
body = body ? JSON.parse(body) : {} | ||
switch(req.method) { | ||
case 'GET': // Flinch on | ||
event = events.find(body.event); | ||
break; | ||
event = events.find(body.event) | ||
break | ||
case 'POST': // Flinch at OR Flinch gg | ||
event = events.add(body); | ||
notify.event(body); | ||
break; | ||
event = events.add(body) | ||
notify.event(body) | ||
break | ||
case 'DELETE': // Flinch flush | ||
events.clear(); | ||
notify.flush(); | ||
res.writeHead(204); | ||
return res.end(); | ||
events.clear() | ||
notify.flush() | ||
res.writeHead(204) | ||
return res.end() | ||
default: // Bad request | ||
res.writeHead(400); | ||
return res.end(); | ||
res.writeHead(400) | ||
return res.end() | ||
} | ||
res.writeHead(200, {'Content-Type': 'text/json'}); | ||
res.end(JSON.stringify(event)); | ||
}); | ||
}; | ||
res.writeHead(200, {'Content-Type': 'text/json'}) | ||
res.end(JSON.stringify(event)) | ||
}) | ||
} | ||
exports.start = function(opts) { | ||
notify.set_growl_support(opts && opts.growl); | ||
var server = http.createServer(exports.requestHandler); | ||
server.listen(this.port); | ||
console.log("Listening on port " + this.port); | ||
notify.set_growl_support(opts && opts.growl) | ||
var server = http.createServer(exports.requestHandler) | ||
server.listen(this.port) | ||
console.log("Listening on port " + this.port) | ||
return server; | ||
}; | ||
return server | ||
} |
@@ -7,3 +7,3 @@ var flinch = require('commander') | ||
, flush = require('./commands/flush') | ||
, pjson = require('../package.json'); | ||
, pjson = require('../package.json') | ||
@@ -13,3 +13,3 @@ module.exports = function() { | ||
.version(pjson.version) | ||
.option('-p, --port [port]', 'specify which port to use [Default: 3030]', parseInt, 3030); | ||
.option('-p, --port [port]', 'specify which port to use [Default: 3030]', parseInt, 3030) | ||
@@ -20,3 +20,3 @@ flinch | ||
.option('-g, --growl', 'enable growl notifications') | ||
.action(server.start); | ||
.action(server.start) | ||
@@ -27,3 +27,3 @@ flinch | ||
.option('-g, --growl', 'enable growl notifications') | ||
.action(server.start); | ||
.action(server.start) | ||
@@ -33,3 +33,3 @@ flinch | ||
.description('block on the specified event') | ||
.action(on); | ||
.action(on) | ||
@@ -40,3 +40,3 @@ flinch | ||
.option('-t, --ttl [ttl]', 'set time to live for event success announcement in minutes', parseInt, 10) | ||
.action(at); | ||
.action(at) | ||
@@ -47,3 +47,3 @@ flinch | ||
.option('-t, --ttl [ttl]', 'set time to live for event failure announcement in minutes', parseInt, 10) | ||
.action(gg); | ||
.action(gg) | ||
@@ -53,3 +53,3 @@ flinch | ||
.description('clear list of announced events') | ||
.action(flush); | ||
.action(flush) | ||
@@ -59,5 +59,5 @@ flinch | ||
.description('alias for flush command') | ||
.action(flush); | ||
.action(flush) | ||
return flinch; | ||
}; | ||
return flinch | ||
} |
exports.minutesToMilliseconds = function(minutes) { | ||
return Math.abs(parseInt(minutes, 10) * 60000); | ||
}; | ||
return Math.abs(parseInt(minutes, 10) * 60000) | ||
} | ||
exports.millisecondsToMinutes = function(millseconds) { | ||
return Math.abs(parseInt(millseconds, 10)) / 60000; | ||
}; | ||
return Math.abs(parseInt(millseconds, 10)) / 60000 | ||
} |
@@ -1,29 +0,29 @@ | ||
var _ = require('underscore'); | ||
var _ = require('underscore') | ||
var eventList = []; | ||
var eventList = [] | ||
exports.find = function(e) { | ||
var event = _.findWhere(eventList, { event: e }); | ||
event = event || { flinched: false, event: e }; | ||
return event; | ||
}; | ||
var event = _.findWhere(eventList, { event: e }) | ||
event = event || { flinched: false, event: e } | ||
return event | ||
} | ||
exports.all = function() { | ||
return eventList; | ||
}; | ||
return eventList | ||
} | ||
exports.add = function(body) { | ||
body.flinched = true; | ||
exports.remove(body.event); | ||
eventList.push(body); | ||
exports.expire(body); | ||
return body; | ||
}; | ||
body.flinched = true | ||
exports.remove(body.event) | ||
eventList.push(body) | ||
exports.expire(body) | ||
return body | ||
} | ||
exports.remove = function(event) { | ||
eventList = _.reject(eventList, function(e) { | ||
return e.event === event; | ||
}); | ||
return eventList; | ||
}; | ||
return e.event === event | ||
}) | ||
return eventList | ||
} | ||
@@ -33,9 +33,9 @@ exports.expire = function(body) { | ||
setTimeout(function() { | ||
exports.remove(body.event); | ||
}, body.ttl); | ||
exports.remove(body.event) | ||
}, body.ttl) | ||
} | ||
}; | ||
} | ||
exports.clear = function() { | ||
eventList.length = 0; | ||
}; | ||
eventList.length = 0 | ||
} |
var padZeroes = function(val) { | ||
return ('0' + val).slice(-2); | ||
}; | ||
return ('0' + val).slice(-2) | ||
} | ||
exports.date = function(date) { | ||
date = date || new Date(); | ||
date = date || new Date() | ||
var readableDate = '['; | ||
var readableDate = '[' | ||
readableDate += date.getFullYear() + '-' + | ||
@@ -14,4 +14,4 @@ padZeroes(date.getMonth() + 1) + '-' + | ||
padZeroes(date.getMinutes()) + ':' + | ||
padZeroes(date.getSeconds()) + ']'; | ||
return readableDate; | ||
}; | ||
padZeroes(date.getSeconds()) + ']' | ||
return readableDate | ||
} |
@@ -5,11 +5,11 @@ var clc = require('cli-color') | ||
, humanize = require('./humanizer') | ||
, growl_enabled; | ||
, growl_enabled | ||
var notify = function(console_msg, growl_msg) { | ||
console.log(console_msg); | ||
console.log(console_msg) | ||
if (growl_enabled) { | ||
exports.growl(growl_msg, { title: 'Flinch' }); | ||
exports.growl(growl_msg, { title: 'Flinch' }) | ||
} | ||
return console_msg; | ||
}; | ||
return console_msg | ||
} | ||
@@ -19,26 +19,26 @@ exports.event = function(body) { | ||
, ttl = (body.ttl) ? convert.millisecondsToMinutes(body.ttl) : 'Infinite' | ||
, ttlMessage = '[TTL: ' + ttl + ']'; | ||
, ttlMessage = '[TTL: ' + ttl + ']' | ||
if (body.statusCode === 0) { | ||
cmd = 'at'; | ||
color = 'green'; | ||
cmd = 'at' | ||
color = 'green' | ||
} else { | ||
cmd = 'gg'; | ||
color = 'red'; | ||
cmd = 'gg' | ||
color = 'red' | ||
} | ||
msg = clc[color]([humanize.date(), ttlMessage, 'flinch', cmd, body.event].join(' ')); | ||
msg = clc[color]([humanize.date(), ttlMessage, 'flinch', cmd, body.event].join(' ')) | ||
return notify(msg, cmd + ' ' + body.event); | ||
}; | ||
return notify(msg, cmd + ' ' + body.event) | ||
} | ||
exports.flush = function() { | ||
var msg = clc.bold(humanize.date() + ' flinch events flushed'); | ||
return notify(msg, 'events flushed'); | ||
}; | ||
var msg = clc.bold(humanize.date() + ' flinch events flushed') | ||
return notify(msg, 'events flushed') | ||
} | ||
exports.set_growl_support = function(enable) { | ||
growl_enabled = enable; | ||
}; | ||
growl_enabled = enable | ||
} | ||
// Export the dependency on growl because there's no other way to stub it | ||
exports.growl = growl; | ||
exports.growl = growl |
{ | ||
"name": "flinch", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Multitask with cat-like reflexes", | ||
@@ -37,14 +37,14 @@ "author": "Bilal Quadri", | ||
"dependencies": { | ||
"commander": "2.2.x", | ||
"request": "2.34.x", | ||
"cli-color": "0.2.x", | ||
"underscore": "1.6.x", | ||
"growl": "1.7.x" | ||
"commander": "^2.2.0", | ||
"request": "^2.34.0", | ||
"cli-color": "^0.3.2", | ||
"underscore": "^1.6.0", | ||
"growl": "^1.7.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "1.18.x", | ||
"sinon": "1.9.x", | ||
"chai": "1.9.x", | ||
"sinon-chai": "2.5.x" | ||
"mocha": "^1.20.1", | ||
"chai": "^1.9.1", | ||
"sinon": "^1.10.2", | ||
"sinon-chai": "^2.5.0" | ||
} | ||
} |
@@ -94,10 +94,10 @@ flinch | ||
[1]: https://travis-ci.org/bilalq/flinch.png?branch=master | ||
[1]: https://travis-ci.org/bilalq/flinch.svg?branch=master | ||
[2]: https://travis-ci.org/bilalq/flinch | ||
[3]: https://coveralls.io/repos/bilalq/flinch/badge.png?branch=master | ||
[4]: https://coveralls.io/r/bilalq/flinch?branch=master | ||
[5]: https://gemnasium.com/bilalq/flinch.png | ||
[5]: https://gemnasium.com/bilalq/flinch.svg | ||
[6]: https://gemnasium.com/bilalq/flinch | ||
[7]: https://badge.fury.io/js/flinch.png | ||
[7]: https://badge.fury.io/js/flinch.svg | ||
[8]: https://npmjs.org/package/flinch | ||
[9]: https://github.com/bilalq/flinch/blob/master/LICENSE |
@@ -6,88 +6,88 @@ var onCmd = require('../../lib/commands/on') | ||
, serverCmd = require('../../lib/commands/server') | ||
, events = require('../../lib/services/event_manager'); | ||
, events = require('../../lib/services/event_manager') | ||
describe('Acceptance spec', function() { | ||
var port, event, ttlOption, context, flinchServer; | ||
var port, event, ttlOption, context, flinchServer | ||
beforeEach(function(done) { | ||
port = 5030; | ||
ttlOption = { ttl: 10 }; | ||
event = 'event'; | ||
context = { port: port }; | ||
mute(); | ||
flinchServer = serverCmd.start.call(context); | ||
unmute(); | ||
done(); | ||
}); | ||
port = 5030 | ||
ttlOption = { ttl: 10 } | ||
event = 'event' | ||
context = { port: port } | ||
mute() | ||
flinchServer = serverCmd.start.call(context) | ||
unmute() | ||
done() | ||
}) | ||
afterEach(function(done) { | ||
flinchServer.close(done); | ||
}); | ||
flinchServer.close(done) | ||
}) | ||
describe('flinch server', function() { | ||
it('starts up a server', function(done) { | ||
flinchServer.address().port.should.equal(port); | ||
done(); | ||
}); | ||
}); | ||
flinchServer.address().port.should.equal(port) | ||
done() | ||
}) | ||
}) | ||
describe('flinch flush', function() { | ||
it('should clear event list record', function(done) { | ||
this.timeout(4000); | ||
var onEvent, atEvent, processMock; | ||
mute(); | ||
this.timeout(4000) | ||
var onEvent, atEvent, processMock | ||
mute() | ||
processMock = sinon.mock(process); | ||
processMock.expects('exit').atLeast(1).withArgs(0); | ||
processMock = sinon.mock(process) | ||
processMock.expects('exit').atLeast(1).withArgs(0) | ||
atEvent = atCmd.call(context, event, { ttl: 10, callback: function() { | ||
flushCmd.call(context, { callback: function() { | ||
onEvent = onCmd.call(context, event, ttlOption); | ||
onEvent = onCmd.call(context, event, ttlOption) | ||
setTimeout(function() { | ||
onEvent.blocking.should.be.true; | ||
atCmd.call(context, event, ttlOption); | ||
onEvent.blocking.should.be.true | ||
atCmd.call(context, event, ttlOption) | ||
setTimeout(function() { | ||
onEvent.blocking.should.be.false; | ||
processMock.verify(); | ||
unmute(); | ||
done(); | ||
}, 1300); | ||
}, 1300); | ||
}}); | ||
}}); | ||
}); | ||
}); | ||
onEvent.blocking.should.be.false | ||
processMock.verify() | ||
unmute() | ||
done() | ||
}, 1300) | ||
}, 1300) | ||
}}) | ||
}}) | ||
}) | ||
}) | ||
describe('flinch at', function() { | ||
it('makes a POST request to the server and gets a status code of 0', function(done) { | ||
this.timeout(4000); | ||
mute(); | ||
this.timeout(4000) | ||
mute() | ||
atCmd.call(context, event, { | ||
ttl: 10 | ||
, callback: function(err, res, body) { | ||
res.statusCode.should.equal(200); | ||
body.flinched.should.be.true; | ||
body.statusCode.should.equal(0); | ||
body.event.should.equal(event); | ||
unmute(); | ||
done(); | ||
ttl: 10, | ||
callback: function(err, res, body) { | ||
res.statusCode.should.equal(200) | ||
body.flinched.should.be.true | ||
body.statusCode.should.equal(0) | ||
body.event.should.equal(event) | ||
unmute() | ||
done() | ||
} | ||
}); | ||
}); | ||
}); | ||
}) | ||
}) | ||
}) | ||
describe('flinch gg', function() { | ||
it('makes a POST request to the server and gets a status code of 1', function(done) { | ||
this.timeout(4000); | ||
mute(); | ||
this.timeout(4000) | ||
mute() | ||
ggCmd.call(context, event, {callback: function(err, res, body) { | ||
res.statusCode.should.equal(200); | ||
body.flinched.should.be.true; | ||
body.statusCode.should.equal(1); | ||
body.event.should.equal(event); | ||
unmute(); | ||
done(); | ||
}}); | ||
}); | ||
}); | ||
res.statusCode.should.equal(200) | ||
body.flinched.should.be.true | ||
body.statusCode.should.equal(1) | ||
body.event.should.equal(event) | ||
unmute() | ||
done() | ||
}}) | ||
}) | ||
}) | ||
@@ -98,116 +98,116 @@ describe('flinch on', function() { | ||
it('blocks until flinched and exits with status code 0', function(done) { | ||
var onEvent, atEvent; | ||
this.timeout(2000); | ||
var onEvent, atEvent | ||
this.timeout(2000) | ||
mute(); | ||
onEvent = onCmd.call(context, event, ttlOption); | ||
onEvent.blocking.should.be.true; | ||
mute() | ||
onEvent = onCmd.call(context, event, ttlOption) | ||
onEvent.blocking.should.be.true | ||
setTimeout(function() { | ||
var processMock = sinon.mock(process); | ||
processMock.expects('exit').atLeast(1).withArgs(0); | ||
onEvent.blocking.should.be.true; | ||
atEvent = atCmd.call(context, event, ttlOption); | ||
var processMock = sinon.mock(process) | ||
processMock.expects('exit').atLeast(1).withArgs(0) | ||
onEvent.blocking.should.be.true | ||
atEvent = atCmd.call(context, event, ttlOption) | ||
setTimeout(function() { | ||
onEvent.blocking.should.be.false; | ||
processMock.verify(); | ||
unmute(); | ||
done(); | ||
}, 1300); | ||
}, 50); | ||
}); | ||
onEvent.blocking.should.be.false | ||
processMock.verify() | ||
unmute() | ||
done() | ||
}, 1300) | ||
}, 50) | ||
}) | ||
it('should stop blocking if flinched at earlier within a TTL', function(done) { | ||
var onEvent, atEvent, processMock; | ||
this.timeout(2000); | ||
var onEvent, atEvent, processMock | ||
this.timeout(2000) | ||
mute(); | ||
mute() | ||
atEvent = atCmd.call(context, event, ttlOption); | ||
atEvent = atCmd.call(context, event, ttlOption) | ||
setTimeout(function() { | ||
processMock = sinon.mock(process); | ||
processMock.expects('exit').atLeast(1).withArgs(0); | ||
onEvent = onCmd.call(context, event, ttlOption); | ||
processMock = sinon.mock(process) | ||
processMock.expects('exit').atLeast(1).withArgs(0) | ||
onEvent = onCmd.call(context, event, ttlOption) | ||
setTimeout(function() { | ||
onEvent.blocking.should.not.be.true; | ||
processMock.verify(); | ||
unmute(); | ||
done(); | ||
}, 1300); | ||
}, 50); | ||
}); | ||
}); | ||
onEvent.blocking.should.not.be.true | ||
processMock.verify() | ||
unmute() | ||
done() | ||
}, 1300) | ||
}, 50) | ||
}) | ||
}) | ||
describe('when flinch gg is invoked', function() { | ||
it('blocks until flinched and exits with status code 1', function(done) { | ||
this.timeout(3000); | ||
var event = 'gg', onEvent, ggEvent, processMock; | ||
this.timeout(3000) | ||
var event = 'gg', onEvent, ggEvent, processMock | ||
mute(); | ||
onEvent = onCmd.call(context, event); | ||
onEvent.blocking.should.be.true; | ||
mute() | ||
onEvent = onCmd.call(context, event) | ||
onEvent.blocking.should.be.true | ||
setTimeout(function() { | ||
processMock = sinon.mock(process); | ||
processMock.expects('exit').atLeast(1).withArgs(1); | ||
onEvent.blocking.should.be.true; | ||
ggEvent = ggCmd.call(context, event, ttlOption); | ||
processMock = sinon.mock(process) | ||
processMock.expects('exit').atLeast(1).withArgs(1) | ||
onEvent.blocking.should.be.true | ||
ggEvent = ggCmd.call(context, event, ttlOption) | ||
setTimeout(function() { | ||
onEvent.blocking.should.be.false; | ||
processMock.verify(); | ||
unmute(); | ||
done(); | ||
}, 1300); | ||
}, 50); | ||
}); | ||
}); | ||
onEvent.blocking.should.be.false | ||
processMock.verify() | ||
unmute() | ||
done() | ||
}, 1300) | ||
}, 50) | ||
}) | ||
}) | ||
}); | ||
}) | ||
describe('when multiple announcements are made on the same event', function() { | ||
var onEvent, processMock; | ||
var onEvent, processMock | ||
beforeEach(function(done) { | ||
processMock = sinon.mock(process); | ||
done(); | ||
}); | ||
processMock = sinon.mock(process) | ||
done() | ||
}) | ||
afterEach(function(done) { | ||
processMock.verify(); | ||
done(); | ||
}); | ||
processMock.verify() | ||
done() | ||
}) | ||
it('keeps only the latest announcement when at is called last', function(done) { | ||
this.timeout(4000); | ||
processMock.expects('exit').withArgs(0).atLeast(1); | ||
processMock.expects('exit').withArgs(1).never(); | ||
this.timeout(4000) | ||
processMock.expects('exit').withArgs(0).atLeast(1) | ||
processMock.expects('exit').withArgs(1).never() | ||
mute(); | ||
mute() | ||
ggCmd.call(context, event, { ttl: 10, callback: function() { | ||
atCmd.call(context, event, { ttl: 10, callback: function() { | ||
onEvent = onCmd.call(context, event); | ||
onEvent = onCmd.call(context, event) | ||
setTimeout(function() { | ||
unmute(); | ||
done(); | ||
}, 1100); | ||
}}); | ||
}}); | ||
}); | ||
unmute() | ||
done() | ||
}, 1100) | ||
}}) | ||
}}) | ||
}) | ||
it('keeps only the latest announcement when gg is called last', function(done) { | ||
this.timeout(4000); | ||
processMock.expects('exit').withArgs(1).atLeast(1); | ||
processMock.expects('exit').withArgs(0).never(); | ||
this.timeout(4000) | ||
processMock.expects('exit').withArgs(1).atLeast(1) | ||
processMock.expects('exit').withArgs(0).never() | ||
mute(); | ||
mute() | ||
atCmd.call(context, event, { ttl: 10, callback: function() { | ||
ggCmd.call(context, event, { ttl: 10, callback: function() { | ||
onEvent = onCmd.call(context, event); | ||
onEvent = onCmd.call(context, event) | ||
setTimeout(function() { | ||
unmute(); | ||
done(); | ||
}, 1100); | ||
}}); | ||
}}); | ||
}); | ||
}); | ||
unmute() | ||
done() | ||
}, 1100) | ||
}}) | ||
}}) | ||
}) | ||
}) | ||
}); | ||
}) |
// Test helpers | ||
global.sinon = require('sinon'); | ||
global.chai = require('chai'); | ||
global.should = require('chai').should(); | ||
global.expect = require('chai').expect; | ||
global.AssertionError = require('chai').AssertionError; | ||
global.sinonChai = require('sinon-chai'); | ||
global._ = require('underscore'); | ||
chai.use(sinonChai); | ||
global.sinon = require('sinon') | ||
global.chai = require('chai') | ||
global.should = require('chai').should() | ||
global.expect = require('chai').expect | ||
global.AssertionError = require('chai').AssertionError | ||
global.sinonChai = require('sinon-chai') | ||
global._ = require('underscore') | ||
chai.use(sinonChai) | ||
@@ -14,30 +14,30 @@ // Styled string matchers | ||
startsAndEndsWith: function(str, start, end) { | ||
return str.startsWith(start) && str.endsWith(end); | ||
return str.startsWith(start) && str.endsWith(end) | ||
}, | ||
green: function(str) { | ||
return styleMatch.startsAndEndsWith(str, '\u001b[32', '\u001b[39m') | ||
}, | ||
red: function(str) { | ||
return styleMatch.startsAndEndsWith(str, '\u001b[31', '\u001b[39m') | ||
}, | ||
bold: function(str) { | ||
return styleMatch.startsAndEndsWith(str, '\u001b[1', '\u001b[22m') | ||
} | ||
, green: function(str) { | ||
return styleMatch.startsAndEndsWith(str, '\u001b[32', '\u001b[39m'); | ||
} | ||
, red: function(str) { | ||
return styleMatch.startsAndEndsWith(str, '\u001b[31', '\u001b[39m'); | ||
} | ||
, bold: function(str) { | ||
return styleMatch.startsAndEndsWith(str, '\u001b[1', '\u001b[22m'); | ||
} | ||
}; | ||
} | ||
// Easy muting/unmuting of console.log | ||
var muted = false; | ||
var console_logger = console.log; | ||
var muted = false | ||
, console_logger = console.log | ||
global.mute = function() { | ||
if (!muted) { | ||
console.log = function() {}; | ||
muted = true; | ||
console.log = function() {} | ||
muted = true | ||
} | ||
}; | ||
} | ||
global.unmute = function() { | ||
if (muted) { | ||
muted = false; | ||
console.log = console_logger; | ||
muted = false | ||
console.log = console_logger | ||
} | ||
}; | ||
} | ||
@@ -48,8 +48,8 @@ // Helper function to run shell commands | ||
, child = spawn(cmd, args) | ||
, res = ''; | ||
, res = '' | ||
child.stdout.on('data', function(buffer) { res += buffer.toString(); }); | ||
child.stdout.on('end', function() { callback(resp); }); | ||
return child; | ||
}; | ||
child.stdout.on('data', function(buffer) { res += buffer.toString() }) | ||
child.stdout.on('end', function() { callback(res) }) | ||
return child | ||
} | ||
@@ -63,6 +63,6 @@ // Polyfills | ||
value: function (searchString, position) { | ||
position = position || 0; | ||
return this.indexOf(searchString, position) === position; | ||
position = position || 0 | ||
return this.indexOf(searchString, position) === position | ||
} | ||
}); | ||
}) | ||
} | ||
@@ -75,8 +75,8 @@ if (!String.prototype.endsWith) { | ||
value: function (searchString, position) { | ||
position = position || this.length; | ||
position = position - searchString.length; | ||
var lastIndex = this.lastIndexOf(searchString); | ||
return lastIndex !== -1 && lastIndex === position; | ||
position = position || this.length | ||
position = position - searchString.length | ||
var lastIndex = this.lastIndexOf(searchString) | ||
return lastIndex !== -1 && lastIndex === position | ||
} | ||
}); | ||
}) | ||
} |
var request = require('request') | ||
, atCmd = require('../../../lib/commands/at'); | ||
, atCmd = require('../../../lib/commands/at') | ||
@@ -8,19 +8,17 @@ describe('At', function() { | ||
, event = 'someEvent' | ||
, port = 3030; | ||
, port = 3030 | ||
requestMock.expects('post').once().withArgs( | ||
{ | ||
url: 'http://localhost:' + port | ||
, json: { | ||
event: event | ||
, statusCode: 0 | ||
, ttl: 10 * 60 * 1000 | ||
} | ||
requestMock.expects('post').once().withArgs({ | ||
url: 'http://localhost:' + port, | ||
json: { | ||
event: event, | ||
statusCode: 0, | ||
ttl: 10 * 60 * 1000 | ||
} | ||
); | ||
}) | ||
atCmd.call({ port: port }, event, { ttl: 10 }); | ||
requestMock.verify(); | ||
done(); | ||
}); | ||
}); | ||
atCmd.call({ port: port }, event, { ttl: 10 }) | ||
requestMock.verify() | ||
done() | ||
}) | ||
}) |
@@ -1,9 +0,9 @@ | ||
var flinchCommander = require('../../../lib/flinch'); | ||
var flinchCommander = require('../../../lib/flinch') | ||
describe('Flinch commander', function() { | ||
var flinch; | ||
var flinch | ||
before(function(done) { | ||
flinch = flinch || flinchCommander(); | ||
done(); | ||
}); | ||
flinch = flinch || flinchCommander() | ||
done() | ||
}) | ||
@@ -13,63 +13,63 @@ it('has an option to specify the port', function(done) { | ||
return opt.short === '-p' && opt.long === '--port' && | ||
opt.optional && !opt.required; | ||
})).to.exist; | ||
done(); | ||
}); | ||
opt.optional && !opt.required | ||
})).to.exist | ||
done() | ||
}) | ||
describe('command list', function() { | ||
var findCommand, findOption; | ||
var findCommand, findOption | ||
before(function(done) { | ||
findCommand = function(cmdName) { | ||
return _.find(flinch.commands, function(cmd) { | ||
return cmd._name === cmdName; | ||
}); | ||
}; | ||
return cmd._name === cmdName | ||
}) | ||
} | ||
findOption = function(optShortName, optLongName) { | ||
return _.find(this.options, function(opt) { | ||
return opt.short === optShortName && opt.long === optLongName; | ||
}); | ||
}; | ||
done(); | ||
}); | ||
return opt.short === optShortName && opt.long === optLongName | ||
}) | ||
} | ||
done() | ||
}) | ||
it('includes "server"', function(done) { | ||
findCommand('server').should.exist; | ||
done(); | ||
}); | ||
findCommand('server').should.exist | ||
done() | ||
}) | ||
it('includes "s"', function(done) { | ||
findCommand('s').should.exist; | ||
done(); | ||
}); | ||
findCommand('s').should.exist | ||
done() | ||
}) | ||
it('includes "flush"', function(done) { | ||
findCommand('flush').should.exist; | ||
done(); | ||
}); | ||
findCommand('flush').should.exist | ||
done() | ||
}) | ||
it('includes "f"', function(done) { | ||
findCommand('f').should.exist; | ||
done(); | ||
}); | ||
findCommand('f').should.exist | ||
done() | ||
}) | ||
it('includes "at"', function(done) { | ||
var atCmd = findCommand('at'); | ||
atCmd.should.exist; | ||
findOption.call(atCmd, '-t', '--ttl').should.exist; | ||
done(); | ||
}); | ||
var atCmd = findCommand('at') | ||
atCmd.should.exist | ||
findOption.call(atCmd, '-t', '--ttl').should.exist | ||
done() | ||
}) | ||
it('includes "gg"', function(done) { | ||
var ggCmd = findCommand('gg'); | ||
ggCmd.should.exist; | ||
findOption.call(ggCmd, '-t', '--ttl').should.exist; | ||
done(); | ||
}); | ||
var ggCmd = findCommand('gg') | ||
ggCmd.should.exist | ||
findOption.call(ggCmd, '-t', '--ttl').should.exist | ||
done() | ||
}) | ||
it('includes "on"', function(done) { | ||
findCommand('on').should.exist; | ||
done(); | ||
}); | ||
}); | ||
findCommand('on').should.exist | ||
done() | ||
}) | ||
}) | ||
}); | ||
}) |
var request = require('request') | ||
, flushCmd = require('../../../lib/commands/flush'); | ||
, flushCmd = require('../../../lib/commands/flush') | ||
@@ -7,9 +7,10 @@ describe('Flush', function() { | ||
var requestMock = sinon.mock(request) | ||
, port = 3030; | ||
requestMock.expects('del').once(); | ||
, port = 3030 | ||
flushCmd.call({ port: port }); | ||
requestMock.verify(); | ||
done(); | ||
}); | ||
}); | ||
requestMock.expects('del').once() | ||
flushCmd.call({ port: port }) | ||
requestMock.verify() | ||
done() | ||
}) | ||
}) |
var request = require('request') | ||
, ggCmd = require('../../../lib/commands/gg'); | ||
, ggCmd = require('../../../lib/commands/gg') | ||
@@ -8,19 +8,17 @@ describe('GG', function() { | ||
, event = 'someEvent' | ||
, port = 3030; | ||
, port = 3030 | ||
requestMock.expects('post').once().withArgs( | ||
{ | ||
url: 'http://localhost:' + port | ||
, json: { | ||
event: event | ||
, statusCode: 1 | ||
, ttl: 10 * 60 * 1000 | ||
} | ||
requestMock.expects('post').once().withArgs({ | ||
url: 'http://localhost:' + port, | ||
json: { | ||
event: event, | ||
statusCode: 1, | ||
ttl: 10 * 60 * 1000 | ||
} | ||
); | ||
}) | ||
ggCmd.call({ port: port }, event, { ttl: 10 }); | ||
requestMock.verify(); | ||
done(); | ||
}); | ||
}); | ||
ggCmd.call({ port: port }, event, { ttl: 10 }) | ||
requestMock.verify() | ||
done() | ||
}) | ||
}) |
var request = require('request') | ||
, onCmd = require('../../../lib/commands/on'); | ||
, onCmd = require('../../../lib/commands/on') | ||
@@ -8,21 +8,21 @@ describe('On', function() { | ||
, flinchState = { flinched: false } | ||
, blockState; | ||
, blockState | ||
processMock.expects('exit').atLeast(1).withArgs(0); | ||
processMock.expects('exit').atLeast(1).withArgs(0) | ||
sinon.stub(request, 'get', function(data, callback) { | ||
callback(null, null, flinchState); | ||
}); | ||
callback(null, null, flinchState) | ||
}) | ||
blockState = onCmd('someEvent', { intervalTime: 60 }); | ||
blockState.blocking.should.be.true; | ||
blockState = onCmd('someEvent', { intervalTime: 60 }) | ||
blockState.blocking.should.be.true | ||
flinchState.flinched = true; | ||
flinchState.statusCode = 0; | ||
flinchState.flinched = true | ||
flinchState.statusCode = 0 | ||
setTimeout(function() { | ||
blockState.blocking.should.be.false; | ||
processMock.verify(); | ||
request.get.restore(); | ||
done(); | ||
}, 120); | ||
}); | ||
}); | ||
blockState.blocking.should.be.false | ||
processMock.verify() | ||
request.get.restore() | ||
done() | ||
}, 120) | ||
}) | ||
}) |
var http = require('http') | ||
, server = require('../../../lib/commands/server') | ||
, events = require('../../../lib/services/event_manager') | ||
, notify = require('../../../lib/services/notifier'); | ||
, notify = require('../../../lib/services/notifier') | ||
describe('Server', function() { | ||
var listenSpy; | ||
var listenSpy | ||
beforeEach(function(done) { | ||
listenSpy = sinon.spy(); | ||
sinon.stub(http, 'createServer').returns({listen: listenSpy}); | ||
done(); | ||
}); | ||
listenSpy = sinon.spy() | ||
sinon.stub(http, 'createServer').returns({listen: listenSpy}) | ||
done() | ||
}) | ||
afterEach(function(done) { | ||
http.createServer.restore(); | ||
done(); | ||
}); | ||
http.createServer.restore() | ||
done() | ||
}) | ||
describe('requestHandler', function() { | ||
var reqStub, resSpy, headers, body, stub_request_body; | ||
var reqStub, resSpy, headers, body, stub_request_body | ||
beforeEach(function(done) { | ||
headers = { 'Content-Type': 'text/json' }; | ||
body = { event: 'e' }; | ||
reqStub = { on: sinon.stub() }; | ||
resSpy = { writeHead: sinon.spy() , end: sinon.spy() }; | ||
headers = { 'Content-Type': 'text/json' } | ||
body = { event: 'e' } | ||
reqStub = { on: sinon.stub() } | ||
resSpy = { writeHead: sinon.spy() , end: sinon.spy() } | ||
stub_request_body = function() { | ||
reqStub.on.withArgs('data').yields(JSON.stringify(body)); | ||
}; | ||
reqStub.on.withArgs('data').yields(JSON.stringify(body)) | ||
} | ||
reqStub.on.withArgs('end').yields(); | ||
done(); | ||
}); | ||
reqStub.on.withArgs('end').yields() | ||
done() | ||
}) | ||
it('responds with the event and flinched status on GET', function(done) { | ||
stub_request_body(); | ||
reqStub.method = 'GET'; | ||
server.requestHandler(reqStub, resSpy); | ||
resSpy.writeHead.should.have.been.calledWith(200, headers); | ||
resSpy.end.should.have.been.calledWithMatch(JSON.stringify({flinched: false, event: 'e'})); | ||
done(); | ||
}); | ||
stub_request_body() | ||
reqStub.method = 'GET' | ||
server.requestHandler(reqStub, resSpy) | ||
resSpy.writeHead.should.have.been.calledWith(200, headers) | ||
resSpy.end.should.have.been.calledWithMatch(JSON.stringify({flinched: false, event: 'e'})) | ||
done() | ||
}) | ||
describe('POST request for announcing flinch event', function() { | ||
var eventsMock, notifyMock; | ||
var eventsMock, notifyMock | ||
beforeEach(function(done) { | ||
reqStub.method = 'POST'; | ||
eventsMock = sinon.mock(events); | ||
notifyMock = sinon.mock(notify); | ||
done(); | ||
}); | ||
reqStub.method = 'POST' | ||
eventsMock = sinon.mock(events) | ||
notifyMock = sinon.mock(notify) | ||
done() | ||
}) | ||
afterEach(function(done) { | ||
eventsMock.verify(); | ||
notifyMock.verify(); | ||
done(); | ||
}); | ||
eventsMock.verify() | ||
notifyMock.verify() | ||
done() | ||
}) | ||
it('adds event to internal list and notifies on flinch at', function(done) { | ||
body.statusCode = 0; | ||
stub_request_body(); | ||
eventsMock.expects('add').withArgs(body).once(); | ||
notifyMock.expects('event').withArgs(body).once(); | ||
body.statusCode = 0 | ||
stub_request_body() | ||
eventsMock.expects('add').withArgs(body).once() | ||
notifyMock.expects('event').withArgs(body).once() | ||
mute(); | ||
server.requestHandler(reqStub, resSpy); | ||
unmute(); | ||
mute() | ||
server.requestHandler(reqStub, resSpy) | ||
unmute() | ||
resSpy.writeHead.should.have.been.calledWith(200, headers); | ||
resSpy.end.should.have.been.called; | ||
done(); | ||
}); | ||
resSpy.writeHead.should.have.been.calledWith(200, headers) | ||
resSpy.end.should.have.been.called | ||
done() | ||
}) | ||
it('adds event to internal list and notifies on flinch gg', function(done) { | ||
body.statusCode = 1; | ||
stub_request_body(); | ||
eventsMock.expects('add').withArgs(body).once(); | ||
notifyMock.expects('event').withArgs(body).once(); | ||
body.statusCode = 1 | ||
stub_request_body() | ||
eventsMock.expects('add').withArgs(body).once() | ||
notifyMock.expects('event').withArgs(body).once() | ||
mute(); | ||
server.requestHandler(reqStub, resSpy); | ||
unmute(); | ||
mute() | ||
server.requestHandler(reqStub, resSpy) | ||
unmute() | ||
resSpy.writeHead.should.have.been.calledWith(200, headers); | ||
resSpy.end.should.have.been.called; | ||
done(); | ||
}); | ||
}); | ||
resSpy.writeHead.should.have.been.calledWith(200, headers) | ||
resSpy.end.should.have.been.called | ||
done() | ||
}) | ||
}) | ||
it('clears events on a DELETE request', function(done) { | ||
var eventsMock = sinon.mock(events); | ||
var notifyMock = sinon.mock(notify); | ||
eventsMock.expects('clear').once(); | ||
notifyMock.expects('flush').once(); | ||
var eventsMock = sinon.mock(events) | ||
var notifyMock = sinon.mock(notify) | ||
eventsMock.expects('clear').once() | ||
notifyMock.expects('flush').once() | ||
reqStub.method = 'DELETE'; | ||
stub_request_body(); | ||
mute(); | ||
server.requestHandler(reqStub, resSpy); | ||
unmute(); | ||
reqStub.method = 'DELETE' | ||
stub_request_body() | ||
mute() | ||
server.requestHandler(reqStub, resSpy) | ||
unmute() | ||
resSpy.writeHead.should.have.been.calledWith(204); | ||
resSpy.end.should.have.been.called; | ||
eventsMock.verify(); | ||
notifyMock.verify(); | ||
done(); | ||
}); | ||
resSpy.writeHead.should.have.been.calledWith(204) | ||
resSpy.end.should.have.been.called | ||
eventsMock.verify() | ||
notifyMock.verify() | ||
done() | ||
}) | ||
it('responds with 400 on a PUT request', function(done) { | ||
reqStub.method = 'PUT'; | ||
stub_request_body(); | ||
mute(); | ||
server.requestHandler(reqStub, resSpy); | ||
unmute(); | ||
reqStub.method = 'PUT' | ||
stub_request_body() | ||
mute() | ||
server.requestHandler(reqStub, resSpy) | ||
unmute() | ||
resSpy.writeHead.should.have.been.calledWith(400); | ||
resSpy.end.should.have.been.called; | ||
done(); | ||
}); | ||
}); | ||
resSpy.writeHead.should.have.been.calledWith(400) | ||
resSpy.end.should.have.been.called | ||
done() | ||
}) | ||
}) | ||
describe('start', function() { | ||
it('listens on the port value of the caller', function(done) { | ||
mute(); | ||
server.start.call({ port: 5000 }); | ||
listenSpy.should.have.been.calledWith(5000); | ||
unmute(); | ||
done(); | ||
}); | ||
mute() | ||
server.start.call({ port: 5000 }) | ||
listenSpy.should.have.been.calledWith(5000) | ||
unmute() | ||
done() | ||
}) | ||
it('enables growl notifications if options say to', function(done) { | ||
var notifyMock = sinon.mock(notify); | ||
notifyMock.expects('set_growl_support').withArgs(true).once(); | ||
server.start.call({ port: 5000 }, { growl: true }); | ||
notifyMock.verify(); | ||
done(); | ||
}); | ||
}); | ||
var notifyMock = sinon.mock(notify) | ||
notifyMock.expects('set_growl_support').withArgs(true).once() | ||
server.start.call({ port: 5000 }, { growl: true }) | ||
notifyMock.verify() | ||
done() | ||
}) | ||
}) | ||
}); | ||
}) |
@@ -1,2 +0,2 @@ | ||
var convert = require('../../../lib/services/converter'); | ||
var convert = require('../../../lib/services/converter') | ||
@@ -7,22 +7,22 @@ describe('Converter', function() { | ||
it('converts minutes to milliseconds', function(done) { | ||
convert.minutesToMilliseconds(2).should.equal(120000); | ||
done(); | ||
}); | ||
convert.minutesToMilliseconds(2).should.equal(120000) | ||
done() | ||
}) | ||
it('converts negative numbers to positive', function(done) { | ||
convert.minutesToMilliseconds(-1).should.equal(60000); | ||
done(); | ||
}); | ||
convert.minutesToMilliseconds(-1).should.equal(60000) | ||
done() | ||
}) | ||
it('returns 0 when given 0', function(done) { | ||
convert.minutesToMilliseconds(0).should.equal(0); | ||
done(); | ||
}); | ||
convert.minutesToMilliseconds(0).should.equal(0) | ||
done() | ||
}) | ||
it('works with string arguments', function(done) { | ||
convert.minutesToMilliseconds('5').should.equal(300000); | ||
done(); | ||
}); | ||
}); | ||
convert.minutesToMilliseconds('5').should.equal(300000) | ||
done() | ||
}) | ||
}) | ||
}); | ||
}) |
@@ -1,2 +0,2 @@ | ||
var events = require('../../../lib/services/event_manager'); | ||
var events = require('../../../lib/services/event_manager') | ||
@@ -6,128 +6,128 @@ describe('Events', function() { | ||
beforeEach(function(done) { | ||
events.clear(); | ||
done(); | ||
}); | ||
events.clear() | ||
done() | ||
}) | ||
describe('find', function() { | ||
it('returns a matching event from the event list', function(done) { | ||
var event = { event: 'test', flinched: true }; | ||
events.all().push(event); | ||
events.find('test').should.eql(event); | ||
done(); | ||
}); | ||
var event = { event: 'test', flinched: true } | ||
events.all().push(event) | ||
events.find('test').should.eql(event) | ||
done() | ||
}) | ||
it('returns an object when the event is not in the list', function(done) { | ||
var event = events.find('missing'); | ||
event.flinched.should.be.false; | ||
event.event.should.equal('missing'); | ||
done(); | ||
}); | ||
}); | ||
var event = events.find('missing') | ||
event.flinched.should.be.false | ||
event.event.should.equal('missing') | ||
done() | ||
}) | ||
}) | ||
describe('all', function() { | ||
it('has an empty event list in the beginning', function(done) { | ||
events.all().should.be.empty; | ||
done(); | ||
}); | ||
}); | ||
events.all().should.be.empty | ||
done() | ||
}) | ||
}) | ||
describe('add', function() { | ||
var removeSpy, expireSpy; | ||
var removeSpy, expireSpy | ||
beforeEach(function(done) { | ||
removeSpy = sinon.spy(events, 'remove'); | ||
expireSpy = sinon.spy(events, 'expire'); | ||
done(); | ||
}); | ||
removeSpy = sinon.spy(events, 'remove') | ||
expireSpy = sinon.spy(events, 'expire') | ||
done() | ||
}) | ||
afterEach(function(done) { | ||
events.remove.restore(); | ||
events.expire.restore(); | ||
done(); | ||
}); | ||
events.remove.restore() | ||
events.expire.restore() | ||
done() | ||
}) | ||
it('adds event to the event list', function(done) { | ||
events.add({event: 'ok'}); | ||
events.all().length.should.equal(1); | ||
events.all()[0].flinched.should.be.true; | ||
events.all()[0].event.should.equal('ok'); | ||
events.add({event: 'ok'}) | ||
events.all().length.should.equal(1) | ||
events.all()[0].flinched.should.be.true | ||
events.all()[0].event.should.equal('ok') | ||
removeSpy.should.have.been.calledOnce; | ||
expireSpy.should.have.been.calledOnce; | ||
done(); | ||
}); | ||
removeSpy.should.have.been.calledOnce | ||
expireSpy.should.have.been.calledOnce | ||
done() | ||
}) | ||
}); | ||
}) | ||
describe('clear', function() { | ||
it('empties the event list', function(done) { | ||
events.all().push({event: 'a', flinched: false}); | ||
events.all().push({event: 'b', flinched: true}); | ||
events.clear(); | ||
events.all().should.be.empty; | ||
done(); | ||
}); | ||
}); | ||
events.all().push({event: 'a', flinched: false}) | ||
events.all().push({event: 'b', flinched: true}) | ||
events.clear() | ||
events.all().should.be.empty | ||
done() | ||
}) | ||
}) | ||
describe('remove', function() { | ||
beforeEach(function(done) { | ||
var eventList = events.all(); | ||
eventList.push({event: 'a', flinched: false}); | ||
eventList.push({event: 'b', flinched: true}); | ||
eventList.push({event: 'c', flinched: true}); | ||
done(); | ||
}); | ||
var eventList = events.all() | ||
eventList.push({event: 'a', flinched: false}) | ||
eventList.push({event: 'b', flinched: true}) | ||
eventList.push({event: 'c', flinched: true}) | ||
done() | ||
}) | ||
it('removes only the event being searched for', function(done) { | ||
events.all().length.should.equal(3); | ||
events.remove('b'); | ||
events.all().length.should.equal(2); | ||
events.all()[0].event.should.not.equal('b'); | ||
events.all()[1].event.should.not.equal('b'); | ||
done(); | ||
}); | ||
events.all().length.should.equal(3) | ||
events.remove('b') | ||
events.all().length.should.equal(2) | ||
events.all()[0].event.should.not.equal('b') | ||
events.all()[1].event.should.not.equal('b') | ||
done() | ||
}) | ||
it('makes no change if the event is not in the list', function(done) { | ||
events.all().length.should.equal(3); | ||
events.remove('other'); | ||
events.all().length.should.equal(3); | ||
events.all()[0].event.should.equal('a'); | ||
events.all()[1].event.should.equal('b'); | ||
events.all()[2].event.should.equal('c'); | ||
done(); | ||
}); | ||
}); | ||
events.all().length.should.equal(3) | ||
events.remove('other') | ||
events.all().length.should.equal(3) | ||
events.all()[0].event.should.equal('a') | ||
events.all()[1].event.should.equal('b') | ||
events.all()[2].event.should.equal('c') | ||
done() | ||
}) | ||
}) | ||
describe('expire', function() { | ||
var clock, removeSpy; | ||
var clock, removeSpy | ||
beforeEach(function(done) { | ||
clock = sinon.useFakeTimers(); | ||
removeSpy = sinon.spy(events, 'remove'); | ||
done(); | ||
}); | ||
clock = sinon.useFakeTimers() | ||
removeSpy = sinon.spy(events, 'remove') | ||
done() | ||
}) | ||
afterEach(function(done) { | ||
events.remove.restore(); | ||
clock.restore(); | ||
done(); | ||
}); | ||
events.remove.restore() | ||
clock.restore() | ||
done() | ||
}) | ||
it('calls rejectEvent after the ttl expires', function(done) { | ||
events.expire({event: 'event', ttl: 40000}); | ||
clock.tick(20000); | ||
removeSpy.should.not.have.been.called; | ||
clock.tick(30000); | ||
removeSpy.should.have.been.calledWith('event'); | ||
done(); | ||
}); | ||
events.expire({event: 'event', ttl: 40000}) | ||
clock.tick(20000) | ||
removeSpy.should.not.have.been.called | ||
clock.tick(30000) | ||
removeSpy.should.have.been.calledWith('event') | ||
done() | ||
}) | ||
it('never calls rejectEvent when the ttl is 0', function(done) { | ||
events.expire({event: 'event', ttl: 0}); | ||
removeSpy.should.not.have.been.called; | ||
clock.tick(900000); | ||
removeSpy.should.not.have.been.called; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
events.expire({event: 'event', ttl: 0}) | ||
removeSpy.should.not.have.been.called | ||
clock.tick(900000) | ||
removeSpy.should.not.have.been.called | ||
done() | ||
}) | ||
}) | ||
}) |
@@ -1,2 +0,2 @@ | ||
var humanizer = require('../../../lib/services/humanizer'); | ||
var humanizer = require('../../../lib/services/humanizer') | ||
@@ -6,13 +6,13 @@ describe('Humanizer', function() { | ||
it('formats to [YYYY-MM-DD HH:MM:SS]', function(done) { | ||
var fakeDate; | ||
var fakeDate | ||
fakeDate = new Date(Date.parse('2013-02-03 02:04:02')); | ||
humanizer.date(fakeDate).should.equal('[2013-02-03 02:04:02]'); | ||
fakeDate = new Date(Date.parse('2013-02-03 02:04:02')) | ||
humanizer.date(fakeDate).should.equal('[2013-02-03 02:04:02]') | ||
fakeDate = new Date(Date.parse('2003-12-31 12:44:02')); | ||
humanizer.date(fakeDate).should.equal('[2003-12-31 12:44:02]'); | ||
fakeDate = new Date(Date.parse('2003-12-31 12:44:02')) | ||
humanizer.date(fakeDate).should.equal('[2003-12-31 12:44:02]') | ||
done(); | ||
}); | ||
}); | ||
}); | ||
done() | ||
}) | ||
}) | ||
}) |
@@ -1,64 +0,64 @@ | ||
var notify = require('../../../lib/services/notifier'); | ||
var clc = require('cli-color'); | ||
var notify = require('../../../lib/services/notifier') | ||
var clc = require('cli-color') | ||
describe('Notifier', function() { | ||
var consoleStub, msg, growlStub; | ||
var consoleStub, msg, growlStub | ||
beforeEach(function(done) { | ||
growlStub = sinon.stub(notify, 'growl'); | ||
done(); | ||
}); | ||
growlStub = sinon.stub(notify, 'growl') | ||
done() | ||
}) | ||
afterEach(function(done) { | ||
growlStub.restore(); | ||
done(); | ||
}); | ||
growlStub.restore() | ||
done() | ||
}) | ||
describe('event', function() { | ||
it('logs a green message on flinch at', function(done) { | ||
consoleStub = sinon.stub(console, 'log'); | ||
notify.event({ ttl: 5, statusCode: 0, event: 'e'}); | ||
consoleStub.should.have.been.calledWithMatch(sinon.match(styleMatch.green)); | ||
consoleStub.restore(); | ||
done(); | ||
}); | ||
consoleStub = sinon.stub(console, 'log') | ||
notify.event({ ttl: 5, statusCode: 0, event: 'e'}) | ||
consoleStub.should.have.been.calledWithMatch(sinon.match(styleMatch.green)) | ||
consoleStub.restore() | ||
done() | ||
}) | ||
it('logs a red message on flinch at', function(done) { | ||
consoleStub = sinon.stub(console, 'log'); | ||
notify.event({ ttl: 5, statusCode: 1, event: 'e'}); | ||
consoleStub.should.have.been.calledWithMatch(sinon.match(styleMatch.red)); | ||
consoleStub.restore(); | ||
done(); | ||
}); | ||
}); | ||
consoleStub = sinon.stub(console, 'log') | ||
notify.event({ ttl: 5, statusCode: 1, event: 'e'}) | ||
consoleStub.should.have.been.calledWithMatch(sinon.match(styleMatch.red)) | ||
consoleStub.restore() | ||
done() | ||
}) | ||
}) | ||
describe('flush', function() { | ||
it('logs a bold message on flinch flush', function(done) { | ||
consoleStub = sinon.stub(console, 'log'); | ||
notify.flush(); | ||
consoleStub.should.have.been.calledWithMatch(sinon.match(styleMatch.bold)); | ||
consoleStub.restore(); | ||
done(); | ||
}); | ||
}); | ||
consoleStub = sinon.stub(console, 'log') | ||
notify.flush() | ||
consoleStub.should.have.been.calledWithMatch(sinon.match(styleMatch.bold)) | ||
consoleStub.restore() | ||
done() | ||
}) | ||
}) | ||
describe('growl support', function() { | ||
it('is disabled by default', function(done) { | ||
mute(); | ||
notify.flush(); | ||
growlStub.should.not.have.been.called; | ||
unmute(); | ||
done(); | ||
}); | ||
mute() | ||
notify.flush() | ||
growlStub.should.not.have.been.called | ||
unmute() | ||
done() | ||
}) | ||
it('can be enabled via set_growl_support', function(done) { | ||
mute(); | ||
notify.set_growl_support(true); | ||
notify.flush(); | ||
growlStub.should.have.been.called; | ||
unmute(); | ||
done(); | ||
}); | ||
}); | ||
mute() | ||
notify.set_growl_support(true) | ||
notify.flush() | ||
growlStub.should.have.been.called | ||
unmute() | ||
done() | ||
}) | ||
}) | ||
}); | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
39561
33
950
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcli-color@0.3.3(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addedd@0.1.11.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedes5-ext@0.10.64(transitive)
+ Addedes6-iterator@0.1.32.0.3(transitive)
+ Addedes6-symbol@2.0.13.1.4(transitive)
+ Addedes6-weak-map@0.1.4(transitive)
+ Addedesniff@2.0.1(transitive)
+ Addedevent-emitter@0.3.5(transitive)
+ Addedext@1.7.0(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedgrowl@1.10.5(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlru-queue@0.1.0(transitive)
+ Addedmemoizee@0.3.10(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addednext-tick@0.2.21.1.0(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.9.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtimers-ext@0.1.8(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedtype@2.7.3(transitive)
+ Addedunderscore@1.13.7(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
- Removedasn1@0.1.11(transitive)
- Removedassert-plus@0.1.5(transitive)
- Removedasync@0.9.2(transitive)
- Removedaws-sign2@0.5.0(transitive)
- Removedboom@0.4.2(transitive)
- Removedcli-color@0.2.3(transitive)
- Removedcombined-stream@0.0.7(transitive)
- Removedcommander@2.2.0(transitive)
- Removedcryptiles@0.2.2(transitive)
- Removedctype@0.5.3(transitive)
- Removeddelayed-stream@0.0.5(transitive)
- Removedes5-ext@0.9.2(transitive)
- Removedevent-emitter@0.2.2(transitive)
- Removedforever-agent@0.5.2(transitive)
- Removedform-data@0.1.4(transitive)
- Removedgrowl@1.7.0(transitive)
- Removedhawk@1.0.0(transitive)
- Removedhoek@0.9.1(transitive)
- Removedhttp-signature@0.10.1(transitive)
- Removedmemoizee@0.2.6(transitive)
- Removedmime@1.2.11(transitive)
- Removednext-tick@0.1.0(transitive)
- Removednode-uuid@1.4.8(transitive)
- Removedoauth-sign@0.3.0(transitive)
- Removedqs@0.6.6(transitive)
- Removedrequest@2.34.0(transitive)
- Removedsntp@0.2.4(transitive)
- Removedtldts@6.1.48(transitive)
- Removedtldts-core@6.1.48(transitive)
- Removedtough-cookie@5.0.0(transitive)
- Removedtunnel-agent@0.3.0(transitive)
- Removedunderscore@1.6.0(transitive)
Updatedcli-color@^0.3.2
Updatedcommander@^2.2.0
Updatedgrowl@^1.7.0
Updatedrequest@^2.34.0
Updatedunderscore@^1.6.0