From f9c0edf4b92255cb109b72836d99a9ee016898d9 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 9 Aug 2017 18:21:25 +0200 Subject: [PATCH] Always execute local karma This ensure the dev will run the version specified in the package.json. Besides, makes the rake task work as all rails tests, allowing you to pass a RAILS_ENV. --- lib/tasks/karma.rake | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/tasks/karma.rake b/lib/tasks/karma.rake index 3755dacc63..7cc245cfa4 100644 --- a/lib/tasks/karma.rake +++ b/lib/tasks/karma.rake @@ -1,28 +1,22 @@ +ENV["RAILS_ENV"] ||= 'test' + namespace :karma do - task :start => :environment do |task| - continue_only_in_test_env task + task :start => :environment do |_task| with_tmp_config :start end - task :run => :environment do |task| - continue_only_in_test_env task + task :run => :environment do |_task| with_tmp_config :start, "--single-run" end private - def continue_only_in_test_env task - if Rails.env != 'test' - raise "Task must be called in test environment:\n bundle exec rake #{task.name} RAILS_ENV=test" - end - end - 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 << i18n_file) f.flush trap('SIGINT') { puts "Killing Karma"; exit } - exec "karma #{command} #{f.path} #{args}" + exec "node_modules/.bin/karma #{command} #{f.path} #{args}" end end