name: Test frontend

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  test-frontend:
    runs-on: ubuntu-20.04

    steps:
      - uses: actions/checkout@v2

      - name: Use Node.js 15
        uses: actions/setup-node@v1
        with:
          node-version: 15

      - run: sudo apt-get install -y rtorrent

      - run: sudo npm i -g wait-on
      - run: sudo CYPRESS_INSTALL_BINARY=0 npm i -g cypress

      - run: npm ci
      - run: npm run build-assets

      - run: node scripts/testsetup.js -p 4200 & echo $! > testenv.pid
      - run: wait-on tcp:4200

      - run: npm link cypress
      - run: cypress install
      - uses: cypress-io/github-action@v2
        with:
          install: false
          record: true
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
