istanbuljs / nyc

the Istanbul command line interface
https://istanbul.js.org/
ISC License
5.61k stars 360 forks source link

Code coverage is impacting webpack #885

Closed thexodus closed 6 years ago

thexodus commented 6 years ago

Expected Behavior

After using nyc I should be able to se see code coverage and the webpack working as is.

Observed Behavior

But after using nyc though I was able to see code coverage, webpack is genrating unnecessary code while bundling. It include every single js/jsx file code coverage content while bundling.

Considered guidelines from https://github.com/istanbuljs/nyc https://github.com/istanbuljs/babel-plugin-istanbul

Bonus Points! Code (or Repository) that Reproduces Issue

.babelrc

{
  "presets": [
    "es2015",
    "react",
    "stage-0"
  ],
  "env": {
    "development": {
      "plugins": [
        ["istanbul", {
          "useInlineSourceMaps": false
        }]
      ]
    }
  }
}

nyc config

"nyc": {
    "check-coverage": true,
    "lines": 20,
    "require": [
      "babel-register",
      "jsdom-global/register",
      "ignore-styles"
    ],
    "extension": [
      ".js",
      ".jsx"
    ],
    "include": [
      "app/assets/javascripts/react/**/*"
    ],
    "reporter": [
      "text",
      "text-summary",
      "lcov"
    ],
    "sourceMap": false,
    "instrument": false,
    "cache": true,
    "all": true
  },

package.json

"scripts": {
    "dev": "cross-env NODE_ENV=development webpack -d --watch",

Forensic Information

Operating System: mac osx high sierra, 10.13.1 Environment Information: information about your project's environment, see instructions below:

  1. run the following script: node: v8.5.0 npm: 6.0.0
    "dependencies": {
    "axios": "^0.15.3",
    "babel-polyfill": "^6.26.0",
    "css-loader": "^0.26.4",
    "filepicker-js": "^2.4.18",
    "install": "^0.8.2",
    "jquery": "^3.2.1",
    "json-loader": "^0.5.4",
    "moment": "^2.15.0",
    "moment-timezone": "^0.5.5",
    "node-sass": "^4.4.0",
    "pluralize": "^6.0.0",
    "prop-types": "^15.5.10",
    "ramda": "^0.23.0",
    "rc-time-picker": "^2.3.3",
    "react": "^16.2.0",
    "react-bootstrap": "^0.31.0",
    "react-bootstrap-toggle": "^2.0.8",
    "react-datepicker": "^1.2.2",
    "react-dropzone-component": "^3.1.0",
    "react-google-charts": "^1.5.5",
    "react-js-pagination": "^2.2.0",
    "react-nouislider": "^2.0.1",
    "react-redux": "^5.0.2",
    "react-router": "^3.0.2",
    "react-select": "^1.0.0-rc.1",
    "react-sidebar": "^2.3.0",
    "react-skylight": "^0.4.2",
    "react-tabs": "^2.2.2",
    "react-user-tour": "^3.0.0",
    "redux": "^3.6.0",
    "redux-mock-store": "^1.2.1",
    "redux-thunk": "^2.1.0",
    "sass-loader": "^4.1.1",
    "style-loader": "^0.16.0",
    "toastr": "^2.1.2"
    },
    "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-eslint": "^7.1.1",
    "babel-loader": "^6.3.1",
    "babel-plugin-istanbul": "^4.1.6",
    "babel-plugin-transform-class-properties": "^6.23.0",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react": "^6.23.0",
    "babel-preset-stage-0": "^6.22.0",
    "babel-register": "^6.26.0",
    "chai": "^3.5.0",
    "cross-env": "^5.2.0",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "eslint": "^3.4.0",
    "eslint-config-airbnb": "^14.1.0",
    "eslint-import-resolver-webpack": "^0.8.1",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^4.0.0",
    "eslint-plugin-react": "^6.10.0",
    "ignore-styles": "^5.0.1",
    "jsdom": "^11.6.2",
    "jsdom-global": "^3.0.0",
    "mocha": "^4.1.0",
    "moxios": "^0.3.0",
    "nyc": "^11.7.1",
    "proxyquire": "^1.7.11",
    "react-dom": "^16.2.0",
    "react-test-renderer": "^15.6.2",
    "request": "^2.79.0",
    "sinon": "^1.17.5",
    "tween": "^0.9.0",
    "webpack": "^2.3.2"
    }
  2. share a gist with the contents of output.txt. https://gist.github.com/a5his/8a2a283ff6f2f25d963335a7aac5c4ff
thexodus commented 6 years ago

Actually it was babel-loader used in webpack. This loader uses options specified in .babelrc so whenever webpack is ran, babel-istanbul-plugin is executed as well which was adding all the test coverage related information into the bundle file.

I have to disable this option while running webpack. Here's how is configured it.

{
  test: /\.jsx?/,
  include: APP_DIR,
  use: {
    loader: 'babel-loader',
    options: {
      babelrc: false
    },
  },
}