# Run Unit test without Harnesses
name: unit-ci

on:
  workflow_dispatch:
  push:
    branches:
      - main
      - beta
    paths:
      - 'src/**'
      - 'test/**'
      - 'package.json'
      - 'package-lock.json'
      - 'tsconfig.json'
      - 'vite.config.ts'
      - 'vitest.config*.ts'
      - 'esbuild.config.mjs'
      - 'eslint.config.mjs'
      - '.github/workflows/unit-ci.yml'
  pull_request:
    paths:
      - 'src/**'
      - 'test/**'
      - 'package.json'
      - 'package-lock.json'
      - 'tsconfig.json'
      - 'vite.config.ts'
      - 'vitest.config*.ts'
      - 'esbuild.config.mjs'
      - 'eslint.config.mjs'
      - '.github/workflows/unit-ci.yml'

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          submodules: recursive

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

      - name: Install dependencies
        run: npm ci

      # unit tests do not require Playwright, so we can skip installing its dependencies to save time
      # - name: Install test dependencies (Playwright Chromium)
      #   run: npm run test:install-dependencies

      - name: Run unit tests suite with coverage
        run: npm run test:unit:coverage

      - name: Upload coverage report
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: coverage-report
          path: coverage/**