Skip to content

Instantly share code, notes, and snippets.

@novemberborn
Created November 26, 2015 12:11
Show Gist options
  • Save novemberborn/e133e9edabbb380229ca to your computer and use it in GitHub Desktop.
Save novemberborn/e133e9edabbb380229ca to your computer and use it in GitHub Desktop.
Code Coverage with Babel, Istanbul & NYC
#!/bin/bash
set -e
# Shell script to compute code coverage even after the Babel transforms have
# been applied.
# Clear previous coverage.
rm -rf coverage
# Generate test coverage based on however `npm test` performs the tests.
nyc --reporter=json npm test
# Move generated JSON file so it can be remapped and won't confuse Istanbul
# later.
mv coverage/coverage-final.json coverage/coverage.json
# Rewrite the coverage file taking the Babel source maps into account.
remap-istanbul -i coverage/coverage.json -o coverage/coverage.json
# Generate an lcov.info file and an HTML report, and output a text report.
istanbul report lcov text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment