# Github actions workflow name
name: CI

# Triggers the workflow on push or pull request events
on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

jobs:
  test:
    name: 'Tests on ${{matrix.os}} with Node "${{matrix.node}}"'
    strategy:
      matrix:
        # Test all mainstream operating systems
        os: [ubuntu-latest, macos-latest, windows-latest]
        node: ['current']
        include:
          - os: ubuntu-latest
            node: 'lts/*'
          - os: ubuntu-latest
            node: 'lts/-1'
          - os: ubuntu-latest
            node: 'lts/-2'
          - os: ubuntu-latest
            node: 'lts/-3'

    runs-on: ${{ matrix.os }}
    # This has copy/paste steps and should be refactored using DRY
    steps:
      - uses: actions/checkout@v4
      - name: Install pnpm
        uses: pnpm/action-setup@v4
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
          cache: 'pnpm'
      - name: Install dependencies
        run: pnpm install
      - name: Print put node & npm version
        run: node --version && pnpm --version 
      # Pin the version of Playwright to match package.json to avoid installing a newer version which may expect different binaries
      - name: Install chromium
        run: npx playwright@1.50.1 install chromium
      - name: Run unit test
        run: pnpm run test
