【问题标题】:Jest test suites failed to passJest 测试套件未能通过
【发布时间】:2021-10-22 16:11:09
【问题描述】:

当我一次运行所有测试并且每次失败的测试套件的数量不同时,就会出现此问题。当我分别运行失败的测试套件时,测试成功通过。堆栈跟踪导致 node_modules 依赖项。这是一个笑话日志的一部分:



 FAIL  tests/unit/middleware/organization.middleware.test.js
  ● Test suite failed to run

    TypeError: Invalid URL: http://localhost

      at new URLImpl (node_modules/whatwg-url/dist/URL-impl.js:21:13)
      at Object.exports.setup (node_modules/whatwg-url/dist/URL.js:54:12)
      at new URL (node_modules/whatwg-url/dist/URL.js:107:22)
      at transformOptions (node_modules/jsdom/lib/api.js:235:38)
      at new JSDOM (node_modules/jsdom/lib/api.js:34:15)

 FAIL  tests/unit/services/logstash.service.test.js
● Test suite failed to run

    TypeError: Invalid URL: http://localhost

      at new URLImpl (node_modules/whatwg-url/dist/URL-impl.js:21:13)
      at Object.exports.setup (node_modules/whatwg-url/dist/URL.js:54:12)
      at new URL (node_modules/whatwg-url/dist/URL.js:107:22)
      at transformOptions (node_modules/jsdom/lib/api.js:235:38)
      at new JSDOM (node_modules/jsdom/lib/api.js:34:15)

我安装了以下依赖项:

  "dependencies": {
    "@xmpp/client": "^0.11.1",
    "accesscontrol": "^2.2.1",
    "bcryptjs": "^2.4.3",
    "cookie-parser": "~1.4.3",
    "cors": "^2.8.5",
    "debug": "^2.6.9",
    "express": "~4.16.0",
    "express-async-handler": "^1.1.4",
    "express-rate-limit": "^5.1.3",
    "express-validator": "^6.12.0",
    "geoip-lite": "^1.3.8",
    "got": "^11.5.1",
    "jsonwebtoken": "^8.5.1",
    "lodash": "^4.17.21",
    "log4js": "^6.3.0",
    "mongo-mock": "^4.0.0",
    "mongodb": "^3.2.7",
    "morgan": "~1.9.0",
    "node-cache": "^4.2.1",
    "node-schedule": "^1.3.2",
    "p-retry": "^4.2.0",
    "pako": "^1.0.11",
    "saslprep": "^1.0.3",
    "search-query-parser": "^1.5.4",
    "sinon": "^9.0.2"
  },
  "devDependencies": {
    "@types/jest": "^26.0.22",
    "eslint": "^7.24.0",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-jest": "^24.3.5",
    "jest": "^26.6.3",
    "jest-sonar-reporter": "^2.0.0",
    "mongodb-memory-server": "^6.9.6",
    "node-mocks-http": "^1.10.1",
    "nyc": "^14.1.1",
    "proxyquire": "^2.1.3",
    "randomstring": "^1.1.5",
    "rewire": "^5.0.0",
    "rewiremock": "^3.14.3",
    "supertest": "^6.1.3"
  },
  "jestSonar": {
    "reportFile": "test-results.xml"
  }

【问题讨论】:

    标签: node.js express unit-testing jestjs


    【解决方案1】:

    为了解决这个问题,我将jest 版本更新为27.0.6

    【讨论】:

      【解决方案2】:

      我也遇到了同样的问题,并设法通过在运行 jest 时禁用缓存来修复它,看起来缓存已损坏。

      尝试像这样将参数传递给 npm test:

      npm test -- --no-cache
      

      或者直接运行 jest

      jest --no-cache
      

      【讨论】:

        猜你喜欢
        • 2018-06-25
        • 1970-01-01
        • 1970-01-01
        • 2017-07-15
        • 1970-01-01
        • 2019-10-21
        • 2011-07-02
        • 2018-10-14
        • 2022-01-05
        相关资源
        最近更新 更多