Skip to content

Commit

Permalink
Improved termination tests. Still not hitting _fatal_ and dont want t…
Browse files Browse the repository at this point in the history
…o change things now in hook loading because I need to merge the PR from @ragulka.  These tests should be good enough to guide that merge.
  • Loading branch information
mikermcneil committed Jan 5, 2014
1 parent 4ce7ddf commit 08196ec
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
17 changes: 5 additions & 12 deletions test/unit/app.initializeHooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ describe('app.initializeHooks()', function() {


describe('configured with a hook (`noop2`), but not its dependency (`noop`)', function () {
$Sails.load
.expectTerminatedProcess({
$Sails.load.expectFatalError({
hooks: {

// This forced failure is only temporary--
// very hard to test right now as things stand.
whadga: function (sails) {
throw 'forced failure';
throw 'temporary forced failure to simulate dependency issue';
},

noop2: customHooks.NOOP2
Expand All @@ -77,18 +76,12 @@ describe('app.initializeHooks()', function() {



describe('configured with a hook that throws', function () {
$Sails.load
.expectTerminatedProcess({
describe('configured with a hook that always throws', function () {
$Sails.load.expectFatalError({
hooks: {

// This forced failure is only temporary--
// very hard to test right now as things stand.
whadga: function (sails) {
throw 'forced failure';
},

noop2: customHooks.NOOP2
badHook: customHooks.SPOILED_HOOK
}
});
});
Expand Down
5 changes: 5 additions & 0 deletions test/unit/fixtures/customHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ module.exports = {
// TODO: indicate dependency on 'noop' hook
identity: 'noop2'
};
},

// Deliberately rotten hook- it throws.
SPOILED_HOOK: function (sails) {
throw new Error('smells nasty');
}
};
24 changes: 22 additions & 2 deletions test/unit/helpers/sails.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ var helper = {
}



/**
* [_load description]
* @param {[type]} options [description]
* @return {[type]} [description]
*/
var _load = function (options) {

var testDescription, msSlowThreshold;
Expand All @@ -60,6 +64,11 @@ var helper = {
return _with(testDescription, sailsOpts, msSlowThreshold);
};


/**
* [withAllHooksDisabled description]
* @return {[type]} [description]
*/
_load.withAllHooksDisabled = function () {
return _with('all hooks disabled', {
log: {level: 'error'},
Expand All @@ -68,13 +77,24 @@ var helper = {
}, 500);
};

_load.expectTerminatedProcess = function( options ) {

/**
* [expectFatalError description]
* @param {[type]} options [description]
* @return {[type]} [description]
*/
_load.expectFatalError = function( options ) {
options = _.isObject(options) ? options : {};
var sailsOpts = _cleanOptions(options);

it(', sails should deliberately terminate process', function (done) {
var sails = new Sails();

// TODO:
// Pull this error domain into the core and
// wrap the hook loading process (or a comparable solution.)
// Should not have to do this here!

// Use error domain to catch failure
var DELIBERATE_ERROR = domain.create();
DELIBERATE_ERROR.on('error', function (err) {
Expand Down

0 comments on commit 08196ec

Please sign in to comment.