name: test

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

jobs:
  install: 
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x]

    steps:
    - uses: actions/checkout@v2

    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}

    - name: Cache node_modules
      uses: actions/cache@v2
      id: cache-node_modules
      with: 
        path: node_modules
        key: node_modules-${{ hashFiles('**/package-lock.json') }}

    - name: Install
      if: steps.cache-node_modules.outputs.cache-hit != 'true'
      run: npm ci

  test:
    runs-on: ubuntu-latest
    needs: install

    strategy:
      matrix:
        node-version: [14.x]

    steps:
    - uses: actions/checkout@v2

    - name: Restore cache from node_modules
      uses: actions/cache@v2
      with: 
        path: node_modules
        key: node_modules-${{ hashFiles('**/package-lock.json') }}

    - run: npm run test
