如何防止 mocha 以状态 1 退出进程 [英] how to prevent mocha from exiting process with status 1
问题描述
我已经编写了一个简单的 node.js 应用程序,现在我想添加一些测试.现在我只有一些示例测试来测试我的 Gitlab-CI、SonarQube 和 Mocha,我正在使用它们进行测试.
I have written a simple node.js application and now I want to add some tests. For now I have only some example Tests to test my Gitlab-CI, SonarQube and Mocha, which i am using for testing.
现在我的问题是,我想解析 mocha 的结果(报告者是声纳摩卡报告者).我的问题是,如果测试失败,mocha 会以状态 1 退出进程.这意味着 gitlab-ci 正在破坏构建并且不会运行到最后.所以我不能像它应该的那样解析结果.
Now my problem is, that I want to parse the results from mocha (reporter is the sonar-mocha-reporter). My problem is that mocha exits the process with status 1 if a test is failing. That means gitlab-ci is breaking the build and will not run to the end. So i can not parse the results like it should.
有没有办法将 mocha 配置为不破坏我的构建,以便它只将结果保存在这个 xml 文件中?
Is there a way to configure mocha to not break my build so that it only saves the results in this xml file?
我开始使用摩卡咖啡:
./node_modules/.bin/mocha -R mocha-sonar-reporter --recursive --no-exit
在我的 package.json 中有配置:
and in my package.json i have the configuration:
"config": {
"mocha-sonar-reporter": {
"outputfile": "build/reports/tests/TEST-mocha.xml"
}
},
推荐答案
也许你可以这样做:
./node_modules/.bin/mocha || true
如果失败,则返回true
,并成功.
If it fails, it will then return true
, and be successful.
这篇关于如何防止 mocha 以状态 1 退出进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!