FROM node:14 AS install

ARG NPM_TOKEN

# Install dependencies
ADD package.json /tmp/package.json
ADD .npmrc /tmp/.npmrc
ADD yarn.lock /tmp/yarn.lock
RUN cd /tmp && yarn

# Set working directory
WORKDIR /app

# Copy sources
COPY . .

#Copy dependencies
RUN cp -a /tmp/node_modules .

# Set working directory
WORKDIR /app

# Build app
RUN yarn build

FROM install AS test

ARG NPM_TOKEN

# Run tests
RUN yarn test