jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.23k stars 6.46k forks source link

Incorrect coverage reported for fat arrow functions #5293

Closed jlengstorf closed 6 years ago

jlengstorf commented 6 years ago

Do you want to request a feature or report a bug?

bug

What is the current behavior?

Code coverage for fat arrow functions is misreported. After running tests, the coverage shows as missing, despite the functions being called:

screencap-by-jlengstorf 50

However, changing to standard functions (with no other code changes) correctly shows coverage:

screencap-by-jlengstorf 51

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

This commit shows the missing coverage: https://github.com/gramps-graphql/data-source-xkcd/tree/2704e75e0a6fd89ce7962f346c53d6521029cfdd

What is the expected behavior?

Tests that run using fat arrow functions should properly record coverage.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

Node v9.0.0 (confirmed behavior on Node 8 and Node 6 as well) yarn v1.3.2

Jest/Babel packages and versions

{
  "@babel/cli": "^7.0.0-beta.37",
  "@babel/core": "^7.0.0-beta.37",
  "@babel/plugin-proposal-class-properties": "^7.0.0-beta.37",
  "@babel/preset-env": "^7.0.0-beta.37",
  "babel-core": "^7.0.0-0",
  "babel-eslint": "^8.2.1",
  "babel-jest": "^22.0.6",
  "babel-plugin-inline-import": "^2.0.6",
  "jest": "^22.0.6"
}

Jest config:

  "jest": {
    "coverageReporters": [
      "text",
      "lcov"
    ],
    "collectCoverageFrom": [
      "src/**/*.js"
    ],
    "coverageThreshold": {
      "global": {
        "branches": 80,
        "functions": 80,
        "lines": 80,
        "statements": 80
      }
    }
  }
SimenB commented 6 years ago

Duplicate of #5001

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.