jest: Coverage Broken: metrics.isEmpty is not a function at tableRow

command run: jest --forceExit --verbose --bail --useStderr --runInBand --expand --colors --coverage

output: Failed to write coverage reports: ERROR: TypeError: metrics.isEmpty is not a function STACK: TypeError: metrics.isEmpty is not a function at tableRow (/Users/qtb9604/bmw/packages/http/node_modules/istanbul-reports/lib/text/index.js:133:27) at TextReport.onSummary (/Users/qtb9604/bmw/packages/http/node_modules/istanbul-reports/lib/text/index.js:188:15) at TextReport.onDetail (/Users/qtb9604/bmw/packages/http/node_modules/istanbul-reports/lib/text/index.js:193:17) at Visitor.(anonymous function) [as onDetail] (/Users/qtb9604/bmw/packages/http/node_modules/istanbul-lib-report/lib/tree.js:34:30) at ReportNode.Node.visit (/Users/qtb9604/bmw/packages/http/node_modules/istanbul-lib-report/lib/tree.js:123:17) at /Users/qtb9604/bmw/packages/http/node_modules/istanbul-lib-report/lib/tree.js:116:23 at Array.forEach (native) at visitChildren (/Users/qtb9604/bmw/packages/http/node_modules/istanbul-lib-report/lib/tree.js:115:32) at ReportNode.Node.visit (/Users/qtb9604/bmw/packages/http/node_modules/istanbul-lib-report/lib/tree.js:126:5) at /Users/qtb9604/bmw/packages/http/node_modules/istanbul-lib-report/lib/tree.js:116:23

jest --debug yields: { "configs": [ { "automock": false, "browser": false, "cache": true, "cacheDirectory": "/var/folders/t6/0brzsz0s6v5fqttj19rylpn18r1g3z/T/jest_mm3xxb", "clearMocks": false, "coveragePathIgnorePatterns": [ "index.ts", "locales", "src/controllers", "src/middleware", "src/prototypes", "src/types", "tests/unit/mocks" ], "detectLeaks": false, "forceCoverageMatch": [], "globals": { "ts-jest": { "tsConfigFile": "tsconfig.json" } }, "haste": { "providesModuleNodeModules": [] }, "moduleDirectories": [ "node_modules" ], "moduleFileExtensions": [ "ts", "js" ], "moduleNameMapper": {}, "modulePathIgnorePatterns": [], "name": "3fa0a9dc4bb9d4586ae003b68f15eda0", "resetMocks": false, "resetModules": false, "restoreMocks": false, "rootDir": "/Users/qtb9604/vea-server", "roots": [ "/Users/qtb9604/vea-server" ], "runner": "jest-runner", "setupFiles": [], "snapshotSerializers": [], "testEnvironment": "/Users/qtb9604/vea-server/node_modules/jest-environment-node/build/index.js", "testEnvironmentOptions": {}, "testLocationInResults": false, "testMatch": [ "**/tests/**/*.test.(ts)" ], "testPathIgnorePatterns": [ "/node_modules/" ], "testRegex": "", "testRunner": "/Users/qtb9604/vea-server/node_modules/jest-jasmine2/build/index.js", "testURL": "about:blank", "timers": "real", "transform": [ [ "^.+\\.(ts|tsx)$", "/Users/qtb9604/vea-server/node_modules/ts-jest/preprocessor.js" ] ], "transformIgnorePatterns": [ "/node_modules/" ], "watchPathIgnorePatterns": [] } ], "globalConfig": { "bail": false, "changedFilesWithAncestor": false, "collectCoverageFrom": [ "src/**" ], "coverageDirectory": "/Users/qtb9604/vea-server/coverage", "coverageReporters": [ "json", "text", "lcov", "clover" ], "detectLeaks": false, "expand": false, "globalSetup": null, "globalTeardown": null, "listTests": false, "maxWorkers": 7, "noStackTrace": false, "nonFlagArgs": [], "notify": false, "notifyMode": "always", "passWithNoTests": false, "rootDir": "/Users/qtb9604/vea-server", "runTestsByPath": false, "testFailureExitCode": 1, "testPathPattern": "", "testResultsProcessor": null, "updateSnapshot": "new", "useStderr": false, "verbose": null, "watch": false, "watchman": true }, "version": "22.4.2" }

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 5
  • Comments: 24 (13 by maintainers)

