Skip to content

Commit

Permalink
Merge cypress reports and upload as one artifact (#4143)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
wojteknowacki and poulch authored Aug 31, 2023
1 parent 6e39972 commit 70c67c7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 20 deletions.
58 changes: 46 additions & 12 deletions .github/workflows/test-env-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand All @@ -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
Expand All @@ -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
14 changes: 12 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -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}",
Expand Down
5 changes: 2 additions & 3 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
});
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}

0 comments on commit 70c67c7

Please sign in to comment.