name: test

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  test:

    runs-on: ubuntu-latest

    env:
      CI: true
      TZ: utc
      NODE_ENV: test

    strategy:
      matrix:
        node-version: ['10', '12', '14', '16']

    name: test on nodejs ${{ matrix.node-version }}

    steps:
      - uses: actions/checkout@v2

      - name: install node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'

      - uses: bahmutov/npm-install@v1

      - name: run tests
        run: npm run test

  test-success:
    name: Tests
    if: ${{ always() }}
    runs-on: ubuntu-latest
    needs: test
    steps:
      - name: Check build matrix status
        if: ${{ needs.test.result != 'success' }}
        run: exit 1
