diff --git a/.gitmodules b/.gitmodules index e69de29bb2..3c8158cf80 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "common/test/phantom-jasmine"] + path = common/test/phantom-jasmine + url = https://github.com/jcarver989/phantom-jasmine.git diff --git a/Gemfile b/Gemfile index 9ad08c7adb..0fe7df217d 100644 --- a/Gemfile +++ b/Gemfile @@ -3,3 +3,5 @@ ruby "1.9.3" gem 'rake' gem 'sass', '3.1.15' gem 'bourbon', '~> 1.3.6' +gem 'colorize' +gem 'launchy' diff --git a/cms/templates/jasmine/base.html b/common/templates/jasmine/base.html similarity index 87% rename from cms/templates/jasmine/base.html rename to common/templates/jasmine/base.html index 0cbf63bb29..96507bdebf 100644 --- a/cms/templates/jasmine/base.html +++ b/common/templates/jasmine/base.html @@ -11,6 +11,7 @@ + {# source files #} {% for url in suite.js_files %} @@ -19,7 +20,7 @@ {% load compressed %} {# static files #} - {% compressed_js 'main' %} + {% compressed_js 'js-test-source' %} {# spec files #} {% compressed_js 'spec' %} @@ -31,6 +32,7 @@ - - - - {# source files #} - {% for url in suite.js_files %} - - {% endfor %} - - {% load compressed %} - {# static files #} - {% compressed_js 'application' %} - {% compressed_js 'module-js' %} - - {# spec files #} - {% compressed_js 'spec' %} - - - - -

Jasmine Spec Runner

- - - - - diff --git a/rakefile b/rakefile index 90cd5fe87f..ad02355f74 100644 --- a/rakefile +++ b/rakefile @@ -1,5 +1,8 @@ require 'rake/clean' require 'tempfile' +require 'net/http' +require 'launchy' +require 'colorize' # Build Constants REPO_ROOT = File.dirname(__FILE__) @@ -38,6 +41,32 @@ def django_admin(system, env, command, *args) return "#{django_admin} #{command} --settings=#{system}.envs.#{env} --pythonpath=. #{args.join(' ')}" end +def django_for_jasmine(system) + django_pid = fork do + exec(*django_admin(system, 'dev', 'runserver', '12345').split(' ')) + end + puts django_pid + jasmine_url = 'http://localhost:12345/_jasmine/' + up = false + until up do + begin + response = Net::HTTP.get_response(URI(jasmine_url)) + puts response.code + up = response.code == '200' + rescue => e + puts e.message + ensure + puts('Waiting server to start') + sleep(0.5) + end + end + begin + yield jasmine_url + ensure + Process.kill(:SIGKILL, -Process.getpgid(django_pid)) + Process.wait(django_pid) + end +end task :default => [:test, :pep8, :pylint] directory REPORT_DIR @@ -80,6 +109,23 @@ end end end task :pylint => "pylint_#{system}" + + desc "Open jasmine tests in your default browser" + task "browse_jasmine_#{system}" do + django_for_jasmine(system) do |jasmine_url| + Launchy.open(jasmine_url) + puts "Press ENTER to terminate".red + $stdin.gets + end + end + + desc "Use phantomjs to run jasmine tests from the console" + task "phantomjs_jasmine_#{system}" do + phantomjs = ENV['PHANTOMJS_PATH'] || 'phantomjs' + django_for_jasmine(system) do |jasmine_url| + sh("#{phantomjs} common/test/phantom-jasmine/lib/run_jasmine_test.coffee #{jasmine_url}") + end + end end $failed_tests = 0