Skip to content

Commit

Permalink
chore(intern): extract and log failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Jan 12, 2016
1 parent 92527bb commit 5efe1d3
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/intern.base-config.js
Expand Up @@ -65,6 +65,10 @@ define([
id: 'JUnit',
filename: 'reports/junit.xml',
},
{
id: '../../../test/reporters/Errors',
filename: 'reports/errors.log',
},
],

// Non-functional test suite(s) to run in each browser
Expand Down
78 changes: 78 additions & 0 deletions test/reporters/Errors.js
@@ -0,0 +1,78 @@
/**
* There is no formal spec for this format and everyone does it differently, so good luck! We've mashed as many of the
* different incompatible JUnit/xUnit XSDs as possible into one reporter.
*/
define([
'intern/dojo/node!charm',
'intern/lib/util',
], function(charm, util) {

function Errors(config) {
config = config || {};
this._failedUnits = {};
this._failedFunctional = {};

this.charm = charm();
this.config = config;
}

Errors.prototype.testFail = function(test) {
var p = test.id.split(' - ');
var _env = p.shift();
var _section = p.shift();
var _test = p.join(' - ');
var _map;

if (_section === 'unit tests') {
_map = this._failedUnits;
} else {
_map = this._failedFunctional;
}

if (!_map[_test]) {
_map[_test] = {};
}

_map[_test][_env] = util.getErrorMessage(test.error);
};

Errors.prototype._mapToString = function(map) {
var lines = [];
Object.keys(map).forEach(function(_test) {
var _lines = [];
var _environments = Object.keys(map[_test]);
_lines.push('× ' + _test + ' failing in ' + _environments.join(', '));
_environments.forEach(function(_env) {
var _error = map[_test][_env];
_lines.push(_env + ': ' + _error);
});

lines.push(_lines.join('\n'));
});

return lines.join('\n\n');
};

Errors.prototype.runEnd = function() {
var report = [
this._mapToString(this._failedUnits),
this._mapToString(this._failedFunctional),
].filter(Boolean).join('\n\n');

if (!report) {
return;
}

this.output = this.config.output;

this.charm
.display('reset')
.write('\n\nCollected Errors\n')
.write(report)
.write('\n\n');

this.output.end(report);
};

return Errors;
});

0 comments on commit 5efe1d3

Please sign in to comment.