From 70c67c7c373cd0f8294453da2e9f9478ace90747 Mon Sep 17 00:00:00 2001 From: wojteknowacki <124166231+wojteknowacki@users.noreply.github.com> Date: Thu, 31 Aug 2023 20:04:16 +0200 Subject: [PATCH] Merge cypress reports and upload as one artifact (#4143) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix sending empty attribute * Add changeset * Fix tests * merging reports * combining mocha, screnshots, videos from artifacts * combining mocha, screnshots, videos from artifacts v2 * install dependencies and cache * install dependencies and cache 2 * renamed report artifact, changed path to html, retention day bumped * remove videos when tests passes * reports merging from artifacts should pass always * reports merging from artifacts should pass always * wip - paths fix * wip - video and screenshots path fix * remove videos from reports * remove fake fail --------- Co-authored-by: Paweł Chyła --- .github/workflows/test-env-deploy.yml | 58 +++++++++++++++++++++------ cypress.config.js | 14 ++++++- cypress/support/e2e.js | 5 +-- package.json | 8 ++-- 4 files changed, 65 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test-env-deploy.yml b/.github/workflows/test-env-deploy.yml index 6f1fd61d97f..ecfb6613322 100644 --- a/.github/workflows/test-env-deploy.yml +++ b/.github/workflows/test-env-deploy.yml @@ -263,18 +263,6 @@ jobs: - name: Move screenshots into reports dir if: ${{ ! cancelled() }} run: npm run qa:move-screenshots - - name: Move videos into reports dir - if: ${{ ! cancelled() }} - run: npm run qa:move-videos - - name: Merge report files - if: ${{ ! cancelled() }} - run: npm run qa:generate-html-report - - name: Upload reports - uses: actions/upload-artifact@v3 - if: always() - with: - name: mochawesome-${{ strategy.job-index }} - path: ./cypress/reports/mochareports - name: Install dependencies if: ${{ ! cancelled() }} working-directory: .github/workflows @@ -291,6 +279,14 @@ jobs: TESTMO_URL: ${{ secrets.TESTMO_URL }} TESTMO_TOKEN: ${{ secrets.TESTMO_TOKEN }} TESTMO_RUN_ID: ${{ needs.testmo-report-preparation.outputs.testmo-run-id }} + - name: Upload reports + uses: actions/upload-artifact@v3 + if: always() + with: + name: report-${{ strategy.job-index }} + path: ./cypress/reports + retention-days: 5 + if-no-files-found: ignore test-complete: needs: [testmo-report-preparation, cypress-run-selected] if: | @@ -302,6 +298,20 @@ jobs: with: node-version-file: ".nvmrc" cache: npm + - name: Cache node modules + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + path: ~/.npm + key: ${{ runner.os }}-qa-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-qa-${{ env.cache-name }}- + ${{ runner.os }}-qa- + ${{ runner.os }}- + - name: Install Dependencies + if: steps.cache-node-modules.outputs.cache-hit != 'true' + run: NODE_OPTIONS=--max_old_space_size=4096 npm install - run: npm ci working-directory: .github/workflows - name: complete testmo report @@ -314,3 +324,27 @@ jobs: TESTMO_URL: ${{ secrets.TESTMO_URL }} TESTMO_TOKEN: ${{ secrets.TESTMO_TOKEN }} TESTMO_RUN_ID: ${{ needs.testmo-report-preparation.outputs.testmo-run-id }} + - name: Download reports artifacts + uses: actions/download-artifact@v3 + with: + path: ./cypress/reports + - name: Display structure of downloaded files + run: ls -R + working-directory: ./cypress/reports + - name: Create reports dir + continue-on-error: true + run: npm run qa:create-artifacts-dirs + - name: Merge report files + continue-on-error: true + run: npm run qa:generate-html-report + - name: Move artifacts screenshots into reports dir + continue-on-error: true + run: npm run qa:artifact-move-screenshots + - name: Upload reports + uses: actions/upload-artifact@v3 + if: always() + with: + name: combined-report + path: ./cypress/reports + retention-days: 5 + if-no-files-found: ignore diff --git a/cypress.config.js b/cypress.config.js index 39e732d14b7..838d580eb9f 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -14,11 +14,10 @@ module.exports = defineConfig({ screenshotsFolder: "cypress/reports/mochareports", screenshotOnRunFailure: true, retries: { - runMode: 1, + runMode: 2, openMode: 0, }, reporter: "cypress-multi-reporters", - screenshotOnRunFailure: true, reporterOptions: { configFile: "reporter-config.json", }, @@ -33,6 +32,17 @@ module.exports = defineConfig({ config = require("./cypress/support/cypress-grep/plugin")(config); config = await require("./cypress/plugins/index.js")(on, config); cypressSplit(on, config); + on("after:spec", (spec, results) => { + if (results && results.video) { + return fs.unlink(results.video, function (err) { + if (err) { + console.warn(`Could not remove video - ${err}`); + } else { + console.log("File removed:", results.video); + } + }); + } + }); return config; }, specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}", diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 547704c1a8f..60a9f98ca30 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -178,8 +178,7 @@ Cypress.on("test:after:run", (test, runnable) => { filename = `${titleToFileName(parent.title)} -- ${filename}`; parent = parent.parent; } - filename += `${titleToFileName(test.title)} (failed).png`; - addContext({ test }, `${Cypress.spec.name}/${filename}`); - addContext({ test }, `videos/${Cypress.spec.name}.mp4`); + filename += `${titleToFileName(test.title)}(failed).png`; + addContext({ test }, `mochareports/${Cypress.spec.name}/${filename}`); } }); diff --git a/package.json b/package.json index 22991d50b86..85412671fc7 100644 --- a/package.json +++ b/package.json @@ -339,12 +339,14 @@ "change:add": "changeset add", "release:prepare-main": "./scripts/prepare-main-after-release.sh", "format:code": "prettier --ignore-unknown --write src/*", - "qa:combine-reports": "mochawesome-merge cypress/reports/mocha/*.json > cypress/reports/mochareports/report.json", - "qa:generate-mocha-report": "marge cypress/reports/mochareports/report.json --reportDir cypress/reports/mochareports", + "qa:combine-reports": "mochawesome-merge cypress/reports/*/mocha/*.json > cypress/reports/mochareports/report.json", + "qa:generate-mocha-report": "marge cypress/reports/mochareports/report.json --reportDir cypress/reports/", "qa:generate-html-report": "npm run qa:combine-reports && npm run qa:generate-mocha-report", "qa:create-artifacts-dirs": "mkdir -p cypress/reports/mochareports && mkdir -p cypress/reports/mochareports/videos", "qa:move-screenshots": "find cypress/reports/mochareports -type d -name \"*.js\" -exec mv {} cypress/reports/mochareports \\;", - "qa:move-videos": "find cypress/videos -type f -name \"*.js.mp4\" -exec mv {} cypress/reports/mochareports/videos \\;" + "qa:move-videos": "find cypress/videos -type f -name \"*.js.mp4\" -exec mv {} cypress/reports/mochareports/videos \\;", + "qa:artifact-move-screenshots": "find cypress/reports/*/mochareports -type d -name \"*.js\" -exec mv {} cypress/reports/mochareports \\;", + "qa:artifact-move-videos": "find cypress/reports/*/mochareports/videos -type f -name \"*.js.mp4\" -exec mv {} cypress/reports/mochareports/videos \\;" }, "description": "![Saleor Dashboard](https://user-images.githubusercontent.com/44495184/185379472-2a204c0b-9b7a-4a3e-93c0-2cb85205ed5e.png)" }