gpt4 book ai didi

node.js - 如果 npm 测试失败,npm posttest 不会触发

转载 作者:搜寻专家 更新时间:2023-10-31 22:36:46 26 4
gpt4 key购买 nike

有没有办法在测试失败时触发 npm 的后测?如果 package.json 包含

"scripts": {
"pretest": "echo pretest",
"test": "some_failed_test_or_error",
"posttest": "echo posttest"
}

$ npm test 将回显“pretest”而不是“posttest”。

如果我使用 mocha 并且测试失败,我会得到相同的行为,即使 mocha 没有触发任何异常(只是一些简单的失败 assert(true==false))。

我在预测试中启动一个资源,我想在后测试中终止该资源,无论测试本身是通过还是失败。

MacOS OS X 10.9.4,npm 版本 1.4.21, Node v0.10.30。

最佳答案

解决了。不确定以下是否适用于 Windows。 bash || 运算符后跟空注释 : 更改退出代码。

例如,使用 mocha:

"scripts": {
"pretest": "echo pretest",
"test": "mocha || :",
"posttest": "echo posttest"
}

关于node.js - 如果 npm 测试失败,npm posttest 不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25292344/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com