nathanboktae / mocha-casperjs

Write CasperJS tests using Mocha
MIT License
120 stars 30 forks source link

Assertion fails with error code 0 #70

Closed fabioel closed 8 years ago

fabioel commented 8 years ago

I have a problem with running my CasperJS tests with mocha-casperjs on Travis CI.

Whenever a test fails CasperJS returns status code 1, which would be the correct status code to be returned on a failed test.

I am running all my tests with a bash script and I would need the exit code of the tests in the bash script. I tried the $? operator, but this only returns wheter the command was executed properly or not. Since it is done properly it always returns 0.

So my question is: Is there an issue with mocha-casper that somehow it doesn't pass on the exit code?

The reason I need all this is that I am running my tests on Travis CI and Travis always exits with status 0, since the tests are executed correctly and I would need to have Travis exit with the proper exit codes.

Here is my script:

WIDGET_NAME=${1:-widget} # defaults to 'widget'
PORT=${2:-4001} # default port is 4001
SERVER_PORT=${3:-4002} # default port is 4002
TEST_CASES=${4:-./test/features/*/*/*-test.casper.js} # default run     all subdirectories

# bail on errors
set -e

# switch to root folder
cd `dirname $0`/..

echo "Starting feature tests ..."

echo "- start App server on port $PORT"
WIDGET_NAME_PASCAL_CASE=`node -e "console.log(require('pascal-case')    (process.argv[1]))"         $WIDGET_NAME`
./node_modules/.bin/beefy app/widget.js $PORT \
  --cwd public \
  --index public/widget-test.html \
  -- \
  --standalone $WIDGET_NAME_PASCAL_CASE \
    -t [ babelify --sourceMapRelative . ] \
    -t browserify-shim \
  --exclude moment 1>/dev/null &
echo $! > /tmp/appointment-widget-tester-process1.pid
sleep 1

echo "- start Fake API server on port $SERVER_PORT"
bin/fake-api $SERVER_PORT 1>/dev/null &
echo $! > /tmp/appointment-widget-tester-process2.pid
sleep 1

echo "- run feature tests"
mocha-casperjs $TEST_CASES --viewport-width=800 --viewport-height=600 --fail-fast | grep --line-buffered -v -e '^$' | grep --line-buffered -v "Unsafe JavaScript"

echo "- stop App and Fake API server"
kill -9 `cat /tmp/appointment-widget-tester-process*.pid`
rm /tmp/appointment-widget-tester-process*.pid

echo "done."
fabioel commented 8 years ago

I have found the solution of my problem. It had nothing to do with mocha-casperjs, but with the nature of the |-operator. I fixed it by using the bash environment variable $(PIPESTATUS)