From 4326eaba4b198e7b0e4ad96cf6ff4bf341e4e530 Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Fri, 9 Feb 2024 16:38:21 -0800 Subject: [PATCH 1/3] chore: Improve JUnit generation --- src/sauce-testreporter.ts | 9 +++++++-- src/testcafe-runner.ts | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/sauce-testreporter.ts b/src/sauce-testreporter.ts index 41dfcd4e..d01d6bed 100644 --- a/src/sauce-testreporter.ts +++ b/src/sauce-testreporter.ts @@ -11,14 +11,19 @@ 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(${junitPath}) not found`); + 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) { diff --git a/src/testcafe-runner.ts b/src/testcafe-runner.ts index 01436eae..abf9269b 100644 --- a/src/testcafe-runner.ts +++ b/src/testcafe-runner.ts @@ -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( @@ -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; From 6be7dbda17deb3d2cc30c84be8d1b0c3cebe5392 Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Mon, 12 Feb 2024 10:20:34 -0800 Subject: [PATCH 2/3] improve warning msg --- src/sauce-testreporter.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sauce-testreporter.ts b/src/sauce-testreporter.ts index d01d6bed..48e6dc2a 100644 --- a/src/sauce-testreporter.ts +++ b/src/sauce-testreporter.ts @@ -19,7 +19,9 @@ export function generateJUnitFile( ) { const junitPath = path.join(assetsPath, `report.xml`); if (!fs.existsSync(junitPath)) { - console.warn(`JUnit file(${junitPath}) not found`); + console.warn( + `JUnit file generation skipped as the original JUnit file (${junitPath}) from TestCafe was not located.`, + ); return; } const opts = { compact: true, spaces: 4, textFn: (val: string) => val }; From 5d70d12e489b732101efaaa3e62dc51c5913c085 Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Mon, 12 Feb 2024 13:03:58 -0800 Subject: [PATCH 3/3] improve warning msg --- src/sauce-testreporter.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sauce-testreporter.ts b/src/sauce-testreporter.ts index 48e6dc2a..c1f0dc6d 100644 --- a/src/sauce-testreporter.ts +++ b/src/sauce-testreporter.ts @@ -20,7 +20,7 @@ export function generateJUnitFile( const junitPath = path.join(assetsPath, `report.xml`); if (!fs.existsSync(junitPath)) { console.warn( - `JUnit file generation skipped as the original JUnit file (${junitPath}) from TestCafe was not located.`, + `JUnit file generation skipped: the original JUnit file (${junitPath}) from TestCafe was not located.`, ); return; } @@ -29,6 +29,7 @@ export function generateJUnitFile( const result: any = convert.xml2js(xmlData, opts); if (!result.testsuite) { + console.warn('JUnit file generation skipped: no test suites detected.'); return; }