在我的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 …Run Code Online (Sandbox Code Playgroud) 我的Mocha测试工作正常,但是当我添加一个新模块(和测试)时,mocha停止运行我的所有测试文件,现在只运行单个新测试.
我的测试脚本:
env NODE_PATH=$NODE_PATH:$PWD/src mocha --recursive --compilers js:babel-core/register src/**/*.test.js --require babel-polyfill
Run Code Online (Sandbox Code Playgroud)
我的项目结构如下:
/src
/components
/component-name
index.js
component.js
component-name.test.js
style.scss
/util
/module-name
index.js
module-name.test.js
/some-other-module
index.js
some-other-module.test.js
Run Code Online (Sandbox Code Playgroud)
我有几个测试,/components并且/util一切正常,但是当我将一个模块放入/src(像/some-other-module)中的.test.js文件时,Mocha只运行该测试文件,而不运行其他任何一个.