Preprocessor for react jsx files
The easiest way is to keep karma-react-preprocessor
as a devDependency in your package.json
.
{
"devDependencies": {
"karma": "~0.10",
"karma-react-preprocessor": "~0.1"
}
}
You can simple do it by:
npm install karma-react-preprocessor --save-dev
Following code shows the default configuration...
// karma.conf.js
module.exports = function(config) {
config.set({
preprocessors: {
'**/*.jsx': ['react']
}
});
};
By default preprocessor transform extension from jsx to js. You can change it by:
// karma.conf.js
module.exports = function(config) {
config.set({
preprocessors: {
'**/*.jsx': ['react']
},
reactPreprocessor: {
transformPath: function(path) {
return path.replace(/\.jsx$/, '.js');
}
}
});
};
You can pass an options object that will be passed to react-tools module. See available options.
// karma.conf.js
module.exports = function(config) {
config.set({
preprocessors: {
'**/*.jsx': ['react']
},
reactPreprocessor: {
harmony: true,
es6module: true
}
});
};
You can look at karma.conf.js how example
For more information on Karma see the homepage.