Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Last active May 21, 2024 06:51
Show Gist options
  • Select an option

  • Save wilmoore/da6ddcf88a0b413d036bce4e8d9f39fd to your computer and use it in GitHub Desktop.

Select an option

Save wilmoore/da6ddcf88a0b413d036bce4e8d9f39fd to your computer and use it in GitHub Desktop.
Software Engineering :: Programming :: Languages :: JavaScript :: TypeScript :: Test Coverage - Istanbul

Software Engineering :: Programming :: Languages :: JavaScript :: TypeScript :: Test Coverage - Istanbul

Made with ♥ by Polyglot.

Node.JS, Mocha, NYC

> npm install --save-dev @istanbuljs/nyc-config-typescript nyc mocha
> echo '**/.nyc_output' >> .npmignore
package.json
   "scripts": {
+    "test:w": "mocha ./.mocharc.js 'src/**/*.spec.ts' --watch",
+    "test": "nyc -s mocha ./.mocharc.js 'src/**/*.spec.ts' && npm run coverage:report",
+    "coverage:report": "nyc report --temp-dir './public/.nyc_output' --report-dir './public' --reporter html --reporter text",
+    "coverage:report:view": "open ./public/index.html",
   },

+  "nyc": {
+    "extends": "@istanbuljs/nyc-config-typescript",
+    "check-coverage": true,
+    "all": true,
+    "include": [
+        "src/lib/**/!(*.spec.*).[tj]s?(x)"
+    ],
+    "exclude": [
+        "src/lib/test/**/*.*"
+    ],
+    "reporter": [
+        "html",
+        "lcov",
+        "text",
+        "text-summary"
+    ],
+    "report-dir": "coverage"
+  }
.mochrc.js
"use strict"

module.exports = {
  "timeout": "10000",
  "reporter": "mochawesome",
  "extension": ["ts"],
  "require": ["ts-node/register"],
  "file": "src/test/init.ts",
  "enable-source-maps": true,
  "recursive": true,
  "exit": true,
  "fail-zero": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment