Skip to content

Commit 0f46a2a

Browse files
Merge pull request #6 from ctrf-io/feat/surefire
feat: support surefire and failsafe reports
2 parents 00936c3 + a295328 commit 0f46a2a

File tree

7 files changed

+81
-31
lines changed

7 files changed

+81
-31
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "junit-to-ctrf",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

src/convert.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs-extra';
22
import path from 'path';
33
import xml2js from 'xml2js';
4-
import { CtrfReport, CtrfTest, CtrfEnvironment, Tool } from '../types/ctrf';
4+
import { CtrfReport, CtrfTest, Tool } from '../types/ctrf';
55

66
interface JUnitTestCase {
77
suite: string;
@@ -39,15 +39,24 @@ async function parseJUnitReport(filePath: string): Promise<JUnitTestCase[]> {
3939
}
4040
if (suite.testsuite) {
4141
suite.testsuite.forEach((nestedSuite: any) => {
42-
parseTestSuite(nestedSuite, suiteName);
42+
const nestedSuiteName = nestedSuite.$.name || suiteName;
43+
parseTestSuite(nestedSuite, nestedSuiteName);
4344
});
4445
}
4546
};
4647

47-
result.testsuites.testsuite.forEach((suite: any) => {
48+
if (result.testsuites && result.testsuites.testsuite) {
49+
result.testsuites.testsuite.forEach((suite: any) => {
50+
const suiteName = suite.$.name;
51+
parseTestSuite(suite, suiteName);
52+
});
53+
} else if (result.testsuite) {
54+
const suite = result.testsuite;
4855
const suiteName = suite.$.name;
4956
parseTestSuite(suite, suiteName);
50-
});
57+
} else {
58+
console.warn('No test suites found in the provided file.');
59+
}
5160

5261
return testCases;
5362
}

test-junit.xml

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

test-surefire.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuite name="com.example.MyTest" tests="10" failures="2" errors="1" skipped="1" time="0.058">
3+
<properties>
4+
<property name="java.version" value="1.8.0_292"/>
5+
<property name="os.name" value="Linux"/>
6+
</properties>
7+
<testcase name="testPass1" classname="com.example.MyTest" time="0.002"/>
8+
<testcase name="testPass2" classname="com.example.MyTest" time="0.003"/>
9+
<testcase name="testFail1" classname="com.example.MyTest" time="0.005">
10+
<failure message="Test failed due to assertion" type="AssertionError">
11+
Stack trace details here
12+
</failure>
13+
</testcase>
14+
<testcase name="testPass3" classname="com.example.MyTest" time="0.002"/>
15+
<testcase name="testError1" classname="com.example.MyTest" time="0.001">
16+
<error message="Unexpected exception" type="java.lang.NullPointerException">
17+
NullPointerException stack trace details
18+
</error>
19+
</testcase>
20+
<testcase name="testPass4" classname="com.example.MyTest" time="0.010"/>
21+
<testcase name="testPass5" classname="com.example.MyTest" time="0.020"/>
22+
<testcase name="testFail2" classname="com.example.MyTest" time="0.005">
23+
<failure message="Assertion failed on condition" type="AssertionError">
24+
Another stack trace
25+
</failure>
26+
</testcase>
27+
<testcase name="testSkipped1" classname="com.example.MyTest" time="0.000">
28+
<skipped/>
29+
</testcase>
30+
<testcase name="testPass6" classname="com.example.MyTest" time="0.010"/>
31+
<system-out><![CDATA[Standard output logs here]]></system-out>
32+
<system-err><![CDATA[Standard error logs here]]></system-err>
33+
</testsuite>

test.xml

Lines changed: 0 additions & 23 deletions
This file was deleted.

types/ctrf.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export interface CtrfTest {
3232
suite?: string
3333
message?: string
3434
trace?: string
35-
line?: string
3635
rawStatus?: string
3736
tags?: string[]
3837
type?: string

0 commit comments

Comments
 (0)