#!/bin/bash

set -e

npm run test:style

function cleanup {
  set +e

  cp .tmp/.npmrc ~/.npmrc

  cat .tmp/sinopia.pid | xargs kill

  cat .tmp/ghrs.pid | xargs kill

  rm -rf .tmp
}

trap cleanup EXIT

mkdir -p .tmp/modules

export DEBUG=ghrs:cli

./node_modules/.bin/sinopia ./tests/config.yml & echo $! >> .tmp/sinopia.pid
./node_modules/.bin/github-release-fake-server -p 4343 & echo $! >> .tmp/ghrs.pid

sleep 0.5

cp ~/.npmrc .tmp/.npmrc

cp tests/.npmrc ~/.npmrc

npm run test:integration
