Skip to content

Commit b01bca4

Browse files
authored
chore: Improve JUnit generation (#216)
* chore: Improve JUnit generation * improve warning msg * improve warning msg
1 parent 6d3d157 commit b01bca4

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/sauce-testreporter.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,25 @@ const getPlatformName = (platform: string) => {
1111
return platform;
1212
};
1313

14-
export function generateJunitFile(
14+
export function generateJUnitFile(
1515
assetsPath: string,
1616
suiteName: string,
1717
browserName: string,
1818
platform: string,
1919
) {
20+
const junitPath = path.join(assetsPath, `report.xml`);
21+
if (!fs.existsSync(junitPath)) {
22+
console.warn(
23+
`JUnit file generation skipped: the original JUnit file (${junitPath}) from TestCafe was not located.`,
24+
);
25+
return;
26+
}
2027
const opts = { compact: true, spaces: 4, textFn: (val: string) => val };
21-
const xmlData = fs.readFileSync(path.join(assetsPath, `report.xml`), 'utf8');
28+
const xmlData = fs.readFileSync(junitPath, 'utf8');
2229
const result: any = convert.xml2js(xmlData, opts);
2330

2431
if (!result.testsuite) {
32+
console.warn('JUnit file generation skipped: no test suites detected.');
2533
return;
2634
}
2735

src/testcafe-runner.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from 'sauce-testrunner-utils';
1212

1313
import { TestCafeConfig, Suite, CompilerOptions, second } from './type';
14-
import { generateJunitFile } from './sauce-testreporter';
14+
import { generateJUnitFile } from './sauce-testreporter';
1515
import { setupProxy, isProxyAvailable } from './network-proxy';
1616

1717
async function prepareConfiguration(
@@ -368,14 +368,14 @@ async function run(nodeBin: string, runCfgPath: string, suiteName: string) {
368368
const passed = await runTestCafe(tcCommandLine, projectPath, timeout);
369369

370370
try {
371-
generateJunitFile(
371+
generateJUnitFile(
372372
assetsPath,
373373
suiteName,
374374
suite.browserName,
375375
suite.platformName || '',
376376
);
377-
} catch (err) {
378-
console.error(`Failed to generate junit file: ${err}`);
377+
} catch (e) {
378+
console.warn('Skipping JUnit file generation:', e);
379379
}
380380

381381
return passed;

0 commit comments

Comments
 (0)