name: CI
on: [push, pull_request]

env:
  SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
  SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}

permissions:
  contents: read #  to fetch code (actions/checkout)

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
       include:
        - node-version: 18.x
        - node-version: 20.x
        - node-version: 22.x
        - node-version: 24.x
    steps:
      - uses: actions/checkout@v4

      - name: Install Node - ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'
      - name: Install dependencies
        run: npm ci
      - name: Build
        run: npm run build
      - name: Test On Node ${{ matrix.node-version }}
        env:
          BROWSER: ${{ matrix.test-on-brower }}
          HTTP2_TEST_DISABLED: ${{ matrix.http2-test-disabled }}
          OLD_NODE_TEST: ${{ matrix.test-on-old-node }}
        run: |
          if [ "$OLD_NODE_TEST" = "1" ]; then
            make test
          else
            npm run lint
            make test
          fi
      - name: Coverage On Node ${{ matrix.node-version }}
        run: npm run coverage
      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v4
