newjs 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +68 -0
- data/README.txt +9 -0
- data/Rakefile +4 -0
- data/app_generators/newjs/USAGE +9 -0
- data/app_generators/newjs/newjs_generator.rb +113 -0
- data/app_generators/newjs/templates/History.txt.erb +4 -0
- data/app_generators/newjs/templates/License.txt.erb +20 -0
- data/app_generators/newjs/templates/README.txt +1 -0
- data/app_generators/newjs/templates/Rakefile.erb +82 -0
- data/app_generators/newjs/templates/config/javascript_test_autotest.yml.sample +15 -0
- data/app_generators/newjs/templates/lib/jstest.rb +382 -0
- data/app_generators/newjs/templates/lib/protodoc.rb +36 -0
- data/app_generators/newjs/templates/script/js_autotest +1 -0
- data/app_generators/newjs/templates/script/rstakeout +98 -0
- data/app_generators/newjs/templates/src/HEADER.erb +8 -0
- data/app_generators/newjs/templates/src/library.js.erb +7 -0
- data/app_generators/newjs/templates/tasks/environment.rake +7 -0
- data/app_generators/newjs/templates/tasks/javascript_test_autotest_tasks.rake +44 -0
- data/app_generators/newjs/templates/test/assets/prototype.js +4236 -0
- data/app_generators/newjs/templates/test/assets/unittest.css +50 -0
- data/app_generators/newjs/templates/test/assets/unittest.js +556 -0
- data/bin/newjs +17 -0
- data/config/hoe.rb +75 -0
- data/config/requirements.rb +17 -0
- data/javascript_test_generators/javascript_test/USAGE +2 -0
- data/javascript_test_generators/javascript_test/javascript_test_generator.rb +54 -0
- data/javascript_test_generators/javascript_test/templates/test/test.html.erb +58 -0
- data/lib/newjs.rb +7 -0
- data/lib/newjs/autotest.rb +3 -0
- data/lib/newjs/autotest/javascript_test_autotest.rb +22 -0
- data/lib/newjs/autotest/javascript_test_autotest/config.rb +20 -0
- data/lib/newjs/autotest/javascript_test_ext.rb +29 -0
- data/lib/newjs/jstest.rb +382 -0
- data/lib/newjs/version.rb +9 -0
- data/log/debug.log +0 -0
- data/newjs_generators/install_website/USAGE +5 -0
- data/newjs_generators/install_website/install_website_generator.rb +79 -0
- data/newjs_generators/install_website/templates/script/txt2html +74 -0
- data/newjs_generators/install_website/templates/script/win_script.cmd +1 -0
- data/newjs_generators/install_website/templates/tasks/website.rake +17 -0
- data/newjs_generators/install_website/templates/website/index.html +11 -0
- data/newjs_generators/install_website/templates/website/index.txt +37 -0
- data/newjs_theme_generators/plain_theme/USAGE +0 -0
- data/newjs_theme_generators/plain_theme/plain_theme_generator.rb +54 -0
- data/newjs_theme_generators/plain_theme/templates/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/newjs_theme_generators/plain_theme/templates/website/stylesheets/screen.css +138 -0
- data/newjs_theme_generators/plain_theme/templates/website/template.html.erb +48 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/test_generator_helper.rb +20 -0
- data/test/test_helper.rb +4 -0
- data/test/test_install_website_generator.rb +39 -0
- data/test/test_javascript_test_generator.rb +43 -0
- data/test/test_newjs_generator.rb +63 -0
- data/test/test_plain_theme_generator.rb +37 -0
- data/website/images/example-unittest-log.jpg +0 -0
- data/website/index.html +271 -0
- data/website/index.txt +181 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.html.erb +48 -0
- metadata +168 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Dr Nic Williams
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
app_generators/newjs/USAGE
|
7
|
+
app_generators/newjs/newjs_generator.rb
|
8
|
+
app_generators/newjs/templates/History.txt.erb
|
9
|
+
app_generators/newjs/templates/License.txt.erb
|
10
|
+
app_generators/newjs/templates/README.txt
|
11
|
+
app_generators/newjs/templates/Rakefile.erb
|
12
|
+
app_generators/newjs/templates/config/javascript_test_autotest.yml.sample
|
13
|
+
app_generators/newjs/templates/lib/jstest.rb
|
14
|
+
app_generators/newjs/templates/lib/protodoc.rb
|
15
|
+
app_generators/newjs/templates/script/js_autotest
|
16
|
+
app_generators/newjs/templates/script/rstakeout
|
17
|
+
app_generators/newjs/templates/src/HEADER.erb
|
18
|
+
app_generators/newjs/templates/src/library.js.erb
|
19
|
+
app_generators/newjs/templates/tasks/environment.rake
|
20
|
+
app_generators/newjs/templates/tasks/javascript_test_autotest_tasks.rake
|
21
|
+
app_generators/newjs/templates/test/assets/prototype.js
|
22
|
+
app_generators/newjs/templates/test/assets/unittest.css
|
23
|
+
app_generators/newjs/templates/test/assets/unittest.js
|
24
|
+
bin/newjs
|
25
|
+
config/hoe.rb
|
26
|
+
config/requirements.rb
|
27
|
+
javascript_test_generators/javascript_test/USAGE
|
28
|
+
javascript_test_generators/javascript_test/javascript_test_generator.rb
|
29
|
+
javascript_test_generators/javascript_test/templates/test/test.html.erb
|
30
|
+
lib/newjs.rb
|
31
|
+
lib/newjs/autotest.rb
|
32
|
+
lib/newjs/autotest/javascript_test_autotest.rb
|
33
|
+
lib/newjs/autotest/javascript_test_autotest/config.rb
|
34
|
+
lib/newjs/autotest/javascript_test_ext.rb
|
35
|
+
lib/newjs/jstest.rb
|
36
|
+
lib/newjs/version.rb
|
37
|
+
log/debug.log
|
38
|
+
newjs_generators/install_website/USAGE
|
39
|
+
newjs_generators/install_website/install_website_generator.rb
|
40
|
+
newjs_generators/install_website/templates/script/txt2html
|
41
|
+
newjs_generators/install_website/templates/script/win_script.cmd
|
42
|
+
newjs_generators/install_website/templates/tasks/website.rake
|
43
|
+
newjs_generators/install_website/templates/website/index.html
|
44
|
+
newjs_generators/install_website/templates/website/index.txt
|
45
|
+
newjs_theme_generators/plain_theme/USAGE
|
46
|
+
newjs_theme_generators/plain_theme/plain_theme_generator.rb
|
47
|
+
newjs_theme_generators/plain_theme/templates/website/javascripts/rounded_corners_lite.inc.js
|
48
|
+
newjs_theme_generators/plain_theme/templates/website/stylesheets/screen.css
|
49
|
+
newjs_theme_generators/plain_theme/templates/website/template.html.erb
|
50
|
+
script/destroy
|
51
|
+
script/generate
|
52
|
+
script/txt2html
|
53
|
+
setup.rb
|
54
|
+
tasks/deployment.rake
|
55
|
+
tasks/environment.rake
|
56
|
+
tasks/website.rake
|
57
|
+
test/test_generator_helper.rb
|
58
|
+
test/test_helper.rb
|
59
|
+
test/test_install_website_generator.rb
|
60
|
+
test/test_javascript_test_generator.rb
|
61
|
+
test/test_newjs_generator.rb
|
62
|
+
test/test_plain_theme_generator.rb
|
63
|
+
website/images/example-unittest-log.jpg
|
64
|
+
website/index.html
|
65
|
+
website/index.txt
|
66
|
+
website/javascripts/rounded_corners_lite.inc.js
|
67
|
+
website/stylesheets/screen.css
|
68
|
+
website/template.html.erb
|
data/README.txt
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Description:
|
2
|
+
The +newjs+ command creates a new JavaScript project/application
|
3
|
+
with a default directory structure and configuration at the path you specify.
|
4
|
+
|
5
|
+
Example:
|
6
|
+
+newjs path/to/my-app-name+
|
7
|
+
|
8
|
+
This generates a skeletal JavaScript project/application
|
9
|
+
installation in path/to/my-app-name
|
data/Rakefile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Description:
|
2
|
+
The 'newjs' command creates a new JavaScript project/application
|
3
|
+
with a default directory structure and configuration at the path you specify.
|
4
|
+
|
5
|
+
Example:
|
6
|
+
newjs path/to/my-app-name
|
7
|
+
|
8
|
+
This generates a skeletal JavaScript project/application
|
9
|
+
installation in path/to/my-app-name
|
@@ -0,0 +1,113 @@
|
|
1
|
+
class NewjsGenerator < RubiGen::Base
|
2
|
+
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
|
3
|
+
Config::CONFIG['ruby_install_name'])
|
4
|
+
|
5
|
+
default_options :shebang => DEFAULT_SHEBANG,
|
6
|
+
:author => nil,
|
7
|
+
:email => nil,
|
8
|
+
:version => '0.0.1'
|
9
|
+
|
10
|
+
|
11
|
+
attr_reader :name, :module_name
|
12
|
+
attr_reader :version, :version_str, :author, :email
|
13
|
+
attr_reader :title, :url
|
14
|
+
|
15
|
+
|
16
|
+
def initialize(runtime_args, runtime_options = {})
|
17
|
+
super
|
18
|
+
usage if args.empty?
|
19
|
+
@destination_root = File.expand_path(args.shift)
|
20
|
+
@name = base_name
|
21
|
+
@module_name = name.camelize
|
22
|
+
extract_options
|
23
|
+
@title ||= @name.titleize
|
24
|
+
@url ||= "http://NOTE-ENTER-URL.com"
|
25
|
+
end
|
26
|
+
|
27
|
+
def manifest
|
28
|
+
script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
|
29
|
+
windows = (RUBY_PLATFORM =~ /dos|win32|cygwin/i) || (RUBY_PLATFORM =~ /(:?mswin|mingw)/)
|
30
|
+
|
31
|
+
record do |m|
|
32
|
+
# Ensure appropriate folder(s) exists
|
33
|
+
m.directory ''
|
34
|
+
BASEDIRS.each { |path| m.directory path }
|
35
|
+
|
36
|
+
# Create stubs
|
37
|
+
# m.template "template.rb", "some_file_after_erb.rb"
|
38
|
+
# m.file "file", "some_file_copied"
|
39
|
+
m.file_copy_each %w[unittest.css unittest.js prototype.js], "test/assets"
|
40
|
+
m.file_copy_each %w[javascript_test_autotest_tasks.rake environment.rake], "tasks"
|
41
|
+
m.file_copy_each %w[javascript_test_autotest.yml.sample], "config"
|
42
|
+
m.file_copy_each %w[protodoc.rb jstest.rb], "lib"
|
43
|
+
m.file_copy_each %w[README.txt]
|
44
|
+
m.template_copy_each %w[Rakefile.erb History.txt.erb License.txt.erb]
|
45
|
+
m.template_copy_each %w[HEADER.erb], "src"
|
46
|
+
m.template "src/library.js.erb", "src/#{name}.js"
|
47
|
+
|
48
|
+
%w[rstakeout js_autotest].each do |file|
|
49
|
+
m.template "script/#{file}", "script/#{file}", script_options
|
50
|
+
m.template "script/win_script.cmd", "script/#{file}.cmd",
|
51
|
+
:assigns => { :filename => file } if windows
|
52
|
+
end
|
53
|
+
|
54
|
+
m.dependency "install_rubigen_scripts",
|
55
|
+
[destination_root, 'javascript', 'javascript_test', 'newjs', 'newjs_theme'],
|
56
|
+
:shebang => options[:shebang], :collision => :force
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
def banner
|
62
|
+
<<-EOS
|
63
|
+
Creates a JavaScript project.
|
64
|
+
|
65
|
+
USAGE: #{spec.name} name"
|
66
|
+
EOS
|
67
|
+
end
|
68
|
+
|
69
|
+
def add_options!(opts)
|
70
|
+
opts.separator ''
|
71
|
+
opts.separator 'Options:'
|
72
|
+
# For each option below, place the default
|
73
|
+
# at the top of the file next to "default_options"
|
74
|
+
opts.on("-a", "--author=\"Your Name\"", String,
|
75
|
+
"Default: none") { |x| options[:author] = x }
|
76
|
+
opts.on("-e", "--email=\"your@email.com\"", String,
|
77
|
+
"Your email to be inserted into generated files.",
|
78
|
+
"Default: ~/.rubyforge/user-config.yml[email]") { |x| options[:email] = x }
|
79
|
+
opts.on("-t", "--title=\"Project Title\"", String,
|
80
|
+
"Human-readable/marketing name for project.",
|
81
|
+
"Default: Project Name") { |x| options[:title] = x }
|
82
|
+
opts.on("-u", "--url=\"http://url-to-project.com\"", String,
|
83
|
+
"Default: http://NOTE-ENTER-URL.com") { |x| options[:url] = x }
|
84
|
+
opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
85
|
+
opts.on("-V", "--set-version=X.Y.Z", String,
|
86
|
+
"Initial version of the project you are creating.",
|
87
|
+
"Default: 0.0.1") { |x| options[:version] = x }
|
88
|
+
end
|
89
|
+
|
90
|
+
def extract_options
|
91
|
+
@version = options[:version].to_s.split(/\./)
|
92
|
+
@version_str = @version.join('.')
|
93
|
+
@author = options[:author]
|
94
|
+
@email = options[:email]
|
95
|
+
unless @author && @email
|
96
|
+
require 'newgem/rubyforge'
|
97
|
+
rubyforge_config = Newgem::Rubyforge.new
|
98
|
+
@author ||= rubyforge_config.full_name
|
99
|
+
@email ||= rubyforge_config.email
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Installation skeleton. Intermediate directories are automatically
|
104
|
+
# created so don't sweat their absence here.
|
105
|
+
BASEDIRS = %w(
|
106
|
+
config
|
107
|
+
lib
|
108
|
+
src
|
109
|
+
script
|
110
|
+
tasks
|
111
|
+
test/assets
|
112
|
+
)
|
113
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) <%= Time.now.year %> <%= author %>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1 @@
|
|
1
|
+
README
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
begin
|
3
|
+
require 'rake'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'This script should only be accessed via the "rake" command.'
|
6
|
+
puts 'Installation: gem install rake -y'
|
7
|
+
exit
|
8
|
+
end
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/clean'
|
11
|
+
require 'rake/packagetask'
|
12
|
+
|
13
|
+
$:.unshift File.dirname(__FILE__) + "/lib"
|
14
|
+
|
15
|
+
APP_ROOT = File.expand_path(File.dirname(__FILE__))
|
16
|
+
APP_SRC_DIR = File.join(APP_ROOT, 'src')
|
17
|
+
APP_DIST_DIR = File.join(APP_ROOT, 'dist')
|
18
|
+
APP_PKG_DIR = File.join(APP_ROOT, 'pkg')
|
19
|
+
APP_VERSION = '<%= version_str %>'
|
20
|
+
|
21
|
+
task :default => [:dist, :package, :clean_package_source]
|
22
|
+
|
23
|
+
desc "Builds the distribution"
|
24
|
+
task :dist do
|
25
|
+
$:.unshift File.join(APP_ROOT, 'lib')
|
26
|
+
require 'protodoc'
|
27
|
+
require 'fileutils'
|
28
|
+
FileUtils.mkdir_p APP_DIST_DIR
|
29
|
+
|
30
|
+
Dir.chdir(APP_SRC_DIR) do
|
31
|
+
File.open(File.join(APP_DIST_DIR, '<%= name %>.js'), 'w+') do |dist|
|
32
|
+
dist << Protodoc::Preprocessor.new('<%= name %>.js')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
Rake::PackageTask.new('<%= name %>', APP_VERSION) do |package|
|
38
|
+
package.need_tar_gz = true
|
39
|
+
package.package_dir = APP_PKG_DIR
|
40
|
+
package.package_files.include(
|
41
|
+
'[A-Z]*',
|
42
|
+
'config/*.sample',
|
43
|
+
'dist/<%= name %>.js',
|
44
|
+
'lib/**',
|
45
|
+
'src/**',
|
46
|
+
'script/**',
|
47
|
+
'tasks/**',
|
48
|
+
'test/**',
|
49
|
+
'website/**'
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "Builds the distribution, runs the JavaScript unit tests and collects their results."
|
54
|
+
task :test => [:dist, :test_units]
|
55
|
+
|
56
|
+
require 'jstest'
|
57
|
+
desc "Runs all the JavaScript unit tests and collects the results"
|
58
|
+
JavaScriptTestTask.new(:test_units) do |t|
|
59
|
+
testcases = ENV['TESTCASES']
|
60
|
+
tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
|
61
|
+
browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
|
62
|
+
|
63
|
+
t.mount("/dist")
|
64
|
+
t.mount("/src")
|
65
|
+
t.mount("/test")
|
66
|
+
|
67
|
+
Dir["test/*_test.html"].sort.each do |test_file|
|
68
|
+
tests = testcases ? { :url => "/#{test_file}", :testcases => testcases } : "/#{test_file}"
|
69
|
+
test_filename = test_file[/.*\/(.+?)\.html/, 1]
|
70
|
+
t.run(tests) unless tests_to_run && !tests_to_run.include?(test_filename)
|
71
|
+
end
|
72
|
+
|
73
|
+
%w( safari firefox ie konqueror opera ).each do |browser|
|
74
|
+
t.browser(browser.to_sym) unless browsers_to_test && !browsers_to_test.include?(browser)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
task :clean_package_source do
|
79
|
+
rm_rf File.join(APP_PKG_DIR, "'<%= name %>'-#{APP_VERSION}")
|
80
|
+
end
|
81
|
+
|
82
|
+
Dir['tasks/**/*.rake'].each { |rake| load rake }
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file has been copied here by the javascript_test_autotest plugin.
|
2
|
+
# Comment/uncomment the browsers you wish to autotest with.
|
3
|
+
# Same schema as per selenium-on-rails plugin, which is nice.
|
4
|
+
browsers:
|
5
|
+
# Windows
|
6
|
+
# firefox: 'c:\Program Files\Mozilla Firefox\firefox.exe'
|
7
|
+
# ie: 'c:\Program Files\Internet Explorer\iexplore.exe'
|
8
|
+
|
9
|
+
# Mac OS X
|
10
|
+
# firefox: '/Applications/Firefox.app/Contents/MacOS/firefox-bin'
|
11
|
+
safari: '/Applications/Safari.app/Contents/MacOS/Safari'
|
12
|
+
|
13
|
+
# Unix
|
14
|
+
# ?
|
15
|
+
# ?
|
@@ -0,0 +1,382 @@
|
|
1
|
+
require 'rake/tasklib'
|
2
|
+
require 'thread'
|
3
|
+
require 'webrick'
|
4
|
+
require 'fileutils'
|
5
|
+
include FileUtils
|
6
|
+
|
7
|
+
class Browser
|
8
|
+
def supported?; true; end
|
9
|
+
def setup ; end
|
10
|
+
def open(url) ; end
|
11
|
+
def teardown ; end
|
12
|
+
|
13
|
+
def host
|
14
|
+
require 'rbconfig'
|
15
|
+
Config::CONFIG['host']
|
16
|
+
end
|
17
|
+
|
18
|
+
def macos?
|
19
|
+
host.include?('darwin')
|
20
|
+
end
|
21
|
+
|
22
|
+
def windows?
|
23
|
+
host.include?('mswin')
|
24
|
+
end
|
25
|
+
|
26
|
+
def linux?
|
27
|
+
host.include?('linux')
|
28
|
+
end
|
29
|
+
|
30
|
+
def applescript(script)
|
31
|
+
raise "Can't run AppleScript on #{host}" unless macos?
|
32
|
+
system "osascript -e '#{script}' 2>&1 >/dev/null"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class FirefoxBrowser < Browser
|
37
|
+
def initialize(path=File.join(ENV['ProgramFiles'] || 'c:\Program Files', '\Mozilla Firefox\firefox.exe'))
|
38
|
+
@path = path
|
39
|
+
end
|
40
|
+
|
41
|
+
def visit(url)
|
42
|
+
system("open -a Firefox '#{url}'") if macos?
|
43
|
+
system("#{@path} #{url}") if windows?
|
44
|
+
system("firefox #{url}") if linux?
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
"Firefox"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class SafariBrowser < Browser
|
53
|
+
def supported?
|
54
|
+
macos?
|
55
|
+
end
|
56
|
+
|
57
|
+
def setup
|
58
|
+
applescript('tell application "Safari" to make new document')
|
59
|
+
end
|
60
|
+
|
61
|
+
def visit(url)
|
62
|
+
applescript('tell application "Safari" to set URL of front document to "' + url + '"')
|
63
|
+
end
|
64
|
+
|
65
|
+
def teardown
|
66
|
+
#applescript('tell application "Safari" to close front document')
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_s
|
70
|
+
"Safari"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class IEBrowser < Browser
|
75
|
+
def setup
|
76
|
+
require 'win32ole' if windows?
|
77
|
+
end
|
78
|
+
|
79
|
+
def supported?
|
80
|
+
windows?
|
81
|
+
end
|
82
|
+
|
83
|
+
def visit(url)
|
84
|
+
if windows?
|
85
|
+
ie = WIN32OLE.new('InternetExplorer.Application')
|
86
|
+
ie.visible = true
|
87
|
+
ie.Navigate(url)
|
88
|
+
while ie.ReadyState != 4 do
|
89
|
+
sleep(1)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def to_s
|
95
|
+
"Internet Explorer"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class KonquerorBrowser < Browser
|
100
|
+
@@configDir = File.join((ENV['HOME'] || ''), '.kde', 'share', 'config')
|
101
|
+
@@globalConfig = File.join(@@configDir, 'kdeglobals')
|
102
|
+
@@konquerorConfig = File.join(@@configDir, 'konquerorrc')
|
103
|
+
|
104
|
+
def supported?
|
105
|
+
linux?
|
106
|
+
end
|
107
|
+
|
108
|
+
# Forces KDE's default browser to be Konqueror during the tests, and forces
|
109
|
+
# Konqueror to open external URL requests in new tabs instead of a new
|
110
|
+
# window.
|
111
|
+
def setup
|
112
|
+
cd @@configDir, :verbose => false do
|
113
|
+
copy @@globalConfig, "#{@@globalConfig}.bak", :preserve => true, :verbose => false
|
114
|
+
copy @@konquerorConfig, "#{@@konquerorConfig}.bak", :preserve => true, :verbose => false
|
115
|
+
# Too lazy to write it in Ruby... Is sed dependency so bad?
|
116
|
+
system "sed -ri /^BrowserApplication=/d '#{@@globalConfig}'"
|
117
|
+
system "sed -ri /^KonquerorTabforExternalURL=/s:false:true: '#{@@konquerorConfig}'"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def teardown
|
122
|
+
cd @@configDir, :verbose => false do
|
123
|
+
copy "#{@@globalConfig}.bak", @@globalConfig, :preserve => true, :verbose => false
|
124
|
+
copy "#{@@konquerorConfig}.bak", @@konquerorConfig, :preserve => true, :verbose => false
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def visit(url)
|
129
|
+
system("kfmclient openURL #{url}")
|
130
|
+
end
|
131
|
+
|
132
|
+
def to_s
|
133
|
+
"Konqueror"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
class OperaBrowser < Browser
|
138
|
+
def initialize(path='c:\Program Files\Opera\Opera.exe')
|
139
|
+
@path = path
|
140
|
+
end
|
141
|
+
|
142
|
+
def setup
|
143
|
+
if windows?
|
144
|
+
puts %{
|
145
|
+
MAJOR ANNOYANCE on Windows.
|
146
|
+
You have to shut down Opera manually after each test
|
147
|
+
for the script to proceed.
|
148
|
+
Any suggestions on fixing this is GREATLY appreciated!
|
149
|
+
Thank you for your understanding.
|
150
|
+
}
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def visit(url)
|
155
|
+
applescript('tell application "Opera" to GetURL "' + url + '"') if macos?
|
156
|
+
system("#{@path} #{url}") if windows?
|
157
|
+
system("opera #{url}") if linux?
|
158
|
+
end
|
159
|
+
|
160
|
+
def to_s
|
161
|
+
"Opera"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# shut up, webrick :-)
|
166
|
+
class ::WEBrick::HTTPServer
|
167
|
+
def access_log(config, req, res)
|
168
|
+
# nop
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
class ::WEBrick::BasicLog
|
173
|
+
def log(level, data)
|
174
|
+
# nop
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
class WEBrick::HTTPResponse
|
179
|
+
alias send send_response
|
180
|
+
def send_response(socket)
|
181
|
+
send(socket) unless fail_silently?
|
182
|
+
end
|
183
|
+
|
184
|
+
def fail_silently?
|
185
|
+
@fail_silently
|
186
|
+
end
|
187
|
+
|
188
|
+
def fail_silently
|
189
|
+
@fail_silently = true
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
class WEBrick::HTTPRequest
|
194
|
+
def to_json
|
195
|
+
headers = []
|
196
|
+
each { |k, v| headers.push "#{k.inspect}: #{v.inspect}" }
|
197
|
+
headers = "{" << headers.join(', ') << "}"
|
198
|
+
%({ "headers": #{headers}, "body": #{body.inspect}, "method": #{request_method.inspect} })
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
class WEBrick::HTTPServlet::AbstractServlet
|
203
|
+
def prevent_caching(res)
|
204
|
+
res['ETag'] = nil
|
205
|
+
res['Last-Modified'] = Time.now + 100**4
|
206
|
+
res['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
|
207
|
+
res['Pragma'] = 'no-cache'
|
208
|
+
res['Expires'] = Time.now - 100**4
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
class BasicServlet < WEBrick::HTTPServlet::AbstractServlet
|
213
|
+
def do_GET(req, res)
|
214
|
+
prevent_caching(res)
|
215
|
+
res['Content-Type'] = "text/plain"
|
216
|
+
|
217
|
+
req.query.each do |k, v|
|
218
|
+
res[k] = v unless k == 'responseBody'
|
219
|
+
end
|
220
|
+
res.body = req.query["responseBody"]
|
221
|
+
|
222
|
+
raise WEBrick::HTTPStatus::OK
|
223
|
+
end
|
224
|
+
|
225
|
+
def do_POST(req, res)
|
226
|
+
do_GET(req, res)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
class SlowServlet < BasicServlet
|
231
|
+
def do_GET(req, res)
|
232
|
+
sleep(2)
|
233
|
+
super
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
class DownServlet < BasicServlet
|
238
|
+
def do_GET(req, res)
|
239
|
+
res.fail_silently
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
class InspectionServlet < BasicServlet
|
244
|
+
def do_GET(req, res)
|
245
|
+
prevent_caching(res)
|
246
|
+
res['Content-Type'] = "application/json"
|
247
|
+
res.body = req.to_json
|
248
|
+
raise WEBrick::HTTPStatus::OK
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
class NonCachingFileHandler < WEBrick::HTTPServlet::FileHandler
|
253
|
+
def do_GET(req, res)
|
254
|
+
super
|
255
|
+
set_default_content_type(res, req.path)
|
256
|
+
prevent_caching(res)
|
257
|
+
end
|
258
|
+
|
259
|
+
def set_default_content_type(res, path)
|
260
|
+
res['Content-Type'] = case path
|
261
|
+
when /\.js$/ then 'text/javascript'
|
262
|
+
when /\.html$/ then 'text/html'
|
263
|
+
when /\.css$/ then 'text/css'
|
264
|
+
else 'text/plain'
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
class JavaScriptTestTask < ::Rake::TaskLib
|
270
|
+
|
271
|
+
def initialize(name=:test)
|
272
|
+
@name = name
|
273
|
+
@tests = []
|
274
|
+
@browsers = []
|
275
|
+
|
276
|
+
@queue = Queue.new
|
277
|
+
|
278
|
+
@server = WEBrick::HTTPServer.new(:Port => 4711) # TODO: make port configurable
|
279
|
+
@server.mount_proc("/results") do |req, res|
|
280
|
+
@queue.push({
|
281
|
+
:tests => req.query['tests'].to_i,
|
282
|
+
:assertions => req.query['assertions'].to_i,
|
283
|
+
:failures => req.query['failures'].to_i,
|
284
|
+
:errors => req.query['errors'].to_i
|
285
|
+
})
|
286
|
+
res.body = "OK"
|
287
|
+
end
|
288
|
+
@server.mount("/response", BasicServlet)
|
289
|
+
@server.mount("/slow", SlowServlet)
|
290
|
+
@server.mount("/down", DownServlet)
|
291
|
+
@server.mount("/inspect", InspectionServlet)
|
292
|
+
yield self if block_given?
|
293
|
+
define
|
294
|
+
end
|
295
|
+
|
296
|
+
def define
|
297
|
+
task @name do
|
298
|
+
trap("INT") { @server.shutdown }
|
299
|
+
t = Thread.new { @server.start }
|
300
|
+
|
301
|
+
# run all combinations of browsers and tests
|
302
|
+
@browsers.each do |browser|
|
303
|
+
if browser.supported?
|
304
|
+
t0 = Time.now
|
305
|
+
results = {:tests => 0, :assertions => 0, :failures => 0, :errors => 0}
|
306
|
+
errors = []
|
307
|
+
failures = []
|
308
|
+
browser.setup
|
309
|
+
puts "\nStarted tests in #{browser}"
|
310
|
+
@tests.each do |test|
|
311
|
+
params = "resultsURL=http://localhost:4711/results&t=" + ("%.6f" % Time.now.to_f)
|
312
|
+
if test.is_a?(Hash)
|
313
|
+
params << "&tests=#{test[:testcases]}" if test[:testcases]
|
314
|
+
test = test[:url]
|
315
|
+
end
|
316
|
+
browser.visit("http://localhost:4711#{test}?#{params}")
|
317
|
+
|
318
|
+
result = @queue.pop
|
319
|
+
result.each { |k, v| results[k] += v }
|
320
|
+
value = "."
|
321
|
+
|
322
|
+
if result[:failures] > 0
|
323
|
+
value = "F"
|
324
|
+
failures.push(test)
|
325
|
+
end
|
326
|
+
|
327
|
+
if result[:errors] > 0
|
328
|
+
value = "E"
|
329
|
+
errors.push(test)
|
330
|
+
end
|
331
|
+
|
332
|
+
print value
|
333
|
+
end
|
334
|
+
|
335
|
+
puts "\nFinished in #{(Time.now - t0).round.to_s} seconds."
|
336
|
+
puts " Failures: #{failures.join(', ')}" unless failures.empty?
|
337
|
+
puts " Errors: #{errors.join(', ')}" unless errors.empty?
|
338
|
+
puts "#{results[:tests]} tests, #{results[:assertions]} assertions, #{results[:failures]} failures, #{results[:errors]} errors"
|
339
|
+
browser.teardown
|
340
|
+
else
|
341
|
+
puts "\nSkipping #{browser}, not supported on this OS"
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
@server.shutdown
|
346
|
+
t.join
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
def mount(path, dir=nil)
|
351
|
+
dir = Dir.pwd + path unless dir
|
352
|
+
|
353
|
+
# don't cache anything in our tests
|
354
|
+
@server.mount(path, NonCachingFileHandler, dir)
|
355
|
+
end
|
356
|
+
|
357
|
+
# test should be specified as a url or as a hash of the form
|
358
|
+
# {:url => "url", :testcases => "testFoo,testBar"}
|
359
|
+
def run(test)
|
360
|
+
@tests<<test
|
361
|
+
end
|
362
|
+
|
363
|
+
def browser(browser)
|
364
|
+
browser =
|
365
|
+
case(browser)
|
366
|
+
when :firefox
|
367
|
+
FirefoxBrowser.new
|
368
|
+
when :safari
|
369
|
+
SafariBrowser.new
|
370
|
+
when :ie
|
371
|
+
IEBrowser.new
|
372
|
+
when :konqueror
|
373
|
+
KonquerorBrowser.new
|
374
|
+
when :opera
|
375
|
+
OperaBrowser.new
|
376
|
+
else
|
377
|
+
browser
|
378
|
+
end
|
379
|
+
|
380
|
+
@browsers<<browser
|
381
|
+
end
|
382
|
+
end
|