CasperJS 将退出代码传递给 Bash

CasperJS pass exit code to Bash

我在 Travis CI.运行 上的 CasperJS 测试有问题 运行。

每当 CasperJS 测试失败时 returns status code 1,这将是在测试失败时返回的正确状态代码。

我 运行 我的所有测试都使用 bash 脚本,我需要 bash 脚本中测试的退出代码。我尝试了 $? 运算符,但这只是 returns 无论命令是否正确执行。由于它做得正确,它总是 returns 0.

所以我的问题是:有没有办法将 CasperJs-Test 状态代码传递给我的 bash 脚本?

我需要所有这些的原因是我 运行 我在 Travis CI 上的测试,Travis 总是以 status 0 退出,因为测试执行正确,我需要让 Travis 使用正确的退出代码退出。

更新:

这是我的脚本:

#!/bin/sh


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 [=11=]`/..

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."

我发现了我的问题:

就在于|运算符的本质!第一个操作是我的测试的开始, | 运算符之后的第二个操作是 grep 和我的 $? 对控制台上最后一个命令的引用,因此它 returns grep 的退出代码不是 mocha-casperjs-runner

一个解决方案:Pipe output and capture exit status in Bash