Skip to content

Commit

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

* add more warning msg

* add more warning msg

* why did it use testcafe but without err

* Revert "why did it use testcafe but without err", will create a PR later

This reverts commit 8a2dddc.
  • Loading branch information
tianfeng92 authored Feb 13, 2024
1 parent 15def59 commit ffaec15
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ coverage
node_modules

console.log

.DS_Store

36 changes: 21 additions & 15 deletions src/playwright-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,29 @@ function getPlatformName(platformName: string) {
return platformName;
}

function generateJunitFile(
function generateJUnitFile(
sourceFile: string,
suiteName: string,
browserName: string,
platformName: string,
) {
if (!fs.existsSync(sourceFile)) {
console.warn(
`JUnit file generation skipped: the original JUnit file (${sourceFile}) from Playwright was not located.`,
);
return;
}

const xmlData = fs.readFileSync(sourceFile, 'utf8');
if (!xmlData) {
console.warn(
`JUnit file generation skipped: failed to read the Playwright original JUnit file(${sourceFile}).`,
);
return;
}
let result: any = convert.xml2js(xmlData, { compact: true });
if (!result.testsuites || !result.testsuites.testsuite) {
console.warn('JUnit file generation skipped: no test suites detected.');
return;
}

Expand Down Expand Up @@ -181,21 +188,20 @@ async function run(nodeBin: string, runCfgPath: string, suiteName: string) {
`Running Playwright ${packageInfo.dependencies?.playwright || ''}`,
);

let passed = false;
if (runCfg.Kind === 'playwright-cucumberjs') {
passed = await runCucumber(nodeBin, runCfg);
} else {
passed = await runPlaywright(nodeBin, runCfg);
try {
generateJunitFile(
runCfg.junitFile,
runCfg.suite.name,
runCfg.suite.param.browser,
runCfg.suite.platformName,
);
} catch (err) {
console.error(`Failed to generate junit file: ${err}`);
}
return await runCucumber(nodeBin, runCfg);
}

const passed = await runPlaywright(nodeBin, runCfg);
try {
generateJUnitFile(
runCfg.junitFile,
runCfg.suite.name,
runCfg.suite.param.browser,
runCfg.suite.platformName,
);
} catch (e) {
console.warn('Skipping JUnit file generation:', e);
}

return passed;
Expand Down

0 comments on commit ffaec15

Please sign in to comment.