Skip to content

Commit 919f59b

Browse files
committed
feat: add programmatic method
1 parent d96eb91 commit 919f59b

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "junit-to-ctrf",
33
"version": "0.0.8",
44
"description": "Convert JUnit XML reports to CTRF JSON",
5-
"main": "index.js",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
67
"scripts": {
78
"build": "npx tsc",
89
"run:junit": "node dist/cli.js test-junit.xml",

src/convert.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,14 @@ export async function convertJUnitToCTRF(
182182
console.log('Writing CTRF report to:', finalOutputPath);
183183
await fs.outputJson(finalOutputPath, ctrfReport, { spaces: 2 });
184184
}
185+
186+
export async function convertJUnitToCTRFReport(
187+
junitPath: string,
188+
toolName?: string,
189+
envProps?: string[],
190+
useSuiteName?: boolean
191+
): Promise<CtrfReport> {
192+
const testCases = await parseJUnitReport(junitPath);
193+
const envPropsObj = envProps ? Object.fromEntries(envProps.map(prop => prop.split('='))) : {};
194+
return createCTRFReport(testCases, toolName, envPropsObj, useSuiteName);
195+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { convertJUnitToCTRF } from './convert';

0 commit comments

Comments
 (0)