簡體   English   中英

如何使用玩笑模式匹配在一個文件夾中調用所有測試?

[英]how to call all test in one folder using jest pattern matching?

我的服務在文件夾中進行常規單元測試

現在,我創建了一個名為integration/新文件夾,並且在該文件夾中,所有測試都看起來像anotherFolder/testSomeApi.integration.js

我這樣做是為了讓我在調用node jest時運行所有單元測試,而不運行集成測試。 我想用單獨的命令從我的Docker容器調用集成測試

如何調用諸如jest *integration.js以便調用擴展名為integration.js Integration文件夾中的所有測試?

在您的集成文件夾中,為jest創建一個配置文件,例如jest-integration.json

{
    "rootDir": ".",
    "testEnvironment": "node",
    "testRegex": ".integration.js$",
}

現在,您可以從項目根目錄運行jest,如下所示:

jest --config ./integration/jest-integration.json

您可以將該行另存為package.json中的NPM腳本,並像

npm run test:integration

最后我做了

jest "(/integration/.*|\\\\.(integration))\\\\.(js)$"

jest --testPathPattern=".*/folderName/.*.spec.ts"

為我工作。

暫無
暫無

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

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