jest无限期挂起,不进行任何测试

时间:2018-02-17 21:33:40

标签: node.js testing npm jestjs babel-jest

每次我开玩笑时,它都不会运行任何东西。我让柜台任意高。我用--no-cache

运行了jest

jest --debug输出如下:

{
  "configs": [
    {
      "automock": false,
      "browser": false,
      "cache": true,
      "cacheDirectory": "/var/folders/7v/64n1tsk11zs2pbwf5bm_c9kc0000gn/T/jest_dx",
      "clearMocks": false,
      "coveragePathIgnorePatterns": [
        "/node_modules/"
      ],
      "detectLeaks": false,
      "forceCoverageMatch": [],
      "globals": {},
      "haste": {
        "defaultPlatform": "ios",
        "platforms": [
          "android",
          "ios",
          "native"
        ],
        "providesModuleNodeModules": [
          "react-native"
        ]
      },
      "moduleDirectories": [
        "node_modules"
      ],
      "moduleFileExtensions": [
        "js",
        "json",
        "jsx",
        "node"
      ],
      "moduleNameMapper": [
        [
          "^React$",
          "/Users/skilurus/github/flock-react-app/node_modules/react"
        ]
      ],
      "modulePathIgnorePatterns": [
        "/Users/skilurus/github/flock-react-app/node_modules/react-native/Libraries/react-native/"
      ],
      "name": "b29a126b130a0be47202d3bc7b00f1b4",
      "resetMocks": false,
      "resetModules": false,
      "restoreMocks": false,
      "rootDir": "/Users/skilurus/github/flock-react-app",
      "roots": [
        "/Users/skilurus/github/flock-react-app"
      ],
      "runner": "jest-runner",
      "setupFiles": [
        "/Users/skilurus/github/flock-react-app/node_modules/regenerator-runtime/runtime.js",
        "/Users/skilurus/github/flock-react-app/node_modules/react-native/jest/setup.js",
        "/Users/skilurus/github/flock-react-app/test-setup.js"
      ],
      "snapshotSerializers": [
        "/Users/skilurus/github/flock-react-app/node_modules/enzyme-to-json/serializer.js"
      ],
      "testEnvironment": "/Users/skilurus/github/flock-react-app/node_modules/jest-environment-jsdom/build/index.js",
      "testEnvironmentOptions": {},
      "testLocationInResults": false,
      "testMatch": [
        "**/__tests__/**/*.js?(x)",
        "**/?(*.)(spec|test).js?(x)"
      ],
      "testPathIgnorePatterns": [
        "/node_modules/",
        "e2e"
      ],
      "testRegex": "",
      "testRunner": "/Users/skilurus/github/flock-react-app/node_modules/jest-jasmine2/build/index.js",
      "testURL": "about:blank",
      "timers": "real",
      "transform": [
        [
          "^.+\\.js$",
          "/Users/skilurus/github/flock-react-app/node_modules/babel-jest/build/index.js"
        ],
        [
          "^[./a-zA-Z0-9$_-]+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$",
          "/Users/skilurus/github/flock-react-app/node_modules/react-native/jest/assetFileTransformer.js"
        ]
      ],
      "transformIgnorePatterns": [
        "node_modules/(?!react-native|native-base|react-navigation|react-native-fabric|tipsi-stripe)"
      ],
      "watchPathIgnorePatterns": []
    }
  ],
  "globalConfig": {
    "bail": false,
    "changedFilesWithAncestor": false,
    "collectCoverageFrom": [
      "src/**/*.{js,jsx}"
    ],
    "coverageDirectory": "/Users/skilurus/github/flock-react-app/__coverage__",
    "coverageReporters": [
      "json",
      "lcov",
      "text"
    ],
    "coverageThreshold": {
      "global": {
        "branches": 70,
        "functions": 75,
        "lines": 85,
        "statements": 80
      }
    },
    "detectLeaks": false,
    "expand": false,
    "globalSetup": null,
    "globalTeardown": null,
    "listTests": false,
    "mapCoverage": false,
    "maxWorkers": 7,
    "noStackTrace": false,
    "nonFlagArgs": [],
    "notify": false,
    "notifyMode": "always",
    "passWithNoTests": false,
    "rootDir": "/Users/skilurus/github/flock-react-app",
    "runTestsByPath": false,
    "testFailureExitCode": 1,
    "testPathPattern": "",
    "testResultsProcessor": null,
    "updateSnapshot": "new",
    "useStderr": false,
    "verbose": true,
    "watch": false,
    "watchman": true
  },
  "version": "22.3.0"
}

node --version:8.9.4

npm --version:5.6.0

纱线 - 版本1.3.2

有人见过类似的东西吗?有人知道解决这个问题很热吗?

9 个答案:

答案 0 :(得分:4)

在 MacOS 上,我通过使用 watchman 卸载并重新安装 brew uninstall watchman,然后使用 brew install watchman 重新安装来解决此问题。我最近升级了操作系统,所以可能与它有关。

答案 1 :(得分:3)

像这样运行测试:

jest --runInBand --detectOpenHandles --forceExit 

--runInBand 确保您的测试在相同的线程中运行,因此不会重叠。 --detectOpenHandles 会记录阻止您的测试退出的错误,与 --forceExit 结合使用可在出现问题而不是挂起时终止您的测试。

答案 2 :(得分:2)

这也发生在我身上,但它是断断续续的,但是非常令人沮丧。我发现一种解决方法是使用--runInBand标志运行,该标志仅在同一线程中运行测试:

jest --runInBand

答案 3 :(得分:1)

从记录来看,在我看来,这是一个缓存问题(之前我尝试过很多其他事情)。

对于开玩笑> = 22.0.0 ,请使用--clearCache选项清除缓存。

要开玩笑 <22.0.0 ,请使用--showConfig选项,搜索cacheDirectory属性并删除提到的目录。

希望这对某人有帮助。

答案 4 :(得分:1)

在我的情况下,这是因为我在对VS代码使用了jest插件,并且启用了自动保存。因此,玩笑玩了太多次后就绞死了。

删除/ tmp / jest_rs解决了我的问题。

答案 5 :(得分:1)

我遇到了同样的问题,测试通过了,然后挂起,CI也挂起。我偶然发现了--forceExit,它为我解决了这个问题。

答案 6 :(得分:0)

我已通过修改.babelrc来解决此问题

{
 "presets": ["@babel/preset-env", "@babel/preset-react"],
 "plugins": [
   [
     "styled-jsx/babel",
     {
       // "plugins": ["styled-jsx-plugin-postcss"]
     }
   ]
 ]
}

答案 7 :(得分:0)

就我而言,我尝试了互联网的所有操作,唯一的解决方法是设置isolatedModules: true(我将其显式设置为false)。

答案 8 :(得分:0)

所以我遇到了类似的情况,只是那个玩笑拒绝运行我的任何测试!原因有点复杂: 我已经超过 6 个月没有运行该项目,并且各种依赖项都发现了漏洞问题。 回到我上次运行项目和测试时,我开玩笑地使用全局配置全局安装。 然后有一次,我从 global 中卸载了 jest(因此丢失了全局配置),但不记得在我正在谈论的项目中添加本地一个。

在调试以尝试运行测试时,我核对了节点模块并进行了全新安装。

只有在添加 jest.config 并设置无缓存选项后,它才最终解决。

总结:

  • 如果您没有全局安装 jest,请确保为您的项目安装了 jest 配置。
  • 使用 cli 设置配置后,返回并手动检查您选择的所有选项是否存在,并修改 cli 未提示的选项。