Skip to content

Commit

Permalink
Show diff in xunit
Browse files Browse the repository at this point in the history
  • Loading branch information
mlucool authored and boneskull committed Nov 5, 2018
1 parent f2b62ec commit 8256b65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/reporters/xunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ XUnit.prototype.write = function(line) {
* @param {Test} test
*/
XUnit.prototype.test = function(test) {
Base.useColors = false;

var attrs = {
classname: test.parent.fullTitle(),
name: test.title,
Expand All @@ -159,6 +161,10 @@ XUnit.prototype.test = function(test) {

if (test.state === 'failed') {
var err = test.err;
var diff =
Base.hideDiff || !err.actual || !err.expected
? ''
: '\n' + Base.generateDiff(err.actual, err.expected);
this.write(
tag(
'testcase',
Expand All @@ -168,7 +174,7 @@ XUnit.prototype.test = function(test) {
'failure',
{},
false,
escape(err.message) + '\n' + escape(err.stack)
escape(err.message) + escape(diff) + '\n' + escape(err.stack)
)
)
);
Expand Down
6 changes: 6 additions & 0 deletions test/reporters/xunit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ describe('XUnit reporter', function() {
var expectedClassName = 'fullTitle';
var expectedTitle = 'some title';
var expectedMessage = 'some message';
var expectedDiff =
'\n + expected - actual\n\n -foo\n +bar\n ';
var expectedStack = 'some-stack';
var expectedWrite = null;

Expand Down Expand Up @@ -214,6 +216,8 @@ describe('XUnit reporter', function() {
},
duration: 1000,
err: {
actual: 'foo',
expected: 'bar',
message: expectedMessage,
stack: expectedStack
}
Expand All @@ -235,6 +239,8 @@ describe('XUnit reporter', function() {
'" time="1"><failure>' +
expectedMessage +
'\n' +
expectedDiff +
'\n' +
expectedStack +
'</failure></testcase>';

Expand Down

0 comments on commit 8256b65

Please sign in to comment.