# This workflow will run tests using node.
name: Run NodeJS Tests

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

  # Run on every push.
  push:

  # Run on every pull request.
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        # Note: Node 20.8 introduces a change which breaks mock-fs.
        # https://github.com/tschaub/mock-fs/issues/380
        node: [ 10, 12, 14, 16, 18, 20.7 ]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node }}

      # Clean install of all dependencies.
      - run: npm ci

      # Run the tests
      - run: npm test

      - name: Coveralls Parallel
        uses: coverallsapp/github-action@v2
        with:
          flag-name: run-${{ join(matrix.*, '-') }}
          parallel: true

  finish:
    needs: test
    if: ${{ always() }}
    runs-on: ubuntu-latest
    steps:
    - name: Coveralls Finished
      uses: coverallsapp/github-action@v2
      with:
        parallel-finished: true
