Skip to content

Instantly share code, notes, and snippets.

@coderbyheart
Last active November 16, 2020 09:51
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderbyheart/2b947fd09d93b58356ebeb009df233cb to your computer and use it in GitHub Desktop.
Save coderbyheart/2b947fd09d93b58356ebeb009df233cb to your computer and use it in GitHub Desktop.
Code coverage with Mocha and ES6 code

// package.json

{
  "scripts": {
    "test": "mocha --require babel-polyfill --compilers js:babel-register --reporter=dot --timeout=1350 test/\\*\\*/\\*.js",
    "test:coverage": "NODE_ENV=nyc babel src --out-dir instrumented-src && nyc --reporter=text-summary --reporter=lcov npm run test",
  },
  "devDependencies": {
    "babel-cli": "^6.18.0",
    "babel-plugin-istanbul": "^3.0.0",
    "babel-polyfill": "^6.16.0",
    "babel-preset-es2015": "^6.18.0",
    "babel-register": "^6.18.0",
    "mocha": "^3.2.0",
    "nyc": "^10.0.0"
  }
}

// .babelrc

{
  "presets": [
    "es2015"
  ],
  "env": {
    "nyc": {
      "plugins": [
        "istanbul"
      ]
    }
  }
}

// .nyc

{
  "reporter"   : ["text", "text-summary", "lcov", "html"],
  "include"    : ["src/**/*.js"],
  "require"    : ["babel-register"],
  "sourceMap"  : false,
  "instrument" : false,
  "all"        : true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment