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 787 forks source link

"else path not taken" for class in ES6 #735

Open brunoosilva opened 7 years ago

brunoosilva commented 7 years ago

I hava a problem with the coverage, look:

image

But, written in this way, it works: image image

albertolive commented 7 years ago

Any update on that?

loick commented 7 years ago

Actually, I had the same issue and I found this gist https://gist.github.com/pbeshai/7bb7ba4bf257249493de, which I converted to:

// bin/jestPreprocessor.js
var babel = require('babel-core')
var fs = require('fs')

// setup source mapping as per https://github.com/facebook/jest/issues/114
var map_path = function(string) {
  return '/tmp/' + require('crypto').createHash('md5').update(string).digest('hex') + '.map'
}

module.exports = {
  process: function(src, filename) {
    if (!babel.util.canCompile(filename)) {
      return ''
    }

    if (filename.indexOf('node_modules') !== -1) {
      return src
    }

    if (babel.util.canCompile(filename)) {
      // Force inclusion of the polyfill, then append regular compiled output.
      var compiled = babel.transform(src, { filename: filename, sourceMap: true })
      var result = compiled.code

      fs.writeFileSync(map_path(filename), JSON.stringify(compiled.map))

      return result
    }

    return src
  },
}

Then, in my package.json, I have in the Jest section:

"transform": {
      "^.+\\.jsx$": "<rootDir>/node_modules/babel-jest",
      ".*": "<rootDir>/bin/jestPreprocessor"
    }

I hope it will work for you too.

albertolive commented 7 years ago

No, doesn't work for me. But thanks anyway :)

loick commented 7 years ago

What is your configuration ?

olegdeezus commented 7 years ago

Have same strange issue for React and React Native import statements image

I'm using Jest for testing. My Jest config looks like:

"jest": {
    "preset": "react-native",
    "transform": {
        "^.+\\.jsx?$": "babel-jest",
        "^.+\\.(ts|tsx)$": "typescript-babel-jest"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "testPathIgnorePatterns": [
        "/node_modules/",
        "packager/react-packager/src/Activity/"
    ],
    "globals": {
        "__TS_CONFIG__": {
            "jsx": "react"
        }
    },
    "setupFiles": [
        "<rootDir>/jestconfig.js"
    ],
    "transformIgnorePatterns": [
        "<rootDir>/node_modules/(?!(jest-)?react-native|react-navigation|react-clone-referenced-element)"
    ],
    "moduleFileExtensions": [
        "ts",
        "tsx",
        "js"
    ],
    "collectCoverageFrom": [
        "**/*.{ts,tsx}"
    ],
    "coverageDirectory": "./reports/coverage",
    "coverageReporters": ["lcov", "text-summary"]
}
Ratikant01 commented 6 years ago

image

lend-a-tailor commented 5 years ago

I'm getting the same results. My code has no logic at this point. I tried removing empty lines and the error showed on different lines.

2018-10-23_16-14-14 2018-10-23_16-14-58

amallo commented 5 years ago

+1

sammysium commented 4 years ago

Have same strange issue for React and React Native import statements image

I'm using Jest for testing. My Jest config looks like:

"jest": {
    "preset": "react-native",
    "transform": {
        "^.+\\.jsx?$": "babel-jest",
        "^.+\\.(ts|tsx)$": "typescript-babel-jest"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "testPathIgnorePatterns": [
        "/node_modules/",
        "packager/react-packager/src/Activity/"
    ],
    "globals": {
        "__TS_CONFIG__": {
            "jsx": "react"
        }
    },
    "setupFiles": [
        "<rootDir>/jestconfig.js"
    ],
    "transformIgnorePatterns": [
        "<rootDir>/node_modules/(?!(jest-)?react-native|react-navigation|react-clone-referenced-element)"
    ],
    "moduleFileExtensions": [
        "ts",
        "tsx",
        "js"
    ],
    "collectCoverageFrom": [
        "**/*.{ts,tsx}"
    ],
    "coverageDirectory": "./reports/coverage",
    "coverageReporters": ["lcov", "text-summary"]
}

did you get this to work @olegdeezus ?

sammysium commented 4 years ago

Have same strange issue for React and React Native import statements image

I'm using Jest for testing. My Jest config looks like:

"jest": {
    "preset": "react-native",
    "transform": {
        "^.+\\.jsx?$": "babel-jest",
        "^.+\\.(ts|tsx)$": "typescript-babel-jest"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "testPathIgnorePatterns": [
        "/node_modules/",
        "packager/react-packager/src/Activity/"
    ],
    "globals": {
        "__TS_CONFIG__": {
            "jsx": "react"
        }
    },
    "setupFiles": [
        "<rootDir>/jestconfig.js"
    ],
    "transformIgnorePatterns": [
        "<rootDir>/node_modules/(?!(jest-)?react-native|react-navigation|react-clone-referenced-element)"
    ],
    "moduleFileExtensions": [
        "ts",
        "tsx",
        "js"
    ],
    "collectCoverageFrom": [
        "**/*.{ts,tsx}"
    ],
    "coverageDirectory": "./reports/coverage",
    "coverageReporters": ["lcov", "text-summary"]
}

almost four years now...any solution?