From b2b6ca5f7ba5acd89bb8e2e0b4704db6d1edc2fa Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 15 May 2013 13:10:52 -0400 Subject: [PATCH] Record junit reports of jasmine tests --- cms/envs/jasmine.py | 7 ++- common/lib/capa/jasmine_test_runner.html.erb | 48 ------------------- common/templates/jasmine/base.html | 8 ++-- .../jasmine/jasmine_test_runner.html.erb | 29 ++--------- common/test/phantom-jasmine | 1 - jenkins/test.sh | 2 +- lms/envs/jasmine.py | 7 ++- package.json | 3 +- rakefiles/jasmine.rake | 33 ++++++------- requirements/edx/base.txt | 2 + 10 files changed, 41 insertions(+), 99 deletions(-) delete mode 100644 common/lib/capa/jasmine_test_runner.html.erb delete mode 160000 common/test/phantom-jasmine diff --git a/cms/envs/jasmine.py b/cms/envs/jasmine.py index f3a982aa43..a4b8292d71 100644 --- a/cms/envs/jasmine.py +++ b/cms/envs/jasmine.py @@ -36,8 +36,13 @@ PIPELINE_JS['spec'] = { } JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee' +JASMINE_REPORT_DIR = os.environ.get('JASMINE_REPORT_DIR', 'reports/cms/jasmine') + +TEMPLATE_CONTEXT_PROCESSORS += ('settings_context_processor.context_processors.settings',) +TEMPLATE_VISIBLE_SETTINGS = ('JASMINE_REPORT_DIR', ) STATICFILES_DIRS.append(REPO_ROOT/'node_modules/phantom-jasmine/lib') +STATICFILES_DIRS.append(REPO_ROOT/'node_modules/jasmine-reporters/src') # Remove the localization middleware class because it requires the test database # to be sync'd and migrated in order to run the jasmine tests interactively @@ -45,4 +50,4 @@ STATICFILES_DIRS.append(REPO_ROOT/'node_modules/phantom-jasmine/lib') MIDDLEWARE_CLASSES = tuple(e for e in MIDDLEWARE_CLASSES \ if e != 'django.middleware.locale.LocaleMiddleware') -INSTALLED_APPS += ('django_jasmine', ) +INSTALLED_APPS += ('django_jasmine', 'settings_context_processor') diff --git a/common/lib/capa/jasmine_test_runner.html.erb b/common/lib/capa/jasmine_test_runner.html.erb deleted file mode 100644 index 7b078daedd..0000000000 --- a/common/lib/capa/jasmine_test_runner.html.erb +++ /dev/null @@ -1,48 +0,0 @@ - - - - Jasmine Test Runner - - - - - - - - - - - - - - - - - - - <% for src in js_source %> - - <% end %> - - - <% for src in js_specs %> - - <% end %> - - - - - - - - diff --git a/common/templates/jasmine/base.html b/common/templates/jasmine/base.html index 9a1b3bed92..0133edadfa 100644 --- a/common/templates/jasmine/base.html +++ b/common/templates/jasmine/base.html @@ -12,6 +12,7 @@ + {% load compressed %} {# static files #} @@ -37,15 +38,14 @@ + @@ -44,30 +45,10 @@ diff --git a/common/test/phantom-jasmine b/common/test/phantom-jasmine deleted file mode 160000 index a54d435b55..0000000000 --- a/common/test/phantom-jasmine +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a54d435b5556650efbcdb0490e6c7928ac75238a diff --git a/jenkins/test.sh b/jenkins/test.sh index d8cd2c1843..e8b032f195 100755 --- a/jenkins/test.sh +++ b/jenkins/test.sh @@ -82,7 +82,7 @@ rake test_common/lib/xmodule || TESTS_FAILED=1 rake phantomjs_jasmine_lms || TESTS_FAILED=1 rake phantomjs_jasmine_cms || TESTS_FAILED=1 rake phantomjs_jasmine_common/lib/xmodule || TESTS_FAILED=1 -rake phantomjs_jasmine_discussion || TESTS_FAILED=1 +rake phantomjs_jasmine_common/static/coffee || TESTS_FAILED=1 rake coverage:xml coverage:html diff --git a/lms/envs/jasmine.py b/lms/envs/jasmine.py index 2c30bc7de7..4a78ed8075 100644 --- a/lms/envs/jasmine.py +++ b/lms/envs/jasmine.py @@ -36,7 +36,12 @@ PIPELINE_JS['spec'] = { } JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee' +JASMINE_REPORT_DIR = os.environ.get('JASMINE_REPORT_DIR', 'reports/lms/jasmine') + +TEMPLATE_CONTEXT_PROCESSORS += ('settings_context_processor.context_processors.settings',) +TEMPLATE_VISIBLE_SETTINGS = ('JASMINE_REPORT_DIR', ) STATICFILES_DIRS.append(REPO_ROOT/'node_modules/phantom-jasmine/lib') +STATICFILES_DIRS.append(REPO_ROOT/'node_modules/jasmine-reporters/src') -INSTALLED_APPS += ('django_jasmine', ) +INSTALLED_APPS += ('django_jasmine', 'settings_context_processor') diff --git a/package.json b/package.json index 7fa287018a..2dd67d5be4 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "dependencies": { "coffee-script": "1.6.X", - "phantom-jasmine": "0.1.0" + "phantom-jasmine": "0.1.0", + "jasmine-reporters": "0.2.1" } } diff --git a/rakefiles/jasmine.rake b/rakefiles/jasmine.rake index 1e5050801e..4182bef9e2 100644 --- a/rakefiles/jasmine.rake +++ b/rakefiles/jasmine.rake @@ -48,6 +48,7 @@ def template_jasmine_runner(lib) sh("node_modules/.bin/coffee -c #{coffee_files.join(' ')}") end phantom_jasmine_path = File.expand_path("node_modules/phantom-jasmine") + jasmine_reporters_path = File.expand_path("node_modules/jasmine-reporters") common_js_root = File.expand_path("common/static/js") common_coffee_root = File.expand_path("common/static/coffee/src") @@ -58,6 +59,7 @@ def template_jasmine_runner(lib) js_specs = Dir[spec_glob].sort_by {|p| [p.split('/').length, p]} .map {|f| File.expand_path(f)} js_source = Dir[src_glob].sort_by {|p| [p.split('/').length, p]} .map {|f| File.expand_path(f)} + report_dir = report_dir_path("#{lib}/jasmine") template = ERB.new(File.read("common/templates/jasmine/jasmine_test_runner.html.erb")) template_output = "#{lib}/jasmine_test_runner.html" File.open(template_output, 'w') do |f| @@ -66,6 +68,11 @@ def template_jasmine_runner(lib) yield File.expand_path(template_output) end +def run_phantom_js(url) + phantomjs = ENV['PHANTOMJS_PATH'] || 'phantomjs' + sh("#{phantomjs} node_modules/jasmine-reporters/test/phantomjs-testrunner.js #{url}") +end + [:lms, :cms].each do |system| desc "Open jasmine tests for #{system} in your default browser" task "browse_jasmine_#{system}" => :assets do @@ -78,14 +85,16 @@ end desc "Use phantomjs to run jasmine tests for #{system} from the console" task "phantomjs_jasmine_#{system}" => :assets do - phantomjs = ENV['PHANTOMJS_PATH'] || 'phantomjs' django_for_jasmine(system, false) do |jasmine_url| - sh("#{phantomjs} node_modules/phantom-jasmine/lib/run_jasmine_test.coffee #{jasmine_url}") + run_phantom_js(jasmine_url) end end end -Dir["common/lib/*"].select{|lib| File.directory?(lib)}.each do |lib| +STATIC_JASMINE_TESTS = Dir["common/lib/*"].select{|lib| File.directory?(lib)} +STATIC_JASMINE_TESTS << 'common/static/coffee' + +STATIC_JASMINE_TESTS.each do |lib| desc "Open jasmine tests for #{lib} in your default browser" task "browse_jasmine_#{lib}" do template_jasmine_runner(lib) do |f| @@ -97,26 +106,14 @@ Dir["common/lib/*"].select{|lib| File.directory?(lib)}.each do |lib| desc "Use phantomjs to run jasmine tests for #{lib} from the console" task "phantomjs_jasmine_#{lib}" do - phantomjs = ENV['PHANTOMJS_PATH'] || 'phantomjs' template_jasmine_runner(lib) do |f| - sh("#{phantomjs} node_modules/phantom-jasmine/lib/run_jasmine_test.coffee #{f}") + run_phantom_js(f) end end end desc "Open jasmine tests for discussion in your default browser" -task "browse_jasmine_discussion" do - template_jasmine_runner("common/static/coffee") do |f| - sh("python -m webbrowser -t 'file://#{f}'") - puts "Press ENTER to terminate".red - $stdin.gets - end -end +task "browse_jasmine_discussion" => "browse_jasmine_common/static/coffee" desc "Use phantomjs to run jasmine tests for discussion from the console" -task "phantomjs_jasmine_discussion" do - phantomjs = ENV['PHANTOMJS_PATH'] || 'phantomjs' - template_jasmine_runner("common/static/coffee") do |f| - sh("#{phantomjs} node_modules/phantom-jasmine/lib/run_jasmine_test.coffee #{f}") - end -end +task "phantomjs_jasmine_discussion" => "phantomjs_jasmine_common/static/coffee" diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index 3d8b95f8e2..69ee484a94 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -82,3 +82,5 @@ django_nose==1.1 django-jasmine==0.3.2 django_debug_toolbar django-debug-toolbar-mongo + +git+https://github.com/mfogel/django-settings-context-processor.git