From 0d6d8002e607115e52311884630d63d8de408f6a Mon Sep 17 00:00:00 2001 From: Nick Howes Date: Fri, 22 Jul 2022 09:07:23 +0100 Subject: [PATCH 1/4] Fixes #171. --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c680b84..b1a275d 100644 --- a/index.js +++ b/index.js @@ -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) { From 45b2561ba719d6f3afdd142442dddc1beadfe723 Mon Sep 17 00:00:00 2001 From: Nick Howes Date: Tue, 27 Sep 2022 21:41:25 +0100 Subject: [PATCH 2/4] Test case. --- test/mocha-junit-reporter-spec.js | 7 ++++++ test/mock-junit-suites.js | 41 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/mock-junit-suites.js diff --git a/test/mocha-junit-reporter-spec.js b/test/mocha-junit-reporter-spec.js index 6663582..2f72d29 100644 --- a/test/mocha-junit-reporter-spec.js +++ b/test/mocha-junit-reporter-spec.js @@ -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'); @@ -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(); diff --git a/test/mock-junit-suites.js b/test/mock-junit-suites.js new file mode 100644 index 0000000..59cf218 --- /dev/null +++ b/test/mock-junit-suites.js @@ -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" + } + } + ] + }, + ] + }, + ]; + } +}; From 5f47ff20c9769a4a22b32782a5867fcfd1548b62 Mon Sep 17 00:00:00 2001 From: Clay Jensen-Reimann Date: Tue, 27 Sep 2022 17:53:05 -0400 Subject: [PATCH 3/4] Revert to older JS syntax --- test/mocha-junit-reporter-spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/mocha-junit-reporter-spec.js b/test/mocha-junit-reporter-spec.js index 2f72d29..6279e6a 100644 --- a/test/mocha-junit-reporter-spec.js +++ b/test/mocha-junit-reporter-spec.js @@ -234,8 +234,8 @@ 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(); + var reporter = createReporter({mochaFile: 'test/output/mocha.xml'}); + var testsuites = mockJunitSuites.withStringTimes(); reporter.getXml(testsuites); }) From 874e098ef748b85f5a12fcc4f0fd901b716a0e48 Mon Sep 17 00:00:00 2001 From: Clay Jensen-Reimann Date: Tue, 27 Sep 2022 17:55:59 -0400 Subject: [PATCH 4/4] Add missing semicolon --- test/mocha-junit-reporter-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mocha-junit-reporter-spec.js b/test/mocha-junit-reporter-spec.js index 6279e6a..d14a7ef 100644 --- a/test/mocha-junit-reporter-spec.js +++ b/test/mocha-junit-reporter-spec.js @@ -237,7 +237,7 @@ describe('mocha-junit-reporter', function() { var reporter = createReporter({mochaFile: 'test/output/mocha.xml'}); var testsuites = mockJunitSuites.withStringTimes(); reporter.getXml(testsuites); - }) + }); it('respects `process.env.MOCHA_FILE`', function(done) { process.env.MOCHA_FILE = 'test/output/results.xml';