jim*_*101 5 testing node.js npm
测试失败时有没有办法触发npm的posttest?如果package.json包含
"scripts": {
"pretest": "echo pretest",
"test": "some_failed_test_or_error",
"posttest": "echo posttest"
}
Run Code Online (Sandbox Code Playgroud)
$ npm test
将回应"预测试"但不是"后测".
如果我使用mocha并且测试失败,我会得到相同的行为,即使mocha没有触发任何异常(只是一些简单的失败assert(true==false)
).
我正在启动预测试资源,我想在posttest上杀死资源,无论测试本身是通过还是失败.
MacOS OS X 10.9.4,npm版本1.4.21,节点v0.10.30.
jim*_*101 12
解决了这个问题.不确定以下内容是否适用于Windows.bash ||
运算符后跟空注释会:
更改退出代码.
例如,使用mocha:
"scripts": {
"pretest": "echo pretest",
"test": "mocha || :",
"posttest": "echo posttest"
}
Run Code Online (Sandbox Code Playgroud)
这个问题的另一个答案简洁而简短,但有点不正统。我知道如果我使用它,每次回来看到“ || : ”时都会在我的头上形成一个大大的问号。它是如此简洁,您甚至可能会错过它。它在某处需要文档。
我花了一点时间寻找更正统的解决方案,并在这里找到:https : //github.com/npm/npm/issues/5493
你需要 npm-run-all
"test": "npm-run-all the-actual-test run-after-test-even-if-failed --continue-on-error"
Run Code Online (Sandbox Code Playgroud)
但是,您不能对前脚本和后脚本使用“pretest”或“posttest”名称,因为它们会运行两次。
归档时间: |
|
查看次数: |
2124 次 |
最近记录: |