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

Fixes #171. #172

Merged
merged 4 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ MochaJUnitReporter.prototype.getXml = function(testsuites) {

_suiteAttr.skipped += Number('skipped' in lastNode);
_suiteAttr.failures += Number('failure' in lastNode);
testcase.testcase[0]._attr.time = testcase.testcase[0]._attr.time.toFixed(3);
if (typeof testcase.testcase[0]._attr.time === 'number') {
testcase.testcase[0]._attr.time = testcase.testcase[0]._attr.time.toFixed(3);
}
});

if (antMode) {
Expand Down
7 changes: 7 additions & 0 deletions test/mocha-junit-reporter-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var FakeTimer = require('@sinonjs/fake-timers');
var xmllint = require('xmllint');
var chaiXML = require('chai-xml');
var mockXml = require('./mock-results');
var mockJunitSuites = require('./mock-junit-suites');
var testConsole = require('test-console');

var debug = require('debug')('mocha-junit-reporter:tests');
Expand Down Expand Up @@ -232,6 +233,12 @@ describe('mocha-junit-reporter', function() {
});
});

it('can handle getXml being called twice', function() {
const reporter = createReporter({mochaFile: 'test/output/mocha.xml'});
const testsuites = mockJunitSuites.withStringTimes();
reporter.getXml(testsuites);
})

it('respects `process.env.MOCHA_FILE`', function(done) {
process.env.MOCHA_FILE = 'test/output/results.xml';
var reporter = createReporter();
Expand Down
41 changes: 41 additions & 0 deletions test/mock-junit-suites.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

module.exports = {
withStringTimes: function() {
return [
{
testsuite: [
{
_attr: {
name: "Foo Bar",
timestamp: "1970-01-01T00:00:00",
tests: "3",
failures: "2",
time: "100.001"
}
},
{
testcase: [
{
_attr: {
name: "Foo Bar can narfle the garthog",
classname: "can narfle the garthog",
time: "2.002"
}
},
{
failure: {
_attr: {
message: "expected garthog to be dead",
type: "Error"
},
_cdata: "this is where the stack would be"
}
}
]
},
]
},
];
}
};