-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
babel-jest issues with monorepo and jest multi project runner #7359
Comments
The Babel issue looks like it is because the transformer runs with cwd set to the repo root instead of cwd set to each package's directory when Jest runs tests for that package. Reading through the runner code (https://github.com/facebook/jest/blob/9822231fba8ef6a8558700c61682751f397c1cd0/packages/jest-runner/src/index.js) it looks like we could include the desired cwd with each test's config and call Alternatively -- for this specific issue with Babel -- we could have babel-jest take options like |
Manually add expo-sms to the list of projects to test. Eventually it'd be nice to use Jest's multi-project runner but it doesn't work for us right now so this commit just does the straightforward thing and runs the SMS tests directly. Related Jest issue: jestjs/jest#7359
I created a package jest-esnext that comes with babel7-ES.Next transpilation pre-packaged basically one would do: This would avoid some troubles:
|
for @sibelius it might be more convenient to put your jest configuration in a fake sibling package than up at the workspace root, possibly. I used one test@0.0.1 with yarn workspaces before I moved it to jest-esnext |
I did some analysis of this issue on #7771, before I found this issue. Summary: Analysis: Also worth noting that the jest repo itself demonstrates the issue in examples/react, but works around it by adding Solution: What if users want top-level babel config?: Aside:
Currently, babel.config.js would not apply to globalSetup.js when running |
There is another issue in a monorepo setup, where we are using bazel (https://bazel.build/) it, runs jest in the repository root and passes the test files directly to jest using
and apart from setting up a custom transformer like so:
I do not see an easier way on telling |
@Globegitter do you have a sample repo of this bazel + jest config? |
@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 :
module.exports = {
presets: [ "@babel/env", "@babel/react" ],
babelrcRoots: ["./packages/*"]
};
const path = require('path');
module.exports = {
transform: {
"^.+\\.js$": path.resolve(__dirname, "./jestBabelTransform.js")
},
};
const babelJest = require('babel-jest');
module.exports = babelJest.createTransformer({
rootMode: 'upward'
}); I'm already using the |
This commit adds a set of config files to enable jest in the structures package. This allows babel transformation to take place when running jest tests. Further, support is added to make sure jest works when run on the package level, or from the workspace root. This method of setting up jest with babel is taken from: jestjs/jest#7359 (comment)
I can't get this to work at all, can someone have a look?
Repository is here: |
The quick and dirty general work-around for this problem is to add
Use That solution makes your The |
@bradfordlemley Thanks, your module.exports = {
presets: ['react-app'],
} With this setup and the What i'm still missing is a way to add a Edit: Doesn't work on a second computer - regardless of |
@haraldrudell where is the code for this package? |
@bobbybobby do you have a top level jest.config.js in your example #7359 (comment)? do you have a repo with the full example? |
Adding |
I found to get jest/lerna/yarn workspace monorepo testing working I have to symlink (or duplicate) jest 24.8.0 |
I am using jest multi project runner with babel-jest and it works just fine. Each of my packages has a
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 |
I also have it working, although I can't say how. It's shame that it has to be so confusing. @ofhouse 👍 Looked at my setup and yeah - I basically have everything everywhere. Guess that's the way. |
Hi guys, |
@ofhouse solution worked for me thanks! |
Setting
|
fixes babel not running when executing jest from the repo root ref: jestjs/jest#7359 (comment)
fixes import not being recognised in `setupTests.ts` when executing jest from the repo root ref: jestjs/jest#7359 (comment)
fixes import not being recognised in `setupTests.ts` when executing jest from the repo root ref: jestjs/jest#7359 (comment)
@ofhouse 100% working solution for me, thanks a lot! 👍 |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 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 entria/entria-fullstack#12, where you can reproduce some of the issues.
To Reproduce
Neither of this transforms works:
I think the problem here is that
babel-jest
resolution strategy is failing to find the correct babel.config.js fileOnly creating a custom babel transformer the transform works, like the below:
Steps to reproduce the behavior:
Run
jest
on root of this project entria/entria-fullstack#12modify 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 projectExpected 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)
entria/entria-fullstack#12
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: