测试失败时有没有办法触发npm的posttest?如果package.json包含
"scripts": { "pretest": "echo pretest", "test": "some_failed_test_or_error", "posttest": "echo posttest" }
$ npm test
将回应"预测试"但不是"后测".
如果我使用mocha并且测试失败,我会得到相同的行为,即使mocha没有触发任何异常(只是一些简单的失败assert(true==false)
).
我正在启动预测试资源,我想在posttest上杀死资源,无论测试本身是通过还是失败.
MacOS OS X 10.9.4,npm版本1.4.21,节点v0.10.30.
解决了这个问题.不确定以下内容是否适用于Windows.bash ||
运算符后跟空注释会:
更改退出代码.
例如,使用mocha:
"scripts": { "pretest": "echo pretest", "test": "mocha || :", "posttest": "echo posttest" }