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

Getting "Unsafe JavaScript attempt to access frame" when running specs from the command line #153

Closed gfrivolt closed 8 years ago

gfrivolt commented 9 years ago

I get error running bundle exec rake spec:javascript..

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///Users/fifigyuri/proj/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/assets/javascripts/jasmine-runner.js. Domains, protocols and ports must match.

The specs pass from the browser without any error showing up in the console, but they fail with the above error from command line. It seems like some CORS error.

I use phamtonjs 1.9.8, the lastest jasmine-rails.

searls commented 9 years ago

Do you get the error when you comment out all but, say, a dummy test?

gfrivolt commented 9 years ago

it passes but the strange error messages are still there

Running `"/usr/local/bin/phantomjs" "/Users/fifigyuri/projs/ui/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/jasmine_rails/../assets/javascripts/jasmine-runner.js" "/Users/fifigyuri/projs/ui/tmp/jasmine/runner.html?spec="`
Running: /Users/fifigyuri/projs/ui/tmp/jasmine/runner.html?spec=
Starting...

Finished
-----------------
1 spec, 0 failures in 0.003s.

ConsoleReporter finished
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///Users/fifigyuri/projs/ui/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/assets/javascripts/jasmine-runner.js. Domains, protocols and ports must match.

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///Users/fifigyuri/projs/ui/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/assets/javascripts/jasmine-runner.js. Domains, protocols and ports must match.

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///Users/fifigyuri/projs/ui/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/assets/javascripts/jasmine-runner.js. Domains, protocols and ports must match.
searls commented 9 years ago

Then I suspect you have production JavaScript running and doing illegal frame stuff

On Fri, Jan 2, 2015 at 10:43 AM, György Frivolt notifications@github.com wrote:

it passes but the strange error messages are still there

Running `"/usr/local/bin/phantomjs" "/Users/fifigyuri/projs/ui/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/jasmine_rails/../assets/javascripts/jasmine-runner.js" "/Users/fifigyuri/projs/ui/tmp/jasmine/runner.html?spec="`
Running: /Users/fifigyuri/projs/ui/tmp/jasmine/runner.html?spec=
Starting...
Finished
-----------------
1 spec, 0 failures in 0.003s.
ConsoleReporter finished
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///Users/fifigyuri/projs/ui/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/assets/javascripts/jasmine-runner.js. Domains, protocols and ports must match.
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///Users/fifigyuri/projs/ui/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/assets/javascripts/jasmine-runner.js. Domains, protocols and ports must match.
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///Users/fifigyuri/projs/ui/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/assets/javascripts/jasmine-runner.js. Domains, protocols and ports must match.

Reply to this email directly or view it on GitHub: https://github.com/searls/jasmine-rails/issues/153#issuecomment-68535481

gfrivolt commented 9 years ago

