image: node:6

# Set up MySQL test-database
services:
  - mysql:latest

# Configure test-database
variables:
  MYSQL_DATABASE: db
  MYSQL_ROOT_PASSWORD: password
  
# Create database tables
#connect:
#  image: mysql
#  script:
#  - echo "SELECT 'OK';" | mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql "$MYSQL_DATABASE" < create_tables.sql

# Install node libraries
before_script:
  - npm install
  - apt-get update -q && apt-get install -qqy --no-install-recommends mysql-client
  - mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql "$MYSQL_DATABASE" < create_tables.sql
  
# Run JEST tests
test:
  script:
    - npm test
    
# Publish coverage report on gitlab-pages
pages:
  stage: deploy
  script:
  - mkdir .public
  - cp -r coverage/* .public
  - mv .public public
  artifacts:
    paths:
    - public
  only:
  - master

