E-Commerce Testing Pipeline #123
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: E-Commerce Testing Pipeline | |
| on: | |
| push: | |
| branches: [main, develop] | |
| pull_request: | |
| branches: [main, develop] | |
| schedule: | |
| # Run nightly tests at 2 AM UTC | |
| - cron: '0 2 * * *' | |
| env: | |
| NODE_VERSION: '18' | |
| CYPRESS_CACHE_FOLDER: ~/.cache/Cypress | |
| jobs: | |
| # Code Quality and Linting | |
| quality: | |
| name: Code Quality | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| cache-dependency-path: 'client/package-lock.json' | |
| - name: Install dependencies | |
| run: | | |
| cd client | |
| npm ci | |
| - name: Run ESLint | |
| run: | | |
| cd client | |
| npm run lint | |
| - name: Type check | |
| run: | | |
| cd client | |
| npm run type-check | |
| # Unit and Integration Tests | |
| unit-tests: | |
| name: Unit & Integration Tests | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| test-type: [unit, integration, a11y] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| cache-dependency-path: 'client/package-lock.json' | |
| - name: Install dependencies | |
| run: | | |
| cd client | |
| npm ci | |
| - name: Run ${{ matrix.test-type }} tests | |
| run: | | |
| cd client | |
| npm run test:${{ matrix.test-type }} | |
| - name: Upload coverage reports | |
| if: matrix.test-type == 'unit' | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./client/coverage/lcov.info | |
| flags: unit-tests | |
| # E2E Tests | |
| e2e-tests: | |
| name: E2E Tests | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| browser: [chrome, firefox, edge] | |
| spec: [auth, shopping, cart-checkout] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| cache-dependency-path: 'client/package-lock.json' | |
| - name: Install dependencies | |
| run: | | |
| cd client | |
| npm ci | |
| - name: Install server dependencies | |
| run: | | |
| cd server | |
| npm ci | |
| - name: Start server | |
| run: | | |
| cd server | |
| npm start & | |
| sleep 10 | |
| - name: Start client | |
| run: | | |
| cd client | |
| npm start & | |
| sleep 30 | |
| - name: Run Cypress tests | |
| uses: cypress-io/github-action@v6 | |
| with: | |
| working-directory: client | |
| spec: cypress/e2e/${{ matrix.spec }}.cy.js | |
| browser: ${{ matrix.browser }} | |
| wait-on: 'http://localhost:3000' | |
| wait-on-timeout: 120 | |
| - name: Upload screenshots | |
| if: failure() | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: cypress-screenshots-${{ matrix.browser }}-${{ matrix.spec }} | |
| path: client/cypress/screenshots | |
| - name: Upload videos | |
| if: always() | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: cypress-videos-${{ matrix.browser }}-${{ matrix.spec }} | |
| path: client/cypress/videos | |
| # Performance Testing | |
| performance: | |
| name: Performance Tests | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'schedule' || contains(github.event.head_commit.message, '[perf]') | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| cache-dependency-path: 'client/package-lock.json' | |
| - name: Install dependencies | |
| run: | | |
| cd client | |
| npm ci | |
| - name: Build application | |
| run: | | |
| cd client | |
| npm run build | |
| - name: Serve application | |
| run: | | |
| cd client | |
| npx serve -s build -l 3000 & | |
| sleep 10 | |
| - name: Run Lighthouse CI | |
| uses: treosh/lighthouse-ci-action@v10 | |
| with: | |
| configPath: './client/lighthouserc.json' | |
| uploadArtifacts: true | |
| temporaryPublicStorage: true | |
| - name: Run performance tests | |
| run: | | |
| cd client | |
| npm run test:performance | |
| # Visual Regression Testing | |
| visual-tests: | |
| name: Visual Regression Tests | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'pull_request' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| cache-dependency-path: 'client/package-lock.json' | |
| - name: Install dependencies | |
| run: | | |
| cd client | |
| npm ci | |
| - name: Start application | |
| run: | | |
| cd client | |
| npm start & | |
| sleep 30 | |
| - name: Run visual regression tests | |
| run: | | |
| cd client | |
| npx cypress run --spec "cypress/e2e/visual/**/*" | |
| - name: Upload visual diff artifacts | |
| if: failure() | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: visual-diffs | |
| path: client/cypress/screenshots/visual-diffs | |
| # Security Scanning | |
| security: | |
| name: Security Scan | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Run npm audit | |
| run: | | |
| cd client | |
| npm audit --audit-level moderate | |
| - name: Run Snyk to check for vulnerabilities | |
| uses: snyk/actions/node@master | |
| env: | |
| SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | |
| with: | |
| args: --severity-threshold=high | |
| command: test | |
| # Deployment Preview (for PRs) | |
| deploy-preview: | |
| name: Deploy Preview | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'pull_request' | |
| needs: [quality, unit-tests] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| cache-dependency-path: 'client/package-lock.json' | |
| - name: Install dependencies | |
| run: | | |
| cd client | |
| npm ci | |
| - name: Build application | |
| run: | | |
| cd client | |
| npm run build | |
| - name: Deploy to Netlify | |
| uses: nwtgck/[email protected] | |
| with: | |
| publish-dir: './client/build' | |
| production-branch: main | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| deploy-message: "Deploy from GitHub Actions" | |
| env: | |
| NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
| NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
| # Test Results Summary | |
| test-summary: | |
| name: Test Summary | |
| runs-on: ubuntu-latest | |
| needs: [quality, unit-tests, e2e-tests] | |
| if: always() | |
| steps: | |
| - name: Download test artifacts | |
| uses: actions/download-artifact@v3 | |
| - name: Generate test report | |
| run: | | |
| echo "## Test Results Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "- Quality Checks: ${{ needs.quality.result }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Unit Tests: ${{ needs.unit-tests.result }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- E2E Tests: ${{ needs.e2e-tests.result }}" >> $GITHUB_STEP_SUMMARY | |
| - name: Comment PR | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `## 🧪 Test Results | |
| - **Code Quality**: ${{ needs.quality.result }} | |
| - **Unit Tests**: ${{ needs.unit-tests.result }} | |
| - **E2E Tests**: ${{ needs.e2e-tests.result }} | |
| ${context.sha.substring(0, 7)} - View detailed results in the [Actions tab](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})` | |
| }) |