Skip to content

Instantly share code, notes, and snippets.

@thomassuckow
Last active June 18, 2017 13:26
Show Gist options
  • Save thomassuckow/6372324 to your computer and use it in GitHub Desktop.
Save thomassuckow/6372324 to your computer and use it in GitHub Desktop.
Using karma to load requirejs tests with the .spec.js suffix. Note the base url needs the / otherwise karma-requirejs will whine about no timestamp (paths will differ) We mangle the files list to be relative, otherwise using relative paths in the form of "./bar" will fail. In my use case I have a shared config.js file that has more configuration…
var tests = Object.keys(window.__karma__.files).filter(function (file) {
return /\.spec\.js$/.test(file);
}).map(function(file){
return file.replace(/^\/base\/src\/js\/|\.js$/g,'');
});
require.config({
baseUrl: '/base/src/js',
paths: {
"lib":"../../target/js/lib"
}
});
require(['config'],function(){
require(tests, function(){
window.__karma__.start();
});
});
var tests = Object.keys(window.__karma__.files).filter(function (file) {
return /\.spec\.js$/.test(file);
}).map(function(file){
return file.replace(/^\/base\/src\/js\/|\.js$/g,'');
});
require.config({
baseUrl: '/base/src/js'
});
require(tests, function(){
window.__karma__.start();
});
@anson-vandoren
Copy link

Thanks so much! This really helped me get my Karma/Require configuration straightened out... After 12 hours of searching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment