forked from ember-cli/ember-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DI to allow for unit testing the
builder
- Loading branch information
Showing
7 changed files
with
165 additions
and
27 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
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,19 @@ | ||
'use strict'; | ||
|
||
exports.Builder = Builder; | ||
|
||
function Builder(tree) { | ||
this.tree = tree; | ||
this.cleanups = 0; | ||
} | ||
Builder.prototype.build = function(){}; | ||
|
||
Builder.prototype.cleanup = function() { | ||
this.cleanups += 1; | ||
}; | ||
|
||
function MockBuilder() { | ||
|
||
} | ||
|
||
MockBuilder.prototype.Builder = Builder; |
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,28 @@ | ||
'use strict'; | ||
|
||
module.exports = MockProcess; | ||
function MockProcess() { | ||
this.signals = {}; | ||
this.listeners = {}; | ||
this.exits = 0; | ||
} | ||
|
||
MockProcess.prototype = Object.create({}); | ||
MockProcess.prototype.on = function(sig, fn) { | ||
if (typeof this.signals[sig] === 'undefined') { | ||
this.signals[sig] = []; | ||
} | ||
this.signals[sig].push(fn); | ||
}; | ||
|
||
MockProcess.prototype.addListener = function(evt, fn) { | ||
if (typeof this.listeners[evt] === 'undefined') { | ||
this.listeners[evt] = []; | ||
} | ||
this.listeners[evt].push(fn); | ||
}; | ||
|
||
|
||
MockProcess.prototype.exit = function(code) { | ||
this.exits += code; | ||
}; |
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,69 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
|
||
var MockProcess = require('../../helpers/mock-process'); | ||
var MockBrocBuilder = require('../../helpers/mock-builder'); | ||
var Builder = require('../../../lib/models/builder'); | ||
|
||
describe('Builder', function() { | ||
var process; | ||
var subject; | ||
var builder; | ||
|
||
before(function() { | ||
builder = MockBrocBuilder; | ||
process = new MockProcess(); | ||
|
||
subject = new Builder({ | ||
brocLoader: function(){}, | ||
brocBuilder: builder.Builder, | ||
process: process, | ||
}); | ||
}); | ||
|
||
describe('builder:init', function() { | ||
it('binds signals', function() { | ||
assert.equal(1, subject.process.signals.SIGINT.length); | ||
assert.equal(1, subject.process.signals.SIGTERM.length); | ||
assert.equal(1, subject.process.listeners.exit.length); | ||
}); | ||
}); | ||
|
||
describe('builder:end', function() { | ||
it('handles SIGTERM', function() { | ||
process.signals.SIGTERM[0](); | ||
assert.equal(1, process.exits); | ||
}); | ||
it('handles SIGINT', function() { | ||
process.signals.SIGINT[0](); | ||
assert.equal(2, process.exits); | ||
}); | ||
it('handles exit', function() { | ||
process.listeners.exit[0](); | ||
assert.equal(1, subject.builder.cleanups); | ||
}); | ||
}); | ||
|
||
describe('builder:additional', function() { | ||
var newSubject; | ||
|
||
before(function() { | ||
builder = MockBrocBuilder; | ||
process = new MockProcess(); | ||
|
||
newSubject = new Builder({ | ||
brocLoader: function(){}, | ||
brocBuilder: builder.Builder, | ||
process: process, | ||
}); | ||
}); | ||
|
||
it('does not bind additional signal handlers', function() { | ||
assert.ok(!newSubject.process.signals.SIGINT); | ||
assert.ok(!newSubject.process.signals.SIGTERM); | ||
}); | ||
|
||
}); | ||
|
||
}); |