Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 160 lines (136 sloc) 4.933 kb
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
1 require 'rake'
2 require 'rake/packagetask'
3
52a781a @tobie Switch to UnittestJS.
tobie authored
4 PROTOTYPE_ROOT = File.expand_path(File.dirname(__FILE__))
5 PROTOTYPE_SRC_DIR = File.join(PROTOTYPE_ROOT, 'src')
6 PROTOTYPE_DIST_DIR = File.join(PROTOTYPE_ROOT, 'dist')
7 PROTOTYPE_PKG_DIR = File.join(PROTOTYPE_ROOT, 'pkg')
8 PROTOTYPE_TEST_DIR = File.join(PROTOTYPE_ROOT, 'test')
9 PROTOTYPE_TEST_UNIT_DIR = File.join(PROTOTYPE_TEST_DIR, 'unit')
10 PROTOTYPE_TMP_DIR = File.join(PROTOTYPE_TEST_UNIT_DIR, 'tmp')
11 PROTOTYPE_VERSION = '1.6.0.3'
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
12
b2597ec @samleb Start PDoc integration.
samleb authored
13 $:.unshift File.join(PROTOTYPE_ROOT, 'lib')
14
87ce153 @tobie prototype: Complete rewrite of the deprecation helper.
tobie authored
15 task :default => [:dist, :dist_helper, :package, :clean_package_source]
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
16
cf5d180 @tobie refactored unit tests quite a bit. Added JS and CSS fixtures.
tobie authored
17 desc "Builds the distribution."
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
18 task :dist do
19 require 'protodoc'
b2597ec @samleb Start PDoc integration.
samleb authored
20
21 File.open(File.join(PROTOTYPE_DIST_DIR, 'prototype.js'), 'w+') do |dist|
22 source = File.join(PROTOTYPE_SRC_DIR, 'prototype.js')
23 dist << Protodoc::Preprocessor.new(source, :strip_documentation => true)
24 end
25 end
26
27 desc "Builds the documentation."
28 task :doc do
29 require 'protodoc'
30 require 'pdoc'
31
32 Tempfile.open("prototype-doc") do |temp|
33 source = File.join(PROTOTYPE_SRC_DIR, 'prototype.js')
34 temp << Protodoc::Preprocessor.new(source, :strip_documentation => false)
35 temp.flush
36 rm_rf PROTOTYPE_DOC_DIR
37 PDoc::Runner.new(temp.path, :output => PROTOTYPE_DOC_DIR).run
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
38 end
39 end
40
cf5d180 @tobie refactored unit tests quite a bit. Added JS and CSS fixtures.
tobie authored
41 desc "Builds the updating helper."
87ce153 @tobie prototype: Complete rewrite of the deprecation helper.
tobie authored
42 task :dist_helper do
43 require 'protodoc'
b2597ec @samleb Start PDoc integration.
samleb authored
44
45 File.open(File.join(PROTOTYPE_DIST_DIR, 'prototype_update_helper.js'), 'w+') do |dist|
46 source = File.join(PROTOTYPE_ROOT, 'ext', 'update_helper', 'prototype_update_helper.js')
47 dist << Protodoc::Preprocessor.new(source)
87ce153 @tobie prototype: Complete rewrite of the deprecation helper.
tobie authored
48 end
49 end
50
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
51 Rake::PackageTask.new('prototype', PROTOTYPE_VERSION) do |package|
52 package.need_tar_gz = true
53 package.package_dir = PROTOTYPE_PKG_DIR
54 package.package_files.include(
55 '[A-Z]*',
56 'dist/prototype.js',
57 'lib/**',
58 'src/**',
59 'test/**'
60 )
61 end
62
52a781a @tobie Switch to UnittestJS.
tobie authored
63 task :clean_package_source do
64 rm_rf File.join(PROTOTYPE_PKG_DIR, "prototype-#{PROTOTYPE_VERSION}")
65 end
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
66
52a781a @tobie Switch to UnittestJS.
tobie authored
67 task :test => ['test:build', 'test:run']
68 namespace :test do
69 desc 'Runs all the JavaScript unit tests and collects the results'
70 task :run => [:require] do
71 testcases = ENV['TESTCASES']
72 browsers_to_test = ENV['BROWSERS'] && ENV['BROWSERS'].split(',')
73 tests_to_run = ENV['TESTS'] && ENV['TESTS'].split(',')
74 runner = UnittestJS::WEBrickRunner::Runner.new(:test_dir => PROTOTYPE_TMP_DIR)
75
76 Dir[File.join(PROTOTYPE_TMP_DIR, '*_test.html')].each do |file|
77 file = File.basename(file)
78 test = file.sub('_test.html', '')
79 unless tests_to_run && !tests_to_run.include?(test)
80 runner.add_test(file, testcases)
81 end
82 end
83
84 UnittestJS::Browser::SUPPORTED.each do |browser|
85 unless browsers_to_test && !browsers_to_test.include?(browser)
86 runner.add_browser(browser.to_sym)
87 end
88 end
89
90 trap('INT') { runner.teardown; exit }
91 runner.run
92 end
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
93
52a781a @tobie Switch to UnittestJS.
tobie authored
94 task :build => [:clean, :dist] do
95 builder = UnittestJS::Builder::SuiteBuilder.new({
96 :input_dir => PROTOTYPE_TEST_UNIT_DIR,
97 :assets_dir => PROTOTYPE_DIST_DIR
98 })
99 selected_tests = (ENV['TESTS'] || '').split(',')
100 builder.collect(*selected_tests)
101 builder.render
102 end
ba6934e @tobie Make Rake auto-generate test/unit/temp directory if it is missing.
tobie authored
103
52a781a @tobie Switch to UnittestJS.
tobie authored
104 task :clean => [:require] do
105 UnittestJS::Builder.empty_dir!(PROTOTYPE_TMP_DIR)
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
106 end
107
52a781a @tobie Switch to UnittestJS.
tobie authored
108 task :require do
109 lib = 'vendor/unittest_js/lib/unittest_js'
110 unless File.exists?(lib)
111 puts "\nYou'll need UnittestJS to run the tests. Just run:\n\n"
112 puts " $ git submodule init"
113 puts " $ git submodule update"
114 puts "\nand you should be all set.\n\n"
115 end
116 require lib
bb4d189 @sstephenson prototype: Reorganize the source tree.
authored
117 end
118 end
41ef42e @tobie Unit test lib reorganizing.
tobie authored
119
52a781a @tobie Switch to UnittestJS.
tobie authored
120 task :test_units do
121 puts '"rake test_units" is deprecated. Please use "rake test" instead.'
41ef42e @tobie Unit test lib reorganizing.
tobie authored
122 end
123
52a781a @tobie Switch to UnittestJS.
tobie authored
124 task :build_unit_tests do
125 puts '"rake test_units" is deprecated. Please use "rake test:build" instead.'
41ef42e @tobie Unit test lib reorganizing.
tobie authored
126 end
127
128 task :clean_tmp do
52a781a @tobie Switch to UnittestJS.
tobie authored
129 puts '"rake clean_tmp" is deprecated. Please use "rake test:clean" instead.'
41ef42e @tobie Unit test lib reorganizing.
tobie authored
130 end
99f74b5 @tobie Add caja_builder for optional cajoled tests.
tobie authored
131
132 namespace :caja do
133 task :test => ['test:build', 'test:run']
134
135 namespace :test do
136 task :run => ['rake:test:run']
137
138 task :build => [:require, 'rake:test:clean', :dist] do
139 builder = UnittestJS::CajaBuilder::SuiteBuilder.new({
140 :input_dir => PROTOTYPE_TEST_UNIT_DIR,
141 :assets_dir => PROTOTYPE_DIST_DIR,
142 :whitelist_dir => File.join(PROTOTYPE_TEST_DIR, 'unit', 'caja_whitelists'),
143 :html_attrib_schema => 'html_attrib.json'
144 })
145 selected_tests = (ENV['TESTS'] || '').split(',')
146 builder.collect(*selected_tests)
147 builder.render
148 end
149 end
150 task :require => ['rake:test:require'] do
151 lib = 'vendor/caja_builder/lib/caja_builder'
152 unless File.exists?(lib)
153 puts "\nYou'll need UnittestJS to run the tests. Just run:\n\n"
154 puts " $ git submodule init"
155 puts " $ git submodule update"
156 puts "\nand you should be all set.\n\n"
157 end
158 require lib
159 end
160 end
Something went wrong with that request. Please try again.