【问题标题】:Passing options to mocha when running from npm从 npm 运行时将选项传递给 mocha
【发布时间】:2017-11-21 08:41:44
【问题描述】:

我正在为我的项目设置 nyc/mocha。在使用/不使用 nyc 运行 mocha 时,我想将 --exit 选项传递给 mocha。

这是我的 packages.json:

"scripts": {
    "start": "node ./app",
    "test": "./node_modules/.bin/mocha --exit",
    "test-with-coverage": "nyc --reporter=html mocha --reporter mochawesome --exit",
    "apidoc": "apidoc -i routes/ -o apidocs/"
  }

但是当我运行 npm test 或 npm run test-with-coverage 时,这会引发无效选项错误。

如何将任何选项从 npm 传递给 mocha?

【问题讨论】:

  • 不太确定,但你的命令中没有时间 --(在 html mocha 之后)
  • 即使删除 -- 后它也不起作用。
  • 你确实试过这个nyc --reporter=html mocha -- --reporter mochawesome

标签: node.js unit-testing npm mocha.js nyc


【解决方案1】:

我能看到您显示的代码存在问题的唯一原因是 --exit 已添加到 Mocha 4.0.0 中,而您恰好使用的是旧版本。

【讨论】:

    猜你喜欢
    • 2013-12-01
    • 2010-12-03
    • 1970-01-01
    • 2015-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-02
    • 2016-09-15
    相关资源
    最近更新 更多