I found that the frame issue is phantomjs related (https://github.com/ariya/phantomjs/issues/12697). The issue was resolved by simply calling RAILS_ENV=test bundle exec rake spec:javascript in test environment.

Locally on my development machine it works fine, ConsoleReporter is used, but for some reason on the CI service jsApiReporter is missed.. Although it should be executed using phantomjs.

Running `"/usr/local/bin/phantomjs" "/home/runner/proj/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/jasmine_rails/../assets/javascripts/jasmine-runner.js" "/home/runner/proj/tmp/jasmine/runner.html?spec="`
Running: /home/runner/proj/tmp/jasmine/runner.html?spec=
Starting...

Finished
-----------------
101 specs, 2 skipped or pending, 0 failures in 0.124s.

ConsoleReporter finished
ERROR: ReferenceError: Can't find variable: jsApiReporter
TRACE:
 -> phantomjs://webpage.evaluate(): 4
ERROR: ReferenceError: Can't find variable: jsApiReporter
TRACE:
 -> phantomjs://webpage.evaluate(): 4
ERROR: ReferenceError: Can't find variable: jsApiReporter
........
.... LOT OF TIMES
........
rake aborted!
Error executing command: "/usr/local/bin/phantomjs" "/home/runner/proj/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/jasmine_rails/../assets/javascripts/jasmine-runner.js" "/home/runner/proj/tmp/jasmine/runner.html?spec="
/home/runner/proj/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/jasmine_rails/runner.rb:71:in `run_cmd'
/home/runner/proj/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/jasmine_rails/runner.rb:21:in `block in run'
/home/runner/proj/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/jasmine_rails/runner.rb:48:in `override_rails_config'
/home/runner/proj/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/jasmine_rails/runner.rb:9:in `run'
/home/runner/proj/vendor/bundle/ruby/2.2.0/gems/jasmine-rails-0.10.5/lib/tasks/jasmine-rails_tasks.rake:8:in `block (2 levels) in <top (required)>'
Tasks: TOP => spec:javascript
(See full trace by running task with --trace)

How can force to use ConsoleReporter?

gfrivolt commented 9 years ago

Sorry, I found it, it's in the docs. The console reporter shipped with jasmine-rails will be used by default, and you can explicitly use it by the name console.

gfrivolt commented 9 years ago

Even if I set REPORTERS='console' the same happens. It misses JsApiReporter. Issue #47 is about the same it seems, do you have any idea what can be the cause? It happens only on the CI. Is it a jasmine-rails or a phantomjs related issue?

searls commented 9 years ago

Are you saying that the issue is resolved if you set RAILS_ENV=test?

On Fri, Jan 2, 2015 at 1:09 PM, György Frivolt notifications@github.com wrote:

Even if I set REPORTERS='console' the same happens. It misses JsApiReporter. Issue #47 is about the same it seems, do you have any idea what can be the cause? It happens only on the CI. Is it a jasmine-rails or a phantomjs related issue?

Reply to this email directly or view it on GitHub: https://github.com/searls/jasmine-rails/issues/153#issuecomment-68547653

gfrivolt commented 9 years ago

yes, it seems so, nothing else seems to be different

searls commented 9 years ago

Yeah this is a long known issue. I don't think anyone ever figured out why t has to be set to the test env to work, and rails loads the environment before the rake task can override. Would LOVE someone to submit a PR that checks the env in the rake task and forks a child invocation with the env variable set.

On Fri, Jan 2, 2015 at 1:23 PM, György Frivolt notifications@github.com wrote:

yes

Reply to this email directly or view it on GitHub: https://github.com/searls/jasmine-rails/issues/153#issuecomment-68548790

hisenb3rg commented 9 years ago

@fifigyuri I have the same issue as you - the test run on CI (semaphore) fails due to missing jsApiReporter. Funny thing is the test suite runs and passes, but the phantomjs doesn't stop at that point and starts emitting this errors after ConsoleReporter finished...

I'm having pretty hard time working around this issue... how did you solve it in the end?

I'm running it on Rails 4.0.13 in test environment, and although it works locally it emits "Unsafe JavaScript attempt..." messages. On the semaphore CI the test task exits with failure and a lot of "missing jsApiReporter" messages... although it outputs the test suite passed.

Fryie commented 9 years ago

@jurglic Had the same issue (also on Semaphore), could get it to pass by locking the phantomjs gem to '~> 1.9.7.0'. Seems there's some trouble with 1.9.8.

If that doesn't work, I'd consider adding a capybara spec that just visits the /spec route and checks for the "0 failures" string. HTH

searls commented 9 years ago

@Fryie make sure you check for ", 0 failures" so that you don't go green when you have 10, 20, 30 failures ;-)

@jurglic sorry but without a reproducible project, I'd encourage you to bundle open jasmine-rails and debug yourself to find the root cause. If it turns out that Phantom 1.9.7 is the issue, then we'll have to look at why >1.9.7 is broken

gregors commented 9 years ago

Also seeing this. I'll see if I can figure it out at our next hacknight

jasongonzales23 commented 9 years ago

+1 on this. Additionally, the CLI is not even running my tests. I'm seeing this on the command line:

0 specs, 0 failures in 0.002s.

Whereas in the browser all my specs are running.

Please to help!

jasongonzales23 commented 9 years ago

Downgrading to 1.9.7.1 made these errors go away for me, but still not getting any specs on the CLI. So I have another unrelated problem apparently.

searls commented 9 years ago

@jasongonzales23 could you provide a minimal repro case and/or open another ticket for that issue?

jasongonzales23 commented 9 years ago

Justin, thanks for the reply! However, I have a use case you don't support. Trying to set up tests for existing code that uses require.js. Thanks anyway!

searls commented 8 years ago

Going to close this thread because it's gone in several directions and it's not clear what would be resolved.

jasper-lyons commented 8 years ago

I know this is closed but for anyone looking for a cleaner solution:

1) add this to your jasmine.yml

use_phantom_gem: false

This will cause jasmine-rails to use the system defined phantomjs command

2) install phantomjs 2.0

Mac \w homebrew:

brew install phantomjs
chrissun-gs commented 8 years ago

@jasper-lyons Thanks for the tip.
After updating jasmine.yml with your suggested change, I'm no longer seeing "Unsafe JavaScript attempt ...".