Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) 
like image 935
Carles Barrobés Avatar asked May 04 '15 10:05

Carles Barrobés


People also ask

Where do I put Jest configuration?

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.

What is Jest config?

The directory where Jest should store its cached dependency information. Jest attempts to scan your dependency tree once (up-front) and cache it in order to ease some of the filesystem churn that needs to happen while running tests. This config option lets you customize where Jest stores that cache data on disk.

How do you write a Jest test?

To create a test case in Jest we use the test() function. It takes a test name string and handler function as the first two arguments. The test() function can also be called under the alias - it() .


1 Answers

I figured out that the config file is JSON.

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

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

like image 55
Carles Barrobés Avatar answered Sep 28 '22 03:09

Carles Barrobés