From 2cc6dd017f670f557fc2c908fe8c46e4246aac69 Mon Sep 17 00:00:00 2001 From: Vim USDS Date: Thu, 14 Oct 2021 18:38:02 -0700 Subject: [PATCH] Create a new GHA for cypress tests --- .github/workflows/cypress-tests.yml | 102 ++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 .github/workflows/cypress-tests.yml diff --git a/.github/workflows/cypress-tests.yml b/.github/workflows/cypress-tests.yml new file mode 100644 index 00000000..1ed64ae0 --- /dev/null +++ b/.github/workflows/cypress-tests.yml @@ -0,0 +1,102 @@ +name: Cypress Tests + +on: + push: + # Add this back when working with dashboard and parallel + # paths: + # - "client/**/*" + +jobs: + + install: + runs-on: ubuntu-latest + defaults: + run: + working-directory: client + strategy: + matrix: + node-version: [14.x] + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + + - name: Set DESTINATION_FOLDER for branch + run: | + echo "DESTINATION_FOLDER=$(echo $PR_NUMBER-$GITHUB_SHA | cut -c 1-11)" >> $GITHUB_ENV + + - name: Install app + run: npm ci + + - name: Build app + run: npm run build --if-present + env: + # See the client readme for more info on environment variables: + # https://github.com/usds/justice40-tool/blob/main/client/README.md + DATA_SOURCE: cdn + SITE_URL: "http://usds-geoplatform-justice40-website.s3-website-us-east-1.amazonaws.com/" + PATH_PREFIX: "/justice40-tool/${{env.DESTINATION_FOLDER}}" + + - name: Lint app + run: npm run lint + + # Disabling for now due to jsonlint - TODO: put this back + # - name: License Check + # run: npm run licenses + + - name: Run unit tests on app + run: npm test + + - name: Check for security vulnerabilities + run: npm audit --production + + - name: Upload Artifact + uses: actions/upload-artifact@v2 + with: + name: J40Static + # Upload-artifact does not support the default working directory + # See more: https://github.com/actions/upload-artifact/issues/87 + path: ./client/public + + ui-chrome-tests: + timeout-minutes: 15 + runs-on: ubuntu-latest + container: cypress/browsers:node14.17.0-chrome88-ff89 + needs: install + 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 copies of the current job in parallel + containers: [1, 2, 3, 4, 5] + steps: + - name: Checkout source + uses: actions/checkout@v2 + + - name: Download artifacts + uses: actions/download-artifact@v2 + with: + name: J40Static + path: ./public + + - name: "UI Tests - Chrome" + uses: cypress-io/github-action@v2 + with: + start: npm start + wait-on: "http://localhost:3000" + browser: chrome + record: true + parallel: true + group: "UI - Chrome" + env: + CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }} + CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} + # Recommended: pass the GitHub token lets this action correctly + # determine the unique run id necessary to re-run the checks + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}