language: node_js

node_js:
  - "10"

addons:
  apt:
    packages:
    - libgif-dev
    - libpng-dev
    - libpango1.0-dev
    - libjpeg-dev
    - librsvg2-dev
# libcairo2-dev is preinstalled
stages:
  - Linting and Building
  - Unit Tests
  - Visual Tests

cache:
  directories:
    - node_modules

env:
  global:
    - LAUNCHER=Node

matrix:
  fast_finish: true

jobs:
  fast_finish: true
  allow_failures:
    - env: LAUNCHER=Node CANFAIL=TRUE
    - env: LAUNCHER=Firefox CANFAIL=TRUE
    - env: LAUNCHER=Chrome CANFAIL=TRUE
  include:
    - stage: Linting and Building
      env: STEP=LINT
      install: npm install eslint@4.7.x
      script: 'npm run lint && npm run lint_tests'
      addons:
        apt:
          packages: # avoid installing packages
    - stage: Linting and Building
      env: STEP=BUILD
      install: npm install uglify-js@3.3.x
      script: 'npm run build'
      addons:
        apt:
          packages: # avoid installing packages
    - stage: Unit Tests
      env: LAUNCHER=Chrome
      script: npm run build:fast && testem ci --port 8080 -f testem.json -l $LAUNCHER
      install: npm install testem@1.18.4 qunit@2.6.1
      addons:
        apt:
          packages: # avoid installing packages
    - stage: Unit Tests
      env: LAUNCHER=Firefox
      script: npm run build:fast && testem ci --port 8080 -f testem.json -l $LAUNCHER
      install: npm install testem@1.18.4 qunit@2.6.1
      addons:
        apt:
          packages: # avoid installing packages
    - stage: Unit Tests
      env: LAUNCHER=Node
      node_js: "10"
    - stage: Unit Tests
      node_js: "8"
    - stage: Unit Tests
      node_js: "6"
    - stage: Unit Tests
      node_js: "4"
    - stage: Unit Tests
      env: CANVAS=canvas-prebuilt
      node_js: "8"
      install: npm install && npm remove canvas && npm install canvas-prebuilt@^1.6.11 qunit@2.6.1
      addons:
        apt:
          packages: # avoid installing packages
    - stage: Visual Tests
      env: LAUNCHER=Node CANFAIL=TRUE
      node_js: "8"
      script: npm run build:fast && npm run test:visual
    - stage: Visual Tests
      env: LAUNCHER=Chrome
      install: npm install testem@1.18.4 qunit@2.6.2
      script: npm run build:fast && testem ci --port 8080 -f testem-visual.json -l $LAUNCHER
      addons:
        apt:
          packages: # avoid installing packages
    - stage: Visual Tests
      env: LAUNCHER=Firefox
      install: npm install testem@1.18.4 qunit@2.6.2
      script: npm run build:fast && testem ci --port 8080 -f testem-visual.json -l $LAUNCHER
      addons:
        apt:
          packages: # avoid installing packages

script: npm run build:fast && npm run test

dist: trusty
