name: Tests
on: [workflow_call]


defaults:
  run:
    shell: 'bash'

jobs:

  unit:
    strategy:
      fail-fast: false
      matrix:
        os: [ windows-latest, ubuntu-latest, macos-latest ]
        package: [ main, preload, renderer ]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
          cache: 'npm'
      - run: npm ci
      - run: npm run test:${{ matrix.package }} --if-present

  e2e:
    strategy:
      fail-fast: false
      matrix:
        os: [ windows-latest, ubuntu-latest, macos-latest ]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
          cache: 'npm'
      - run: npm ci
      - run: npx playwright install --with-deps
      - run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test:e2e --if-present
        if: matrix.os == 'ubuntu-latest'
      - run: npm run test:e2e --if-present
        if: matrix.os != 'ubuntu-latest'
