language: node_js
node_js:
  - "0.10"
  - "0.12"
  - "1.8"
  - "2.5"
  - "3.3"
  - "4.9"
  - "5.12"
  - "6.14"
  - "7.10"
  - "8.12"
matrix:
  include:
    - node_js: "9"
      env: "NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly"
    - node_js: "10"
      env: "NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly"
  allow_failures:
    # Allow the nightly installs to fail
    - env: "NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly"
sudo: false
cache:
  directories:
    - node_modules
before_install:
  # Configure npm
  - |
    # Skip updating shrinkwrap / lock
    npm config set shrinkwrap false
  # Remove all non-test dependencies
  - |
    # Remove example dependencies
    npm rm --silent --save-dev connect-redis
  # Setup Node.js version-specific dependencies
  - |
    # mocha for testing
    # - use 3.x for Node.js < 6
    if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then
      npm install --silent --save-dev mocha@3.5.3
    fi
  - |
    # supertest for http calls
    # - use 2.0.0 for Node.js < 4
    if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 4 ]]; then
      npm install --silent --save-dev supertest@2.0.0
    fi
  # Update Node.js modules
  - |
    # Prune and rebuild node_modules
    if [[ -d node_modules ]]; then
      npm prune
      npm rebuild
    fi
script:
  # Run test script
  - npm run test-ci
  # Run linting
  - npm run lint
after_script:
  - |
    # Upload coverage to coveralls
    npm install --save-dev coveralls@2.10.0
    coveralls < ./coverage/lcov.info
