name: test
on:
  pull_request:
  workflow_run:
    workflows: deploy
    types: completed
jobs:
  test:
    strategy:
      matrix:
        os:
          - ubuntu-latest
          - macos-latest
          - windows-latest
    runs-on: ${{ matrix.os }}
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: lts/*
      - name: Install dependencies
        run: npm ci
      - name: Install Playwright Browsers
        run: npx playwright install --with-deps
      - if: github.ref_name != github.event.repository.default_branch
        id: set_preview_env
        shell: bash
        run: echo url="https://$(echo "${HEAD_REF:0:28}" | sed s/[^_0-9a-z]/-/gi).jwk.pages.dev/" >> "${GITHUB_OUTPUT}"
        env:
          HEAD_REF: ${{ github.head_ref }}
      - name: Run tests on ${{ env.BASE_URL }}
        run: npm test
        env:
          BASE_URL: ${{ github.ref_name == github.event.repository.default_branch && 'https://jwk.pages.dev/' || steps.set_preview_env.outputs.url }}
      - uses: actions/upload-artifact@v4
        if: always()
        with:
          name: "playwright-report-${{ matrix.os }}"
          path: playwright-report