Sha256: f612b99ad55e7f280eb4f2e87913cace85dad5c1422dc5bd99a3d730f8928117

Contents?: true

Size: 1.44 KB

Versions: 13

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

namespace :templates do
  desc "Run tests for templates"
  task test: [ :daemonize, :npm, :rackup, :wait, :mocha, :kill, :exit ]
  task serve: [ :npm, :rackup ]

  workdir = Pathname(EXPANDED_CWD).join("test/templates")
  pid     = Pathname(Dir.tmpdir).join("web_console_test.pid")
  runner  = URI.parse("http://#{ENV['IP'] || '127.0.0.1'}:#{ENV['PORT'] || 29292}/html/test_runner.html")
  rackup  = "rackup --host #{runner.host} --port #{runner.port}"
  result  = nil
  browser = "phantomjs"

  def need_to_wait?(uri)
    Net::HTTP.start(uri.host, uri.port) { |http| http.get(uri.path) }
  rescue Errno::ECONNREFUSED
    retry if yield
  end

  task :daemonize do
    rackup += " -D --pid #{pid}"
  end

  task npm: [ :phantomjs ] do
    Dir.chdir(workdir) { system "npm install --silent" }
  end

  task :phantomjs do
    unless system("which #{browser} >/dev/null")
      browser = "./node_modules/.bin/phantomjs"
      Dir.chdir(workdir) { system("test -f #{browser} || npm install --silent phantomjs-prebuilt") }
    end
  end

  task :rackup do
    Dir.chdir(workdir) { system rackup }
  end

  task :wait do
    cnt = 0
    need_to_wait?(runner) { sleep 1; cnt += 1; cnt < 5 }
  end

  task :mocha do
    Dir.chdir(workdir) { result = system("#{browser} ./node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js #{runner} dot") }
  end

  task :kill do
    system "kill #{File.read pid}"
  end

  task :exit do
    exit result
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
web-console-4.2.0 lib/web_console/tasks/templates.rake
web-console-4.1.0 lib/web_console/tasks/templates.rake
web-console-4.0.4 lib/web_console/tasks/templates.rake
web-console-4.0.3 lib/web_console/tasks/templates.rake
web-console-4.0.2 lib/web_console/tasks/templates.rake
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/web-console-4.0.1/lib/web_console/tasks/templates.rake
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/web-console-4.0.1/lib/web_console/tasks/templates.rake
web-console-4.0.1 lib/web_console/tasks/templates.rake
web-console-4.0.0 lib/web_console/tasks/templates.rake
web-console-3.7.0 lib/web_console/tasks/templates.rake
web-console-3.6.2 lib/web_console/tasks/templates.rake
web-console-3.6.1 lib/web_console/tasks/templates.rake
web-console-3.6.0 lib/web_console/tasks/templates.rake