未找到Jest测试

问题描述 投票:1回答:2

我在gitlab作业中有以下输出:

yarn run v1.15.2
$ jest --verbose
No tests found
In /path/to/my/project/
  47 files checked.
  testMatch:  - 47 matches
  testPathIgnorePatterns: /node_modules/,/build,/lib/ - 0 matches
  testRegex: (/__tests__/.*|\.(test|spec))\.(tsx?|jsx?)$ - 1 match
Pattern:  - 0 matches

测试没有被执行,我在这里做错了什么?我一直在其他项目中使用相同的gitlab-ci.yml配置。

任何帮助,将不胜感激!

gitlab jestjs gitlab-ci
2个回答
1
投票

是的,错误在package.json中,我在testPathIgnorePatterns中缺少<rootDir>,在jest选项下缺少modulePathIgnorePatterns路径。

"testPathIgnorePatterns": [
  "<rootDir>/node_modules/",
  "<rootDir>/build",
  "<rootDir>/lib/"
],
"modulePathIgnorePatterns": [
  "<rootDir>/dist/",
  "<rootDir>/build/"
]

1
投票

错误在你的道路上。首先打开你的cmd并导航到你的package.json所在的目录,然后确保你在package.json提供的任何路径,它必须得到。

您也可以尝试对路径进行硬编码。一旦你能够运行它然后去正则表达式。

package.json

"name": "test",
"jest": {
        "transform": {},
        "verbose": true,
        "bail": true,
        "testMatch": ["path"]
   },

有关更多详细信息:testPathIgnorePatternsmodulePathIgnorePatterns

"testPathIgnorePatterns": [
  "<rootDir>/build"
],
"modulePathIgnorePatterns": [
  "<rootDir>/build/"
]
© www.soinside.com 2019 - 2024. All rights reserved.