require 'fileutils' require_relative '../../../lib/flok' require 'securerandom' require 'tmpdir' require 'phantomjs' require 'tempfile' require 'erb' require File.join(File.dirname(__FILE__), "./build_context") require 'cakery' require '../../../spec/lib/helpers.rb' #Compile all the *.js files into one file task :build do raise "No BUILD_PATH given" unless build_path=ENV["BUILD_PATH"] build_path = File.expand_path(build_path) raise "FLOK_ENV must be debug or release got #{ENV['FLOK_ENV']}" unless ["DEBUG", "RELEASE"].include? ENV["FLOK_ENV"] my_path = File.expand_path(File.dirname(__FILE__)) Dir.mktmpdir(SecureRandom.hex) do |dir| Dir.chdir dir do #We are in a temporary directory here Flok.src_glob("js", "#{my_path}/src/vendor", "0src_vendor.js") Flok.src_glob("js", "#{my_path}/src/", "1src.js") #Almost done, we still technically have an ERB file (<%= %> inside our code) #Which isn't technically 'real' JS, and we're still in the temporary folder Flok.src_glob("js", ".", "chrome.js.erb") src = File.read "chrome.js.erb" rdr = ERB.new(src) ctx = Chrome::BuildContext.new File.write File.join(build_path, "chrome.js"), rdr.result(ctx.get_binding) end end end #Make sure it runs task :spec do #Build the driver ENV['BUILD_PATH'] = "../../../products/chrome/drivers/" ENV['FLOK_ENV'] = 'DEBUG' ENV['FLOK_CHROME_SPEC'] = 'TRUE' system('rake build') recipe = Cakery.new("./cakery/spec.js.erb") do |f| f.spec_js_init << "./spec/init/**/*.js" f.spec_js_init << "./spec/config/**/*.js" f.spec_js << "./spec/spec/**/*_spec.js" f.app_js << File.join(ENV['BUILD_PATH'], './chrome.js') #f.app_js << File.join(ENV['BUILD_PATH'], '../application.js') end recipe.bake f = Tempfile.new(SecureRandom.hex) f.puts recipe.src f.close include SpecHelpers $stderr.puts "Starting CHROME spec test" $stderr.puts "-----------------------------------------------------" sh2("boojs #{f.path}") do |stdin, stdout| loop do begin Timeout::timeout(10) do res = stdout.readline $stderr.puts "\t"+res if res =~ /__SUCCESS/ exit 0 elsif res =~ /__FAILED/ exit 1 end end rescue => e $stderr.puts e.inspect exit 1 end end end end #Establish an environment with a pipe assuming the world is built task :pipe => :build do raise "No BUILD_PATH given" unless build_path=ENV["BUILD_PATH"] exec "ruby", "-e", %{ require './pipe' server = InteractiveServer.new "../../../products/chrome/drivers/chrome.js" server.begin_pipe } end