How to capture Karma return/exit code?

2019-07-30 23:16发布

I am trying to execute some unit test on Bamboo CI. As suggested in Karma config, I do have SingleRun = true. The reporter used is "progress". Since we build our application using Angular CLI, so I am taking advantage of ng test --build=false command which I have set up as a npm script. So, I run my test with command as npm run <myscriptname>

problem - I am able to run tests, some pass and some fails, however, my task always returns success as long as I am able to run tests.

I am trying to avoid using gulp/grunt, so if possible let me know something without it. I have also tried directly calling Karma start <config file> but that too didn't help.

2条回答
Root(大扎)
2楼-- · 2019-07-31 00:01

Now able to find correct status by Karma. Issue - When we were executing Karma via ng test. all exit statuses returned by karma were being consumed by ng. So, we used to get "Success" as long as we are able to run tests (irrespective of test failures)

Solution - Call karma directly. This way we can handle exit status which helps during CI.

查看更多
萌系小妹纸
3楼-- · 2019-07-31 00:11

Try adding a Script task instead of the Command. In the script body you can run your script in the same way and try to capture the exit command with "$?", and manually send the exit code. Also make sure your script returns non-zero code if tests failed.

if [ "$?" != "0" ]; then
    echo "The script returned non-zero error code!" >&2
    exit 1
fi
查看更多
登录 后发表回答