isparta

raw JSON →
4.1.1 verified Sat Apr 25 auth: no javascript deprecated

A code coverage tool for ES6 using Babel, built on top of Istanbul. Latest version is 4.1.1, released to support Babel 6.x. The project is unmaintained as of 2016 and deprecated in favor of Istanbul with its own Babel support. It provides CLI and Karma integration for instrumenting ES6 code, but lacks updates and may not work with modern Babel versions. Consider using babel-plugin-istanbul or @istanbuljs/nyc-config-babel instead.

error SyntaxError: Unexpected token import
cause Running isparta CLI with node instead of babel-node
fix
Use babel-node node_modules/.bin/isparta cover ...
error Error: Cannot find module 'babel-core'
cause Missing babel-core dependency
fix
Install babel-core: npm install --save-dev babel-core
error TypeError: Cannot read property 'babel' of undefined
cause Incorrect Karma configuration; instrumenterOptions missing
fix
Check karma-coverage fork and use proper instrumenterOptions: { isparta: { babel: { presets: ['es2015'] } } }
error Error: Coverage file could not be written
cause Incompatibility between istanbul version and isparta
fix
Use isparta@3.5.3 with istanbul@0.4.0 or check node_modules for conflicts
deprecated isparta is no longer maintained. Use babel-plugin-istanbul or @istanbuljs/nyc-config-babel instead.
fix Switch to nyc with babel-plugin-istanbul: npm install --save-dev nyc babel-plugin-istanbul
breaking Babel 6 support changed in v4.0.0; requires babel-core@6 and presets.
fix If using Babel 5, stick with isparta@3.x. For Babel 6+, use isparta@4.x with appropriate presets.
gotcha CLI must be run via babel-node; otherwise it fails with SyntaxError on ES6 modules.
fix Use npx babel-node node_modules/.bin/isparta ... or add to scripts in package.json with babel-node.
breaking Karma integrator requires a specific fork of karma-coverage; official karma-coverage may not work.
fix Use douglasduteil/karma-coverage#next or upgrade to nyc and karma-nyc-reporter.
gotcha Options like --include and --exclude may not work as expected due to underlying istanbul compatibility.
fix Test thoroughly; consider using .istanbul.yml for configuration but beware of breaking changes.
npm install isparta
yarn add isparta
pnpm add isparta

Demonstrates installation, Babel configuration, CLI usage, and Karma integration for ES6 code coverage.

// Install dependencies
npm install --save-dev isparta babel-core babel-preset-es2015 mocha

// Create a .babelrc file
// { "presets": ["es2015"] }

// Run coverage with isparta CLI
npx babel-node node_modules/isparta/bin/isparta cover --report text --report html node_modules/mocha/bin/_mocha -- --reporter dot

// For Karma, add to karma.conf.js:
// coverageReporter: {
//   instrumenters: { isparta: require('isparta') },
//   instrumenter: { '**/*.js': 'isparta' }
// }