mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-11 18:26:50 +00:00
Run karma task only in test environment
and fails otherwise, as it needs the defaults defined in test environment
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -14,4 +14,4 @@ echo "--- Bundling"
|
||||
bundle install
|
||||
|
||||
echo "--- Running tests"
|
||||
bundle exec rake karma:run
|
||||
./script/karma run
|
||||
|
||||
13
script/karma
Executable file
13
script/karma
Executable 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
|
||||
|
||||
Reference in New Issue
Block a user