Skip to content

Instantly share code, notes, and snippets.

@alex-ross
Last active December 30, 2015 15:49
Show Gist options
  • Save alex-ross/7851090 to your computer and use it in GitHub Desktop.
Save alex-ross/7851090 to your computer and use it in GitHub Desktop.
Example of unit.js file for karma in rails applications. This should allow tests to be written in both coffescript or javascript
/**
* Karma configuration
*
* Enables tests to be written in both javascript and coffeescript.
*
* Run your tests with: `karma start spec/karma/config/unit.js`
*
* Place your tests in similar paths: `spec/javascripts/<anydir>/<file>_spec.coffee`
* This file should be in: `spec/karma/config/unit.js`
*
* TODO:
* - For now "localhost:3000" is static in the file. This will prevent other developers to use pow or other ports.
* - While using rails server to host an compiled "application.js" file we wont get valid backtraces.
*/
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '../../..',
// frameworks to use
frameworks: ['jasmine'],
preprocessors: {
'spec/javascripts/**/*.coffee': ['coffee']
},
coffeePreprocessors: {
options: {
bare: true,
sourceMap: false
},
transformPath: function(path) {
return path.replace(/\.js$/, 'coffee');
}
},
// list of files / patterns to load in the browser
files: [
'http://localhost:3000/assets/application.js',
'spec/javascripts/*_spec.js',
'spec/javascripts/*_spec.coffee',
// Watch for changes in assets without serving them.
{ pattern: 'app/assets/javascripts/**/*.js',
watched: true,
included: false,
served: false }
],
// list of files to exclude
exclude: [
'**/*.swp'
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera (has to be installed with `npm install karma-opera-launcher`)
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
// - PhantomJS
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
browsers: ['Chrome'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment