From 0052a050cbc40e9789e3a4d69fbdae86636ecde9 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Sun, 27 Oct 2024 18:51:40 +0100 Subject: [PATCH] chore: fix Cypress summary report --- .github/workflows/build.yml | 16 ++++--- build/mocha-reporter.js | 92 ------------------------------------- cypress.config.ts | 1 + 3 files changed, 10 insertions(+), 99 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d3806bed..586439d8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,11 +25,11 @@ jobs: run: yarn ci:build - name: test summary - uses: dorny/test-reporter@1a288b62f8b75c0f433cbfdbc2e4800fbae50bd7 + uses: phoenix-actions/test-reporting@v15 if: ${{ (success() || failure()) && github.repository == 'mistic100/Photo-Sphere-Viewer' }} with: name: build - use-actions-summary: true + output-to: step-summary path: 'packages/*/reports/mocha.json' reporter: mocha-json @@ -55,16 +55,18 @@ jobs: if: ${{ (success() || failure()) && github.repository == 'mistic100/Photo-Sphere-Viewer' }} with: name: e2e-report-${{ github.ref_name }}-${{ env.SHORT_SHA }} - path: cypress/reports/html + path: | + cypress/reports/html + !cypress/reports/html/.jsons - name: test summary - uses: dorny/test-reporter@1a288b62f8b75c0f433cbfdbc2e4800fbae50bd7 + uses: phoenix-actions/test-reporting@v15 if: ${{ (success() || failure()) && github.repository == 'mistic100/Photo-Sphere-Viewer' }} with: name: e2e - use-actions-summary: true - path: cypress/reports/e2e.json - reporter: mocha-json + output-to: step-summary + path: 'cypress/reports/html/.jsons/*.jsons' + reporter: mochawesome-json build-doc: runs-on: ubuntu-latest diff --git a/build/mocha-reporter.js b/build/mocha-reporter.js index 8ecb23be..cda0b358 100644 --- a/build/mocha-reporter.js +++ b/build/mocha-reporter.js @@ -1,7 +1,5 @@ const BaseReporter = require('mocha/lib/reporters/base'); const SpecReporter = require('mocha/lib/reporters/spec'); -const path = require('path'); -const fs = require('fs'); module.exports = class MultiReporter extends BaseReporter { constructor(runner, options) { @@ -12,12 +10,6 @@ module.exports = class MultiReporter extends BaseReporter { if (options.reporterOptions?.cypress) { const MochawesomeReporter = require('cypress-mochawesome-reporter/lib/reporter'); this.mochawesome = new MochawesomeReporter(runner, {}); - - new CypressJsonReporter(runner, { - reporterOption: { - output: 'cypress/reports/e2e.json', - }, - }); } else { const JsonReporter = require('mocha/lib/reporters/json'); new JsonReporter(runner, { @@ -36,87 +28,3 @@ module.exports = class MultiReporter extends BaseReporter { } } }; - -// custom json reporter for cypress (for some reason, calling JsonReporter does not work) -// - write the results to a json file -// - fill the "file" property of each test -function CypressJsonReporter(runner, options) { - BaseReporter.call(this, runner, options); - - const tests = []; - const pending = []; - const failures = []; - const passes = []; - - runner.on('test end', function (test) { - tests.push(test); - }); - - runner.on('pass', function (test) { - passes.push(test); - }); - - runner.on('fail', function (test) { - failures.push(test); - }); - - runner.on('pending', function (test) { - pending.push(test); - }); - - runner.once('end', () => { - const obj = { - stats: this.stats, - tests: tests.map(clean), - pending: pending.map(clean), - failures: failures.map(clean), - passes: passes.map(clean), - }; - const json = JSON.stringify(obj, null, 2); - const output = options.reporterOption.output; - fs.mkdirSync(path.dirname(output), { recursive: true }); - fs.writeFileSync(output, json); - }); - - function clean(test) { - let err = test.err || {}; - if (err instanceof Error) { - err = errorJSON(err); - } - - return { - title: test.title, - fullTitle: test.fullTitle(), - file: test.invocationDetails.absoluteFile, - duration: test.duration, - currentRetry: test.currentRetry(), - speed: test.speed, - err: cleanCycles(err), - }; - } - - function cleanCycles(obj) { - let cache = []; - return JSON.parse( - JSON.stringify(obj, (key, value) => { - if (typeof value === 'object' && value !== null) { - if (cache.indexOf(value) !== -1) { - // Instead of going in a circle, we'll print [object Object] - return '' + value; - } - cache.push(value); - } - - return value; - }) - ); - } - - function errorJSON(err) { - let res = {}; - Object.getOwnPropertyNames(err).forEach((key) => { - res[key] = err[key]; - }, err); - return res; - } -} diff --git a/cypress.config.ts b/cypress.config.ts index cb9d1b0f..634cbd8f 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -53,5 +53,6 @@ export default defineConfig({ reporter: 'build/mocha-reporter.js', reporterOptions: { cypress: true, + removeJsonsFolderAfterMerge: false, // cypress-mochawesome-reporter }, });