A fast browserify integration for Karma that handles large projects with ease
Get the plug-in via npm.
npm install --save-dev karma-browserify browserify watchify
browserify as a framework to your Karma configuration file. For each file that should be processed and bundled by Karma, configure the
browserify preprocessor. Optionally use the
browserify config entry to configure how the bundle gets created.
karmasetframeworks: 'browserify' 'jasmine' 'or' 'any' 'other' 'framework'files: 'test/**/*.js'preprocessors:'test/**/*.js': 'browserify'browserify:debug: truetransform: 'brfs';
Test bundles can be configured through the
browserify Karma configuration property. Configuration options are passed directly to browserify.
For example to generate source maps for easier debugging, specify:
There are three properties that are not passed directly:
browserify:transform: 'reactify' 'coffeeify' 'brfs'// don't forget to register the extensionsextensions: '.js' '.jsx' '.coffee'
You can also specify options for the transformations:
browserify:transform: 'reactify' 'es6': true 'coffeeify' 'brfs'
The browserify plugin option supports the same syntax as
You may perform additional configuration in a function passed as the
configure option and that receives the browserify instance as an argument. A custom
prebundle event is emitted on the bundle right before a bundling operation takes place. This is useful when setting up things like externals:
You'll also need to use the
'prebundle' event for full control over the order of transforms and plugins:
Note that transforms must only be added once.
You can configure the underlying watchify instance via
config.watchify. This is helpful if you need to fine tune the change detection used during
This project is a preprocessor for Karma that combines test files and dependencies into a browserified bundle. It relies on watchify to generate the bundle and to keep it updated during
Before the initial test run we build one browserify bundle for all test cases and dependencies. Once any of the files change, it incrementally updates the bundle. Each file included in Karma is required from the file bundle via a stub. Thereby it ensures tests are only executed once per test run.
The following code snippet shows a Karma configuration file with all browserify-related options.
karmaset// include browserify first in used frameworksframeworks: 'browserify' 'jasmine'// add all your files here,// including non-commonJS files you need to load before your test casesfiles:'some-non-cjs-library.js''test/**/*.js'// add preprocessor to the files that should be// processed via browserifypreprocessors:'test/**/*.js': 'browserify'// see what is going onlogLevel: 'LOG_DEBUG'// use autoWatch=true for quick and easy test re-execution once files changeautoWatch: true// add additional browserify configuration properties here// such as transform and/or debug=true to generate source mapsbrowserify:debug: truetransform: 'brfs'bundleon'prebundle'bundleexternal'foobar';;;;
Credit goes to to the original karma-browserify and karma-browserifast. This library builds on the lessons learned in these projects and offers improved configurability, speed and/or the ability to handle large projects.