babel-jest issues with monorepo and jest multi project runner
See original GitHub issue🐛 Bug Report
We are moving to a monorepo structure, and we’d like to use jest multi-project-runner structure. We are using yarn workspaces and lerna to manage dependencies. Here is a repro https://github.com/entria/entria-fullstack/pull/12, where you can reproduce some of the issues.
To Reproduce
Neither of this transforms works:
'^.+\\.(js|ts|tsx)?$': 'babel-jest',
^.+\\.(js|ts|tsx)?$': '<rootDir>/node_modules/babel-jest',
I think the problem here is that babel-jest
resolution strategy is failing to find the correct babel.config.js file
Only creating a custom babel transformer the transform works, like the below:
const config = require('../babel.config');
const { createTransformer } = require('babel-jest');
module.exports = createTransformer({
...config,
});
Steps to reproduce the behavior:
Run jest
on root of this project https://github.com/entria/entria-fullstack/pull/12
modify transform config from custom transformer to babel-jest
Another problem is that when using only projects
option on jest.config.js root, it won’t use a different jest config per project, it is looks like all the config should be on root jest.config.js instead of jest.config.js inside each project
Expected behavior
-
it should find correct babel.config.js
-
it should transpile all files inside packages/*
-
it should use the jest.config.js for each project (transform options and so on)
Link to repl or repo (highly encouraged)
https://github.com/entria/entria-fullstack/pull/12
Run npx envinfo --preset jest
Paste the results here:
System:
OS: macOS 10.14.1
CPU: (4) x64 Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
Binaries:
Node: 10.12.0 - ~/.nvm/versions/node/v10.12.0/bin/node
Yarn: 1.12.3 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.12.0/bin/npm
npmPackages:
jest: ^23.6.0 => 23.6.0
Issue Analytics
- State:
- Created 5 years ago
- Reactions:37
- Comments:22 (4 by maintainers)
I am using jest multi project runner with babel-jest and it works just fine. Each package in the monorepo has it’s own local
.babelrc.js
and no.babelrc.js
in the root is required.Each of my packages has a
jest.config.js
with the following settings to make this work:I made an example repo which contains two packages with different babel-configs, feel free to check it out: https://github.com/ofhouse/jest-project-babel-transformer
Edit: You need Jest
>= 24.9.0
to pass options to transformers@bradfordlemley said
Here’s how I configured it in my monorepo project (that uses yarn workspaces for dependency management, and lerna for running commands on sub packages).
Project structure :
/babel.config.js
:/packages/pkg1/jest.config.js
:/packages/pkg1/jestBabelTransform.js
:I’m already using the
rootMode: upward
option with my build process, this way I get the same behaviour running jest. I can run jest from thepkg1
directory withyarn test
or from the monorepo root withlerna run test --scope pkg1
.