Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--all with babel-plugin-istanbul does not report coverage for files not dependents of the test entries #911

Closed
hershmire opened this issue Aug 23, 2018 · 6 comments

Comments

@hershmire
Copy link
Contributor

Expected Behavior

When running NYC with the following script command:

NODE_ENV=test nyc mocha src/**/test-node/**/*.js

And with the following NYC configuration settings from package.json:

"nyc": {
    "sourceMap": false,
    "instrument": false,
    "cache": false,
    "all": true,
    "exclude": [
      "**/test-node/**"
    ],
    "include": [
      "src/**"
    ],
    "reporter": [
      "json",
      "text",
      "text-summary"
    ],
    "require": [
      "babel-core/register"
    ],
    "extension": [
      ".jsx",
      ".js",
      ".mjs"
    ]
  },

And with the following .babelrc configuration setup:

{
  "presets": [
    "babel-preset-react",
    ["babel-preset-env", {
      "targets": {
        "browsers": [
          "last 2 versions"
        ]
      }
    }]
  ],
  "env": {
    "test": {
      "plugins": [
        [
          "babel-plugin-istanbul",
          {
            "exclude": [
              "**/test-node/**"
            ]
          }
        ]
      ]
    }
  },
  "plugins": [
    "babel-plugin-transform-class-properties",
    "babel-plugin-transform-object-rest-spread"
  ]
}

I expect all my files that match the file extensions of .jsx, .js, and .mjs within the src/** directory will be included in the test coverage reports.

Below is what I would expect to see which I only get when I turn off babel-plugin-istanbul and let NYC instrument the files:

screen shot 2018-08-23 at 15 50 04

Observed Behavior

The coverage reports only show the files that are dependencies to the tests. Here is the output I get:

screen shot 2018-08-23 at 15 49 02

Bonus Points! Code (or Repository) that Reproduces Issue

Here is a repository I created that illustrates this problem – https://github.com/hershmire/nyc-all

Forensic Information

Operating System: the operating system you observed the issue on.
macOS High Sierra v10.13.6

Environment Information: information about your project's environment, see instructions below:

  1. run the following script:

sh -c 'node --version; npm --version; npm ls' > output.txt

  1. share a gist with the contents of output.txt.

https://github.com/hershmire/nyc-all/blob/master/output.txt

@coreyfarrell
Copy link
Member

I've seen an issue like this, I believe the problem is that "instrument": false is preventing "all": true from being effective. In some of my own repositories which use babel-plugin-istanbul I was able to get everything working by using:

{
  "instrument": true,
  "sourceMaps": false,
  "all": true
}

Obviously that conflicts with what is documented. I have not had a chance to investigate this further, the "all": true functionality definitely needs work.

@stale stale bot added the wontfix label Jan 5, 2019
@JaKXz
Copy link
Member

JaKXz commented Feb 5, 2019

@hershmire are you still experiencing this with the latest version of nyc and Corey's suggestion?

@JaKXz JaKXz added help wanted and removed wontfix labels Feb 5, 2019
@istanbuljs istanbuljs deleted a comment from stale bot Feb 5, 2019
@CynicalBusiness
Copy link

CynicalBusiness commented Mar 1, 2019

I know this is a bit of an older issue, but I am still seeing this same behavior in another repository. This time, both on Windows 10 Enterprise 1809 and Ubuntu Desktop 18.04.

I'm using the command cross-env NODE_ENV=test DEBUG= nyc mocha through yarn.

I've got the following:

  • @babel/core@^7.2.2
  • babel-plugin-istanbul@^5.1.1
  • nyc@^13.3.0
  • istanbul@^0.4.5
  • mocha@^6.0.2

My .nycrc.json:

{
  "include": [
    "src"
  ],
  "reporter": [
    "lcov",
    "text-summary"
  ],
  "require": [
    "@babel/register"
  ],
  "extension": [
    ".ts",
    ".tsx"
  ],
  "all": true,
  "instrument": false,
  "sourceMap": false
}

...and .babelrc.js:

const presets = [
  [ '@babel/env', {
    targets: {
      node: true
    }
  }],
  '@babel/typescript'
]
const plugins = [
  '@babel/proposal-class-properties',
  '@babel/proposal-object-rest-spread',
  [ 'transform-es2015-modules-commonjs', {
    noInterop: true
  }]
]

exports = module.exports = {
  comments: false,
  compact: true,
  env: {
    test: {
      plugins: [ 'istanbul' ]
    }
  },
  plugins,
  presets,
  sourceMaps: true
}

My directory structure, in short, looks like this:


src/
  app/
    index.ts
    (other TS sources)
    package.json
    tsconfig.json
  base/
    (same as above)
  core/
    (same)
  lib/
    (same)
test/
  (tests and such)
  mocha.opts
.babelrc.js
.nycrc.json
package.json
tsconfig.json
(plus some other files)

In short, I'm trying to cover every TS file in src/, even though (right now, anyway), my tests only require files in lib/. That directory gets covered fine, but the others are not; I get the exact same behavior reguardless of the setting of all.

Switching instrument to true made it now cover the src/core directory (which is the only one right now with no sub-directores), but it's still missing the other two. Additionally, including src versus src/** versus src/**/*.ts has no effect either.

This looks like the same behavior as the original, with the same configuration (that is, @babel/register and babel-plugin-istanbul)

@coreyfarrell
Copy link
Member

@CynicalBusiness can you provide a link to a repository?

@stale
Copy link

stale bot commented May 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 6, 2019
MaximDevoir added a commit to MaximDevoir/event-listener that referenced this issue May 11, 2019
`coverage` script would not fail below specified thresholds. See more
at: istanbuljs/nyc#911
@stale stale bot closed this as completed May 13, 2019
@kernelwhisperer
Copy link

Really weird, but I managed to get it "working" by removing require @babel/register and setting instrument to true.

  "nyc": {
-    "require": [
-      "@babel/register"
-    ],
    "sourceMap": false,
-    "instrument": false,
+    "instrument": true,
    "all": true
  }

Would be awesome if someone could update the tutorial.

Note: I'm quoting working because I'm not sure if the lines of code are calculated correctly since I removed the require hook... 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants