Skip to content
This repository has been archived by the owner on Jun 23, 2018. It is now read-only.

Commit

Permalink
Setting up Karma with Sprockets
Browse files Browse the repository at this point in the history
  • Loading branch information
ssaunier committed Feb 4, 2014
1 parent 1b425ec commit 058bc21
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,3 +14,4 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
node_modules
31 changes: 31 additions & 0 deletions lib/tasks/karma.rake
@@ -0,0 +1,31 @@
namespace :karma do
task :start => :environment do
with_tmp_config :start
end

task :run => :environment do
with_tmp_config :start, "--single-run"
end

private

def with_tmp_config(command, args = nil)
Tempfile.open('karma_unit.js', Rails.root.join('tmp') ) do |f|
f.write unit_js(application_spec_files)
f.flush

system "karma #{command} #{f.path} #{args}"
end
end

def application_spec_files
sprockets = Rails.application.assets
sprockets.append_path Rails.root.join("spec/karma")
files = Rails.application.assets.find_asset("application_spec.js").to_a.map {|e| e.pathname.to_s }
end

def unit_js(files)
unit_js = File.open('spec/karma/config/unit.js', 'r').read
unit_js.gsub "APPLICATION_SPEC", "\"#{files.join("\",\n\"")}\""
end
end
9 changes: 9 additions & 0 deletions package.json
@@ -0,0 +1,9 @@
{
"name": "weroom-app",
"dependencies" : {
"karma": ">= 0.10.9",
"karma-jasmine": "0.1.5",
"karma-ng-scenario": "0.1.0",
"phantomjs": "1.9.7-1"
}
}
Empty file.
Empty file.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions spec/karma/application_spec.js
@@ -0,0 +1,3 @@
//= require angular
//= require angular-mocks
//= require application
75 changes: 75 additions & 0 deletions spec/karma/config/unit.js
@@ -0,0 +1,75 @@
// Karma configuration
// Generated on Mon Feb 03 2014 16:16:15 GMT+0100 (CET)

module.exports = function(config) {
config.set({

// base path, based on tmp/ folder
basePath: '..',


// frameworks to use
frameworks: ['jasmine', 'ng-scenario'],


// list of files / patterns to load in the browser
files: [
"/usr/local/var/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/turbolinks-2.2.1/lib/assets/javascripts/turbolinks.*",
'app/assets/javascripts/angular/*/*.{coffee,js}',
'spec/javascripts/**/*_spec.{coffee,js}'
],

// list of files to exclude
exclude: [

],


// 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: ['PhantomJS'],


// 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,

// Preprocessors
preprocessors: {
'/**/*.coffee':'coffee'
}

});
};

0 comments on commit 058bc21

Please sign in to comment.