# Run tests inside docker without requiring full installation of dependencies on local machine
# Simply run "docker build -f Dockerfile_test ."
# WARNING: sometimes it fails with a core dumped exception

FROM ubuntu:focal

ENV NODE_ENV="development"

RUN set -ex; \
    export DEBIAN_FRONTEND=noninteractive; \
    apt-get -qq update; \
    apt-get -y --no-install-recommends install \
      unzip \
      build-essential \
      ca-certificates \
      wget \
      pkg-config \
      xvfb \
      libglfw3-dev \
      libuv1-dev \
      libjpeg-turbo8 \
      libicu66 \
      libcairo2-dev \
      libpango1.0-dev \
      libjpeg-dev \
      libgif-dev \
      librsvg2-dev \
      libcurl4-openssl-dev \
      libpixman-1-dev; \
    wget -qO- https://deb.nodesource.com/setup_18.x | bash; \
    apt-get install -y nodejs; \
    apt-get clean;

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

RUN wget -O test_data.zip https://github.com/maptiler/tileserver-gl/releases/download/v1.3.0/test_data.zip; \
    unzip -q test_data.zip -d test_data

COPY package.json .
RUN npm install
COPY / .

RUN xvfb-run --server-args="-screen 0 1024x768x24" npm test
