Run karma task only in test environment

and fails otherwise, as it needs the defaults defined in test environment
This commit is contained in:
Em-AK
2017-03-29 04:58:37 +02:00
committed by Maikel
parent 78ffdec693
commit c72d17dc83
4 changed files with 32 additions and 3 deletions

View File

@@ -98,6 +98,14 @@ The site is configured to use
startup time while Rails loads. See the Zeus github page for
usage instructions.
Once [npm dependencies are
installed](https://github.com/openfoodfoundation/openfoodnetwork/wiki/Karma), AngularJS tests can be run with:
./script/karma run
If you want karma to automatically rerun the tests on file modification, use:
./script/karma start
## Credits

View File

@@ -1,14 +1,22 @@
namespace :karma do
task :start => :environment do
task :start => :environment do |task|
continue_only_in_test_env task
with_tmp_config :start
end
task :run => :environment do
task :run => :environment do |task|
continue_only_in_test_env 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)

View File

@@ -14,4 +14,4 @@ echo "--- Bundling"
bundle install
echo "--- Running tests"
bundle exec rake karma:run
./script/karma run

13
script/karma Executable file
View File

@@ -0,0 +1,13 @@
#!/bin/sh
task="$1"
if [ "$task" = "run" ] || [ "$task" = "start" ]; then
exec bundle exec rake "karma:$task" RAILS_ENV=test
else
echo "Usage:"
echo " $0 run # to run the tests once"
echo " $0 start # to run the tests on every file modification"
exit 1
fi