Integrate e2e tests. #7
This file contains hidden or 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: Unit And E2E Tests | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| env: | |
| CI: true | |
| VITE_API_URL: http://localhost:4000 | |
| jobs: | |
| # --------------------------- | |
| # 1) Backend unit tests | |
| # --------------------------- | |
| backend-tests: | |
| name: Backend tests (Jest + Supertest) | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: backend | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: lts/* | |
| cache: "npm" | |
| cache-dependency-path: backend/package-lock.json | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run backend unit tests (Produce json output) | |
| run: | | |
| mkdir -p test-results | |
| npm test -- --runInBand --ci --json --outputFile=./test-results/backend-jest.json | |
| - name: Upload backend test results (artifact) | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: backend-test-results | |
| path: backend/test-results/** | |
| # --------------------------- | |
| # 2) Frontend unit tests | |
| # --------------------------- | |
| frontend-tests: | |
| name: Frontend test (Jest / RTL) | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: frontend | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: lts/* | |
| cache: "npm" | |
| cache-dependency-path: frontend/package-lock.json | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run frontend unit tests (Produce json output) | |
| run: | | |
| mkdir -p test-results | |
| npm test -- --runInBand --ci --json --outputFile=./test-results/frontend-jest.json | |
| - name: Upload frontend test results (artifact) | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: frontend-test-results | |
| path: frontend/test-results/** | |
| # --------------------------- | |
| # 3) End-to-end tests (Playwright) | |
| # depends on both unit-test jobs so we only run E2E when unit-tests pass. | |
| # --------------------------- | |
| e2e-tests: | |
| name: E2E tests (Playwright) with fresh DB | |
| runs-on: ubuntu-latest | |
| needs: [backend-tests, frontend-tests] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: lts/* | |
| - name: Install backend dependencies | |
| working-directory: backend | |
| run: npm ci | |
| - name: Install frontend dependencies | |
| working-directory: frontend | |
| run: npm ci | |
| - name: Install Playwright dependencies | |
| working-directory: e2e | |
| run: | | |
| npm ci | |
| npx playwright install --with-deps | |
| - name: Start backend (with RESET_DB) | |
| working-directory: backend | |
| run: RESET_DB=true npm run dev & | |
| - name: Start frontend | |
| working-directory: frontend | |
| run: npm run dev & | |
| - name: Wait for services | |
| run: | | |
| npx wait-on http://localhost:4000/tasks | |
| npx wait-on http://localhost:5173 | |
| sleep 3 | |
| - name: Run Playwright tests | |
| working-directory: e2e | |
| run: npx playwright test | |
| - name: List Playwright results | |
| run: ls -R e2e/test-results/playwright || echo "No results found" | |
| - name: Upload Playwright HTML Report (always) | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: playwright-html-report | |
| path: e2e/test-results/playwright/html/** | |
| - name: Upload Playwright junit & artifacts (always) | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: playwright-artifacts | |
| path: | | |
| e2e/test-results/playwright/junit.xml | |
| e2e/test-results/playwright/**/* | |
| e2e/test-results/playwright |