#!/usr/bin/env bash

# NOOP in converstation with David Casterton, to be reactivated with a fix
set -euo pipefail

APP_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export NVM_DIR="$HOME/.nvm"
export NODE_VER=$(<$APP_ROOT/.nvmrc)

# remove cached modules, only relevant when running locally
rm -rf node_modules
rm -rf dist

# environment setup
$APP_ROOT/dev_setup.sh

# configure nvm, to get yarn
# prevent nvm error from causing script to exit
set +e
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
set -e
nvm use $NODE_VER

# install cypress dependencies
$APP_ROOT/install_cypress.sh

# Lint the entire project.
yarn lint --max-warnings 0 --no-fix

# Run unit tests.
yarn test:unit --passWithNoTests

# run frontend server, required for cypress. wait up to 10 mins to be available.
$APP_ROOT/dev_run.sh & npx wait-on --timeout 600000 http://localhost:8080

# Run cypress system tests.
yarn test:e2e

# Make a production build.
# Without this we run out of memory
export NODE_OPTIONS="--max-old-space-size=5120"
yarn build
