Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Use knapsack pro to speed up cypress tests (#11863)
Browse files Browse the repository at this point in the history
* Install knapsack pro

* Use knapsack pro command

* Lint

* Use chrome

* Add test file pattern

* Use two different tokens for knapsack

* Use the correct secret

* Update lockfile

* Fix conflict

* Remove redundant options

* Add explaining comment

* Remove outdated variables and steps

* Update comment

* Fix conflict

* Use the chrome we setup earlier

* Add back percy config

* Set knapsack pro branch

* Use github_env to get browser path

* Add badge to readme

* Update .github/workflows/cypress.yaml

Co-authored-by: Michael Telatynski <[email protected]>

* Apply prettier

---------

Co-authored-by: Michael Telatynski <[email protected]>
  • Loading branch information
MidhunSureshR and t3chguy committed Nov 16, 2023
1 parent 62256a3 commit 085b39c
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 48 deletions.
53 changes: 14 additions & 39 deletions .github/workflows/cypress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ jobs:
outputs:
uuid: ${{ steps.uuid.outputs.value }}
pr_id: ${{ steps.prdetails.outputs.pr_id }}
commit_message: ${{ steps.commit.outputs.message }}
commit_author: ${{ steps.commit.outputs.author }}
commit_email: ${{ steps.commit.outputs.email }}
percy_enable: ${{ steps.percy.outputs.value || '0' }}
steps:
# We create the status here and then update it to success/failure in the `report` stage
Expand All @@ -63,21 +60,6 @@ jobs:
owner: ${{ github.event.workflow_run.head_repository.owner.login }}
branch: ${{ github.event.workflow_run.head_branch }}

- name: Get commit details
id: commit
if: github.event.workflow_run.event == 'pull_request' || github.event.workflow_run.event == 'merge_group'
uses: actions/github-script@v7
with:
script: |
const response = await github.rest.git.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: "${{ github.event.workflow_run.head_sha }}",
});
core.setOutput("message", response.data.message);
core.setOutput("author", response.data.author.name);
core.setOutput("email", response.data.author.email);
# Percy is disabled while we're figuring out https://github.com/vector-im/wat-internal/issues/36
# and https://github.com/vector-im/wat-internal/issues/56. We're hoping to turn it back on or switch
# to an alternative in the future.
Expand Down Expand Up @@ -108,11 +90,13 @@ jobs:
strategy:
fail-fast: false
matrix:
# Naive segmentation of tests
segment: ["a-i", "j-p", "q-s", "t-z"]
# Run tests using both crypto stacks
crypto: [legacy, rust]
ci_node_total: [4]
ci_node_index: [0, 1, 2, 3]
steps:
# The version of chrome shipped by default may not be consistent across runners
# so we explicitly use a specific version of chrome here.
- uses: browser-actions/setup-chrome@803ef6dfb4fdf22089c9563225d95e4a515820a0 # v1
- run: echo "BROWSER_PATH=$(which chrome)" >> $GITHUB_ENV

Expand Down Expand Up @@ -154,23 +138,24 @@ jobs:
run: |
echo "CYPRESS_RUST_CRYPTO=1" >> "$GITHUB_ENV"
- name: Run Cypress tests
- name: Run Cypress tests via knapsack pro
uses: cypress-io/github-action@ebe8b24c4428922d0f793a5c4c96853a633180e3 # v6.6.0
with:
working-directory: matrix-react-sdk
# The built-in Electron runner seems to grind to a halt trying to run the tests, so use chrome.
browser: ${{ steps.setup-chrome.outputs.chrome-path }}
headed: true
start: npx serve -p 8080 -L ../webapp
wait-on: "http://localhost:8080"
record: true
record: false
parallel: false
command-prefix: "yarn percy exec --parallel --"
ci-build-id: ${{ needs.prepare.outputs.uuid }}-${{ matrix.crypto }}
spec: cypress/e2e/[${{ matrix.segment }}]*/**
# The built-in Electron runner seems to grind to a halt trying to run the tests, so use chrome.
command: yarn percy exec --parallel -- npx knapsack-pro-cypress --config trashAssetsBeforeRuns=false --browser "$BROWSER_PATH"
env:
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# Knapsack token and config
KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS: ${{ matrix.crypto == 'rust' && secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS_RUST || secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS_LEGACY }}
KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
KNAPSACK_PRO_CI_NODE_INDEX: ${{ matrix.ci_node_index }}
KNAPSACK_PRO_TEST_FILE_PATTERN: cypress/e2e/**/*.spec.ts
KNAPSACK_PRO_BRANCH: ${{ github.event.workflow_run.head_branch }}

