如何编写 Jest 配置文件 [英] How to write a Jest configuration file
问题描述
我正在尝试将配置文件传递给 Jest,以便仅从给定目录运行测试.
I am trying to pass along a configuration file to Jest in order to run tests only from a given directory.
根据文档,您可以使用 config.testPathDirs
:https://facebook.github.io/jest/docs/api.html#config-testpathdirs-array-string 你可以调用 jest --config=<配置文件>
.
According to documentation, you can use config.testPathDirs
: https://facebook.github.io/jest/docs/api.html#config-testpathdirs-array-string and you can call jest --config=<config-file>
.
不幸的是,该文档没有包含任何关于配置文件应该是什么样子的描述.
Unfortunately the documentation doesn't include any description of how the configuration file should look like.
我在 jest-config.js
文件中尝试了这两个选项:
I tried both these options in a jest-config.js
file:
testPathDirs = ['coredata/src'];
和
config.testPathDirs(['coredata/src']);
然后跑了:
$ jest --config=jest-config.js
...但我得到了这种类型的错误:
...but I get this type of error:
$ jest --config=jest-config.js
Using Jest CLI v0.4.0
Failed with unexpected error.
/Users/carles/dev/azazo/coredata/node_modules/jest-cli/src/jest.js:179
throw error;
^
SyntaxError: Unexpected token c
at Object.parse (native)
at /Users/carles/dev/azazo/coredata/node_modules/jest-cli/src/lib/utils.js:291:23
at _fulfilled (/Users/carles/dev/azazo/coredata/node_modules/jest-cli/node_modules/q/q.js:798:54)
at self.promiseDispatch.done (/Users/carles/dev/azazo/coredata/node_modules/jest-cli/node_modules/q/q.js:827:30)
at Promise.promise.promiseDispatch (/Users/carles/dev/azazo/coredata/node_modules/jest-cli/node_modules/q/q.js:760:13)
at /Users/carles/dev/azazo/coredata/node_modules/jest-cli/node_modules/q/q.js:574:44
at flush (/Users/carles/dev/azazo/coredata/node_modules/jest-cli/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:419:13)
推荐答案
我发现配置文件是 JSON.
I figured out that the config file is JSON.
{
"testPathDirs": ["coredata/src"]
}
不幸的是,我在文档中找不到任何有关此的提示.
Unfortunately I found nowhere in the documentation a hint about this.
这篇关于如何编写 Jest 配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!