Skip to content

Commit

Permalink
Dont count xunit failures as errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mlucool authored and Marc Udoff committed Dec 4, 2018
1 parent 4bef574 commit df93ec4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/reporters/xunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function XUnit(runner, options) {
{
name: suiteName,
tests: stats.tests,
failures: stats.failures,
failures: 0,
errors: stats.failures,
skipped: stats.tests - stats.failures - stats.passes,
timestamp: new Date().toUTCString(),
Expand Down
51 changes: 51 additions & 0 deletions test/reporters/xunit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fs = require('fs');
var mkdirp = require('mkdirp');
var path = require('path');
var assert = require('assert');
var EventEmitter = require('events').EventEmitter;
var reporters = require('../../').reporters;
var XUnit = reporters.XUnit;

Expand Down Expand Up @@ -317,6 +318,56 @@ describe('XUnit reporter', function() {
expect(expectedWrite, 'to be', expectedTag);
});
});
describe('should write expected summary statistics', function() {
var count = 0;
var simpleError = {
actual: 'foo',
expected: 'bar',
message: expectedMessage,
stack: expectedStack
};
var generateTest = function(passed) {
var t = {
title: expectedTitle + count,
state: passed ? 'passed' : 'failed',
isPending: function() {
return false;
},
slow: function() {
return false;
},
parent: {
fullTitle: function() {
return expectedClassName;
}
},
duration: 1000
};
return t;
};

var runner = new EventEmitter();
var xunit = new XUnit(runner);
expectedWrite = '';
xunit.write = function(string) {
expectedWrite += string;
};

// 3 tests, no failures (i.e. tests that could not run), and 2 errors
runner.emit('test end');
runner.emit('pass', generateTest(true));
runner.emit('test end');
runner.emit('fail', generateTest(false), simpleError);
runner.emit('test end');
runner.emit('fail', generateTest(false), simpleError);
runner.emit('end');

var expectedTag =
'<testsuite name="Mocha Tests" tests="3" failures="0" errors="2" skipped="0"';

expect(expectedWrite, 'to contain', expectedTag);
expect(expectedWrite, 'to contain', '</testsuite>');
});
});

describe('custom suite name', function() {
Expand Down

0 comments on commit df93ec4

Please sign in to comment.