如何编写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=<config-file>
.
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屋!