#!/usr/bin/env bash
# Run the UI's tests under c8 inside a Node + JDK image; needs only Docker. The report is
# copied out with `docker cp` (not a bind mount) so it works when this itself runs in a
# job container. Output: target/coverage/ui.
set -euo pipefail
cd "$(dirname "$0")/.."
source script/lib/docker.sh

build_ui_test_image

id=$(docker create --security-opt apparmor=unconfined tbd-ui-test npm run coverage)
trap 'docker rm -f "$id" >/dev/null' EXIT

status=0
docker start -a "$id" || status=$?

rm -rf target/coverage/ui
mkdir -p target/coverage
docker cp "$id:/build/target/coverage/ui" target/coverage/ || echo "[test] WARNING: no UI coverage report was produced"
exit "$status"
