# This is the workflow to lint the source code
name: NPM Test

# Controls when the action will run.
on:
  # Allows you to call this workflow from other workflows
  workflow_call:

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

permissions:
  contents: read

jobs:
  test:
    name: '✅ Test'
    runs-on: ubuntu-latest

    steps:
      - name: '☁️ Checkout repository'
        uses: actions/checkout@v6
        with:
          ref: ${{ github.event.workflow_run.head_branch || github.event.pull_request.base.ref }}
          persist-credentials: false

      - name: '⚙️ Use Node.js'
        uses: actions/setup-node@v6
        with:
          node-version-file: '.nvmrc'
          check-latest: true
          cache: 'npm'

      - name: '⛓️ Install dependencies'
        run: npm ci --audit=false --prefer-offline --progress=false

      - name: '🧫 NPM test'
        run: npm run test --if-present
