question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jest tests are failing when running within a Yarn workspace

See original GitHub issue

Is 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

  1. node -v: 894
  2. npm -v: 5.6.0
  3. yarn --version (if you use Yarn): 1.3.2
  4. npm 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:

  1. Operating system: Mac OS X Sierra 10.12
  2. Browser and version (if relevant):

Steps to Reproduce

  1. Clone cra-workspaces
  2. Run yarn install at root
  3. Navigate to apps/cra and run yarn test
  4. Navigate to packages/package-a/packages/package-b and run yarn 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:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
huchenmecommented, May 28, 2018

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
},
1reaction
rolandjitsucommented, Feb 14, 2018

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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found