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 17, 2018
1 parent 00d5e90 commit f99a36c
Show file tree
Hide file tree
Showing 2 changed files with 53 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
52 changes: 52 additions & 0 deletions test/reporters/xunit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var mkdirp = require('mkdirp');
var path = require('path');
var assert = require('assert');
var createStatsCollector = require('../../lib/stats-collector');
var EventEmitter = require('events').EventEmitter;
var reporters = require('../../').reporters;
var XUnit = reporters.XUnit;

Expand Down Expand Up @@ -320,6 +321,57 @@ 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();
createStatsCollector(runner);
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 f99a36c

Please sign in to comment.