(result, config)
| 85 | } |
| 86 | |
| 87 | function buildXml(result, config) { |
| 88 | const doc = new DOMImplementation().createDocument(null, null, null) |
| 89 | const suites = groupBySuite(result.tests) |
| 90 | |
| 91 | const root = doc.createElement('testsuites') |
| 92 | setAttr(root, 'name', config.testGroupName) |
| 93 | setAttr(root, 'tests', result.tests.length) |
| 94 | setAttr(root, 'failures', countState(result.tests, 'failed')) |
| 95 | setAttr(root, 'skipped', countSkipped(result.tests)) |
| 96 | setAttr(root, 'errors', 0) |
| 97 | setAttr(root, 'time', toSeconds(sumDuration(result.tests))) |
| 98 | setAttr(root, 'timestamp', toIso(result.stats && result.stats.start)) |
| 99 | doc.appendChild(root) |
| 100 | |
| 101 | suites.forEach((tests, index) => { |
| 102 | const suite = tests[0] && tests[0].parent |
| 103 | const suiteName = (suite && suite.title) || 'Tests' |
| 104 | const suiteFile = (suite && suite.file) || (tests[0] && tests[0].file) || '' |
| 105 | |
| 106 | const suiteEl = doc.createElement('testsuite') |
| 107 | setAttr(suiteEl, 'name', suiteName) |
| 108 | setAttr(suiteEl, 'id', index) |
| 109 | setAttr(suiteEl, 'tests', tests.length) |
| 110 | setAttr(suiteEl, 'failures', countState(tests, 'failed')) |
| 111 | setAttr(suiteEl, 'skipped', countSkipped(tests)) |
| 112 | setAttr(suiteEl, 'errors', 0) |
| 113 | setAttr(suiteEl, 'time', toSeconds(sumDuration(tests))) |
| 114 | setAttr(suiteEl, 'timestamp', toIso(suite && suite.startedAt)) |
| 115 | setAttr(suiteEl, 'hostname', os.hostname()) |
| 116 | if (suiteFile) setAttr(suiteEl, 'file', suiteFile) |
| 117 | root.appendChild(suiteEl) |
| 118 | |
| 119 | for (const test of tests) { |
| 120 | suiteEl.appendChild(buildTestCase(doc, test, suiteName, config)) |
| 121 | } |
| 122 | }) |
| 123 | |
| 124 | return '<?xml version="1.0" encoding="UTF-8"?>\n' + new XMLSerializer().serializeToString(doc) + '\n' |
| 125 | } |
| 126 | |
| 127 | function buildTestCase(doc, test, suiteName, config) { |
| 128 | const testEl = doc.createElement('testcase') |
no test coverage detected