摩卡只运行一个测试文件

时间:2016-02-09 22:23:40

标签: javascript testing mocha babeljs

我的Mocha测试工作正常,但是当我添加一个新模块(和测试)时,mocha停止运行我的所有测试文件,现在只运行单个新测试。

我的测试脚本:

/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)并{{1}在其中的文件中,Mocha只运行该测试文件而不运行其他文件。

1 个答案:

答案 0 :(得分:16)

在传递给Mocha的模式周围加上单引号,以防止它被shell解释:'src/**/*.test.js'

如果没有引号,您的shell会尝试扩展该模式并且成功。扩展的结果是src/some-other-module/some-other-module.test.js,这是传递给Mocha的。

在创建该文件之前,shell仍尝试扩展模式但未成功并将模式保持原样。所以摩卡得到src/**/*.test.js,其中摩卡本身被解释为一个全球。

如果您想知道,在Bash中,除非启用globstar选项,**相当于*