测试脚本单独工作,但在通过npm测试运行时不能工作?

时间:2016-09-28 17:59:13

标签: node.js npm mocha

节点版本:0.10.36
npm版本1.4.28

当地伊斯坦布尔版本0.3.2
当地摩卡版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测试时,我得到:

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

然而,正如我所料,我也得到了通过和失败测试的次数。

1 个答案:

答案 0 :(得分:0)

问题在于我的pretest命令:

"./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

它有效