Preprocessors in Karma allow you to do some work with your files before
they get served to the browser. These are configured in the preprocessors
block
of the configuration file:
preprocessors: {
'**/*.coffee': ['coffee'],
'**/*.tea': ['coffee'],
'**/*.html': ['html2js']
},
window.__html__['template.html']
. Learn more.base/
added to beginning of their path reference. See discussion in issue 788.Here's an example of how to add the CoffeScript preprocessor to your testing suite:
# Install it first with NPM
$ npm install karma-coffee-preprocessor --save-dev
And then inside your configuration file...
module.exports = function(config) {
config.set({
preprocessors: {
'**/*.coffee': ['coffee']
}
});
};
Of course, you can write custom plugins too!
Some of the preprocessors can be also configured:
coffeePreprocessor: {
options: {
bare: false
}
}
Or define a configured preprocessor:
customPreprocessors: {
bare_coffee: {
base: 'coffee',
options: {bare: true}
}
}
The keys of the preprocessors config object are used to filter the files specified in
the files
configuration.
basePath
configuration and the directory of the configuration file. See
files for more information on that.So for example the path /my/absolute/path/to/test/unit/file.coffee
matched against
the key **/*.coffee
would return true
, but matched against just *.coffee
it would
return false
and the preprocessor would not be executed on the CoffeeScript files.