【问题标题】:test scripts work individually, but not when run through npm test?测试脚本单独工作,但不是通过 npm test 运行?
【发布时间】:2017-02-06 20:25:00
【问题描述】:

节点版本:0.10.36
npm 版本 1.4.28

本地伊斯坦布尔版本 0.3.2
本地 mocha 版本 1.21.4
本地柴版本 1.9.2

在我的 package.json 中有这三个脚本:

"pretest": "./node_modules/.bin/_mocha -R xunit > specs/spec-results.xml ./test/ --recursive --require chai",
"test": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- -R spec ./test/ --recursive --require chai",
"posttest": "./node_modules/.bin/istanbul report cobertura --root ./coverage/ --dir ./coverage/",

当复制并粘贴到命令行时,它们都单独工作,但是当我运行npm test 时,我看不到相同的输出。它似乎在pretest 脚本期间退出。

我该如何解决这个问题?

编辑 1:

我的预测试命令实际上永远不会起作用。编辑为 ./node_modules/.bin/_mocha --reporter-options output=specs/spec-results.xml ./test/ --recursive --require chai,确实有效。

当我单独运行这个命令时,我得到了预期的输出,它显示了通过和失败的测试数量。

当我运行 npm test 时,我得到:

npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0

但是,我也得到了通过和失败的测试数量,正如我所期望的那样。

【问题讨论】:

  • 预测试是否以 0 退出?
  • @jonrsharpe 我没有看到任何迹象表明它确实如此
  • 我们会让你检查它做什么退出?
  • @jonrsharpe 我该怎么做?
  • 如果 pretest 退出时的值不是 0,npm 会发出非常清晰的错误消息。我刚刚尝试将pretest 设置为exit 15。请编辑问题以显示您在 npm 之外运行命令时获得的输出以及使用 npm test 运行命令时实际获得的输出。

标签: node.js npm mocha.js


【解决方案1】:

问题出在我的预测试命令上:

"./node_modules/.bin/_mocha -R xunit > specs/spec-results.xml ./test/ --recursive --require chai"

显然这不是将报告输出到文件的正确方法。进程会突然退出。

我改成这样了:

/node_modules/.bin/_mocha --reporter-options output=specs/spec-results.xml ./test/ --recursive --require chai

成功了

【讨论】:

    猜你喜欢
    • 2021-01-04
    • 1970-01-01
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    • 2017-09-07
    • 1970-01-01
    相关资源
    最近更新 更多