Skip to content

Commit

Permalink
Build the tests from a Rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
jhs committed Mar 30, 2012
1 parent 531f537 commit 6faf19a
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ ENDER = "#{BUILD}/ender"
BROWSER = "#{BUILD}/browser"
REQUIREJS = "#{BUILD}/requirejs"

UGLIFY = "#{HERE}/node_modules/.bin/uglifyjs"
UGLIFY = ENV['uglifyjs'] || "#{HERE}/node_modules/.bin/uglifyjs"
BROWSERIFY = ENV['browserify'] || "#{HERE}/node_modules/.bin/browserify"

XHR_SRC = "#{HERE}/xmlhttprequest/XMLHttpRequest.js"
REQ_SRC = "#{HERE}/src/request.js"
Expand Down Expand Up @@ -157,6 +158,37 @@ file "#{BROWSER}/parts/request-only.js" => [ "#{BROWSER}/parts", BROWSER_TEMPLAT
puts "Generated browser-format #{task.name}"
end

#
# Testing
#

desc "Push a bunch of test apps to a CouchDB server"
task :test => [:build, BROWSERIFY] do
couch_db = ENV['db'] || "http://localhost:5984/test-browser-request"

begin
sh "curl", "--fail", "-XPUT", couch_db
rescue => e
puts "^^ That is fine. The DB already exists." if $?.exitstatus == 22
raise e unless $?.exitstatus == 22
end

# Build a browserify version from this package, to be tested as a first-class deployment type.
Dir.chdir "#{HERE}/test/browserify" do
sh "rm", "-rf", "package.json", "node_modules"
sh "mkdir", "-p", "node_modules/browser-request/dist/ender"
sh "cp", "#{HERE}/package.json", "node_modules/browser-request/"
sh "cp", "#{HERE}/dist/ender/request.js", "node_modules/browser-request/dist/ender/"
sh "cp", "#{HERE}/dist/ender/xmlhttprequest.js", "node_modules/browser-request/dist/ender/"
sh BROWSERIFY, "--outfile=browserified.js", "test.js"
end

sh "test/push.js", couch_db
end

# If you hit <tab> then command-line completion makes you run `rake test/`
task "test/" => :test

#
# Miscellaneous
#
Expand All @@ -165,6 +197,10 @@ file UGLIFY do
throw "uglify-js is missing. Try `npm install` to get the dev dependency: #{UGLIFY}"
end

file BROWSERIFY do
throw "browserify is missing. Try `npm install` to get the dev dependency: #{BROWSERIFY}"
end

#
# Tagging
#
Expand Down

0 comments on commit 6faf19a

Please sign in to comment.