假設我有一個如下所示的專案結構:
src/index.js
src/test/foo.js
test/integration/src/index.test.js
test/unit/src/index.test.js
jest.config.json
在jest.config.json我有我的testMatch
{
"testMatch": [
"test/**"
]
}
當我運行 jest 時,--config jest.config.json它與 0 檔案匹配。
testMatch: test/** - 0 matches
testPathIgnorePatterns: /node_modules/ - 5 matches
testRegex: - 0 matches
Pattern: - 0 matches
我認為這可能與一些不正確有關,rootDir因為testMatch與此相關。我在除錯模式下運行 jest 以查看我的根目錄,它似乎是正確的。它顯示了我的專案目錄。(jest.config.json存在的地方)
當我更改為時testMatch,**/test/**它可以檢測我在test/目錄中的測驗,但這不是我想要的,因為它也與src/test/目錄匹配。
為什么它無法在test/目錄中檢測到我的測驗?我的 glob 模式不正確嗎?
uj5u.com熱心網友回復:
為什么它無法在 test/ 目錄中檢測到我的測驗?我的 glob 模式不正確嗎?
Jest 的 glob 實作最近遇到了一些 問題。在引擎蓋下 Jest 使用micromatch,但為什么它被掛在相對路徑 globs 上尚不清楚。
您可以在 Jest 配置中嘗試以下幾點:
- 將
<rootDir>字串標記直接包含在您的testMatchglob 中,例如testMatch: ['<rootDir>/test/**']. - 更密切地遵循 Jest testMatch 檔案中的 globstar 示例,注意有關 glob 順序的說明:
注意:每個 glob 模式都按照它們在配置中指定的順序應用。(例如[“!/燈具/ ”,“ /測驗/ / .js檔案”]將不排除固定裝置,因為否定與第二圖案覆寫。為了使在這個例子中有來后否定水珠作業/測驗/ /的.js)。
testMatch: [
'**/test/**',
'!**/src/**'
]
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/372019.html
