gpt4 book ai didi

javascript - 没有发现用 grunt 运行 jest 的测试

转载 作者:行者123 更新时间:2023-11-29 20:59:17 24 4
gpt4 key购买 nike

我正在尝试用一个繁重的任务来开 Jest ,但这样做时我在控制台中收到了 No tests found 消息。这是相同的设置:

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 配置,那么它就可以工作。

不确定为什么会这样。

最佳答案

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

在 C:\My-User\UI\Jest-Grunt\proj\test\unit\jest

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

这是我的更新 Jest 配置:

{
"testEnvironment": "jsdom",
"setupTestFrameworkScriptFile": "./enzyme.setup.js",
"testResultsProcessor": "jest-teamcity-reporter",
"coverageReporters": [
"teamcity", "lcov"
],
"roots": [
"../../../__tests__"
]
}

关于javascript - 没有发现用 grunt 运行 jest 的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47426716/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com