Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest doesn't run -- hangs indefinitely

I was originally having this problem with create-react-app, so I did really bare bones setup just of jest:

  1. created new directory
  2. yarn init in that directory
  3. yarn add jest
  4. created new file sum.js:

       function sum(a, b) {
          return a + b;
       }
       module.exports = sum;
    
  5. created file to test above function

    const sum = require('./sum');
    
    test('adds 1 + 2 = 3' , () => {
        expect(sum(1,2)).toBe(3);
    });
    
  6. added to package.json:

    "scripts": {
    "test": "jest"
    

    },

But when I run yarn test, I get this:

terry@terry-sharewalker:~/myProjects/test-jest$ yarn jest
yarn run v1.13.0
$ /home/terry/myProjects/test-jest/node_modules/.bin/jest

and nothing happens from there. It just hangs. The same thing happened with running tests from create-react-app. react-scripts test would show, then nothing.

Here's what I got:

Jest "^24.5.0"
Ubuntu 16.04
yarn 1.13.0
watchman 4.9.0
node 10.15.3

I've reinstalled and upgraded everything I can think of, including npm, node, watchman, linuxbrew, yarn. If anybody can help me I'd be forever grateful!!

like image 363
Coco Avatar asked Mar 15 '19 22:03

Coco


4 Answers

I was getting the same issue as well. It can be fixed be updating or reinstalling watchman brew uninstall watchman && brew install watchman.

More details can be found here https://github.com/facebook/jest/issues/4529

like image 74
slater Avatar answered Nov 09 '22 05:11

slater


I'm not sure WHY this worked, but it did. I reinstalled some global packages on my system:

npm update npm -g (to 6.9.0)

npm update -g  

this updated: parcel-bundler to 1.12.3

updated watchman: brew update watchman (to 4.9.0)

like image 40
Coco Avatar answered Nov 09 '22 05:11

Coco


The problem is due to watchman 4.9.
Try running watchman version, if hangs resolve by running:
brew reinstall watchman if you got 4.9, or brew update watchman if older.

Ref: https://github.com/facebook/jest/issues/4529#issuecomment-333512164

like image 22
Elya Livshitz Avatar answered Nov 09 '22 06:11

Elya Livshitz


Uninstalling and reinstalling watchman didn't work for me on MacOS

I had to do this:

launchctl unload ~/Library/LaunchAgents/com.github.facebook.watchman.plist
watchman version

https://github.com/facebook/watchman/issues/381#issuecomment-257673900

like image 38
Zhong Huiwen Avatar answered Nov 09 '22 06:11

Zhong Huiwen