摩卡只运行一个测试文件 [英] Mocha only running one test file
问题描述
我的Mocha测试工作正常,但是当我添加一个新模块(和测试)时,mocha停止运行我的所有测试文件,现在只运行单个新测试。
My Mocha tests were working fine, but when I added a new module (and test), mocha stopped running all of my test files and now only runs the single new test.
我的测试脚本:
env NODE_PATH=$NODE_PATH:$PWD/src mocha --recursive --compilers js:babel-core/register src/**/*.test.js --require babel-polyfill
我的项目结构如下:
/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
我在 / components
和 / util中进行了多次测试
并且一切正常,但当我将模块放入 / src
(如 / some-other-module
), .tes其中包含t.js
文件,Mocha只运行该测试文件而不运行其他文件。
I had several tests in /components
and /util
and everything worked fine, but when I place a module into /src
(like /some-other-module
) with a .test.js
file in it, Mocha only runs that test file and none of the others.
推荐答案
在传递给Mocha的模式周围加上单引号以防止它被shell解释:'src / ** / * .test.js'
Put single quotes around the pattern you pass to Mocha to prevent it being interpreted by your shell: 'src/**/*.test.js'
如果没有引号,shell会尝试扩展该模式并成功。扩展的结果是 src / some-other-module / some-other-module.test.js
,这是传递给Mocha的内容。
What happens is that, without the quotes, your shell tries to expand that pattern and is successful. The result of expansion is src/some-other-module/some-other-module.test.js
and this is what is passed to Mocha.
在创建该文件之前,shell仍尝试扩展模式但未成功并将模式保持原样。所以Mocha得到 src / ** / * .test.js
,其中Mocha本身被解释为一个glob。
Before you created that file, the shell still tried to expand the pattern but was not successful and left the pattern as-is. So Mocha got src/**/*.test.js
, which Mocha itself interpreted as a glob.
如果您想知道,在Bash中,除非打开 globstar
选项, **
相当于 *
。
In case you wonder, in Bash, unless the globstar
option is turned on, **
is equivalent to *
.
这篇关于摩卡只运行一个测试文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!