Skip to content

Enhancements for templates testing #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ matrix:
- rvm: ruby-head
- rvm: rbx-2
- rvm: jruby
- env: TEST_SUITE=test:templates
- env: TEST_SUITE=templates:test
include:
- env: TEST_SUITE=test:templates
- env: TEST_SUITE=templates:test
rvm: 2.2.5
54 changes: 54 additions & 0 deletions lib/web_console/tasks/templates.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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
56 changes: 0 additions & 56 deletions lib/web_console/tasks/test_templates.rake

This file was deleted.

2 changes: 1 addition & 1 deletion test/templates/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ end

map "/mock/repl_sessions/result" do
headers = { 'Content-Type' => 'application/json' }
body = [ { output: '=> "fake-result"\n' }.to_json ]
body = [ { output: '=> "fake-result"\n', context: [ :something, :somewhat, :somewhere ] }.to_json ]
run lambda { |env| [ 200, headers, body ] }
end

Expand Down
36 changes: 0 additions & 36 deletions test/templates/html/spec_runner.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion test/templates/html/test_runner.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<script src="/templates/console.js"></script>

<!-- find and load test cases -->
<script src="/spec/spec_helper.js"></script>
<script src="/test/test_helper.js"></script>
<% Pathname.glob(TEST_ROOT.join "test/**/*_test.js") do |t| %>
<script src="/<%= t.relative_path_from TEST_ROOT %>"></script>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion test/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"devDependencies": {
"chai": "^3.0.0",
"mocha": "^2.2.5",
"mocha-phantomjs": "^3.5.3"
"mocha-phantomjs-core": "^1.3.1"
}
}
37 changes: 0 additions & 37 deletions test/templates/spec/auto_complete_spec.js

This file was deleted.

105 changes: 0 additions & 105 deletions test/templates/spec/dom_helpers_spec.js

This file was deleted.

Loading