Skip to content

Commit

Permalink
Change suite error handling to fatal error handling in console reporter
Browse files Browse the repository at this point in the history
Suite errors report as fatal errors anyway, so such failures will still
be reported.

Fixes theintern#213.
  • Loading branch information
csnover committed Sep 5, 2014
1 parent fcd959c commit 8494eed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
10 changes: 3 additions & 7 deletions lib/reporters/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ define([
hasGrouping && console.groupEnd(suite.name);
},

'/suite/error': function (suite) {
console.warn('SUITE ERROR: in ' + suite.id);
util.logError(suite.error);
if (suite.error.relatedTest) {
console.error('Related test: ' +
(hasGrouping ? suite.error.relatedTest.name : suite.error.relatedTest.id));
}
'/error': function (error) {
console.warn('FATAL ERROR');
util.logError(error);
},

'/test/pass': function (test) {
Expand Down
19 changes: 6 additions & 13 deletions tests/unit/lib/reporters/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,9 @@ define([
return suite;
})(),

'/suite/error': function () {
'/error': function () {
var result = [],
error = new Error('Oops'),
suite = new Suite({
name: 'suite',
error: error
}),
handles = [
mockConsole('warn', function () {
result = result.concat([].slice.call(arguments, 0));
Expand All @@ -151,17 +147,14 @@ define([
})
];

error.relatedTest = new Test({ name: 'related test', parent: suite });

try {
reporter['/suite/error'](suite);
reporter['/error'](error);

assert.strictEqual(result.length, 3, 'Reporter should log three messages for an error with a related test');
assert.strictEqual(result.length, 2, 'Reporter should log two messages for a fatal error');
result = result.join('\n');
assert.match(result, /\bSUITE ERROR\b/, 'Reporter should indicate that a suite error occurred');
assert.include(result, suite.id, 'Reporter should indicate which suite threw an error');
assert.match(result, /\bRelated test\b/, 'Reporter should indicate there was a related test for the suite error');
assert.include(result, hasGrouping ? error.relatedTest.name : error.relatedTest.id, 'Reporter should indicate the name of the related test');
assert.match(result, /\bFATAL ERROR\b/, 'Reporter should indicate that a fatal error occurred');
assert.include(result, 'Oops', 'Reporter should include the message from the error');
assert.include(result, 'tests/unit/lib/reporters/console.js:140:13', 'Reporter should indicate the location of the error');
}
finally {
var handle;
Expand Down

0 comments on commit 8494eed

Please sign in to comment.