name: JavaScript

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

permissions:
  contents: read

jobs:
  frontend:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: web
    steps:
    - uses: actions/checkout@v5
    - name: Set up Node.js 22
      uses: actions/setup-node@v4
      with:
        node-version: '22'
    - name: Install dependencies
      run: npm ci
    - name: Run JavaScript tests
      run: npm test
    - name: Upload coverage to Codecov
      if: always()
      uses: codecov/codecov-action@v5
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        files: web/reports/javascript-coverage.json
        flags: frontend
        name: frontend
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
    - name: Upload test results to Codecov
      uses: codecov/test-results-action@v1
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        files: web/reports/javascript-junit.xml
        flags: frontend
