Skip to content

Instantly share code, notes, and snippets.

@merqlove
Forked from jr314159/karma.coffee.erb
Created June 10, 2014 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merqlove/f041b039400f392f83a4 to your computer and use it in GitHub Desktop.
Save merqlove/f041b039400f392f83a4 to your computer and use it in GitHub Desktop.
# Karma configuration
# Generated on Tue Aug 20 2013 16:26:25 GMT-0400 (EDT)
module.exports = (config) ->
config.set
# base path, that will be used to resolve all patterns, eg. files, exclude
basePath: '..'
# frameworks to use
frameworks: ['jasmine']
# list of files / patterns to load in the browser
files: [
'http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.js'
'http://code.angularjs.org/1.2.1/angular-mocks.js'
'http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.js'
'http://localhost:<%= @port %>/assets/spec.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
# - Safari (only Mac)
# - PhantomJS
# - IE (only Windows)
browsers: ['PhantomJS']
# If browser does not capture in given timeout [ms], kill it
captureTimeout: 10000
# Continuous Integration mode
# if true, it capture browsers, run tests and exit
singleRun: false
require 'open3'
namespace :test do
desc 'Run all javascript tests with Karma'
task :karma => :environment do
# Use capybara to boot up a rails server for us,
# and configure sprockets to serve javascripts from the spec directory
Rails.application.assets.append_path Rails.root.join('spec', 'javascripts')
server = Capybara::Server.new(Rails.application).boot
puts "Booted Rails test server on port #{server.port}"
Dir.mktmpdir do |dir|
# Generate a temp karma configuration file from our template in config/karma.coffee.erb.
# We're just doing this to stick the server port in, but could add a dynamic list of files too:
view = ActionView::Base.new(Rails.root.join('config'))
view.assign(port: server.port)
karma_conf = File.join(dir, "karma.coffee")
File.open(karma_conf, 'w') { |file| file.write view.render(template: 'karma.coffee.erb') }
puts "Running karma with configuration file #{karma_conf}"
Open3.popen2e("karma start #{karma_conf} --single-run") do |stdin, stdout_and_stderr, wait_thr|
puts stdout_and_stderr.gets(nil)
raise 'Karma tests failed' unless wait_thr.value.success?
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment