name: Test

on:
  push:
    branches:
      - main
  release:
    types:
      - published

jobs:
  test:
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    runs-on: ${{ matrix.os }}
    
    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Setup Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '22.x'
        cache: 'npm'

    - name: Install dependencies
      run: npm ci

    - name: Install xvfb (Linux only)
      if: runner.os == 'Linux'
      run: sudo apt-get update && sudo apt-get install -y xvfb

    - name: Run Test with XVFB (Linux)
      if: runner.os == 'Linux'
      run: xvfb-run --auto-servernum npm run test

    - name: Run Test (Windows/macOS)
      if: runner.os != 'Linux'
      run: npm run test