diff --git a/index.js b/index.js index 96aa308..b2eb66c 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,12 @@ const Testsuites = require('./src/Testsuites'); const xml = require('xml'); const fs = require('fs'); +const path = require('path'); const out = process.env.TEST_REPORT_PATH || process.cwd(); +const filename = process.env.TEST_REPORT_FILENAME || 'test-report.xml'; module.exports = (results) => { const testSuites = new Testsuites(results); const data = xml(testSuites, { declaration: true, indent: ' ' }); - fs.writeFileSync(`${out}/test-report.xml`, data); + fs.writeFileSync(path.join(out, filename), data); }; diff --git a/src/Testcase.js b/src/Testcase.js index c898cfe..f3b8e0a 100644 --- a/src/Testcase.js +++ b/src/Testcase.js @@ -13,6 +13,10 @@ class Testcase { } ]; + if (result.status === 'pending') { + testCase.push({ skipped: {} }); + } + this.testcase = testCase.concat(failures); } } diff --git a/src/Testsuite.js b/src/Testsuite.js index bc073c8..6ff919d 100644 --- a/src/Testsuite.js +++ b/src/Testsuite.js @@ -3,7 +3,6 @@ const Testcase = require('./Testcase'); class Testsuite { constructor (id, result) { let testcases = result.testResults - .filter(result => (result.status !== 'pending')) .map(result => new Testcase(result)); let suite = { @@ -15,17 +14,13 @@ class Testsuite { hostname: 'localhost', tests: (result.numPendingTests + result.numFailingTests + result.numPassingTests), failures: result.numFailingTests, + skipped: result.numPendingTests, time: (result.perfStats.end - result.perfStats.start) / 1000, timestamp: new Date(result.perfStats.start).toISOString().slice(0, -5) } }; - this.testsuite = [suite, { properties: [] }] - .concat( - testcases, - { 'system-out': {} }, - { 'system-err': {} } - ); + this.testsuite = [suite].concat(testcases); } } diff --git a/src/__tests__/Testcase.spec.js b/src/__tests__/Testcase.spec.js index b11e276..7fcfe59 100644 --- a/src/__tests__/Testcase.spec.js +++ b/src/__tests__/Testcase.spec.js @@ -26,3 +26,16 @@ it('should produce a ', () => { const expected = ``; expect(report).toEqual(expected); }); + +it('should produce a ', () => { + const testcase = { + title: 'should foo bar', + status: 'pending', + ancestorTitles: ['boo', 'foo'], + failureMessages: [] + }; + const result = new Testcase(testcase); + const report = xml(result); + const expected = ``; + expect(report).toEqual(expected); +}); diff --git a/src/__tests__/fixtures/junit4.xsd b/src/__tests__/fixtures/junit4.xsd new file mode 100644 index 0000000..1142fb2 --- /dev/null +++ b/src/__tests__/fixtures/junit4.xsd @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/__tests__/fixtures/testsuite.xml b/src/__tests__/fixtures/testsuite.xml index ee51f07..88c9514 100644 --- a/src/__tests__/fixtures/testsuite.xml +++ b/src/__tests__/fixtures/testsuite.xml @@ -1,12 +1,11 @@ - - - + + + + - - diff --git a/src/__tests__/index.spec.js b/src/__tests__/index.spec.js index fe1ec02..a9dcf0e 100644 --- a/src/__tests__/index.spec.js +++ b/src/__tests__/index.spec.js @@ -4,6 +4,7 @@ const cwd = process.cwd(); const reporter = require('../../index'); const { failedCase, pendingCase, passingCase } = require('./fixtures/testcase'); const junitXsd = fs.readFileSync(`${__dirname}/fixtures/junit.xsd`, {encoding: 'utf-8'}); +const junit4Xsd = fs.readFileSync(`${__dirname}/fixtures/junit4.xsd`, {encoding: 'utf-8'}); const mock = { "success": true, "startTime": Date.now(), @@ -30,10 +31,16 @@ const mock = { ] }; +const validateXml = (junitXsd, xml) => { + const schema = xsd.parse(junitXsd); + return schema.validate(xml); +} + it('should produce a valid JUnit XML report', () => { reporter(mock); const report = fs.readFileSync(`${cwd}/test-report.xml`, { encoding: 'utf-8' }); - const schema = xsd.parse(junitXsd); - const errors = schema.validate(report); - expect(errors).toBeNull(); + const errors = validateXml(junitXsd, report); + const errors4 = validateXml(junit4Xsd, report); + // The XML should comply ethier JUnit XSD or JUnit4 XSD + expect(!!errors && !!errors4).toBeFalsy(); });