Fix/dx 3674 improve test coverage #3
Workflow file for this run
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: 'Coverage Check' | |
| on: | |
| pull_request: | |
| branches: | |
| - development | |
| - staging | |
| - main | |
| push: | |
| branches: | |
| - development | |
| - staging | |
| - main | |
| jobs: | |
| coverage: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| checks: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run unit tests with coverage | |
| run: npm test -- --coverage --testMatch="**/test/unit/**/*.spec.ts" --coverageReporters=json-summary --coverageReporters=text --coverageReporters=lcov | |
| - name: Jest Coverage Report (PR Comment) | |
| if: github.event_name == 'pull_request' | |
| uses: artiomtr/jest-coverage-report-action@v2 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| coverage-file: ./reports/contentstack-delivery/coverage/coverage-summary.json | |
| base-coverage-file: ./reports/contentstack-delivery/coverage/coverage-summary.json | |
| threshold: 95 | |
| working-directory: ./ | |
| skip-step: all | |
| - name: Verify coverage threshold | |
| run: | | |
| COVERAGE=$(node -pe " | |
| const c = JSON.parse(require('fs').readFileSync('reports/contentstack-delivery/coverage/coverage-summary.json')).total; | |
| const threshold = 95; | |
| const metrics = ['statements', 'branches', 'functions', 'lines']; | |
| const failed = metrics.filter(m => c[m].pct < threshold); | |
| if (failed.length) { | |
| console.log('❌ Coverage below 95%: ' + failed.join(', ')); | |
| process.exit(1); | |
| } | |
| console.log('✅ All coverage metrics meet the 95% threshold'); | |
| ") | |
| - name: Upload coverage reports | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: | | |
| reports/contentstack-delivery/coverage | |
| retention-days: 30 | |