TestMatch查找匹配项,但找不到文件

发布于 2025-01-23 05:20:45 字数 1717 浏览 2 评论 0原文

我一直在尝试使用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-jestjest-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文