【发布时间】:2017-08-17 18:01:06
【问题描述】:
在我的 npm 包中,我想模拟 Meteor 遵循的模式:源文件(名为 client.js)有一个测试文件(名为 client.tests.js)位于 src/ 文件夹中。使用npm test 命令运行测试。
我正在关注“t”的使用文档。我不想在我的包测试命令中使用find。
-
我了解 mocha 可以递归执行测试:
摩卡--递归
-
我了解 mocha 可以使用
--recursive标志在特定子文件夹中执行测试:mocha src --recursive
-
我也明白我可以通过传递
*.tests.js来指定一个 glob 来过滤文件:摩卡*.tests.js
但是,我想要所有三个。我希望 mocha 仅测试 src 文件夹中以 tests.js 结尾的文件,递归检查子目录。
mocha --recursive *.tests.js
// See the files?
$ > ll ./src/app/
total 168
-rw-r--r-- ... client.js
-rw-r--r-- ... client.tests.js
// Option A
$ > mocha --recursive *.tests.js
Warning: Could not find any test files matching pattern: *.tests.js
No test files found
// Option B
$ > mocha *.tests.js --recursive
Warning: Could not find any test files matching pattern: *.tests.js
No test files found.
// Option C
$ > mocha --recursive src/app/*.tests.js
3 passing (130ms)
3 failing
所以……
- 为什么 mocha 没有提取子文件夹中的
*.tests.js文件? - 如果我指定文件的完整路径,为什么它会起作用?
- 如何让它按需要工作?
【问题讨论】:
-
你试过这个 glob:
src/app/**/*.tests.js? -
确实我没有。对于我自己的参考,我在哪里可以找到这个 glob 语法记录?在投票之前,我转动了几块石头。好奇的。谢谢。
-
您可以在glob 包存储库的自述文件中找到有关 glob 语法的更多信息。那就是mocha使用的包。
-
哦。我的。全球。 LoLz
标签: javascript node.js npm mocha.js