# Use existing chromium rather than downloading another
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
Expand All @@ -181,16 +166,6 @@ jobs:
# make Node's os.tmpdir() return something where we actually have permissions
TMPDIR: ${{ runner.temp }}

# tell Cypress more details about the context of this run
COMMIT_INFO_BRANCH: ${{ github.event.workflow_run.head_branch }}
COMMIT_INFO_SHA: ${{ github.event.workflow_run.head_sha }}
COMMIT_INFO_REMOTE: ${{ github.repositoryUrl }}
COMMIT_INFO_MESSAGE: ${{ needs.prepare.outputs.commit_message }}
COMMIT_INFO_AUTHOR: ${{ needs.prepare.outputs.commit_author }}
COMMIT_INFO_EMAIL: ${{ needs.prepare.outputs.commit_email }}
CYPRESS_PULL_REQUEST_ID: ${{ needs.prepare.outputs.pr_id }}
CYPRESS_PULL_REQUEST_URL: https://github.com/${{ github.repository }}/pull/${{ needs.prepare.outputs.pr_id }}

# pass the Percy token as an environment variable
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[![npm](https://img.shields.io/npm/v/matrix-react-sdk)](https://www.npmjs.com/package/matrix-react-sdk)
![Tests](https://github.com/matrix-org/matrix-react-sdk/actions/workflows/tests.yml/badge.svg)
![Static Analysis](https://github.com/matrix-org/matrix-react-sdk/actions/workflows/static_analysis.yaml/badge.svg)
[![matrix-react-sdk](https://img.shields.io/endpoint?url=https://dashboard.cypress.io/badge/simple/ppvnzg/develop&style=flat&logo=cypress)](https://dashboard.cypress.io/projects/ppvnzg/runs)
[![Knapsack Pro Parallel CI builds for Cypress Test - Legacy Crypto](https://img.shields.io/badge/Knapsack%20Pro-Parallel%20%2F%20Cypress%20Test%20--%20Legacy%20Crypto-%230074ff)](https://knapsackpro.com/dashboard/organizations/3882/projects/2469/test_suites/3724/builds?utm_campaign=organization-id-3882&utm_content=test-suite-id-3724&utm_medium=readme&utm_source=knapsack-pro-badge&utm_term=project-id-2469)
[![Knapsack Pro Parallel CI builds for Cypress Test - Rust Crypto](https://img.shields.io/badge/Knapsack%20Pro-Parallel%20%2F%20Cypress%20Test%20--%20Rust%20Crypto-%230074ff)](https://knapsackpro.com/dashboard/organizations/3882/projects/2469/test_suites/3729/builds?utm_campaign=organization-id-3882&utm_content=test-suite-id-3729&utm_medium=readme&utm_source=knapsack-pro-badge&utm_term=project-id-2469)

<!--
Percy is disabled while we're figuring out https://github.com/vector-im/wat-internal/issues/36
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"@babel/preset-typescript": "^7.12.7",
"@babel/register": "^7.12.10",
"@casualbot/jest-sonar-reporter": "2.2.7",
"@knapsack-pro/cypress": "^8.0.1",
"@peculiar/webcrypto": "^1.4.3",
"@percy/cli": "^1.11.0",
"@percy/cypress": "^3.1.2",
Expand Down
Loading

0 comments on commit 085b39c

Please sign in to comment.