Skip to content

Commit

Permalink
chore: Improve JUnit generation (#216)
Browse files Browse the repository at this point in the history
* chore: Improve JUnit generation

* improve warning msg

* improve warning msg
  • Loading branch information
tianfeng92 committed Feb 13, 2024
1 parent 6d3d157 commit b01bca4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/sauce-testreporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@ const getPlatformName = (platform: string) => {
return platform;
};

export function generateJunitFile(
export function generateJUnitFile(
assetsPath: string,
suiteName: string,
browserName: string,
platform: string,
) {
const junitPath = path.join(assetsPath, `report.xml`);
if (!fs.existsSync(junitPath)) {
console.warn(
`JUnit file generation skipped: the original JUnit file (${junitPath}) from TestCafe was not located.`,
);
return;
}
const opts = { compact: true, spaces: 4, textFn: (val: string) => val };
const xmlData = fs.readFileSync(path.join(assetsPath, `report.xml`), 'utf8');
const xmlData = fs.readFileSync(junitPath, 'utf8');
const result: any = convert.xml2js(xmlData, opts);

if (!result.testsuite) {
console.warn('JUnit file generation skipped: no test suites detected.');
return;
}

Expand Down
8 changes: 4 additions & 4 deletions src/testcafe-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from 'sauce-testrunner-utils';

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

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

try {
generateJunitFile(
generateJUnitFile(
assetsPath,
suiteName,
suite.browserName,
suite.platformName || '',
);
} catch (err) {
console.error(`Failed to generate junit file: ${err}`);
} catch (e) {
console.warn('Skipping JUnit file generation:', e);
}

return passed;
Expand Down

0 comments on commit b01bca4

Please sign in to comment.