karma-bro
Bro is a fast browserify integration for Karma that handles large projects with ease.
Installation
Get the plug-in via npm
npm install --save-dev karma-bro
Usage
Add 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.
module.exports = function(karma) {
karma.set({
frameworks: [ 'browserify', 'any', 'other', 'framework' ],
preprocessors: {
'test/**/*.js': [ 'browserify' ]
},
browserify: {
debug: true,
transform: [ 'brfs' ]
}
});
}
Look at the example directory for a simple browserify + jasmine project that uses this plug-in.
Browserify Config
The way Bro creates browserified test bundles can be tuned through the browserify
configuration property. The following configuration options are supported:
- extensions
- builtins
- basedir
- commondir
- transform
- plugin
Generate Source Maps
Specify debug: true
in the browserify options to generate source maps for easier debugging.
Additional Bundle Configuration
You may perform additional configuration in a function that you pass as the prebundle
option and that receives the bundle as an argument. This is useful when you need to set up things like externals:
module.exports = function(karma) {
karma.set({
browserify: {
prebundle: function(bundle) {
bundle.external('foobar');
}
}
});
};
How it Works
Bro 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 autoWatch=true
.
Before the initial test run Bro builds 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.
Detailed Configuration
The following code snippet shows a Karma configuration file with all Bro related options.
module.exports = function(karma) {
karma.set({
frameworks: [ 'browserify', 'jasmine' ],
files: [
'some-non-cjs-library.js',
'test/**/*.js'
],
preprocessors: {
'test/**/*.js': [ 'browserify' ]
},
logLevel: 'LOG_DEBUG',
autoWatch: true,
browserify: {
debug: true,
transform: [ 'brfs' ],
prebundle: function(bundle) {
bundle.external('foobar');
}
}
});
};
Related
Credit goes to to karma-browserify and karma-browserifast. Bro builds on the lessons learned in these projects and offers improved configurability, speed and/or the ability to handle large projects.
Maintainers
License
MIT