Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing two environments with jest

Tags:

jestjs

I'd like to set two different environments and be able to run both in watch mode.

|-- /server |     |-- index.js  <-  Node |-- /client |     |-- index.js  <-  jsdom |-- package.json 

Actually I run jest twice for each environment, providing a different config file for each:

$ yarn test -- --config=server.config.json $ yarn test -- --config=client.config.json  

But this doesn't let me run both at the same time.

like image 461
Juan Je García Avatar asked Dec 25 '16 01:12

Juan Je García


People also ask

Does Jest run tests in parallel?

By the way @trusktr Jest DOES run tests in parallel, just not ones in the same file. So you can run into issues with interference between tests if they are running on the same database.

Does Jest run tests sequentially?

Once the describe blocks are complete, by default Jest runs all the tests serially in the order they were encountered in the collection phase, waiting for each to finish and be tidied up before moving on.

What is rootDir in Jest?

rootDir [string] Default: The root of the directory containing the package.json or the pwd if no package.json is found. Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

What is Jest environment Jsdom?

By default, jest uses the node testEnvironment. This essentially makes any tests meant for a browser environment invalid. jsdom is an implementation of a browser environment, which supports these types of UI tests.


Video Answer


1 Answers

EDIT (Jan 2018):

It is now possible to do so (since Jest v20), and the option is called projects. Read more about it the docs.

Basically you can define an array of your projects you want Jest to be run within:

{   "projects": ["<rootDir>/client", "<rootDir>/server", "<rootDir>/some-glob/*"] } 

Just remember every project needs to have its own config. If you want the config to be picked up automatically, put it inside jest.config.js file or like usually in package.json.

If you prefer placing your config somewhere else (e.g. in configs/jest.js), you'll need to point to the path of the config file (with the rootDir option set properly):

{   "projects": ["<rootDir>/client/configs/jest.js", "<rootDir>/server/configs/jest.js"] } 

ORIGINAL ANSWER:

Currently this is not possible, but there's an issue for that case: https://github.com/facebook/jest/issues/1206.

Feel free to jump in and leave a comment!

like image 129
Michał Pierzchała Avatar answered Oct 01 '22 08:10

Michał Pierzchała