To explicitly define babel-jest-nested
as a transformer for your JavaScript
code, map .js files to the babel-jest-nested
module.
transform: {
'^.+\\.jsx?$': 'babel-jest-nested'
}
Note: If you are using babel version 7 you have to install
babel-jest
withyarn add --dev babel-jest babel-core@^7.0.0-0 @babel/core
-
Specify the Lerna packages as Jest projects at the root level of your mono-repo in
jest.config.js
:module.exports = { projects: ['<rootDir>/packages/*'] }
-
Create a
jest.base.config.js
on the root level that each project / package will load, in which you usebabel-jest-nested
as the transformer:module.exports = { transform: { '^.+\\.jsx?$': 'babel-jest-nested' } }
-
Then, within each Lerna package, simply provide a
jest.config.js
file that redirects tojest.base.config.js
:module.exports = { ...require('../../jest.base.config.js') }
-
Bingo!