I currently build a server side app with node js. To test it, I use Travis, which runs npm test by default.
Now I want also to test if the dependencies are correct and therefore start the app within Travis with
nodejs app.js
How can I run this task in Travis?
You can run any task like you would expect it to be on a unix shell:
language: node_js
node_js:
- "5"
before_script:
- npm install
script:
- node app.js
- npm test
However your purpose is covered already by the npm install
command. If this fails and also subsequently your npm test
fails, the build will not succeed.
For more complicated examples, where you need to run actual servers, say in API end-2-end testing I would use docker-compose
instead. But this is way too much here.
travis.yml
language: node_js
sudo: required
services:
- docker
cache:
directories:
- node_modules
node_js:
- 5
before_install:
- npm install -g node-gyp
before_script:
- npm install
- npm install -g standard
- docker-compose build
- docker-compose up -d
- sleep 3
script:
- npm test
after_script:
- docker-compose kill
docker-compose.yml
api1:
build: .
dockerfile: ./Dockerfile
ports:
- 3955
links:
- mongo
- redis
environment:
- REDIS_HOST=redis
- MONGO_HOST=mongo
- IS_TEST=true
command: "node app.js"
api2:
build: .
dockerfile: ./Dockerfile
ports:
- 3955
links:
- mongo
- redis
environment:
- REDIS_HOST=redis
- MONGO_HOST=mongo
- IS_TEST=true
command: "node app.js"
mongo:
image: mongo
ports:
- "27017:27017"
command: "--smallfiles --logpath=/dev/null"
redis:
image: redis
ports:
- "6379:6379"
haproxy:
image: haproxy:1.5
volumes:
- ./cluster:/usr/local/etc/haproxy/
links:
- "api1"
- "api2"
ports:
- 80:80
- 70:70
expose:
- "80"
- "70"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With