Skip to content

Commit

Permalink
Add a test to ensure that valid XML is produced by the xunit reporter
Browse files Browse the repository at this point in the history
XML does not allow certain characters to appear in documents. This
failing test demonstrates that one of those characters is not escaped.

This bug means that when a test ends up containing, for example, ANSI
color codes (`[36m<div[39m`) then the generated XML
file is invalid and some consumers (such as CircleCI) are unable to
parse the contents.

This commit does not fix the bug, just creates a failing test.

Link: https://www.w3.org/TR/2006/REC-xml11-20060816/#charsets
  • Loading branch information
malloryavvir committed Jul 21, 2023
1 parent 37deed2 commit dfe272c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/reporters/xunit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,45 @@ describe('XUnit reporter', function () {
expect(expectedWrite, 'to be', expectedTag);
});

it('should write valid XML', function () {
var xunit = new XUnit(runner);
var inputMessage = '\x1Bsome message';
expectedMessage = '�some message';
var expectedTest = {
state: STATE_FAILED,
title: expectedTitle,
parent: {
fullTitle: function () {
return expectedClassName;
}
},
duration: 1000,
err: {
actual: 'foo',
expected: 'bar',
message: inputMessage,
stack: expectedStack
}
};

xunit.test.call(fakeThis, expectedTest);
sinon.restore();

var expectedTag =
'<testcase classname="' +
expectedClassName +
'" name="' +
expectedTitle +
'" time="1"><failure>' +
expectedMessage +
'\n' +
expectedDiff +
'\n' +
expectedStack +
'</failure></testcase>';
expect(expectedWrite, 'to be', expectedTag);
});

it('should handle non-string diff values', function () {
var runner = new EventEmitter();
createStatsCollector(runner);
Expand Down

0 comments on commit dfe272c

Please sign in to comment.