diff --git a/.github/workflows/jest.yml b/.github/workflows/jest.yml new file mode 100644 index 0000000..6fceea6 --- /dev/null +++ b/.github/workflows/jest.yml @@ -0,0 +1,62 @@ +name: Jest + +on: + # Run tests on PRs to verify code doesn't break before merge + pull_request: + types: [opened, synchronize] + # Your production branch. If not the default, update here and set Target Branch at https://gitauto.ai/settings/rules to match + branches: [main] + paths: + - '**/*.js' + - package.json + - package-lock.json + - jest.config.js + # Run tests after merge and collect coverage as canonical source of truth + push: + # Your production branch. If not the default, update here and set Target Branch at https://gitauto.ai/settings/rules to match + branches: [main] + paths: + - '**/*.js' + - package.json + - package-lock.json + - jest.config.js + # Allow manual trigger for debugging + workflow_dispatch: + +# Cancel older runs when new commits are pushed to the same PR/branch +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + # Match your project's Node.js version + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: | + if [ "${{ github.event_name }}" = "pull_request" ]; then + # Skip coverage on PRs to keep runs fast + NODE_OPTIONS='--experimental-vm-modules' npx jest --no-coverage + else + # Collect lcov coverage on push/workflow_dispatch + NODE_OPTIONS='--experimental-vm-modules' npx jest --coverage --coverageReporters=lcov --coverageDirectory=coverage + fi + + - name: Upload coverage report + if: github.event_name != 'pull_request' + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: coverage/lcov.info