使用`npm test`运行mocha时出现意外行为

时间:2017-03-22 07:23:21

标签: npm mocha

Mocha使用两个看似相同的命令运行不同数量的单元测试。当我用createCookie('test','hello','5'); readCookie('test'); eraseCookie('test'); 运行mocha时,我得到以下输出:

npm test

事情是;我在这个项目中有超过35个单元测试。测试命令在> xxx-yyy@1.0.0-alpha.4 test /Users/xxx/repos/some-path > rm -rf ./.unit-test-build/ && tsc && mocha ./.unit-test-build/**/*.spec.js --reporter progress [▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬] 35 passing (78ms)

中定义如下
package.json

现在这是奇怪的部分。当我复制上面的命令并将其粘贴到终端时,我得到以下输出:

{ "scripts": { "test": "rm -rf ./.unit-test-build/ && tsc && mocha ./.unit-test-build/**/*.spec.js --reporter progress", } }

$ rm -rf ./.unit-test-build/ && tsc && mocha ./.unit-test-build/**/*.spec.js --reporter progress

这是预期的行为,123单元测试正在通过。

为什么当我使用 [▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬] 123 passing (1s) 时,mocha会运行35次测试而不是123次?我该如何解决这个问题?

我正在使用节点npm test,npm v7.6.0和mocha 4.1.2

1 个答案:

答案 0 :(得分:1)

another question找到答案。

您需要将queryItems放在glob模式周围,如下所示:

'
相关问题