nutra-jasmine-coverage-babel-preset
raw JSON → 0.0.10 verified Fri May 01 auth: no javascript
A preset for the N.U.T.R.A. unit test runner combining Jasmine, Babel transpilation, Istanbul code coverage, and CommonJS module loading. Current stable version is 0.0.10. It simplifies configuration by bundling these tools into a single preset. Designed specifically for the N.U.T.R.A. test runner ecosystem, it is not a general-purpose tool.
Common errors
error Cannot find module 'nutra' ↓
cause nutra is not installed or not in package.json devDependencies.
fix
Run: npm install --save-dev nutra
error Error: No provider for "framework:nutra-jasmine" ↓
cause nutra-jasmine-coverage-babel-preset is not installed or not registered.
fix
Run: npm install --save-dev nutra-jasmine-coverage-babel-preset
error TypeError: config.set is not a function ↓
cause nutra.config.js does not export a function that accepts a config object.
fix
Ensure module.exports = function(config) { ... };
Warnings
deprecated Babel 6 support is deprecated, upgrade to Babel 7 or later. ↓
fix Use separate Babel preset compatible with Babel 7.
gotcha The preset requires both nutra and nutra-jasmine-coverage-babel-preset to be installed as devDependencies. ↓
fix Ensure both are in devDependencies.
gotcha The configuration uses CommonJS (module.exports) and is not compatible with ES modules. ↓
fix Use CommonJS syntax in nutra.config.js.
gotcha The preset does not support TypeScript; it only transpiles ES6/ES7 JavaScript. ↓
fix Use a separate TypeScript preset if needed.
Install
npm install nutra-jasmine-coverage-babel-preset yarn add nutra-jasmine-coverage-babel-preset pnpm add nutra-jasmine-coverage-babel-preset Imports
- nutra.config.js (module.exports = function config) { config.set({...}) })
// nutra.config.js module.exports = function(config) { config.set({ frameworks: ['nutra-jasmine'], files: ['test/specs/**/*.js', 'src/**/*.js'], preprocessors: { 'test/specs/**/*.js': ['nutra-babel'], 'src/**/*.js': ['nutra-babel', 'nutra-coverage'] }, reporters: ['nutra-coverage'] }); };
Quickstart
// Install preset
npm install --save-dev nutra nutra-jasmine-coverage-babel-preset
// Create nutra.config.js
module.exports = function(config) {
config.set({
frameworks: ['nutra-jasmine'],
files: ['test/specs/**/*.js', 'src/**/*.js'],
preprocessors: {
'test/specs/**/*.js': ['nutra-babel'],
'src/**/*.js': ['nutra-babel', 'nutra-coverage']
},
reporters: ['nutra-coverage'],
babelOptions: {
configFile: './.babelrc'
},
coverageOptions: {
reporters: [{ type: 'html', subdir: '.' }]
}
});
};
// Write a sample spec
// test/specs/exampleSpec.js
describe('Sample', function() {
it('should pass', function() {
expect(1 + 1).toBe(2);
});
});
// Run tests
npx nutra run