fix bug and test #11504
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Test React Application | |
on: | |
push: | |
branches: | |
- "*" | |
jobs: | |
# Only run if SPA code has changed | |
check-changes: | |
runs-on: ubuntu-latest | |
# Required permissions | |
permissions: | |
pull-requests: read | |
# Set job outputs to values from filter step | |
outputs: | |
spa: ${{ steps.filter.outputs.spa }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: dorny/paths-filter@v3 | |
id: filter | |
with: | |
filters: | | |
spa: | |
- 'spa/**' | |
js-test: | |
needs: check-changes | |
if: ${{ needs['check-changes'].outputs.spa == 'true' }} | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
steps: | |
- name: Checkout branch | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
cache: "npm" | |
cache-dependency-path: "spa/package-lock.json" | |
node-version-file: ".nvmrc" | |
- name: Install node dependencies | |
run: | | |
cd spa | |
npm ci | |
- name: Run tests and collect coverage | |
run: | | |
cd spa | |
npm run test:coverage -- --coverageReporters json-summary | |
echo "LINE_PCT=$(cat coverage/coverage-summary.json | jq '.total.lines.pct')" >> $GITHUB_ENV | |
echo "STATEMENT_PCT=$(cat coverage/coverage-summary.json | jq '.total.statements.pct')" >> $GITHUB_ENV | |
echo "BRANCHES_PCT=$(cat coverage/coverage-summary.json | jq '.total.branches.pct')" >> $GITHUB_ENV | |
- name: Comment with coverage percentages | |
uses: mshick/add-pr-comment@v2 | |
with: | |
message: | | |
### Jest unit test coverage | |
| Lines | Statements | Branches | | |
|----------------------|---------------------------|--------------------------| | |
| ${{ env.LINE_PCT }}% | ${{ env.STATEMENT_PCT }}% | ${{ env.BRANCHES_PCT }}% | | |
message-id: jest-coverage-comment | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
cypress-test: | |
needs: check-changes | |
if: ${{ needs['check-changes'].outputs.spa == 'true' }} | |
runs-on: ubuntu-latest | |
strategy: | |
# when one test fails, DO NOT cancel the other | |
# containers, because this will kill Cypress processes | |
# leaving the Dashboard hanging ... | |
# https://github.com/cypress-io/github-action/issues/48 | |
fail-fast: false | |
matrix: | |
# run 3 copies of the current job in parallel | |
containers: [1, 2, 3] | |
env: | |
VITE_HUB_STRIPE_API_PUB_KEY: pk_test_djfoi12312414 | |
VITE_STRIPE_ACCOUNT_ID: acc_3kjfo23jj | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup custom hosts for subdomain testing | |
run: | | |
echo "127.0.0.1 revengine-testabc123.com" | sudo tee -a /etc/hosts | |
echo "127.0.0.1 revenueprogram.revengine-testabc123.com" | sudo tee -a /etc/hosts | |
- name: Debug hosts | |
run: cat /etc/hosts | |
- name: Cypress tests | |
uses: cypress-io/github-action@v6 | |
with: | |
working-directory: spa | |
build: npm run build | |
start: npx vite preview --port 3000 | |
wait-on: http://localhost:3000 | |
wait-on-timeout: 120 | |
# because of "record" and "parallel" parameters | |
# these containers will load balance all found tests among themselves | |
record: true | |
parallel: true | |
group: "Cypress integration tests" | |
env: | |
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
CYPRESS_PROJECT_ID: ${{ secrets.PROJECT_ID }} |