-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ready for 0.8 upgrade lifecycle helper
- Loading branch information
Showing
4 changed files
with
235 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
'use strict'; | ||
var expect = require('chai').expect | ||
|
||
var Lifecycle = require('../helpers/Lifecycle') | ||
|
||
|
||
describe('helpers/Lifecycle',function(){ | ||
var inst | ||
beforeEach(function(done){ | ||
inst = new Lifecycle() | ||
done() | ||
}) | ||
afterEach(function(done){ | ||
inst = null | ||
done() | ||
}) | ||
it('should allow adding of sequences',function(done){ | ||
inst.add('test') | ||
expect(inst.items[0].title).to.equal('test') | ||
done() | ||
}) | ||
it('should allow adding of sequences without title',function(done){ | ||
inst.add(function(next){ | ||
expect(next).to.be.a('function') | ||
next() | ||
}) | ||
inst.start(done) | ||
}) | ||
it('should allow removing of sequences',function(done){ | ||
inst.add('test') | ||
var item = inst.remove('test') | ||
expect(item.title).to.equal('test') | ||
expect(inst.items[0]).to.equal(undefined) | ||
done() | ||
}) | ||
it('should start in order',function(done){ | ||
inst.add('test1') | ||
inst.add('test2') | ||
inst.once('start',function(item){ | ||
expect(item.title).to.equal('test1') | ||
inst.once('start',function(item){ | ||
expect(item.title).to.equal('test2') | ||
}) | ||
}) | ||
inst.start(done) | ||
}) | ||
it('should stop in order',function(done){ | ||
inst.add('test1') | ||
inst.add('test2') | ||
inst.once('stop',function(item){ | ||
expect(item.title).to.equal('test2') | ||
inst.once('stop',function(item){ | ||
expect(item.title).to.equal('test1') | ||
}) | ||
}) | ||
inst.stop(done) | ||
}) | ||
it('should call callbacks during start',function(done){ | ||
inst.add('test1',function(next){ | ||
expect(next).to.be.a('function') | ||
next() | ||
}) | ||
inst.start(done) | ||
}) | ||
it('should call callbacks during stop',function(done){ | ||
inst.add('test2',function(next){ | ||
expect(next).to.be.a('function') | ||
next() | ||
}) | ||
inst.stop(done) | ||
}) | ||
it('should bubble errors on start',function(done){ | ||
inst.add('test1',function(next){ | ||
next('foo') | ||
}) | ||
inst.start(function(err){ | ||
expect(err).to.equal('foo') | ||
done() | ||
}) | ||
}) | ||
it('should bubble errors on stop',function(done){ | ||
inst.add('test1',null,function(next){ | ||
next('foo') | ||
}) | ||
inst.stop(function(err){ | ||
expect(err).to.equal('foo') | ||
done() | ||
}) | ||
}) | ||
it('should emit a start event',function(done){ | ||
inst.add('test1') | ||
inst.once('start',function(item){ | ||
expect(item.title).to.equal('test1') | ||
done() | ||
}) | ||
inst.start(function(err){if(err) done(err)}) | ||
}) | ||
it('should emit a stop event',function(done){ | ||
inst.add('test1') | ||
inst.once('stop',function(item){ | ||
expect(item.title).to.equal('test1') | ||
done() | ||
}) | ||
inst.stop(function(err){if(err) done(err)}) | ||
}) | ||
it('should emit an online event',function(done){ | ||
inst.add('test1') | ||
inst.once('online',function(){ | ||
done() | ||
}) | ||
inst.start(function(err){if(err) done(err)}) | ||
}) | ||
it('should emit an offline event',function(done){ | ||
inst.add('test1') | ||
inst.once('offline',function(){ | ||
done() | ||
}) | ||
inst.stop(function(err){if(err) done(err)}) | ||
}) | ||
it('should emit an add event',function(done){ | ||
inst.once('add',function(item){ | ||
expect(item.title).to.equal('test1') | ||
done() | ||
}) | ||
inst.add('test1') | ||
}) | ||
it('should emit a remove event',function(done){ | ||
inst.once('remove',function(item){ | ||
expect(item.title).to.equal('test1') | ||
done() | ||
}) | ||
inst.add('test1') | ||
inst.remove('test1') | ||
}) | ||
}) |