name: Browser CI

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        browser: [chrome, firefox]

    steps:
      - uses: actions/checkout@v4
        with:
          submodules: recursive

      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: 'npm'

      # Ubuntu 24.04 ('ubuntu-latest') no longer ships firefox-esr / firefox-geckodriver
      # via apt — Mozilla's binaries are downloaded directly via these actions instead.
      - name: Install Firefox
        if: matrix.browser == 'firefox'
        id: setup-firefox
        uses: browser-actions/setup-firefox@v1

      - name: Install geckodriver
        if: matrix.browser == 'firefox'
        # browser-actions/setup-geckodriver only publishes a v0.0.0 tag and
        # documents @latest (a moving branch ref) as the canonical pin.
        uses: browser-actions/setup-geckodriver@latest

      - name: Install npm dependencies
        run: npm ci

      - name: Run vitest browser tests
        env:
          # Ubuntu runners ship with Google Chrome and chromedriver
          # pre-installed; point the chrome project at those rather than
          # apt-installing the snap-based chromium-browser transitional
          # package. (Ignored when matrix.browser == firefox.)
          CHROMIUM_BINARY: /usr/bin/google-chrome
          FIREFOX_BINARY: ${{ steps.setup-firefox.outputs.firefox-path }}
        run: npx vitest run --project=${{ matrix.browser }}
