Make rake commands to run jasmine tests in browser and via phantomjs
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -0,0 +1,3 @@
|
||||
[submodule "common/test/phantom-jasmine"]
|
||||
path = common/test/phantom-jasmine
|
||||
url = https://github.com/jcarver989/phantom-jasmine.git
|
||||
|
||||
2
Gemfile
2
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'
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<script src="{% static 'jasmine-latest/jasmine.js' %}"></script>
|
||||
<script src="{% static 'jasmine-latest/jasmine-html.js' %}"></script>
|
||||
<script src="{% static 'js/vendor/jasmine-jquery.js' %}"></script>
|
||||
<script src="{% static 'console-runner.js' %}"></script>
|
||||
|
||||
{# 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 @@
|
||||
|
||||
<script>
|
||||
{% block jasmine %}
|
||||
var console_reporter = new jasmine.ConsoleReporter();
|
||||
(function() {
|
||||
var jasmineEnv = jasmine.getEnv();
|
||||
jasmineEnv.updateInterval = 1000;
|
||||
@@ -38,6 +40,7 @@
|
||||
var trivialReporter = new jasmine.TrivialReporter();
|
||||
|
||||
jasmineEnv.addReporter(trivialReporter);
|
||||
jasmine.getEnv().addReporter(console_reporter);
|
||||
|
||||
jasmineEnv.specFilter = function(spec) {
|
||||
return trivialReporter.specFilter(spec);
|
||||
1
common/test/phantom-jasmine
Submodule
1
common/test/phantom-jasmine
Submodule
Submodule common/test/phantom-jasmine added at a54d435b55
@@ -1,67 +0,0 @@
|
||||
<!doctype html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Jasmine Spec Runner</title>
|
||||
|
||||
{% load staticfiles %}
|
||||
<link rel="stylesheet" href="{% static 'jasmine-latest/jasmine.css' %}" media="screen">
|
||||
|
||||
{# core files #}
|
||||
<script src="{% static 'jasmine-latest/jasmine.js' %}"></script>
|
||||
<script src="{% static 'jasmine-latest/jasmine-html.js' %}"></script>
|
||||
<script src="{% static 'js/vendor/jasmine-jquery.js' %}"></script>
|
||||
|
||||
{# source files #}
|
||||
{% for url in suite.js_files %}
|
||||
<script src="{{ url }}"></script>
|
||||
{% endfor %}
|
||||
|
||||
{% load compressed %}
|
||||
{# static files #}
|
||||
{% compressed_js 'application' %}
|
||||
{% compressed_js 'module-js' %}
|
||||
|
||||
{# spec files #}
|
||||
{% compressed_js 'spec' %}
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Jasmine Spec Runner</h1>
|
||||
|
||||
<script>
|
||||
{% block jasmine %}
|
||||
(function() {
|
||||
var jasmineEnv = jasmine.getEnv();
|
||||
jasmineEnv.updateInterval = 1000;
|
||||
|
||||
var trivialReporter = new jasmine.TrivialReporter();
|
||||
|
||||
jasmineEnv.addReporter(trivialReporter);
|
||||
|
||||
jasmineEnv.specFilter = function(spec) {
|
||||
return trivialReporter.specFilter(spec);
|
||||
};
|
||||
|
||||
// Additional configuration can be done in this block
|
||||
{% block jasmine_extra %}{% endblock %}
|
||||
|
||||
var currentWindowOnload = window.onload;
|
||||
|
||||
window.onload = function() {
|
||||
if (currentWindowOnload) {
|
||||
currentWindowOnload();
|
||||
}
|
||||
execJasmine();
|
||||
};
|
||||
|
||||
function execJasmine() {
|
||||
jasmineEnv.execute();
|
||||
}
|
||||
})();
|
||||
{% endblock %}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
46
rakefile
46
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
|
||||
|
||||
Reference in New Issue
Block a user