Cucumber tests fail but travis build still passes

I’m running this e2e script through bash into Travis CI.

I think I need to somehow get the build to exit with non-zero, but as you can see at bottom of the log, yarn exits with 0.

#!/usr/bin/env bash

RETRY_INTERVAL=${RETRY_INTERVAL:-0.2}

# Run our API server as a background process
if [[ "$OSTYPE" == "msys" ]]; then
        if ! netstat -aon | grep "0.0.0.0:$SERVER_PORT" | grep "LISTENING"; then
                pm2 start --no-autorestart --name test:serve "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" -- run test:serve
                until netstat -aon | grep "0.0.0.0:$SERVER_PORT" | grep "LISTENING"; do
                sleep $RETRY_INTERVAL
                done
        fi
else
        if ! ss -lnt | grep -q :$SERVER_PORT; then
                yarn run test:serve &
        fi
        until ss -lnt | grep -q :$SERVER_PORT; do
          sleep $RETRY_INTERVAL
        done
fi
npx cucumber-js spec/cucumber/features --require-module @babel/register --require spec/cucumber/steps

if [[ "$OSTYPE" == "msys" ]]; then
        pm2 delete test:serve
fi

travis.yml

language: node_js
node_js:
  - 'node'
  - 'lts/*'
  - '10'
  - '10.15.3'
services:
  - elasticsearch
before_install:
  - curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.1.deb
  - sudo dpkg -i --force-confnew elasticsearch-6.6.1.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

Hello @Northskool,

Add set -e at the top of your bash script, so that it exits on first error, preserving the exit code, and subsequently, failing Travis if its a non zero, also capture whatever exit code you want, and exit with it wherever it makes sense.

run whatever command here
exitcode=$?
[[ $exitcode == 0 ]] || exit $exitcode

As a side note - it seems like your bash script has too many responsibilities. I would consider separating them if possible, and then you give Travis a list of commands to run, and possibly one or two before_script hook instructions. Something along these lines:

before_script:
- ./start_server.sh

script:
- npx cucumber-js spec/cucumber/features ...

I’m hoping this gets you back to building.

1 Like

you’re a legend @montana thank you! this worked

Glad your Cucumber tests are working in Travis again.