Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont count xunit failures as errors #2475

Merged
merged 1 commit into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
it('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