|
| 1 | +--- |
| 2 | +name: Tests |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +jobs: |
| 7 | + tests: |
| 8 | + name: Tests Workflow |
| 9 | + runs-on: ubuntu-latest |
| 10 | + timeout-minutes: 30 |
| 11 | + strategy: |
| 12 | + matrix: |
| 13 | + node-version: [18.12.1] |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout Code 🛎️ |
| 17 | + uses: actions/checkout@v3 |
| 18 | + with: |
| 19 | + persist-credentials: false |
| 20 | + |
| 21 | + - name: Setup Node |
| 22 | + uses: actions/setup-node@v3 |
| 23 | + with: |
| 24 | + node-version: ${{ matrix.node-version }} |
| 25 | + |
| 26 | + - name: Use Node.js Caching ${{ matrix.node-version }} |
| 27 | + id: node-cache |
| 28 | + uses: actions/cache@v3 |
| 29 | + with: |
| 30 | + path: node_modules |
| 31 | + key: node-modules-${{ hashFiles('package-lock.json') }} |
| 32 | + |
| 33 | + - name: Install Dependencies |
| 34 | + if: steps.node-cache.outputs.cache-hit != 'true' |
| 35 | + run: npm ci |
| 36 | + |
| 37 | + - name: Setup test environmental variables |
| 38 | + run: | |
| 39 | + cp .env-local .env |
| 40 | +
|
| 41 | + - name: Start docker container |
| 42 | + run: npm run docker:ci |
| 43 | + |
| 44 | + - name: Build and start web app in the background |
| 45 | + run: npm run build:start |
| 46 | + env: |
| 47 | + ENVIRONMENT: ci |
| 48 | + NODE_ENV: ci |
| 49 | + |
| 50 | + - name: Sleep 30 seconds |
| 51 | + run: sleep 30 |
| 52 | + |
| 53 | + - name: Run prisma db migrations |
| 54 | + run: npm run prisma:deploy |
| 55 | + |
| 56 | + - name: Run jest unit tests |
| 57 | + run: npm run test:jest:ci |
| 58 | + |
| 59 | + - name: Upload coverage jest |
| 60 | + uses: actions/upload-artifact@v3 |
| 61 | + if: always() |
| 62 | + with: |
| 63 | + name: jest-coverage |
| 64 | + path: coverage |
| 65 | + retention-days: 7 |
| 66 | + |
| 67 | + - name: Install Cypress |
| 68 | + run: npx cypress install |
| 69 | + |
| 70 | + - name: Run Cypress E2E tests |
| 71 | + uses: cypress-io/github-action@v5 |
| 72 | + with: |
| 73 | + install: false |
| 74 | + browser: chrome |
| 75 | + headed: true |
| 76 | + wait-on: http://localhost:3000 |
| 77 | + |
| 78 | + - name: Video Cypress |
| 79 | + uses: actions/upload-artifact@v3 |
| 80 | + if: always() |
| 81 | + with: |
| 82 | + name: videos-cypress |
| 83 | + path: cypress/videos |
| 84 | + retention-days: 7 |
| 85 | + |
| 86 | + - name: Screenshots Cypress |
| 87 | + uses: actions/upload-artifact@v3 |
| 88 | + if: failure() |
| 89 | + with: |
| 90 | + name: screenshots-cypress |
| 91 | + path: cypress/screenshots |
| 92 | + retention-days: 7 |
| 93 | + |
| 94 | + - name: Run coverage check |
| 95 | + run: npm run test:coverage:check |
| 96 | + |
| 97 | + - name: Coverage |
| 98 | + uses: actions/upload-artifact@v3 |
| 99 | + if: always() |
| 100 | + with: |
| 101 | + name: merged-coverage |
| 102 | + path: coverage/merged |
| 103 | + retention-days: 7 |
| 104 | + |
| 105 | + - name: Exit on failure |
| 106 | + if: failure() |
| 107 | + run: | |
| 108 | + echo "Error running tests job" |
| 109 | + exit 1 |
0 commit comments