Skip to content

Add tests

Add tests #9235

Workflow file for this run

name: CI Base
on:
push:
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v2
with:
node-version: '16'
cache: 'npm'
cache-dependency-path: |
package-lock.json
cms/package-lock.json
- name: Install Dependencies
run: npm ci
- name: Install CMS Dependencies
working-directory: ./cms
run: npm ci
- uses: concord-consortium/s3-deploy-action/deploy-path@v1
id: s3-deploy-path
- name: Lint
run: npm run lint:build
- name: Clean
run: npm run clean
- name: Build Main App
run: npm run build:webpack
env:
DEPLOY_PATH: ${{ steps.s3-deploy-path.outputs.deployPath }}
- name: Build CMS
run: npm run build:cms
env:
DEPLOY_PATH: ${{ steps.s3-deploy-path.outputs.deployPath }}
- uses: actions/upload-artifact@v4
with:
name: build
path: dist/
jest:
name: Run Jest Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v2
with:
node-version: '16'
cache: 'npm'
cache-dependency-path: |
package-lock.json
cms/package-lock.json
- name: Install Dependencies
run: npm ci
- name: Install CMS Dependencies
working-directory: ./cms
run: npm ci
- name: Cache Jest cache
uses: actions/cache@v3
with:
path: /tmp/jest_rt
key: ${{ hashFiles('**/package-lock.json') }}
- name: Get number of CPU cores
id: cpu-cores
uses: SimenB/github-actions-cpu-cores@v2
- name: Run Tests
run: npm run test:coverage -- --maxWorkers=${{ steps.cpu-cores.outputs.count }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
flags: jest
token: ${{ secrets.CODECOV_TOKEN }}
cypress:
runs-on: ubuntu-latest
container:
image: cypress/browsers:node-20.11.0-chrome-121.0.6167.184-1-ff-123.0-edge-121.0.2277.128-1
# This is needed so the commit info can be recorded by cypress
options: --user 1001
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 1 copy of the current job in parallel
# One thread is enoguh for now, since there is only one smoke test
containers: [1]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install CMS Dependencies
working-directory: ./cms
run: npm ci
- uses: cypress-io/github-action@v4
with:
start: npm start
wait-on: 'http://localhost:8080'
# wait 10 minutes to start the addition of the CMS required this increase
wait-on-timeout: 600
# only record the results to dashboard.cypress.io if CYPRESS_RECORD_KEY is set
record: ${{ !!secrets.CYPRESS_RECORD_KEY }}
# only do parallel if we have a record key
parallel: ${{ !!secrets.CYPRESS_RECORD_KEY }}
browser: chrome
spec: cypress/e2e/smoke/**
group: 'Smoke tests'
env:
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# pass GitHub token to allow accurately detecting a build vs a re-run build
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# turn on code coverage when running npm start
# so far we've been using a webpack coverage-istanbul-loader for this
# but there has been work on using the code coverage support in the browser directly,
# which should be much faster
CODE_COVERAGE: true
# Also turn on the code coverage tasks in cypress itself, these are disabled
# by default.
CYPRESS_coverage: true
# Increase memory allocation
NODE_OPTIONS: "--max_old_space_size=4096"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
flags: cypress-smoke
token: ${{ secrets.CODECOV_TOKEN }}
s3-deploy:
name: S3 Deploy
needs:
- build
- jest
- cypress
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_type == 'branch' && 'branches' || 'versions' }}
url: https://collaborative-learning.concord.org/${{ steps.s3-deploy.outputs.deployPath }}/?demo
steps:
- uses: actions/download-artifact@v4
with:
name: build
path: dist
- uses: concord-consortium/s3-deploy-action@v1
id: s3-deploy
with:
build: echo no build
bucket: models-resources
prefix: collaborative-learning
awsAccessKeyId: ${{ secrets.AWS_ACCESS_KEY_ID }}
awsSecretAccessKey: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# Parameters to GHActions have to be strings, so a regular yaml array cannot
# be used. Instead the `|` turns the following lines into a string
topBranches: |
["master"]
notify-slack:
if: ${{ failure() && github.ref_name == 'master' }}
needs: [jest,cypress]
runs-on: ubuntu-latest
steps:
- name: Notify Slack the tests failed
id: slack
uses: slackapi/[email protected]
with:
# This data can be any valid JSON from a previous step in the GitHub Action
payload: |
{
"ref_name": "${{ github.ref_name }}",
"workflow": "${{ github.workflow }}",
"run_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}