Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(intern): extract and log failed tests
- Loading branch information
1 parent
92527bb
commit 5efe1d3
Showing
2 changed files
with
82 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); |