diff --git a/src/cli/send/junitUtils.spec.ts b/src/cli/send/junitUtils.spec.ts index d64d40a3..3026c69c 100644 --- a/src/cli/send/junitUtils.spec.ts +++ b/src/cli/send/junitUtils.spec.ts @@ -32,7 +32,7 @@ describe('transformToJunit', () => { expect(result).toBe( ` - + @@ -94,7 +94,7 @@ describe('transformToJunit', () => { expect(result).toBe( ` - + @@ -137,7 +137,7 @@ describe('transformToJunit', () => { expect(result).toBe( ` - + @@ -188,7 +188,7 @@ describe('transformToJunit', () => { expect(result).toBe( ` - + failed result @@ -232,7 +232,7 @@ describe('transformToJunit', () => { expect(result).toBe( ` - + diff --git a/src/cli/send/junitUtils.ts b/src/cli/send/junitUtils.ts index 2d3536f3..23d8759e 100644 --- a/src/cli/send/junitUtils.ts +++ b/src/cli/send/junitUtils.ts @@ -5,10 +5,6 @@ import { EOL } from 'os'; import { DOMImplementation } from '@xmldom/xmldom'; import { formatXml } from 'xmldom-format'; -function toFloatSeconds(durationMillis: number): string { - return (durationMillis / 1000).toFixed(3); -} - /** * output in junit format * @param output json object with all test results @@ -24,9 +20,11 @@ export function transformToJunit(output: SendJsonOutput): string { document.appendChild(xmlNode); const root = document.createElement('testsuites'); document.appendChild(root); + root.setAttribute('tests', `${output.summary.totalRequests}`); root.setAttribute('errors', '0'); root.setAttribute('disabled', `${output.summary.disabledRequests}`); root.setAttribute('failues', `${output.summary.failedTests}`); + root.setAttribute('time', `${toFloatSeconds(output.requests.reduce(sumDuration, 0))}`); for (const [filename, requests] of Object.entries(groupedRequests)) { root.appendChild(transformToTestSuite(document, filename, requests)); @@ -38,10 +36,6 @@ export function transformToJunit(output: SendJsonOutput): string { }); } -function sum(x: number, y: SendOutputRequest) { - return x + (y.duration || 0); -} - // eslint-disable-next-line no-undef function transformToTestSuite(document: XMLDocument, file: string, requests: Array) { const summary = createTestSummary(requests); @@ -52,7 +46,7 @@ function transformToTestSuite(document: XMLDocument, file: string, requests: Arr setAttribute(root, 'failures', summary.failedRequests); setAttribute(root, 'skipped', summary.disabledRequests); setAttribute(root, 'package', dirname(file).replace(process.cwd(), '')); - setAttribute(root, 'time', toFloatSeconds(requests.reduce(sum, 0) || 0)); + setAttribute(root, 'time', `${toFloatSeconds(requests.reduce(sumDuration, 0))}`); setAttribute(root, 'file', file); for (const request of requests) { @@ -133,6 +127,13 @@ function transformToProperties(document: XMLDocument, request: SendOutputRequest } return undefined; } +function sumDuration(x: number, y: SendOutputRequest) { + return x + (y.duration || 0); +} + +function toFloatSeconds(durationMillis: number): string { + return (durationMillis / 1000).toFixed(3); +} // eslint-disable-next-line no-undef function setAttribute(node: HTMLElement, key: string, value: string | number | undefined) {