aza*_*tar 21 javascript mocha.js node.js npm
在我的npm包中,我想模仿Meteor遵循的模式:源文件(命名client.js)client.tests.js在src/文件夹中有一个测试文件(命名).使用该npm test命令运行测试.
我正在使用't'的使用文档.我不想find在我的包测试命令中使用a .
我知道mocha可以递归执行测试:
摩卡 - 递归
我知道mocha可以使用--recursive标志在特定的子文件夹中执行测试:
mocha src --recursive
我也明白我可以通过传递指定一个glob来过滤文件*.tests.js:
摩卡*.tests.js
但是,我想要这三个.我希望mocha只测试tests.js以src文件夹结尾的文件,递归检查子目录.
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
所以...
*.tests.js子文件夹中的文件?Lou*_*uis 55
该--recursive标志旨在对目录进行操作.如果你要传递一个匹配目录的glob,那么这些目录将被递归地检查,但如果你传递一个匹配文件的glob,就像你正在做的那样,那么它--recursive是无效的.我建议不要使用--recursiveglob,因为globs已经具有在子目录中递归查看的能力.你可以这样做:
mocha 'src/app/**/*.tests.js'
这将匹配*.tests.js递归匹配的所有文件src/app.请注意我是如何在模式周围使用单引号的.这是引用模式,以便它按原样传递给Mocha的globbing代码.否则,你的shell可能会解释它.根据选项的不同,有些shell会转换**为*您无法获得所需的结果.
| 归档时间: | 
 | 
| 查看次数: | 8663 次 | 
| 最近记录: |