Yes
Yes.
yarn workspaces, jest fails, yarn jest, jest env, dispose is not a function, jest typeError environment, etc.
node -v: 894npm -v: 5.6.0yarn --version (if you use Yarn): 1.3.2npm ls react-scripts (if you haven’t ejected): # react-scripts
[email protected] /Users/agroza/Projects/bbp/sauron
└── (empty)
# react-scripts-ts
[email protected] /Users/agroza/Projects/bbp/sauron
└── [email protected] extraneous
Then, specify:
yarn install at rootapps/cra and run yarn testpackages/package-a/packages/package-b and run yarn run test:covTests should run without errors.
Some tests are throwing:
FAIL src/foo.spec.ts
● Test suite failed to run
TypeError: environment.setup is not a function
at ../../node_modules/jest-runner/build/run_test.js:112:23
See cra-workspaces repo for an example of setup that has this issue.
I'm guessing it could have something to do with https://github.com/facebook/jest/issues/5401?
Ok, after trying out a few more things, it seems like having jest as a dep. in another workspace causes the issue.
It could be some incompatibilities between versions of jest, but I'm actually also fixed at the same version that react-scripts is (22.1.4).
Your app is using [email protected] which uses [email protected], but package-a and -b are using [email protected].
If you change your package-a and package-b to use [email protected], you won't have this error. (I don't think you need the jest-environment-jsdom dependency in package-a or -b -- I think you can just remove those, otherwise they probably need to match, too.)
I don't know of a way to use two different versions of jest, possibly with a --nohoist option which is not yet supported by yarn, but will be soon.
@bradfordlemley yes, that seems to be true. I used the version I saw on the react-scripts-ts repo instead of the package.json from the npm dist.
I'll give it a shot to see if anything changes.
Ok, now the cra app tests throw that error but the packages' tests work just fine.
You probably have some old dependencies hanging around. Delete all the node_modules dirs (cra-workspaces/node_modules, app/cra/node_modules, packages/package-a/node_modules, packages/package-b/node_modules), then run yarn to re-install. (FYI, I was able to successfully run tests from both packages and the app in your example monorepo after updating the packages to use [email protected] as described above.)
Oh, my bad. I tried with 22.0.4, not 20.0.4. Unfortunately for me, I cannot back to 20 due to jsdom upgrade. So if I do, some of my tests will be broken anyway 😆
I created an issue to ask for a version bump though.
Thanks.
Just to update that after hours of trying, I am able to find a way to resolve this issue:
Add this piece of code into your root package.json
"resolutions": {
"jest": "^22.4.3",
"babel-jest": "^22.4.3", // if you are using babel-jest as well
"babel-core": "^7.0.0-bridge.0" // if you are using babel 7
},
Thank you @huchenme .
Looks like this issue has been resolved. Please open a new issue if you continue to experience problems.
Most helpful comment
Just to update that after hours of trying, I am able to find a way to resolve this issue:
Add this piece of code into your root
package.json