name: Unit Tests

on:
  push:
    branches: [master, '**/*-rc']
  pull_request:
    branches: [master, '**/*-rc']

jobs:
  build:
    runs-on: ubuntu-latest

    permissions:
      contents: read
      checks: write  # for dorny/test-reporter to post results

    strategy:
      matrix:
        node-version: [20.x, 22.x, 24.x]

    steps:
      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5  # v4
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020  # v4
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm ci
      - run: npm run test:ci
      - run: npm run build-dist

      - name: Test Report
        uses: dorny/test-reporter@7b7927aa7da8b82e81e755810cb51f39941a2cc7 # v2
        if: success() || failure()
        with:
          name: Unit Tests
          reporter: mocha-json
          path: 'tests/unit/results/*.json'
          list-tests: 'failed'
          fail-on-error: 'false'

