jest: Coverage broken when using babel-jest

The issue can reproduced by following these precise steps:

git clone https://github.com/jehoshua02/react-scaffold.git
cd react-scaffold
npm install
npm test -- --coverage

And I get this output:

~/projects/jehoshua02/react-scaffold 🚀  babel_jest
$ npm test -- --coverage

> react-scaffold@1.0.0 test /Users/employee/projects/jehoshua02/react-scaffold
> jest --coverage

Using Jest CLI v0.4.0
 PASS  __tests__/sum-test.js (0.682s)
 PASS  __tests__/Hello.js (1.048s)
2 tests passed (2 total)
Run time: 1.971s
-----------------------|-----------|-----------|-----------|-----------|
File                   |   % Stmts |% Branches |   % Funcs |   % Lines |
-----------------------|-----------|-----------|-----------|-----------|
   app/components/     |       100 |       100 |       100 |       100 |
      Hello.js         |       100 |       100 |       100 |       100 |
   app/util/           |       100 |       100 |       100 |       100 |
      sum.js           |       100 |       100 |       100 |       100 |
   node_modules/react/ |       100 |       100 |       100 |       100 |
      addons.js        |       100 |       100 |       100 |       100 |
-----------------------|-----------|-----------|-----------|-----------|
All files              |       100 |       100 |       100 |       100 |
-----------------------|-----------|-----------|-----------|-----------|

Failed with unexpected error.

/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/src/jest.js:179
      throw error;
            ^
TypeError: Cannot set property 'covered' of undefined
  at /Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:175:66
  at Array.forEach (native)
  at annotateLines (/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:173:28)
  at HtmlReport.Report.mix.writeDetailPage (/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:406:9)
  at /Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:472:26
  at SyncFileWriter.extend.writeFile (/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/istanbul/lib/util/file-writer.js:57:9)
  at FileWriter.extend.writeFile (/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/istanbul/lib/util/file-writer.js:147:23)
  at /Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:471:24
  at Array.forEach (native)
  at HtmlReport.Report.mix.writeFiles (/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:465:23)
  at /Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:467:22
  at Array.forEach (native)
  at HtmlReport.Report.mix.writeFiles (/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:465:23)
  at HtmlReport.Report.mix.writeReport (/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/istanbul/lib/report/html.js:549:14)
  at LcovReport.Report.mix.writeReport (/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/istanbul/lib/report/lcov.js:55:19)
  at /Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/istanbul/lib/reporter.js:93:20
  at Array.forEach (native)
  at Object.Reporter.write (/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/istanbul/lib/reporter.js:87:30)
  at DefaultTestReporter.IstanbulTestReporter.onRunComplete (/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/src/IstanbulTestReporter.js:33:14)
  at /Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/src/TestRunner.js:453:40
  at _fulfilled (/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/q/q.js:798:54)
  at self.promiseDispatch.done (/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/q/q.js:827:30)
  at Promise.promise.promiseDispatch (/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/q/q.js:760:13)
  at /Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/q/q.js:574:44
  at flush (/Users/employee/projects/jehoshua02/react-scaffold/node_modules/jest-cli/node_modules/q/q.js:108:17)
  at process._tickCallback (node.js:442:13)

npm ERR! Test failed.  See above for more details.

As you can see, the tests run fine, and pass, the coverage is output to the console (which is all I really want), but something after that, I’m assuming when writing out reports to the disk, is failing and generating a big ugly error.

Issue also reported over at babel-jest.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

@jehoshua02 I encountered this issue too when using babel-jest, but I think the problem is more general, in that any time the postprocessed file has more lines than the source file this error will be produced (if it has fewer I assume the coverage report will simply be incorrect). I tried this with the CoffeeScript example off the jest repo and got the same error. I’m wondering if it might be helpful to rephrase the issue?