on:
  workflow_call:
    inputs:
      working-directory:
        required: true
        type: string

jobs:
  test:
    runs-on: ubuntu-latest
    permissions:
      # Required to checkout the code
      contents: read
      # Required to put a comment into the pull-request
      pull-requests: write

    steps:
    - name: Set up Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '22.x'
    - name: Install dependencies
      run: |
        cd ${{ inputs.working-directory }}
        npm ci
    - name: 'Test'
      run: | 
        cd ${{ inputs.working-directory }}
        npx vitest --coverage.enabled true
    - name: 'Report Coverage'
      # Set if: always() to also generate the report if tests are failing
      # Only works if you set `reportOnFailure: true` in your vite config as specified above
      if: always() 
      uses:  davelosert/vitest-coverage-report-action@v2
      with:
        working-directory: ${{ inputs.working-directory }}