jest tests are failing when running within a Yarn workspace
See original GitHub issueIs this a bug report?
Yes
Did you try recovering your dependencies?
Yes.
Which terms did you search for in User Guide?
yarn workspaces, jest fails
, yarn jest
, jest env
, dispose is not a function
, jest typeError environment
, etc.
Environment
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
sauron@0.4.0 /Users/agroza/Projects/bbp/sauron
└── (empty)
# react-scripts-ts
sauron@0.4.0 /Users/agroza/Projects/bbp/sauron
└── react-scripts-ts@2.13.0 extraneous
Then, specify:
- Operating system: Mac OS X Sierra 10.12
- Browser and version (if relevant):
Steps to Reproduce
- Clone cra-workspaces
- Run
yarn install
at root - Navigate to
apps/cra
and runyarn test
- Navigate to
packages/package-a
/packages/package-b
and runyarn run test:cov
Expected Behavior
Tests should run without errors.
Actual Behavior
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
Reproducible Demo
See cra-workspaces repo for an example of setup that has this issue.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:10 (3 by maintainers)
Top Results From Across the Web
vscode-jest doesn't work for a react app in a yarn workspace ...
In this repo: Jest works in command line (yarn workspace frontend test)Jest doesn't work when clicking the button in vscode or on startup....
Read more >Yarn test hangs when one more tests file is added
When the tests are run in sequence (or ran alone), and the tests fail, Jest can show a readable error message. The problem...
Read more >Troubleshooting
Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why. Try using the debugging support built into...
Read more >vscode-jest - Visual Studio Marketplace
Jest failed to run; Performance issue? Intermittent errors for (npm/yarn/node) command not found during test run or debugging ...
Read more >yarn test
Runs the test script defined by the package. yarn test. If you have defined a scripts object in your package, this command will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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
).