gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 786 forks source link

Fixed #429 Added undefined check to prevent "TypeError: Cannot read p… #704

Open jansoren opened 8 years ago

jansoren commented 8 years ago

…roperty 'text' of undefined"

coveralls commented 8 years ago

Coverage Status

Coverage remained the same at 97.523% when pulling 81226a3002df73fa80ac4477c45befd094bd69c3 on jansoren:master into 89e338fcb1c8a7dea3b9e8f851aa55de2bc3abee on gotwarlost:master.

levity commented 8 years ago

For anyone looking for a fix for this issue on the v1 branch, please see https://github.com/istanbuljs/istanbul-reports/pull/10

jansoren commented 8 years ago

@levity - The PR you are referring to does not seem to fix the issue. Could you provide an example of how to use the istanbul-reports plugin?

levity commented 8 years ago

@jansoren the v1 branch of istanbul depends on istanbul-reports. If you add a dependency on the patched version to your package.json, it will use that version. This doesn't apply to the master branch.

e.g.:

{
  ...
  "devDependencies": {
    ...
    "istanbul-reports": "levity/istanbul-reports"
  }
}
jansoren commented 8 years ago

@levity - Does still not work :-/ I'm not using istanbul directly, I'm using istanbul-instrumenter-loader. Could this be a problem?

levity commented 8 years ago

That could certainly be a problem -- I don't have enough knowledge of the project to say for sure.

superzadeh commented 7 years ago

I can also confirm that I run into this issue. My project is based on the ReactJS Boilerplate template v3.3.0 with modifications. It uses webpack 2.2.0, babel-core 6.21.0, babel-plugin-istanbul 2.0.3, and my test runner is Karma 1.3.0 (with phantomJS)

I run into the issue when using Ternary operators that contain react-intl's FormattedMessage component.

The following code causes the coverage to fail with TypeError: Cannot read property 'text' of undefined

import React, { PropTypes } from 'react';
import { FormattedMessage } from 'react-intl';
import messages from './messages';

const FailingComponent = (condition) =>
  <div>
    {condition ? <FormattedMessage {...messages.messageId} /> : 'whatever is used here'}
  </div>;

but the following code does causes these TypeError:

import React, { PropTypes } from 'react';
import { FormattedMessage } from 'react-intl';
import messages from './messages';

const WorkingComponent = (condition) => {
  const message = <FormattedMessage {...messages.messageId} />;
  return (<div>
    {condition ? message : 'whatever is used here'}
  </div>);
};

I can also confirm that the changes of this pull requests (applied locally in my node_modules copy of istanbul) fixes the errors caused by the the first snippet.