当由于错误(如语法错误)导致 Karma 无法运行测试时,Karma 会发出这样的警告:
INFO [karma]: Karma v0.12.31 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Linux)]: Connected on socket WT-AsaXZq4odkQe2DgZJ with id 10861626
WARN [web-server]: 404: /undefinedhttp%3A%2F%2Flocalhost%3A9876%2Fbase%2Ftests%2Funit%2Fjs%2Fspecs%2Fcore%2FDeviceSpec.js%3F1e346ab1ad6e6e9240be6a6d5effaaa8f0dd96d8/9/%22ReferenceError%3A%20Can't%20find%20variable%3A%20SYNTAXERROR%22
未转义的最后一行是:“/undefinedhttp://localhost:9876/base/tests/unit/js/specs/core/DeviceSpec.js?1e346ab1ad6e6e9240be6a6d5effaaa8f0dd96d8/9/”ReferenceError: Can't find variable: SYNTAXERROR” "
这是正确的,因为我出于该问题的目的在测试中的某处插入了 SYNTAXERROR。
因此测试被忽略,但是,由于其他测试都正常,Karma 返回测试已通过:
PhantomJS 1.9.8 (Linux): Executed 41 of 41 SUCCESS (0.354 secs / 0.016 secs)
➜ echo $?
0
如果 Karma 不能执行所有测试,我希望它失败(我想不出有什么理由不这样做!)。
我还没有找到任何配置变量以这种方式运行。
我找到了 Karma 打印 warning above 的行但我不明白为什么它被处理为 404...
有什么想法可以让 Karma 在无法执行所有测试时失败吗?
最佳答案
如果 WARN
被 karma 显示,我使用的脚本会失败:
#!/bin/bash
set -eo pipefail
mkdir -p tests/unit/js/dist || true
./node_modules/.bin/karma start tests/unit/js/karma.conf.js --port 9875 | tee tests/unit/js/dist/results.txt
if grep 'WARN' tests/unit/js/dist/results.txt; then
exit 1
else
exit 0
fi
关于javascript - 如果测试有错误,Karma 不会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30105924/