# Checking unit tests for tracker and assist
name: Tracker tests
on:
  workflow_dispatch:
  push:
    branches: [ "main", "dev" ]
    paths:
      - tracker/**
  pull_request:
    branches: [ "dev", "main" ]
    paths:
      - tracker/**
jobs:
  build-and-test:
    runs-on: macos-latest
    name: Build and test Tracker
    steps:
      - uses: oven-sh/setup-bun@v2
        with:
          bun-version: latest
      - uses: actions/checkout@v3
      - name: Cache tracker modules
        uses: actions/cache@v3
        with:
          path: tracker/node_modules
          key: ${{ runner.OS }}-test_tracker_build-${{ hashFiles('**/bun.lock') }}
          restore-keys: |
            test_tracker_build{{ runner.OS }}-build-
            test_tracker_build{{ runner.OS }}-
      - name: Setup Testing packages
        run: |
          cd tracker
          bun install
      - name: Jest tests
        run: |
          cd tracker/tracker
          bun run test:ci
      - name: Building test
        run: |
          cd tracker/tracker
          bun run build
      - name: (TA) Jest tests
        run: |
          cd tracker/tracker-assist
          bun run test:ci
      - name: (TA) Building test
        run: |
          cd tracker/tracker-assist
          bun run build
      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v3
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          flags: tracker
          iame: tracker
