TestMatch查找匹配项,但找不到文件
我一直在尝试使用Jest在自己的文件夹中运行一些测试,但声称未发现测试。
文件结构如下:
.
└── repo-folder/
├── ...
└── tests/
├── integration/
│ └── ...
└── unit/
├── 1.test.ts
├── 2.test.ts
├── ...
└── 4.test.ts
我要做的是在不运行集成测试的情况下运行单元测试。为此,我尝试使用jest cli命令(来自package.json
):
jest --roots=./tests/unit
但是,这会导致以下错误:
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /home/myusername/repos/repo-folder
4 files checked.
testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 4 matches
testPathIgnorePatterns: build - 0 matches
testRegex: - 0 matches
Pattern: - 0 matches
我尝试了一些不同的jest标志,例如- - tentpathpattern
或只是在命令末尾添加文件路径作为参数,尽管这实际上在根目录中找到了所有测试文件。我发现了一个类似的先前问题 jest找不到测试对于打字稿的构建将被忽略。
该项目使用ts-jest
和jest-extended
如果可能会以某种方式引起任何问题。我的jest.config.js
看起来像这样:
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
clearMocks: true,
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
roots: ['<rootDir>'],
transform: {
'^.+\\.ts?$': 'ts-jest',
},
setupFilesAfterEnv: ['jest-extended'],
globals: {
'ts-jest': {
diagnostics: false,
isolatedModules: true,
},
},
preset: 'ts-jest',
testEnvironment: 'node',
coverageProvider: 'v8',
testPathIgnorePatterns: ['build'],
};
I have been trying to run some tests located in its own folder using Jest but it claims that no tests have been found.
The file structure is as follows:
.
└── repo-folder/
├── ...
└── tests/
├── integration/
│ └── ...
└── unit/
├── 1.test.ts
├── 2.test.ts
├── ...
└── 4.test.ts
What I want to do is to run the unit tests without running the integration tests. To do this I have tried using the Jest CLI command (from package.json
):
jest --roots=./tests/unit
However, this results in the following error:
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /home/myusername/repos/repo-folder
4 files checked.
testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 4 matches
testPathIgnorePatterns: build - 0 matches
testRegex: - 0 matches
Pattern: - 0 matches
I have tried a few different flags for Jest such as --testPathPattern
or just adding the file path as an argument at the end of the command, though this actually found all test files in the root directory. I found a similar previous question Jest No Tests found but in my own Jest config only the build directory for the TypeScript build is ignored.
The project uses ts-jest
and jest-extended
if that may somehow cause any issues for Jest. My jest.config.js
looks like this:
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
clearMocks: true,
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
roots: ['<rootDir>'],
transform: {
'^.+\\.ts?
: 'ts-jest',
},
setupFilesAfterEnv: ['jest-extended'],
globals: {
'ts-jest': {
diagnostics: false,
isolatedModules: true,
},
},
preset: 'ts-jest',
testEnvironment: 'node',
coverageProvider: 'v8',
testPathIgnorePatterns: ['build'],
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论