#!/bin/bash

if ! [ -f /.dockerenv ] && ! grep -q 'devices:/docker' /proc/1/cgroup ; then
  echo "Not running inside docker, exiting to avoid data damage." >&2
  exit 1
fi

set -e
set -u

echo "### Copying and moving files"
cp -Rf . /tmp/
cd /tmp/

echo "################################################################################"
echo "Finished main setup, now running tests ..."

.yarn/releases/yarn-4.18.1.cjs test:unit

echo "### Moving JUnit XML files to /results"
cp /tmp/junit.xml /results/

echo "Finished test execution, test execution returned with exit code."
echo "################################################################################"
