Created
November 2, 2014 15:41
-
-
Save 0xorial/bdd3f430e00cc3df4fd7 to your computer and use it in GitHub Desktop.
using assets from gems with karma-sprockets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require('fs'); | |
path = require('path'); | |
glob = require('/home/ironic/.nvm/v0.11.14/lib/node_modules/glob'); | |
util = require('util'); | |
path.deepdir = function (_path, count) { | |
var result = _path; | |
for (var i = 0; i < count; i++) | |
result = path.dirname(result); | |
return result; | |
}; | |
module.exports = function (config) { | |
var rubyGemsPath = '/home/ironic/.rvm/gems/ruby-2.1.0/gems'; | |
var folders = ['app/assets/javascripts', 'lib/assets/javascripts', 'vendor/assets/javascripts']; | |
var paths = []; | |
var engineLocations = [ | |
{ path: 'lib/*/rails/engine.rb', deep: 4}, | |
{path: 'lib/turbolinks.rb', deep: 2} | |
]; | |
engineLocations.forEach(function(engine){ | |
var search = path.join(rubyGemsPath, '*/' + engine.path); | |
console.log('searching for: '+ search); | |
var files = glob.sync(search); | |
files.forEach(function (file) { | |
var folder = path.deepdir(file, engine.deep); | |
console.log('file: '+ file); | |
console.log('folder: '+ folder); | |
var gemFolders = folders.map(function (item) { | |
return path.join(folder, item) | |
}); | |
gemFolders = gemFolders.filter(function (folder) { | |
return fs.existsSync(folder); | |
}); | |
paths = paths.concat(gemFolders); | |
}); | |
}); | |
paths.forEach(function (dir) { | |
console.log(dir); | |
}); | |
var included = function (file) { | |
return {pattern: file, included: true}; | |
}; | |
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: ['jasmine', 'sprockets'], | |
sprocketsPath: paths.concat([ | |
'vendor/assets/javascripts', | |
'app/assets/javascripts' | |
]), | |
sprocketsBundles: [ | |
'application.js.coffee' | |
], | |
// list of files / patterns to load in the browser | |
files: [ | |
included('app/assets/javascripts/**/*.coffee'), | |
included('spec/javascripts/**/*helper.coffee'), | |
'spec/javascripts/**/*_spec.coffee' | |
], | |
// list of files to exclude | |
exclude: [ | |
], | |
// preprocess matching files before serving them to the browser | |
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | |
preprocessors: { | |
'**/*.coffee': ['coffee'] | |
}, | |
coffeePreprocessor: { | |
options: { bare: true, sourceMap: true | |
} | |
}, | |
// 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: ['Chrome'], | |
// Continuous Integration mode | |
// if true, Karma captures browsers, runs the tests and exits | |
singleRun: false | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment