Skip to content

Commit 2a9c255

Browse files
committed
code updates
1 parent 8caff72 commit 2a9c255

File tree

11 files changed

+106
-76
lines changed

11 files changed

+106
-76
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ report1/
1414
tests/data/tmp/
1515
jest.json
1616
*.xml
17+
tester.js

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ jest.config.js
1515
jest.json
1616
junit.xml
1717
*.xml
18+
tester.js

index.d.ts

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,52 @@ declare module 'junit-converter'{
1414
}
1515

1616
/**
17-
* Test suite JSON representation
17+
* JUnit JSON structure from XML
1818
*/
19+
interface TestSuites {
20+
testsuites: Array<{
21+
name?: string;
22+
classname?: string;
23+
tests: string | number;
24+
failures: string | number;
25+
errors?: string | number;
26+
skipped: string | number;
27+
disabled?: string | number;
28+
assertions?: string | number;
29+
time: string | number;
30+
timestamp?: string;
31+
testsuite: TestSuite[];
32+
}>;
33+
}
34+
1935
interface TestSuite {
2036
name: string;
21-
tests: string;
22-
failures: string;
23-
skipped: string;
24-
time: string;
25-
testcase: TestCase[];
37+
classname?: string;
2638
file?: string;
39+
tests: string | number;
40+
passed?: string | number;
41+
failures: string | number;
42+
errors?: string | number;
43+
skipped: string | number;
44+
disabled?: string | number;
45+
time: string | number;
46+
timestamp?: string;
47+
testcase: TestCase[];
2748
}
28-
/**
29-
* Test case JSON representation
30-
*/
49+
3150
interface TestCase {
32-
classname: string;
3351
name: string;
34-
time: number;
35-
status?: string;
36-
[key: string]: any;
37-
}
38-
/**
39-
* Test suites JSON structure
40-
*/
41-
interface TestSuites {
42-
testsuites: Array<{
43-
time?: string | number;
44-
testsuite: TestSuite[];
45-
}>;
52+
classname: string;
53+
status: string;
54+
time: string;
55+
failure?: any;
56+
error?: any;
57+
properties?: any;
58+
skipped?: any;
59+
'system-out'?: any;
60+
'system-err'?: any;
4661
}
4762

48-
4963
/**
5064
* Convert test report to JUnit XML and write to file async.
5165
*
@@ -69,6 +83,4 @@ declare module 'junit-converter'{
6983
* @return {Promise<object>}
7084
*/
7185
function toJson(options: TestReportConverterOptions): Promise<TestSuites>;
72-
}
73-
74-
86+
}

lib/junit.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/junit.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 12 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@
4040
"MSTest"
4141
],
4242
"dependencies": {
43-
"lodash": "^4.17.21",
43+
"lodash": "^4.17.23",
4444
"p3x-xml2json": "^2025.4.123",
4545
"xml-formatter": "^3.6.7",
4646
"xslt-processor": "^3.4.0",
4747
"yargs": "^18.0.0"
4848
},
4949
"devDependencies": {
50-
"@types/lodash": "^4.17.21",
51-
"@types/node": "^24.10.1",
50+
"@types/lodash": "^4.17.23",
51+
"@types/node": "^25.2.1",
5252
"jest": "^30.2.0",
5353
"jest-junit": "^16.0.0",
5454
"ts-jest": "^29.4.6",

src/interfaces.ts

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,50 @@ export interface XmlParserOptions {
4343
sanitize: boolean;
4444
reversible: boolean;
4545
}
46+
4647
/**
47-
* Test suite JSON representation
48+
* JUnit JSON structure from XML
4849
*/
50+
export interface TestSuites {
51+
testsuites: Array<{
52+
name?: string;
53+
classname?: string;
54+
tests: string | number;
55+
failures: string | number;
56+
errors?: string | number;
57+
skipped: string | number;
58+
disabled?: string | number;
59+
assertions?: string | number;
60+
time: string | number;
61+
timestamp?: string;
62+
testsuite: TestSuite[];
63+
}>;
64+
}
65+
4966
export interface TestSuite {
5067
name: string;
51-
tests: string;
52-
failures: string;
53-
skipped: string;
54-
time: string;
55-
testcase: TestCase[];
68+
classname?: string;
5669
file?: string;
70+
tests: string | number;
71+
passed?: string | number;
72+
failures: string | number;
73+
errors?: string | number;
74+
skipped: string | number;
75+
disabled?: string | number;
76+
time: string | number;
77+
timestamp?: string;
78+
testcase: TestCase[];
5779
}
58-
/**
59-
* Test case JSON representation
60-
*/
80+
6181
export interface TestCase {
62-
classname: string;
6382
name: string;
64-
time: number;
65-
status?: string;
66-
[key: string]: any;
67-
}
68-
/**
69-
* Test suites JSON structure
70-
*/
71-
export interface TestSuites {
72-
testsuites: Array<{
73-
time?: string | number;
74-
testsuite: TestSuite[];
75-
}>;
83+
classname: string;
84+
status: string;
85+
time: string;
86+
failure?: any;
87+
error?: any;
88+
properties?: any;
89+
skipped?: any;
90+
'system-out'?: any;
91+
'system-err'?: any;
7692
}

src/junit.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import xmlFormat from 'xml-formatter';
44
import * as _ from 'lodash';
5-
const parser: any = require('p3x-xml2json');
5+
import {toJson, toXml} from 'p3x-xml2json';
66
import { ConverterOptions, XmlParserOptions, TestSuites, TestCase } from './interfaces';
77

88
/**
@@ -89,7 +89,7 @@ export class XmlProcessor {
8989
let json: TestSuites;
9090

9191
try {
92-
json = parser.toJson(xml, xmlParserOptions) as TestSuites;
92+
json = toJson(xml, xmlParserOptions) as TestSuites;
9393
} catch (e) {
9494
throw new Error(
9595
`Could not parse JSON from converted XML ${options.testFile}.\n ${
@@ -130,7 +130,7 @@ export class XmlProcessor {
130130

131131
// Convert back to XML and format
132132
xmlParserOptions.sanitize = true;
133-
const xmlOutput = parser.toXml(json, xmlParserOptions);
133+
const xmlOutput = toXml(json, xmlParserOptions);
134134

135135
return options.minify
136136
? xmlFormat.minify(xmlOutput, { forceSelfClosingEmptyTag: true })

src/p3x-xml2json.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module 'p3x-xml2json' {
2+
export function toJson(data: any, opts: any): string | object;
3+
export function toXml(data: any, opts: any): string;
4+
}

0 commit comments

Comments
 (0)