#!/bin/sh

# See here for more information: https://github.com/actualbudget/actual/tree/master/packages/desktop-client#visual-regression

if [ ! -d "node_modules" ] || [ "$(ls -A node_modules)" = "" ]; then
    yarn
fi

E2E_START_URL="${E2E_START_URL:-https://localhost:3001}"
VRT_ARGS=""

# Loop through all arguments
while [ $# -gt 0 ]; do
    key="$1"
    case $key in
        --e2e-start-url)
            E2E_START_URL="$2"
            shift
            ;;
        *)
            VRT_ARGS="$VRT_ARGS $1"
            ;;
    esac
    shift
done

echo "Running VRT tests with the following parameters:"
echo "E2E_START_URL: $E2E_START_URL"
echo "VRT_ARGS: $VRT_ARGS"

MSYS_NO_PATHCONV=1 docker run --rm --network host -v "$(pwd)":/work/ -w /work/ -it mcr.microsoft.com/playwright:v1.58.2-jammy /bin/bash \
  -c "E2E_START_URL=$E2E_START_URL yarn vrt $VRT_ARGS"
