guard / guard-jasmine

The Swiss Army knife for automated Jasmine specs in your console.

Home Page:http://guard.github.io/guard-jasmine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error "Cannot decode JSON from PhantomJS runner" for phantomjs v1.9.8

gfrivolt opened this issue · comments

Running the specs in the browser pass, but running guard-jasmine fails with "Cannot decode JSON from PhantomJS runner".

Hi @fifigyuri

Thanks for the report. Can you please enable debug support for GuardJasmine and report what it shows it receives? You can enable debugging by changing the Guardfile from something like:

guard :jasmine do
    watch(%r{^spec/javascripts/.*(?:_s|S)pec\.(coffee|js)$})
end

To:

guard :jasmine, debug: true do
    watch(%r{^spec/javascripts/.*(?:_s|S)pec\.(coffee|js)$})
end

Thank you for you help. Here it is:

16:53:56 - INFO - Guard is using Tmux to send notifications.
16:53:56 - INFO - Guard is using TerminalTitle to send notifications.
16:53:57 - INFO - Guard::Jasmine starts Unicorn spec server on port 53187 in development environment (coverage off).
16:53:58 - INFO - Waiting for Jasmine test runner at http://localhost:53187/jasmine
16:54:13 - INFO - Run all Jasmine suites
16:54:13 - INFO - Run Jasmine suite at http://localhost:53187/jasmine
16:54:24 - ERROR - Cannot decode JSON from PhantomJS runner: unexpected character at line 2, column 2 [parse.c:649]
16:54:24 - ERROR - JSON response: {"passed":true,"stats":{"failures":0,"specs":74,"time":0.089},"suites":[{"description":"data point","passed":true,"specs":[],"suites":[{"description":"presenting name","passed":true,"specs":[{"description":"returns only the data point name if unit not set","passed":true},{"description":"returns name with unit when unit is present","passed":true}],"suites":[]},{"description":"#blendMeasurement","passed":true,"specs":[{"description":"updates the last measurement if it is more recent","passed":true},{"description":"does not update the last measurement if it is old","passed":true}],"suites":[]}]},{"description":"data point with series","passed":true,"specs":[{"description":"adds the data point initial value to measurements","passed":true},{"description":"adds nothing if no initial value is passed","passed":true}],"suites":[{"description":"#blendMeasurement","passed":true,"specs":[{"description":"adds the measurement to the data point measurements","passed":true}],"suites":[]}]},{"description":"data points collection","passed":true,"specs":[],"suites":[{"description":"#blendMeasurements","passed":true,"specs":[{"description":"calls blendMeasurements to each data point","passed":true},{"description":"creates the new data point if not found","passed":true}],"suites":[]}]},{"description":"measurement","passed":true,"specs":[{"description":"throws an error when the passed in attrs are not correct","passed":true},{"description":"serializes its value in toJSON to a tuple","passed":true}],"suites":[]},{"description":"measurements collection","passed":true,"specs":[{"description":"serializes the measurement to an array of tuples","passed":true}],"suites":[]},{"description":"sensor model","passed":true,"specs":[{"description":"sets the vendor based on the sensor type","passed":true},{"description":"sets the sensor_type to default when vendor changes","passed":true},{"description":"does not change the sensor_type if the vendor is empty","passed":true},{"description":"clears the vendor if the sensor_type is set to empty","passed":true}],"suites":[]},{"description":"node configuration","passed":true,"specs":[{"description":"gets the list of available vendors","passed":true},{"description":"gets the list of available sensor type names for a vendor","passed":true},{"description":"gets the vendor for the sensor type","passed":true},{"description":"gets the list of com types for the sensor type","passed":true},{"description":"gets the list of com ports for the sensor type and com type","passed":true},{"description":"knows the editability of the address field","passed":true}],"suites":[]},{"description":"node widget","passed":true,"specs":[{"description":"resets filter_data_point_ids when node_id is changed","passed":true}],"suites":[]},{"description":"organization collection","passed":true,"specs":[{"description":"should extract value, label tuples from the collection","passed":true}],"suites":[]},{"description":"report model","passed":true,"specs":[{"description":"creates a widget collection on initialization","passed":true},{"description":"does not serialize node_id to json","passed":true}],"suites":[]},{"description":"user model","passed":true,"specs":[],"suites":[{"description":"clearing the password and password_confirmation","passed":true,"specs":[{"description":"unsets the fields when sync was triggered","passed":true},{"description":"unsets the fields when error was triggered","passed":true},{"description":"unsets the fields when invalid was triggered","passed":true}],"suites":[]},{"description":"#isManager","passed":true,"specs":[{"description":"is true for a manager","passed":true},{"description":"is false for a user","passed":true},{"description":"is false for a manager but in other organization","passed":true}],"suites":[]},{"description":"#isAdmin","passed":true,"specs":[{"description":"is true for an admin","passed":true},{"description":"is false for a user","passed":true}],"suites":[]},{"description":"serialization","passed":true,"specs":[{"description":"has user as the root of the json","passed":true}],"suites":[]}]},{"description":"users collection","passed":true,"specs":[{"description":"extracts value, label tuples from the collection","passed":true}],"suites":[]},{"description":"roles serialization","passed":true,"specs":[{"description":"uses _attributes suffix for rails","passed":true}],"suites":[]},{"description":"widget","passed":true,"specs":[{"description":"serializes \"widget\" as root key","passed":true}],"suites":[]},{"description":"Clusternet.AppEventSource","passed":true,"specs":[],"suites":[{"description":"#getSessionAjaxPromise","passed":true,"specs":[{"description":"performs session registration only once returning the same promise","passed":true}],"suites":[]},{"description":"#registerSession","passed":true,"specs":[{"description":"sets the uuid when ajax request delivered","passed":true},{"description":"starts to listen to event source","passed":true}],"suites":[]}]},{"description":"Controllers.ListedPageController","passed":true,"specs":[],"suites":[{"description":"events handling","passed":true,"specs":[{"description":"listens to modify:details","passed":true},{"description":"listens to view:details","passed":true},{"description":"listens to cancel:details","passed":true}],"suites":[]},{"description":"navigating","passed":true,"specs":[{"description":"has indexPath","passed":true},{"description":"navigates to modify details","passed":true},{"description":"navigates to view details","passed":true},{"description":"navigates to index","passed":true}],"suites":[]}]},{"description":"Entities.AppModel","passed":true,"specs":[],"suites":[{"description":"access rights","passed":true,"specs":[{"description":"knows when it is modifiable","passed":true},{"description":"knows when it is destroyable","passed":true}],"suites":[]},{"description":"serialization","passed":true,"specs":[{"description":"does not serialize the access rights attrs","passed":true}],"suites":[{"description":"access rights","passed":true,"specs":[{"description":"does not serialize the access rights attrs","passed":true}],"suites":[]}]},{"description":"serialization","passed":true,"specs":[{"description":"does not serialize attribute chosen","passed":true},{"description":"does not serialize validations","passed":true},{"description":"does not serialize attributes listed in transientAttrs","passed":true},{"description":"has root key in serialized json when toJSON is called with renderRootKey option","passed":true},{"description":"does not serialize root key when toJSON is not called with renderRootKey option","passed":true},{"description":"save calls sync with renderJsonKey option set","passed":true}],"suites":[]},{"description":"validations","passed":true,"specs":[{"description":"has validation method returning the value of validation attr","passed":true},{"description":"returns empty object when not validation are present","passed":true}],"suites":[]},{"description":"#getNewFormModel","passed":true,"specs":[{"description":"clones the original with the relations","passed":true}],"suites":[]}]},{"description":"Entities.Collection","passed":true,"specs":[],"suites":[{"description":"with AssociatedModel","passed":true,"specs":[],"suites":[{"description":"serialization","passed":true,"specs":[{"description":"serialize remoteKey","passed":true},{"description":"doesn't serialize remoteKey","passed":true}],"suites":[]}]}]},{"description":"underscore mixins","passed":true,"specs":[],"suites":[{"description":"string","passed":true,"specs":[{"description":"is converted to snake_case","passed":true},{"description":"is convertable to Camelize","passed":true},{"description":"is capitalized","passed":true}],"suites":[]},{"description":"#pickFormParts","passed":true,"specs":[{"description":"picks formModel as model","passed":true},{"description":"picks listed attrs","passed":true}],"suites":[]},{"description":"#formatNumber","passed":true,"specs":[{"description":"present number < 1000 as it is","passed":true},{"description":"present number > 1000 but < 1000000 with K suffix","passed":true},{"description":"present number > 1000000 with M suffix","passed":true}],"suites":[]},{"description":"#extendObject","passed":true,"specs":[{"description":"leaves the original object intact","passed":true},{"description":"extends the original object","passed":true}],"suites":[]},{"description":"#convertI18Str","passed":true,"specs":[{"description":"converts the server side i18n string to backbone.validations format","passed":true}],"suites":[]}]}]}
> [#6E2E8DCDC0CB] Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///Users/fifigyuri/Projects/proj/ui/vendor/bundle/ruby/2.1.0/gems/guard-jasmine-1.19.2/lib/guard/jasmine/phantomjs/guard-jasmine.js. Domains, protocols and ports must match.
> [#6E2E8DCDC0CB]
> [#6E2E8DCDC0CB] Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///Users/fifigyuri/Projects/proj/ui/vendor/bundle/ruby/2.1.0/gems/guard-jasmine-1.19.2/lib/guard/jasmine/phantomjs/guard-jasmine.js. Domains, protocols and ports must match.
> [#6E2E8DCDC0CB]
> [#6E2E8DCDC0CB]
1

Interesting. That looks like phantomjs is outputting an error message that is interfering with the JSON output.

I wonder what's triggering the "Unsafe JavaScript attempt to access frame with URL about:blank"? The message seems to indicate that it comes from guard-jasmine itself, but I'm not sure why you are receiving the message but others are not.

Two questions:

  • Do you know if any of your specs are accessing frames and/or using cross-site ajax requests? Based on the error message, it looks like the exception's happening twice.
  • Would it be possible to test the code with the newly released beta version 2.0.0beta1 and see the problem continues? I'm guessing it will, but it'll make it easier for me to trace the code path if we can make sure we're both using the same code.

Appears to be introduced in PhantomJS v1.9.8 and fixed in ariya/phantomjs#12720

Yep - there's also PR #177 open that purports to fix the issue. I haven't evaluated it yet though.

@danwu Thanks for the tip on the version. I'm running 1.9.7 which is why I haven't encountered it yet.

I've just cut a new 2.0.1 release that incorporates the fix from #177.

Please give it a try and see if that fixes the issue.

thank you, I tried to start it by bundle exec guard-jasmine --server-timeout=180 --verbose and I get a very different error.

/proj/ui/vendor/bundle/ruby/2.2.0/gems/guard-jasmine-2.0.1/lib/guard/jasmine/cli.rb:228:in `rescue in spec': uninitialized constant Guard::UI (NameError)
        from /proj/ui/vendor/bundle/ruby/2.2.0/gems/guard-jasmine-2.0.1/lib/guard/jasmine/cli.rb:232:in `spec'
        from /proj/ui/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
        from /proj/ui/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
        from /proj/ui/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
        from /proj/ui/vendor/bundle/ruby/2.2.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
        from /proj/ui/vendor/bundle/ruby/2.2.0/gems/guard-jasmine-2.0.1/bin/guard-jasmine:3:in `<top (required)>'
        from /proj/ui/vendor/bundle/ruby/2.2.0/bin/guard-jasmine:23:in `load'
        from /proj/ui/vendor/bundle/ruby/2.2.0/bin/guard-jasmine:23:in `<main>'

@fifigyuri - that should be fixed by this PR: #181

You can test it by putting this in your Gemfile:

gem 'guard-jasmine', github: 'guard/guard-jasmine', branch: 'update_guard_compat'

@fifigyuri I've just merged #181 and am testing it now. Assuming that goes well, I'll push out a 2.0.2 release shortly that should resolve this.

ok, i've tested out #181 and appears to work excellently on my system. I've also added some improved error reporting and have cut a 2.0.2 release.

Please give that a try and let me know how it works.

After bundle update, rails 4.2 , phamtom 1.9.8

I am getting the following error
Guard::Jasmine starts thin spec server on port 53718 in test environment (coverage off).
Waiting for Jasmine test runner at http://localhost:53718/jasmine
Run all Jasmine suites (waits for few minutes)
Something went wrong: An error occurred in the Jasmine runner
Guard::Jasmine stops server.

Small note
while it is waiting, I can go http://localhost:53718/jasmine and I can see all tests passing.

@nathanstitt

Hi sahin,

I doubt that the error you are receiving is related. Would it be possible for you to share your Guardfile?


interactor :simple

#guard 'livereload', host: '//movielala.com', , apply_css_live: true, override_url: true, grace_period: 0.5 do
guard 'livereload', host: 'movielala.com', port: '35729' do
  watch(%r{app/views/.+\.(erb|haml|slim)$})
  watch(%r{app/helpers/.+\.rb})
  watch(%r{public/.+\.(css|js|html)})
  watch(%r{config/locales/.+\.yml})
  # Rails Assets Pipeline
  watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html))).*}) { |m| "/assets/#{m[3]}" }
end

#guard bundler is not for guard 2.0
guard 'bundler' do
  watch('Gemfile')
  # Uncomment next line if Gemfile contain `gemspec' command
  watch(/^.+\.gemspec/)
end

guard :cucumber, :all_on_start => false, :all_after_pass => false, :cli => '--profile guard -c', :bundler => false do
  watch(%r{^features/.+\.feature$})
  watch(%r{^features/support/.+$})          { 'features' }
  watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
end

guard :rspec, all_on_start: false, failed_mode: :focus  do
  watch('spec/spec_helper.rb')                        { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^spec/support/(.+)\.rb$})                  { 'spec' }

  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$})          { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^lib/(.+)\.rb$})                           { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^app/controllers/api/(.+)\.rb$})           { |m| "spec/api/#{m[1]}_spec.rb" }
