簡體   English   中英

摩卡只運行一個測試文件

[英]Mocha only running one test file

我的Mocha測試工作正常,但是當我添加一個新模塊(和測試)時,mocha停止運行我的所有測試文件,現在只運行單個新測試。

我的測試腳本:

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只運行該測試文件沒有其他人。

在傳遞給Mocha的模式周圍加上單引號,以防止它被shell解釋: 'src/**/*.test.js'

如果沒有引號,您的shell會嘗試擴展該模式並且成功。 擴展的結果是src/some-other-module/some-other-module.test.js ,這是傳遞給Mocha的。

在創建該文件之前,shell仍嘗試擴展模式但未成功並將模式保持原樣。 所以Mocha得到了src/**/*.test.js ,其中Mocha本身被解釋為一個glob。

如果你想知道,在Bash中,除非打開globstar選項, **相當於*

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM