#!/usr/bin/env bash

# Exit build script on first failure
set -e

# Echo commands to stdout.
set -x

REBUILD="true"
if [[ "$1" = "--skip-build" ]]; then
  REBUILD="false"
  shift
fi
readonly REBUILD

# Exit on unset variable.
set -u

# Change directory to repository root.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
readonly SCRIPT_DIR
cd "${SCRIPT_DIR}/.."

if [[ "${REBUILD}" == "true" ]]; then
  ./dev-scripts/build-backend dev
fi

npx playwright test --config=e2e/playwright.config.ts "$@"
