Last active
November 3, 2015 16:09
-
-
Save daino3/a39486ff8bfc1668e923 to your computer and use it in GitHub Desktop.
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
require 'pry' | |
namespace :karma do | |
task :start => :environment do | |
with_tmp_config :start | |
end | |
task :run => :environment do | |
exit with_tmp_config :start, "--single-run" | |
end | |
private | |
def with_tmp_config(command, args = nil) | |
# by default karma looks for a file name "karma.conf.js" so let's not reinvent the wheel here | |
File.open(Rails.root.join('karma.conf.js'), 'w') do |f| | |
f.write unit_js(application_spec_files) | |
f.flush | |
# karma.conf.js should be in root directory that the command is run in. | |
# supplying the file path may work locally, but was giving me issues on | |
# a remote builder | |
system "./node_modules/karma/bin/karma #{command} #{args}" | |
end | |
end | |
def application_spec_files | |
Rails.application.assets.each_file.select { |pathname| pathname.match(/spec\/javascripts\/app/) } | |
end | |
def unit_js(files) | |
unit_js = File.open('spec/javascripts/karma/config/unit.js', 'r').read | |
unit_js.gsub "APPLICATION_SPEC", "\"#{files.join("\",\n\"")}\"" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment