Runner.html is now generated (ensures all source & specs get tested); beginnings of refactoring of Rake tasks.
This commit is contained in:
@@ -1,170 +1,97 @@
|
|||||||
require 'json'
|
require 'json'
|
||||||
|
require 'tilt'
|
||||||
|
|
||||||
def jasmine_sources
|
Dir["#{File.dirname(__FILE__)}/tasks/**/*.rb"].each do |file|
|
||||||
first_sources = JSON.parse(File.read('src/SourcesList.json')).collect {|f| "src/core/#{f}"}
|
require file
|
||||||
|
|
||||||
sources = first_sources
|
|
||||||
sources += Dir.glob('src/core/*.js').reject {|f| first_sources.include?(f)}.sort
|
|
||||||
sources
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def jasmine_html_sources
|
task :require_node do
|
||||||
["src/html/TrivialReporter.js"]
|
raise "\nNode.js is required to develop code for Jasmine. Please visit http://nodejs.org to install.\n\n" unless node_installed?
|
||||||
end
|
|
||||||
|
|
||||||
def jasmine_version
|
|
||||||
"#{version_hash['major']}.#{version_hash['minor']}.#{version_hash['build']}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def version_hash
|
|
||||||
require 'json'
|
|
||||||
@version ||= JSON.parse(File.new("src/core/version.json").read);
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def substitute_jasmine_version(filename)
|
|
||||||
contents = File.read(filename)
|
|
||||||
contents = contents.gsub(/##JASMINE_VERSION##/, (jasmine_version))
|
|
||||||
contents = contents.gsub(/[^\n]*REMOVE_THIS_LINE_FROM_BUILD[^\n]*/, '')
|
|
||||||
File.open(filename, 'w') { |f| f.write(contents) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
task :default => :spec
|
task :default => :spec
|
||||||
|
|
||||||
desc "Run spec suite: Browser, Node, JSHint"
|
#namespace :jasmine do
|
||||||
task :spec => ["jasmine:build", "spec:node", "spec:browser"]
|
#
|
||||||
|
# desc 'Prepares for distribution'
|
||||||
namespace :spec do
|
# task :dist => ['jasmine:build',
|
||||||
desc 'Run specs in Node.js'
|
# 'jasmine:doc',
|
||||||
task :node do
|
# 'jasmine:build_pages',
|
||||||
raise "Node is required to run all jasmine specs" unless system("node spec/node_suite.js")
|
# 'jasmine:build_example_project',
|
||||||
end
|
# 'jasmine:fill_index_downloads']
|
||||||
|
#
|
||||||
desc "Run specs in the default browser (MacOS only)"
|
# end
|
||||||
task :browser do
|
#
|
||||||
system("open spec/runner.html")
|
# downloads_file = 'pages/download.html'
|
||||||
end
|
# task :need_pages_submodule do
|
||||||
end
|
# unless File.exist?(downloads_file)
|
||||||
|
# raise "Jasmine pages submodule isn't present. Run git submodule update --init"
|
||||||
namespace :jasmine do
|
# end
|
||||||
|
# end
|
||||||
desc 'Prepares for distribution'
|
#
|
||||||
task :dist => ['jasmine:build',
|
# desc "Build the Github pages HTML"
|
||||||
'jasmine:doc',
|
# task :build_pages => :need_pages_submodule do
|
||||||
'jasmine:build_pages',
|
# Dir.chdir("pages") do
|
||||||
'jasmine:build_example_project',
|
# FileUtils.rm_r('pages_output') if File.exist?('pages_output')
|
||||||
'jasmine:fill_index_downloads']
|
# Dir.chdir('pages_source') do
|
||||||
|
# system("frank export ../pages_output")
|
||||||
desc 'Check jasmine sources for coding problems'
|
# end
|
||||||
task :lint do
|
# puts "\nCopying Frank output to the root of the gh-pages branch\n\n"
|
||||||
puts "Running JSHint via Node.js"
|
# system("cp -r pages_output/* .")
|
||||||
system("node jshint/run.js") || exit(1)
|
# end
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
desc "Alias to JSHint"
|
# desc "Build jasmine documentation"
|
||||||
task :hint => :lint
|
# task :doc => :need_pages_submodule do
|
||||||
|
# puts 'Creating Jasmine Documentation'
|
||||||
desc 'Builds lib/jasmine from source'
|
# require 'rubygems'
|
||||||
task :build => :lint do
|
# require 'jsdoc_helper'
|
||||||
puts 'Building Jasmine from source'
|
#
|
||||||
|
# FileUtils.rm_r "pages/jsdoc", :force => true
|
||||||
sources = jasmine_sources
|
#
|
||||||
version = version_hash
|
# JsdocHelper::Rake::Task.new(:lambda_jsdoc) do |t|
|
||||||
|
# t[:files] = jasmine_sources << jasmine_html_sources
|
||||||
File.open("lib/jasmine.js", 'w') do |jasmine|
|
# t[:options] = "-a"
|
||||||
sources.each do |source_filename|
|
# t[:out] = "pages/jsdoc"
|
||||||
jasmine.puts(File.read(source_filename))
|
# # JsdocHelper bug: template must be relative to the JsdocHelper gem, ick
|
||||||
end
|
# t[:template] = File.join("../".*(100), Dir::getwd, "jsdoc-template")
|
||||||
|
# end
|
||||||
jasmine.puts %{
|
# Rake::Task[:lambda_jsdoc].invoke
|
||||||
jasmine.version_= {
|
# end
|
||||||
"major": #{version['major'].to_json},
|
#
|
||||||
"minor": #{version['minor'].to_json},
|
# desc "Build example project"
|
||||||
"build": #{version['build'].to_json},
|
# task :build_example_project => :need_pages_submodule do
|
||||||
"revision": #{Time.now.to_i}
|
# require 'tmpdir'
|
||||||
};
|
#
|
||||||
}
|
# temp_dir = File.join(Dir.tmpdir, 'jasmine-standalone-project')
|
||||||
end
|
# puts "Building Example Project in #{temp_dir}"
|
||||||
|
# FileUtils.rm_r temp_dir if File.exist?(temp_dir)
|
||||||
File.open("lib/jasmine-html.js", 'w') do |jasmine_html|
|
# Dir.mkdir(temp_dir)
|
||||||
jasmine_html_sources.each do |source_filename|
|
#
|
||||||
jasmine_html.puts(File.read(source_filename))
|
# root = File.expand_path(File.dirname(__FILE__))
|
||||||
end
|
# FileUtils.cp_r File.join(root, 'example/.'), File.join(temp_dir)
|
||||||
end
|
# substitute_jasmine_version(File.join(temp_dir, "SpecRunner.html"))
|
||||||
|
#
|
||||||
FileUtils.cp("src/html/jasmine.css", "lib/jasmine.css")
|
# lib_dir = File.join(temp_dir, "lib/jasmine-#{jasmine_version}")
|
||||||
end
|
# FileUtils.mkdir_p(lib_dir)
|
||||||
|
# {
|
||||||
downloads_file = 'pages/download.html'
|
# "lib/jasmine.js" => "jasmine.js",
|
||||||
task :need_pages_submodule do
|
# "lib/jasmine-html.js" => "jasmine-html.js",
|
||||||
unless File.exist?(downloads_file)
|
# "src/html/jasmine.css" => "jasmine.css",
|
||||||
raise "Jasmine pages submodule isn't present. Run git submodule update --init"
|
# "MIT.LICENSE" => "MIT.LICENSE"
|
||||||
end
|
# }.each_pair do |src, dest|
|
||||||
end
|
# FileUtils.cp(File.join(root, src), File.join(lib_dir, dest))
|
||||||
|
# end
|
||||||
desc "Build the Github pages HTML"
|
#
|
||||||
task :build_pages => :need_pages_submodule do
|
# dist_dir = File.join(root, 'pages/downloads')
|
||||||
Dir.chdir("pages") do
|
# zip_file_name = File.join(dist_dir, "jasmine-standalone-#{jasmine_version}.zip")
|
||||||
FileUtils.rm_r('pages_output') if File.exist?('pages_output')
|
# puts "Zipping Example Project and moving to #{zip_file_name}"
|
||||||
Dir.chdir('pages_source') do
|
# FileUtils.mkdir(dist_dir) unless File.exist?(dist_dir)
|
||||||
system("frank export ../pages_output")
|
# if File.exist?(zip_file_name)
|
||||||
end
|
# puts "WARNING!!! #{zip_file_name} already exists!"
|
||||||
puts "\nCopying Frank output to the root of the gh-pages branch\n\n"
|
# FileUtils.rm(zip_file_name)
|
||||||
system("cp -r pages_output/* .")
|
# end
|
||||||
end
|
# exec "cd #{temp_dir} && zip -r #{zip_file_name} . -x .[a-zA-Z0-9]*"
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
desc "Build jasmine documentation"
|
#end
|
||||||
task :doc => :need_pages_submodule do
|
|
||||||
puts 'Creating Jasmine Documentation'
|
|
||||||
require 'rubygems'
|
|
||||||
require 'jsdoc_helper'
|
|
||||||
|
|
||||||
FileUtils.rm_r "pages/jsdoc", :force => true
|
|
||||||
|
|
||||||
JsdocHelper::Rake::Task.new(:lambda_jsdoc) do |t|
|
|
||||||
t[:files] = jasmine_sources << jasmine_html_sources
|
|
||||||
t[:options] = "-a"
|
|
||||||
t[:out] = "pages/jsdoc"
|
|
||||||
# JsdocHelper bug: template must be relative to the JsdocHelper gem, ick
|
|
||||||
t[:template] = File.join("../".*(100), Dir::getwd, "jsdoc-template")
|
|
||||||
end
|
|
||||||
Rake::Task[:lambda_jsdoc].invoke
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "Build example project"
|
|
||||||
task :build_example_project => :need_pages_submodule do
|
|
||||||
require 'tmpdir'
|
|
||||||
|
|
||||||
temp_dir = File.join(Dir.tmpdir, 'jasmine-standalone-project')
|
|
||||||
puts "Building Example Project in #{temp_dir}"
|
|
||||||
FileUtils.rm_r temp_dir if File.exist?(temp_dir)
|
|
||||||
Dir.mkdir(temp_dir)
|
|
||||||
|
|
||||||
root = File.expand_path(File.dirname(__FILE__))
|
|
||||||
FileUtils.cp_r File.join(root, 'example/.'), File.join(temp_dir)
|
|
||||||
substitute_jasmine_version(File.join(temp_dir, "SpecRunner.html"))
|
|
||||||
|
|
||||||
lib_dir = File.join(temp_dir, "lib/jasmine-#{jasmine_version}")
|
|
||||||
FileUtils.mkdir_p(lib_dir)
|
|
||||||
{
|
|
||||||
"lib/jasmine.js" => "jasmine.js",
|
|
||||||
"lib/jasmine-html.js" => "jasmine-html.js",
|
|
||||||
"src/html/jasmine.css" => "jasmine.css",
|
|
||||||
"MIT.LICENSE" => "MIT.LICENSE"
|
|
||||||
}.each_pair do |src, dest|
|
|
||||||
FileUtils.cp(File.join(root, src), File.join(lib_dir, dest))
|
|
||||||
end
|
|
||||||
|
|
||||||
dist_dir = File.join(root, 'pages/downloads')
|
|
||||||
zip_file_name = File.join(dist_dir, "jasmine-standalone-#{jasmine_version}.zip")
|
|
||||||
puts "Zipping Example Project and moving to #{zip_file_name}"
|
|
||||||
FileUtils.mkdir(dist_dir) unless File.exist?(dist_dir)
|
|
||||||
if File.exist?(zip_file_name)
|
|
||||||
puts "WARNING!!! #{zip_file_name} already exists!"
|
|
||||||
FileUtils.rm(zip_file_name)
|
|
||||||
end
|
|
||||||
exec "cd #{temp_dir} && zip -r #{zip_file_name} . -x .[a-zA-Z0-9]*"
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|||||||
+2
-3
@@ -2463,10 +2463,9 @@ jasmine.getGlobal().clearInterval = function(timeoutKey) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
jasmine.version_= {
|
jasmine.version_= {
|
||||||
"major": 1,
|
"major": 1,
|
||||||
"minor": 1,
|
"minor": 1,
|
||||||
"build": 0,
|
"build": 0,
|
||||||
"revision": 1307546962
|
"revision": 1307672575
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||||
|
"http://www.w3.org/TR/html4/loose.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Jasmine Test Runner</title>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
// yes, really keep this here to keep us honest, but only for jasmine's own runner! [xw]
|
||||||
|
undefined = "diz be undefined yo";
|
||||||
|
</script>
|
||||||
|
<link rel="shortcut icon" type="image/png" href="../images/jasmine_favicon.png">
|
||||||
|
<script type="text/javascript" src="../lib/jasmine.js"></script>
|
||||||
|
|
||||||
|
<%= source_tags %>
|
||||||
|
|
||||||
|
<%= spec_file_tags %>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
(function() {
|
||||||
|
var jasmineEnv = jasmine.getEnv();
|
||||||
|
jasmineEnv.updateInterval = 1000;
|
||||||
|
|
||||||
|
var trivialReporter = new jasmine.TrivialReporter();
|
||||||
|
|
||||||
|
jasmineEnv.addReporter(trivialReporter);
|
||||||
|
|
||||||
|
jasmineEnv.specFilter = function(spec) {
|
||||||
|
return trivialReporter.specFilter(spec);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.onload = function() {
|
||||||
|
jasmineEnv.execute();
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<link href="../src/html/jasmine.css" rel="stylesheet"/>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<script type="text/javascript" src="<%= file %>"></script>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
desc "Build core jasmine.js"
|
||||||
|
task :build_jasmine_js => :lint do
|
||||||
|
puts 'Building Jasmine from source'
|
||||||
|
|
||||||
|
File.open("lib/jasmine.js", 'w') do |jasmine_js|
|
||||||
|
core_sources.each do |source_filename|
|
||||||
|
file = File.read(source_filename)
|
||||||
|
# file += "\n" unless file.match(/\n$/)
|
||||||
|
file.chomp
|
||||||
|
jasmine_js << file
|
||||||
|
end
|
||||||
|
|
||||||
|
jasmine_js << version_source
|
||||||
|
end
|
||||||
|
|
||||||
|
File.open("lib/jasmine-html.js", 'w') do |jasmine_html|
|
||||||
|
html_sources.each do |source_filename|
|
||||||
|
jasmine_html.puts(File.read(source_filename))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
FileUtils.cp("src/html/jasmine.css", "lib/jasmine.css")
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'Check jasmine sources for coding problems'
|
||||||
|
task :lint do
|
||||||
|
puts "Running JSHint via Node.js"
|
||||||
|
system("node jshint/run.js") || exit(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
task :hint => :lint
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
require 'ostruct'
|
||||||
|
|
||||||
|
desc "build the browser spec runner.html based on current tree"
|
||||||
|
task :build_runner_html do
|
||||||
|
template = Tilt.new('spec/templates/runner.html.erb')
|
||||||
|
|
||||||
|
File.open('spec/runner.html', 'w+') do |f|
|
||||||
|
scope = OpenStruct.new(:source_tags => other_source_file_tags,
|
||||||
|
:spec_file_tags => spec_file_tags)
|
||||||
|
f << template.render(scope)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def other_source_file_tags
|
||||||
|
other_files = html_sources + console_sources
|
||||||
|
script_tags_for other_files.collect { |f| "../#{f}" }
|
||||||
|
end
|
||||||
|
|
||||||
|
def spec_file_tags
|
||||||
|
spec_files = core_specfiles + html_specfiles + console_specfiles
|
||||||
|
script_tags_for spec_files.collect { |f| "../#{f}" }
|
||||||
|
end
|
||||||
|
|
||||||
|
def script_tags_for(files)
|
||||||
|
script_tag = Tilt::new('spec/templates/script_tag.html.erb')
|
||||||
|
|
||||||
|
files.inject([]) do |tags, f|
|
||||||
|
scope = OpenStruct.new :file => f
|
||||||
|
tags << script_tag.render(scope)
|
||||||
|
tags
|
||||||
|
end.join("\n ")
|
||||||
|
end
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
require 'json'
|
||||||
|
|
||||||
|
def core_sources
|
||||||
|
first_sources = JSON.parse(File.read('src/SourcesList.json')).collect { |f| "src/core/#{f}" }
|
||||||
|
|
||||||
|
remaining_sources = Dir.glob('src/core/*.js').reject { |f| first_sources.include?(f) }.sort
|
||||||
|
|
||||||
|
first_sources + remaining_sources
|
||||||
|
end
|
||||||
|
|
||||||
|
def html_sources
|
||||||
|
Dir.glob('src/html/*.js')
|
||||||
|
end
|
||||||
|
|
||||||
|
def console_sources
|
||||||
|
Dir.glob('src/console/*.js')
|
||||||
|
end
|
||||||
|
|
||||||
|
def core_specfiles
|
||||||
|
Dir.glob('spec/core/*.js')
|
||||||
|
end
|
||||||
|
|
||||||
|
def html_specfiles
|
||||||
|
Dir.glob('spec/html/*.js')
|
||||||
|
end
|
||||||
|
|
||||||
|
def console_specfiles
|
||||||
|
Dir.glob('spec/console/*.js')
|
||||||
|
end
|
||||||
|
|
||||||
|
def version_string
|
||||||
|
"#{version_hash['major']}.#{version_hash['minor']}.#{version_hash['build']}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def version_source
|
||||||
|
<<-JS
|
||||||
|
jasmine.version_= {
|
||||||
|
"major": #{version_hash['major'].to_json},
|
||||||
|
"minor": #{version_hash['minor'].to_json},
|
||||||
|
"build": #{version_hash['build'].to_json},
|
||||||
|
"revision": #{Time.now.to_i}
|
||||||
|
}
|
||||||
|
JS
|
||||||
|
end
|
||||||
|
|
||||||
|
def version_hash
|
||||||
|
@version ||= JSON.parse(File.new("src/core/version.json").read);
|
||||||
|
end
|
||||||
|
|
||||||
|
def node_installed?
|
||||||
|
`which node` =~ /node/
|
||||||
|
end
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
desc "Run spec suite: Browser, Node, JSHint"
|
||||||
|
task :spec => ["build_jasmine_js", "spec:node", "spec:browser"]
|
||||||
|
|
||||||
|
desc 'Run specs in Node.js'
|
||||||
|
task "spec:node" => :require_node do
|
||||||
|
puts "Running all appropriate specs via Node.js"
|
||||||
|
system("node spec/node_suite.js")
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Run specs in the default browser (MacOS only)"
|
||||||
|
task "spec:browser" => :build_runner_html do
|
||||||
|
puts "Running all appropriate specs via the default web browser"
|
||||||
|
system("open spec/runner.html")
|
||||||
|
end
|
||||||
|
|
||||||
|
#def core_spec_count
|
||||||
|
#
|
||||||
|
#end
|
||||||
Reference in New Issue
Block a user