Lastly, our application reads variables from the environment. Since the .env and test.env files are not included as part of our repository, we need to manually provide them to Travis. We can do this by adding an env.global block:
env:
global:
- NODE_ENV=test
- SERVER_PROTOCOL=http
- SERVER_HOSTNAME=localhost
- SERVER_PORT=8888
- ELASTICSEARCH_PROTOCOL=http
- ELASTICSEARCH_HOSTNAME=localhost
- ELASTICSEARCH_PORT=9200
- ELASTICSEARCH_INDEX=test
Our final .travis.yml should look like this:
language: node_js
node_js:
- "node"
- "lts/*"
- "8"
- "8.11.4"
services:
- elasticsearch
before_install:
- curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.deb
- sudo dpkg -i --force-confnew elasticsearch-6.3.2.deb
- sudo service elasticsearch restart
before_script:
- sleep 10
env:
global:
- NODE_ENV=test
- SERVER_PROTOCOL=http
- SERVER_HOSTNAME=localhost
- SERVER_PORT=8888
- ELASTICSEARCH_PROTOCOL=http
- ELASTICSEARCH_HOSTNAME=localhost
- ELASTICSEARCH_PORT=9200
- ELASTICSEARCH_INDEX=test
For more information about different fields in the .travis.yml file, check out docs.travis-ci.com/user/customizing-the-build/.