Skip to content

Instantly share code, notes, and snippets.

@RubenCordeiro
Created July 23, 2014 14:14
Show Gist options
  • Save RubenCordeiro/37771cd5329b8106e036 to your computer and use it in GitHub Desktop.
Save RubenCordeiro/37771cd5329b8106e036 to your computer and use it in GitHub Desktop.
// Karma configuration, placed in the root of the project
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'requirejs'],
// list of files / patterns to load in the browser
files: [
'test/test-main.js',
{pattern: 'src/**/*.js', included: false }
{pattern: 'test/**/*Spec.js', included: false}
],
// list of files to exclude
exclude: [
'src/js/main.js',
'src/js/bootstrap.js',
'src/js/services/module.js',
'src/js/all.js'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
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
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
requirejs(['require-config'], function() {
// RequireJS has been configured. It's now safe to load application code.
requirejs(['bootstrap'], function(bootstrap) {
// "main" logic
});
});
/* I moved the requirejs configuration to a separate file in order to share it with the test setup with having to
duplicate the code.
*/
requirejs.config({
// Application configuration option
paths: {
'domReady': '../lib/requirejs-domready/domReady',
'angular': '../lib/angular/angular',
'angular-ui-router': '../lib/angular-ui-router/release/angular-ui-router',
'text': '../lib/requirejs-text/text',
'_': '../lib/lodash/dist/lodash',
'$': '../lib/jquery/jquery',
'angular-bootstrap': '../lib/angular-bootstrap/ui-bootstrap',
'angular-bootstrap-tmpls': '../lib/angular-bootstrap/ui-bootstrap-tpls',
'moment': '../lib/moment/moment',
'angular-animate': '../lib/angular-animate/angular-animate',
'angular-ui-sortable': '../lib/angular-ui-sortable/sortable',
'jquery-ui': '../lib/jquery-ui/ui/jquery-ui',
'angular-moment': '../lib/angular-moment/angular-moment',
'angular-ui-utils-keypress': '../lib/angular-ui-utils/keypress',
'hello': '../lib/hello/dist/hello.all'
},
/**
* for libs that either do not support AMD out of the box, or
* require some fine tuning to dependency mgt'
*/
shim: {
'angular': {
exports: 'angular'
},
'angular-ui-router': {
deps: ['angular']
},
'_': {
exports: '_'
},
'angular-bootstrap-tmpls': {
deps: ['angular']
},
'angular-bootstrap': {
deps: ['angular', '$', 'angular-bootstrap-tmpls']
},
'moment': {
exports: 'moment'
},
'angular-animate': {
deps: ['angular']
},
'angular-ui-sortable': {
deps: ['angular', 'jquery-ui']
},
'jquery-ui': {
deps: ['$']
},
'angular-moment': {
deps: ['moment', 'angular']
},
'angular-ui-utils-keypress': {
deps: ['angular']
}
}
});
var tests = [];
for (var file in window.__karma__.files) {
if (/Spec\.js$/.test(file)) { // every test file should end up in Spec for this configuration
tests.push(file);
}
}
// reference the requirejs configuration
require.config({
baseUrl: '/base/src/js',
deps: ['/base/src/js/require-config.js'],
callback: function() {
'use strict';
require(tests, window.__karma__.start);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment