From a64f66f8213fe849d7be1e5bd3889fba1f5df7a3 Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Fri, 9 Feb 2024 13:36:49 -0800 Subject: [PATCH 1/6] chore: Improve JUnit generation --- src/custom-reporter.ts | 3 +-- src/cypress-runner.ts | 6 +++--- src/sauce-reporter.ts | 12 +++++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/custom-reporter.ts b/src/custom-reporter.ts index ac0ae03c..b36b912b 100644 --- a/src/custom-reporter.ts +++ b/src/custom-reporter.ts @@ -1,5 +1,5 @@ /** - * This is an extension of MochaJunitReporter + * This is an extension of mocha-junit-reporter */ import xml from 'xml'; @@ -345,7 +345,6 @@ MochaJUnitReporter.prototype.getSauceTestsuiteData = function (suite: any) { }; MochaJUnitReporter.prototype.getSauceTestcaseData = function (testcase: any) { - // console.log(testcase); return { id: testcase.order, screenshot: 0, diff --git a/src/cypress-runner.ts b/src/cypress-runner.ts index 0a083d83..0a382cf6 100644 --- a/src/cypress-runner.ts +++ b/src/cypress-runner.ts @@ -1,4 +1,4 @@ -import { mergeJunitFile } from './sauce-reporter'; +import { mergeJUnitFile } from './sauce-reporter'; import path from 'path'; import fs from 'fs'; import { @@ -38,7 +38,7 @@ async function report( } try { - mergeJunitFile( + mergeJUnitFile( specFiles, runCfg.resultsDir, suiteName, @@ -46,7 +46,7 @@ async function report( platformName, ); } catch (e) { - console.error('Failed to generate junit file:', e); + console.warn('Skipping JUnit file generation:', e); } try { diff --git a/src/sauce-reporter.ts b/src/sauce-reporter.ts index d9b969b0..444e79a9 100644 --- a/src/sauce-reporter.ts +++ b/src/sauce-reporter.ts @@ -4,7 +4,7 @@ import { escapeXML } from 'sauce-testrunner-utils'; import convert from 'xml-js'; import { XmlSuiteContainer } from './types'; -export function mergeJunitFile( +export function mergeJUnitFile( specFiles: any[], resultsFolder: string, testName: string, @@ -22,10 +22,12 @@ export function mergeJunitFile( } = { compact: true, spaces: 4 }; const testsuites = []; for (let i = 0; i < specFiles.length; i++) { - const xmlData = fs.readFileSync( - path.join(resultsFolder, `${specFiles[i]}.xml`), - 'utf8', - ); + const specJUnitFile = path.join(resultsFolder, `${specFiles[i]}.xml`); + if (!fs.existsSync(specJUnitFile)) { + console.warn(`JUnit file not found for spec: ${specFiles[i]}`); + continue; + } + const xmlData = fs.readFileSync(specJUnitFile, 'utf8'); const jsObj = convert.xml2js(xmlData, opts) as XmlSuiteContainer; if (jsObj.testsuites && jsObj.testsuites.testsuite) { testsuites.push(...jsObj.testsuites.testsuite); From f23b9d357ae88d0342f1eee71072a4fd4424c66a Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Fri, 9 Feb 2024 15:26:34 -0800 Subject: [PATCH 2/6] try to fix e2e test :-/ --- tests/integration/config-tests/sauce-runner.json | 2 -- tests/integration/env-tests/cypress/e2e/env.cy.js | 2 +- tests/integration/env-tests/sauce-runner.json | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/integration/config-tests/sauce-runner.json b/tests/integration/config-tests/sauce-runner.json index e32a328a..5a749361 100644 --- a/tests/integration/config-tests/sauce-runner.json +++ b/tests/integration/config-tests/sauce-runner.json @@ -8,7 +8,6 @@ "name": "default", "browser": "chrome", "browserVersion": "", - "headless": true, "config": { "testingType": "e2e", "specPattern": [ @@ -20,7 +19,6 @@ "name": "webkit", "browser": "webkit", "browserVersion": "", - "headless": true, "config": { "testingType": "e2e", "specPattern": [ diff --git a/tests/integration/env-tests/cypress/e2e/env.cy.js b/tests/integration/env-tests/cypress/e2e/env.cy.js index 10f09476..6e7534d8 100644 --- a/tests/integration/env-tests/cypress/e2e/env.cy.js +++ b/tests/integration/env-tests/cypress/e2e/env.cy.js @@ -4,7 +4,7 @@ context('Actions', function () { it('should use host', function () { expect(Cypress.env('FOO')).to.equal('bar'); expect(Cypress.env('VALUE')).to.equal('Some test value'); - expect(Cypress.env('host')).to.equal('https://saucelabs.com/'); + expect(Cypress.env('host')).to.equal('https://saucelabs.com'); expect(Cypress.env('SAUCE_SUITE_NAME')).to.equal('default'); cy.visit(Cypress.env('host')); cy.title().should( diff --git a/tests/integration/env-tests/sauce-runner.json b/tests/integration/env-tests/sauce-runner.json index 547259dd..f2ab5143 100644 --- a/tests/integration/env-tests/sauce-runner.json +++ b/tests/integration/env-tests/sauce-runner.json @@ -17,7 +17,7 @@ ], "env": { "FOO": "bar", - "host": "https://saucelabs.com/", + "host": "https://saucelabs.com", "HELLO": "WORLD", "VALUE": "$TEST_VALUE" } From 1159ed4e83db0333c069cd30a2bc12099d4a5114 Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Mon, 12 Feb 2024 09:23:50 -0800 Subject: [PATCH 3/6] Revert "try to fix e2e test :-/" This reverts commit f23b9d357ae88d0342f1eee71072a4fd4424c66a. --- tests/integration/config-tests/sauce-runner.json | 2 ++ tests/integration/env-tests/cypress/e2e/env.cy.js | 2 +- tests/integration/env-tests/sauce-runner.json | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/integration/config-tests/sauce-runner.json b/tests/integration/config-tests/sauce-runner.json index 5a749361..e32a328a 100644 --- a/tests/integration/config-tests/sauce-runner.json +++ b/tests/integration/config-tests/sauce-runner.json @@ -8,6 +8,7 @@ "name": "default", "browser": "chrome", "browserVersion": "", + "headless": true, "config": { "testingType": "e2e", "specPattern": [ @@ -19,6 +20,7 @@ "name": "webkit", "browser": "webkit", "browserVersion": "", + "headless": true, "config": { "testingType": "e2e", "specPattern": [ diff --git a/tests/integration/env-tests/cypress/e2e/env.cy.js b/tests/integration/env-tests/cypress/e2e/env.cy.js index 6e7534d8..10f09476 100644 --- a/tests/integration/env-tests/cypress/e2e/env.cy.js +++ b/tests/integration/env-tests/cypress/e2e/env.cy.js @@ -4,7 +4,7 @@ context('Actions', function () { it('should use host', function () { expect(Cypress.env('FOO')).to.equal('bar'); expect(Cypress.env('VALUE')).to.equal('Some test value'); - expect(Cypress.env('host')).to.equal('https://saucelabs.com'); + expect(Cypress.env('host')).to.equal('https://saucelabs.com/'); expect(Cypress.env('SAUCE_SUITE_NAME')).to.equal('default'); cy.visit(Cypress.env('host')); cy.title().should( diff --git a/tests/integration/env-tests/sauce-runner.json b/tests/integration/env-tests/sauce-runner.json index f2ab5143..547259dd 100644 --- a/tests/integration/env-tests/sauce-runner.json +++ b/tests/integration/env-tests/sauce-runner.json @@ -17,7 +17,7 @@ ], "env": { "FOO": "bar", - "host": "https://saucelabs.com", + "host": "https://saucelabs.com/", "HELLO": "WORLD", "VALUE": "$TEST_VALUE" } From 8b8d42d2f828f83c7899564a6b8816d657cdbf79 Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Mon, 12 Feb 2024 10:34:03 -0800 Subject: [PATCH 4/6] revise the warning msg --- src/sauce-reporter.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sauce-reporter.ts b/src/sauce-reporter.ts index 444e79a9..0ff77a46 100644 --- a/src/sauce-reporter.ts +++ b/src/sauce-reporter.ts @@ -24,7 +24,9 @@ export function mergeJUnitFile( for (let i = 0; i < specFiles.length; i++) { const specJUnitFile = path.join(resultsFolder, `${specFiles[i]}.xml`); if (!fs.existsSync(specJUnitFile)) { - console.warn(`JUnit file not found for spec: ${specFiles[i]}`); + console.warn( + `JUnit file not found for spec: ${specFiles[i]}. Proceeding without it...`, + ); continue; } const xmlData = fs.readFileSync(specJUnitFile, 'utf8'); From 45bd45b34670fde5d334d1525ef4fd52aa4ea7af Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Mon, 12 Feb 2024 12:56:52 -0800 Subject: [PATCH 5/6] add more warn msg --- src/sauce-reporter.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sauce-reporter.ts b/src/sauce-reporter.ts index 0ff77a46..45bd01fa 100644 --- a/src/sauce-reporter.ts +++ b/src/sauce-reporter.ts @@ -36,6 +36,7 @@ export function mergeJUnitFile( } } if (testsuites.length === 0) { + console.warn('JUnit file generation skipped: No test suites detected.'); return; } From 16e12a0b3d919333eaee177c1a08c9a19abd4484 Mon Sep 17 00:00:00 2001 From: Tian Feng Date: Mon, 12 Feb 2024 13:07:46 -0800 Subject: [PATCH 6/6] improve warning msg --- src/sauce-reporter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sauce-reporter.ts b/src/sauce-reporter.ts index 45bd01fa..b23ab4f1 100644 --- a/src/sauce-reporter.ts +++ b/src/sauce-reporter.ts @@ -36,7 +36,7 @@ export function mergeJUnitFile( } } if (testsuites.length === 0) { - console.warn('JUnit file generation skipped: No test suites detected.'); + console.warn('JUnit file generation skipped: no test suites detected.'); return; }