name: CI

on:
  push:
    branches:
      - 'master'
  pull_request:

jobs:
  test:
    name: Check lint/types/unit-test/build
    runs-on: ubuntu-latest
    env:
      CI: true
    strategy:
      matrix:
        node-version: ['latest']
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node ${{ matrix.node }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
          check-latest: true
          cache: npm

      - name: Install packages
        run: npm ci

      - name: Lint
        run: |-
          npm run format:check;
          npm run lint;

      - name: Test
        run: |-
          npm run test:types;
          npm run test:unit;

      - name: Build # Tests to see if a build can succeed
        run: npm run build

  E2E:
    runs-on: ubuntu-22.04
    name: e2e
    strategy:
      matrix:
        browser: [chrome, firefox]
    timeout-minutes: 20
    container:
      # https://hub.docker.com/r/cypress/browsers/tags
      #
      # NOTE: At least Chrome 102 is required for testing `inert` attribute support.
      #  At least Chrome 105 and Firefox 106 are required for `Element#checkVisibility` support.
      #  At least FireFox 135 is required for Cypress >=15.
      image: cypress/browsers:node-22.21.0-chrome-141.0.7390.107-1-ff-144.0-edge-141.0.3537.92-1
      options: --user 1001 --shm-size=2g # @see https://github.com/cypress-io/github-action/issues/104#issuecomment-666047965
    env:
      BABEL_ENV: test
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Test E2E
        # https://github.com/cypress-io/github-action
        # https://github.com/cypress-io/code-coverage
        uses: cypress-io/github-action@v5 # will run all tests found per cypress.config.js
        with:
          browser: ${{ matrix.browser }}
          env: coverage=true

      - name: Upload coverage to Codecov
        # https://github.com/marketplace/actions/codecov
        uses: codecov/codecov-action@v2
