mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-26 05:55:15 +00:00
Setting up a Rake task for Jasmine/Karma
This commit is contained in:
31
lib/tasks/karma.rake
Normal file
31
lib/tasks/karma.rake
Normal file
@@ -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/javascripts")
|
||||
files = Rails.application.assets.find_asset("application_spec.js").to_a.map {|e| e.pathname.to_s }
|
||||
end
|
||||
|
||||
def unit_js(files)
|
||||
puts files
|
||||
unit_js = File.open('config/ng-test.conf.js', 'r').read
|
||||
unit_js.gsub "APPLICATION_SPEC", "\"#{files.join("\",\n\"")}\""
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user