Skip to content

Instantly share code, notes, and snippets.

@grassdog
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grassdog/4afec303a8a309bb72de to your computer and use it in GitHub Desktop.
Save grassdog/4afec303a8a309bb72de to your computer and use it in GitHub Desktop.
Example karma config for running jasmine tests that uses webpack to support jsx.
/**
* This is the Karma configuration file. It contains information about this skeleton
* that provides the test runner with instructions on how to run the tests and
* generate the code coverage report.
*
* For more info, see: http://karma-runner.github.io/0.12/config/configuration-file.html
*/
module.exports = function(config) {
config.set({
/**
* These are the files required to run the tests.
*
* The `Function.prototype.bind` polyfill is required by PhantomJS
* because it uses an older version of JavaScript.
*/
files: [
'./app/assets/javascripts/test/polyfill.js',
'./app/assets/javascripts/**/__tests__/*Spec.js'
],
/**
* The actual tests are preprocessed by the karma-webpack plugin, so that
* their source can be properly transpiled.
*/
preprocessors: {
'./app/assets/javascripts/**/__tests__/*Spec.js': ['webpack'],
},
/**
* We want to run the tests using the PhantomJS headless browser.
* This is especially useful for continuous integration.
*/
browsers: ['PhantomJS'],
/**
* Use Mocha as the test framework, Sinon for mocking, and
* Chai for assertions.
*/
frameworks: ['jasmine', 'jasmine-matchers'],
/**
* After running the tests, return the results and generate a
* code coverage report.
*/
reporters: ['mocha'],
/**
* The configuration for the karma-webpack plugin.
*
* This is very similar to the main webpack.local.config.js, with the
* exception of specifying an istanbul-transformer post loader so
* that we can generate an accurate code coverage report.
*/
webpack: {
context: __dirname + '/app/assets/javascripts',
module: {
loaders: [
{ test: /\.jsx?$/, exclude: /node_modules/, loader: "jsx-loader?harmony"}
]
},
resolve: {
extensions: ['', '.js', '.jsx']
}
},
/**
* Configuration option to turn off verbose logging of webpack compilation.
*/
webpackMiddleware: {
noInfo: true
},
/**
* Once the mocha test suite returns, we want to exit from the test runner as well.
*/
singleRun: true,
/**
* List of plugins
*/
plugins: [
'karma-webpack',
'karma-jasmine',
'karma-jasmine-matchers',
'karma-phantomjs-launcher',
'karma-mocha-reporter'
],
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment