Jest无法运行--无限挂起

9

我最初在使用create-react-app时遇到了这个问题,所以我只配置了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"
    

    },

但是当我运行yarn test时,会得到以下结果:

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

接着就没有任何反应了,程序就卡住了。使用create-react-app运行测试时也出现了同样的问题,react-scripts test会显示信息,但是随后什么都没有发生。

以下是收到的内容:

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

我已经重新安装和升级了所有我能想到的东西,包括npm、node、watchman、linuxbrew、yarn。如果有人能帮助我,我将永远感激不尽!

4个回答

17

这个加上 brew reinstall watchman 就解决了我的问题! ‍♂️ - Bradley Flood

6
我不确定为什么这样可以,但确实可以。我在系统上重新安装了一些全局包:
npm update npm -g (更新到6.9.0)
npm update -g  

更新内容:

将parcel-bundler升级到1.12.3版本。

更新watchman:

brew update watchman(升级至4.9.0版本)。


5

1
这对我有用,谢谢。 - TkDodo

3
问题出在 watchman 4.9 上面。
尝试运行 watchman version,如果卡住了,请通过运行以下命令解决:
如果你使用的是 4.9 版本,则运行 brew reinstall watchman;如果你使用的是旧版本,则运行 brew update watchman
参考链接: https://github.com/facebook/jest/issues/4529#issuecomment-333512164

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接