#!/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/code
ln -s /tmp/node_modules /tmp/code/node_modules
cd /tmp/code/

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

/tmp/yarn test:unit

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

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