Commits related to this issue

Most upvoted comments

try yarn remove jest && yarn add --dev jest (or npm equivalent) to amke sure all of Jest’s dependencies are updated as well

FWIW, I had to manually delete my yarn.lock file to get this working. Much thanks to others in this thread that pointed me in the correct direction 🙏 … I was banging my head around for a while.


Things tried with no luck (in no particular order):

  • manually remove the yarn cache file from my machine
  • tell yarn to clean up the cache
  • manually lock istanbul deps to earlier versions
  • remove node_modules and reinstall
  • bump jest back down to 22.4.0

If you’re using only npm (not yarn), delete node_modules and package-lock.json and run npm install again.

@dazip @felangel could you try reinstalling, I’m pretty sure the core issue is an incompatible version of istanbul-reports and istanbul-lib-coverage … not quite sure why one would be upgrading and not the other for you (probably lock related).

@bcoe suggestion worked for me. I initially just updated the package.json to get the latest version of jest and that’s when I got the error listed by the OP. I uninstalled and then reinstalled jest and it worked. Thanks @bcoe.

You don’t need the jest beta, you need istanbul-lib-coverage@1.2.0 and istanbul-lib-instrument@1.10.1, which are within semver range of at least Jest 21 and Jest 22.

When can we see the release with this fix? Or it’s released? I didn’t find this fix in CHANGELOG.md

I’m open to apply them all 🤪

For sure, it’s just a matter of applying this:

diff --git i/packages/jest-cli/package.json w/packages/jest-cli/package.json
index 3e4bfd85..bebedaea 100644
--- i/packages/jest-cli/package.json
+++ w/packages/jest-cli/package.json
@@ -12,9 +12,9 @@
     "import-local": "^1.0.0",
     "is-ci": "^1.0.10",
     "istanbul-api": "^1.3.1",
-    "istanbul-lib-coverage": "^1.1.1",
-    "istanbul-lib-instrument": "^1.8.0",
-    "istanbul-lib-source-maps": "^1.2.1",
+    "istanbul-lib-coverage": "^1.2.0",
+    "istanbul-lib-instrument": "^1.10.1",
+    "istanbul-lib-source-maps": "^1.2.3",
     "jest-changed-files": "^22.2.0",
     "jest-config": "^22.4.2",
     "jest-environment-jsdom": "^22.4.1",
diff --git i/packages/jest-runtime/package.json w/packages/jest-runtime/package.json
index 6ab876ad..c4cb00c4 100644
--- i/packages/jest-runtime/package.json
+++ w/packages/jest-runtime/package.json
@@ -9,7 +9,7 @@
   "main": "build/index.js",
   "dependencies": {
     "babel-core": "^6.0.0",
-    "babel-plugin-istanbul": "^4.1.5",
+    "babel-plugin-istanbul": "^4.1.6",
     "chalk": "^2.0.1",
     "convert-source-map": "^1.4.0",
     "exit": "^0.1.2",

Not sure which of them matters, but that should be enough to bump things up enough.

^got it working. I forgot my lockfile updated as well when I did the upgrade. I also ran an npm clear cache just to be sure newer versions were not cached as well. thanks!

It worked for me as well now. Not sure what was going on before…thanks!

The pull request referenced appears to break coverage within jest. In cases where my package-lock.json used version 1.1.4 of istanbul-reports, coverage works. Updating, in which Jest pulls in 1.3.0, and the pull request above, breaks.