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

标签 node.js testing npm

有没有办法在测试失败时触发 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/

相关文章:

javascript - 运行测试用例后清理智能合约存储

javascript - Gulp Watch 未检测到 SASS SCSS 文件夹中的更改

node.js - 在 Raspberry pi 4 上运行 mongodb 服务器

node.js - 调试第三方安装的 Node 模块

postgresql - 如何使用 NodeJS 将 Postgres 数据库迁移到 heroku?

node.js - 使用 uglify-js 和 sass 中 find 的管道输出

node.js - ProcessMaker 4 (EBADENGINE) 的开发人员安装期间出现 NPM 错误

python - 使用 python 的 Electron 应用程序抛出 zmq.node 错误

visual-studio-2010 - 在 VS2010 中执行 BDD 的标准方法是什么?

testing - 不知道如何解决跨浏览器问题