Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Improve JUnit generation #216

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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);

Check warning on line 29 in src/sauce-testreporter.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

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 @@
} 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 @@ -262,7 +262,7 @@
// it indicates that the CDP connection is disabled, and TestCafe uses its own
// proxy to communicate with the browser.
function isCDPDisabled() {
const cfg = require(path.join(__dirname, 'sauce-testcafe-config.cjs'));

Check warning on line 265 in src/testcafe-runner.ts

View workflow job for this annotation

GitHub Actions / test

Require statement not part of import statement
return cfg.disableNativeAutomation;
}

Expand Down Expand Up @@ -368,21 +368,21 @@
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;
}

if (require.main === module) {
const packageInfo = require(path.join(__dirname, '..', 'package.json'));

Check warning on line 385 in src/testcafe-runner.ts

View workflow job for this annotation

GitHub Actions / test

Require statement not part of import statement
console.log(`Sauce TestCafe Runner ${packageInfo.version}`);
console.log(`Running TestCafe ${packageInfo.dependencies?.testcafe || ''}`);
const { nodeBin, runCfgPath, suiteName } = getArgs();
Expand Down
Loading