Skip to content

Commit 5456f83

Browse files
committed
suite as array
1 parent 40495ce commit 5456f83

File tree

4 files changed

+203
-15
lines changed

4 files changed

+203
-15
lines changed

package-lock.json

Lines changed: 154 additions & 12 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "junit-to-ctrf",
3-
"version": "0.0.13",
3+
"version": "0.0.14",
44
"description": "Convert JUnit XML reports to CTRF JSON",
55
"type": "module",
66
"main": "dist/index.js",
@@ -16,6 +16,7 @@
1616
"format": "prettier --write .",
1717
"format:check": "prettier --check .",
1818
"e2e:junit": "node dist/cli.js reports/test-junit.xml --output reports/test-junit-ctrf.json",
19+
"e2e:junit-nested": "node dist/cli.js reports/test-junit-nested.xml --output reports/test-junit-nested-ctrf.json",
1920
"e2e:minitest": "node dist/cli.js reports/test-minitest-junit.xml --output reports/test-minitest-junit-ctrf.json",
2021
"e2e:surefire": "node dist/cli.js reports/test-surefire.xml --output reports/test-surefire-ctrf.json",
2122
"e2e:glob": "node dist/cli.js \"reports/*.xml\" --output reports/test-glob-ctrf.json",
@@ -48,7 +49,7 @@
4849
"homepage": "https://ctrf.io",
4950
"license": "MIT",
5051
"dependencies": {
51-
"ctrf": "^0.0.13",
52+
"ctrf": "^0.0.17",
5253
"fs-extra": "^11.3.0",
5354
"glob": "^11.0.3",
5455
"typescript": "^5.8.3",

reports/test-junit-nested.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="com.example.AllTests" tests="10" failures="1" errors="1" skipped="1" time="1.550">
4+
<testsuite name="com.example.UnitTests" tests="6" failures="1" errors="1" skipped="1" time="0.350">
5+
<testcase name="testAddition" classname="com.example.UnitTests" time="0.015"/>
6+
<testcase name="testSubtraction" classname="com.example.UnitTests" time="0.010"/>
7+
<testcase name="testMultiplication" classname="com.example.UnitTests" time="0.020">
8+
<failure message="Expected 10 but was 9" type="AssertionError">
9+
Stack trace details...
10+
</failure>
11+
</testcase>
12+
<testcase name="testDivision" classname="com.example.UnitTests" time="0.000">
13+
<skipped/>
14+
</testcase>
15+
<testcase name="testModulo" classname="com.example.UnitTests" time="0.005">
16+
<error message="NullPointerException occurred" type="java.lang.NullPointerException">
17+
Stack trace details...
18+
</error>
19+
</testcase>
20+
<testcase name="testSquareRoot" classname="com.example.UnitTests" time="0.300"/>
21+
<system-out><![CDATA[Standard output logs for UnitTests]]></system-out>
22+
<system-err><![CDATA[Standard error logs for UnitTests]]></system-err>
23+
</testsuite>
24+
<testsuite name="com.example.IntegrationTests" tests="4" failures="0" errors="0" skipped="0" time="1.200">
25+
<testcase name="testUserLogin" classname="com.example.IntegrationTests" time="0.400"/>
26+
<testcase name="testUserRegistration" classname="com.example.IntegrationTests" time="0.300"/>
27+
<testcase name="testProductSearch" classname="com.example.IntegrationTests" time="0.200"/>
28+
<testcase name="testCheckoutProcess" classname="com.example.IntegrationTests" time="0.300"/>
29+
<system-out><![CDATA[Integration test logs...]]></system-out>
30+
<system-err><![CDATA[Integration test error logs...]]></system-err>
31+
</testsuite>
32+
<system-out><![CDATA[Standard output logs for AllTests suite]]></system-out>
33+
<system-err><![CDATA[Standard error logs for AllTests suite]]></system-err>
34+
</testsuite>
35+
</testsuites>
36+

src/convert.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,15 @@ function convertToCTRFTest(
285285

286286
const durationMs = Math.round(parseFloat(testCase.time || '0') * 1000)
287287

288+
const suiteAsArray: string[] = []
289+
const suite = sanitizeString(testCase.suite)
290+
291+
if (testCase.suite !== undefined) {
292+
if (suite !== undefined) {
293+
suiteAsArray.push(suite)
294+
}
295+
}
296+
288297
const testName = useSuiteName
289298
? `${sanitizeString(testCase.suite)}: ${sanitizeString(testCase.name)}`
290299
: sanitizeString(testCase.name)
@@ -302,7 +311,7 @@ function convertToCTRFTest(
302311
undefined,
303312
trace:
304313
sanitizeString(testCase.failureTrace || testCase.errorTrace) || undefined,
305-
suite: sanitizeString(testCase.suite),
314+
suite: suiteAsArray,
306315
}
307316

308317
if (testInfo.retryCount > 0) {

0 commit comments

Comments
 (0)