使用grunt运行jest时未找到任何测试

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

我试图用一个咕噜咕噜的任务来运行我的笑话但是这样做我在控制台中找不到测试发现消息。以下是相同的设置:

gruntfile.js片段:

exec: {
        jest: 'node node_modules/jest/bin/jest -u --config="test/unit/jest/jest.conf.json"'
}

jest.conf.json:

{
    "testEnvironment": "jsdom",
    "setupTestFrameworkScriptFile": "./enzyme.setup.js",
    "testResultsProcessor": "jest-teamcity-reporter"
}

enzyme.setup.js:

import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-15.4';

configure({ adapter: new Adapter() });

运行grunt exec任务的控制台如下所示:

No tests found
In C:\Vishal\UI\Jest-Grunt\proj\test\unit\jest
  3 files checked.
  testMatch: .js?(x),**/?(*.)(spec|test).js?(x) - 0 matches
  testPathIgnorePatterns: \\node_modules\\ - 3 matches
Pattern:  - 0 matches

Done, without errors.

然而令人惊讶的是,如果我没有在grunt exec任务中的cli中传递jest配置文件路径,而是在package.json文件中指定jest配置,那么它可以工作。

不知道为什么这样做。

javascript node.js unit-testing gruntjs jest
1个回答
2
投票

Aah,在我的头撞了之后。我注意到这个错误很可惜:

在C:\ My-User \ UI \ Is-Ground \ proj \ test \ unit \中

这清楚地解释了JEST尝试在上面指定的文件夹中执行测试用例。但理想情况下,JEST会调查__tests__。因此我必须自己指定根文件夹。使用包json,这不会发生。奇怪的是!

这是我的更新jest配置:

{
    "testEnvironment": "jsdom",
    "setupTestFrameworkScriptFile": "./enzyme.setup.js",
    "testResultsProcessor": "jest-teamcity-reporter",
    "coverageReporters": [
        "teamcity", "lcov"
   ],
    "roots": [
      "../../../__tests__"
    ]
}
© www.soinside.com 2019 - 2024. All rights reserved.