end

guard :jasmine, port: 8888, server_env: "test", all_on_start: false do
  watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { 'spec/javascripts' }
  watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
  watch(%r{spec/javascripts/fixtures/.+$})
  watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)(?:\.\w+)*$}) { |m| "spec/javascripts/#{ m[1] }_spec.#{ m[2] }" }
end

@sahin - could you rerun guard with the '-d' option? (your Guardfile seems fine)

Does rake jasmine:ci work?

Are there any errors in your log/test.log file?

The issue I reported is fixed for me.. no decode JSON issue any more. Thank you.

@shahin: I looked over the Guardfile, it looks correct. I then attempted to locate the "An error occurred in the Jasmine runner" message in the code base and it's only used when the "guard-jasmine" command line is used. If that's the case, then the Guardfile doesn't come into play at all.

I've just pushed up a tiny code change to include more details about the error that's occurring. If you could, please change your Gemfile to include Guard Jasmine from the latest git source. The line should look like:

gem 'guard-jasmine', github: 'guard/guard-jasmine'

After doing so, run gem update guard-jasmine and then run the program under bundler, i.e. as: bundle exec guard-jasmine You can verify that you're using the updated code by running bundle exec guard-jasmine -v which should display "2.0.3b"

I'm pretty sure you'll still receive an error, but it will hopefully provide enough details now so we can figure out if it's occurring inside guard-jasmine or perhaps in your spec's code.

I'm going to close this issue for right now since it's not related to the error you're receiving. Please open a new issue with the contents of the updated error message and we'll figure it out.

I updated the gem with guard-jasmine.
it shows
bundle exec guard-jasmine -v
Guard::Jasmine version 2.0.3b

now when I run I am getting.

Guard::Jasmine starts Jasmine Gem test server on port 57881.
Timeout while waiting for the server to startup
Most likely there is a configuration error that's preventing the server from starting
You may need to increase the :server_timeout option.
The commandline that was used to start the server was:
ruby -S rake jasmine JASMINE_PORT=57881
You should attempt to run that and see if any errors occur
Waiting for Jasmine test runner at http://localhost:57881/jasmine
Jasmine test runner isn't available: Connection refused - connect(2) for "localhost" port 57881
Guard::Jasmine stops server.

when I run like this

ruby -S rake jasmine JASMINE_PORT=8888 RAILS_ENV=test

I can see the jasmine test page with no problem.