Running jest in a monorepo with create-react-app packages

1.6k views Asked by At

Here is a question.

I'm trying to merge some of my packages into a monorepo. I'm using yarn and it's workspaces-experimental feature. So the repository folder structure looks like:

.
node_modules
packages
  myapp1
  myapp2
  myreactapp1

Now, one of the goals is to simplify testing. I want to run jest in the root dir so that it runs unit tests for all the packages. And it works for myapp1 and myapp2 above which are node.js apps. However, myreactapp1 is build with create-react-app (no eject) and uses ES6 features (like import) and also jsdom rendering. The tests work fine if I run them from myreactapp1 dir with yarn test which pipes the code through babel (if I understand well). But the root jest failes on the first import statement.

How can I do it ?

P.S. I tried to install babel-jest but seems that it cannot be lauched directly from the console (windows).

1

There are 1 answers

0
zaboco On

It seems that CRA does not yet work properly with Yarn Workspaces. A workaround is suggested in the comments.

Anyway, to make jest work, you need to have babel-jest (as you said) and also a .babelrc file in the root folder:

{
  "presets": ["es2015", "react"]
}