Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
145 views
in Technique[技术] by (71.8m points)

javascript - How to write a Jest configuration file

I am trying to pass along a configuration file to Jest in order to run tests only from a given directory.

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.

I tried both these options in a jest-config.js file:

testPathDirs = ['coredata/src'];

and

config.testPathDirs(['coredata/src']);

and ran:

$ 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)
question from:https://stackoverflow.com/questions/30027494/how-to-write-a-jest-configuration-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I figured out that the config file is JSON.

{
  "testPathDirs": ["coredata/src"]
}

Unfortunately I found nowhere in the documentation a hint about this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...