testdouble / jasmine-rails

A Jasmine runner for rails projects that's got you covered in both the terminal and the browser
http://rubygems.org/gems/jasmine-rails
MIT License
378 stars 154 forks source link

Prevent multiple calls to phantom.exit #183

Closed shamus closed 8 years ago

shamus commented 8 years ago

Currently, using jasmine-rails with phantomjs 2.1.1 causes phantomjs to segfault. It appears that the onInitialized handler registered in libe/assets/javascripts/jasmine-runner.js:48 is being executed multiple times. Each call registers a window.onLoad listener which eventually calls phantom.exit. It is unclear why page.onInitialized is called more than once.

This commit introduces an initialized flag which prevents the page.onInitialized callback from registering more than one window.onLoad callback.

Not an ideal fix. It would be better to figure out what causes page.onInitialized to be executed multiple times.

searls commented 8 years ago

Thanks for this. I'd like to see someone replicate the issue and a green build before merging. It looks like the build has incidentally broken again so I'm testing it here: https://travis-ci.org/searls/jasmine-rails/builds/108023254

shamus commented 8 years ago

Fair enough. The failing specs on this branch (and also here: https://github.com/searls/jasmine-rails/pull/181) are due to a change in the markup for the jasmine report page. The status banner classes changed to .jasmine-bar.jasmine-passed.

This branch contains a fix for that now.

As for reproducting, two things:

Here's the full output from my mac

Running `"/Users/shamus/.phantomjs/2.1.1/darwin/bin/phantomjs" "" "/Users/shamus/.rvm/gems/ruby-2.1.5/gems/jasmine-rails-0.12.2/lib/jasmine_rails/../assets/javascripts/jasmine-runner.js" "file:///Users/shamus/projects/me/jasmine_rails_test/tmp/jasmine/runner.html?spec="`
Running: file:///Users/shamus/projects/me/jasmine_rails_test/tmp/jasmine/runner.html?spec=
Starting...

Finished
-----------------
0 specs, 0 failures in 0.002s.

ConsoleReporter finished
PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.
rake aborted!
Error executing command: "/Users/shamus/.phantomjs/2.1.1/darwin/bin/phantomjs" "" "/Users/shamus/.rvm/gems/ruby-2.1.5/gems/jasmine-rails-0.12.2/lib/jasmine_rails/../assets/javascripts/jasmine-runner.js" "file:///Users/shamus/projects/me/jasmine_rails_test/tmp/jasmine/runner.html?spec="
/Users/shamus/.rvm/gems/ruby-2.1.5/gems/jasmine-rails-0.12.2/lib/jasmine_rails/runner.rb:73:in `run_cmd'
/Users/shamus/.rvm/gems/ruby-2.1.5/gems/jasmine-rails-0.12.2/lib/jasmine_rails/runner.rb:23:in `block in run'
/Users/shamus/.rvm/gems/ruby-2.1.5/gems/jasmine-rails-0.12.2/lib/jasmine_rails/runner.rb:50:in `override_rails_config'
/Users/shamus/.rvm/gems/ruby-2.1.5/gems/jasmine-rails-0.12.2/lib/jasmine_rails/runner.rb:9:in `run'
/Users/shamus/.rvm/gems/ruby-2.1.5/gems/jasmine-rails-0.12.2/lib/tasks/jasmine-rails_tasks.rake:9:in `block (2 levels) in <top (required)>'
Tasks: TOP => spec:javascript
(See full trace by running task with --trace)

And here's the full output from Travis

Running `"/home/travis/.phantomjs/2.1.1/x86_64-linux/bin/phantomjs" "" "/home/travis/build/searls/jasmine-rails/lib/jasmine_rails/../assets/javascripts/jasmine-runner.js" "file:///home/travis/build/searls/jasmine-rails/spec/testbeds/rails-3.2/tmp/jasmine/runner.html?spec="`
Running: file:///home/travis/build/searls/jasmine-rails/spec/testbeds/rails-3.2/tmp/jasmine/runner.html?spec=
Starting...
Finished
-----------------
5 specs, 0 failures in 0.017s.
ConsoleReporter finished
Killed
rake aborted!
Error executing command: "/home/travis/.phantomjs/2.1.1/x86_64-linux/bin/phantomjs" "" "/home/travis/build/searls/jasmine-rails/lib/jasmine_rails/../assets/javascripts/jasmine-runner.js" "file:///home/travis/build/searls/jasmine-rails/spec/testbeds/rails-3.2/tmp/jasmine/runner.html?spec="
/home/travis/build/searls/jasmine-rails/lib/jasmine_rails/runner.rb:73:in `run_cmd'
/home/travis/build/searls/jasmine-rails/lib/jasmine_rails/runner.rb:23:in `block in run'
/home/travis/build/searls/jasmine-rails/lib/jasmine_rails/runner.rb:50:in `override_rails_config'
/home/travis/build/searls/jasmine-rails/lib/jasmine_rails/runner.rb:9:in `run'
/home/travis/build/searls/jasmine-rails/lib/tasks/jasmine-rails_tasks.rake:9:in `block (2 levels) in <top (required)>'
/home/travis/.rvm/gems/ruby-2.0.0-p598/bin/ruby_executable_hooks:15:in `eval'
/home/travis/.rvm/gems/ruby-2.0.0-p598/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => testbed:current:spec:javascript
(See full trace by running task with --trace)
rake aborted!
specs failed
/home/travis/build/searls/jasmine-rails/Rakefile:23:in `block (2 levels) in <top (required)>'
/home/travis/.rvm/gems/ruby-2.0.0-p598/bin/ruby_executable_hooks:15:in `eval'
/home/travis/.rvm/gems/ruby-2.0.0-p598/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => testbed:current:all => testbed:rails-3.2:run_jasmine_rake_in_dummy
(See full trace by running task with --trace)
johncalvinyoung commented 8 years ago

This would be really good to get merged. We're using PhantomJS 2.1.1 for our Rails test stack, and it's a real pain having to downgrade to 1.9.8 for jasmine. Getting pressure from others on my team to use something other than Jasmine over it.

searls commented 8 years ago

Green is better than not green. LGTM.

searls commented 8 years ago

Landed in 0.12.3