Mocha 只运行一个测试文件 [英] Mocha only running one test file

查看:25
本文介绍了Mocha 只运行一个测试文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 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) 和一个 .test.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 *.

这篇关于Mocha 只运行一个测试文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