Giter Site home page Giter Site logo

smparkes / env-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thatcher/env-js

80.0 80.0 7.0 7.91 MB

A pure-JavaScript browser environment with early rubygem support.

Home Page: http://github.com/smparkes/env-js

Java 0.73% Ruby 0.75% Shell 0.13% JavaScript 98.39%

env-js's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

env-js's Issues

Add references to specific JS files in backtrace

Quite often I see "inline's" in backtraces and they are pretty maddening. Ideally they should be replaced with references to URLs, or filenames if possible. Here's an example backtrace:

Johnson::Error in 'Feature: Gift this (under Javascript) Scenario: Choosing to gift items and going forward'
b is null
/Library/Ruby/Gems/1.8/gems/envjs-0.3.6/lib/envjs/static.js:1218 [JavaScript]
inline:2302 [JavaScript]
inline:431 [JavaScript]
inline:139 [JavaScript]
inline:392 [JavaScript]
inline:5523 [JavaScript]
/Library/Ruby/Gems/1.8/gems/envjs-0.3.6/lib/envjs/env.js:2193 [JavaScript]
/Library/Ruby/Gems/1.8/gems/envjs-0.3.6/lib/envjs/env.js:2191:in `__dispatchEvent__' [JavaScript]
/Library/Ruby/Gems/1.8/gems/envjs-0.3.6/lib/envjs/env.js:2324:in `__dispatchEvent__' [JavaScript]
/Library/Ruby/Gems/1.8/gems/envjs-0.3.6/lib/envjs/env.js:2324:in `__dispatchEvent__' [JavaScript]
/Library/Ruby/Gems/1.8/gems/envjs-0.3.6/lib/envjs/env.js:2324:in `__dispatchEvent__' [JavaScript]
/Library/Ruby/Gems/1.8/gems/envjs-0.3.6/lib/envjs/env.js:2324:in `__dispatchEvent__' [JavaScript]
/Library/Ruby/Gems/1.8/gems/envjs-0.3.6/lib/envjs/env.js:2324:in `__dispatchEvent__' [JavaScript]
/Library/Ruby/Gems/1.8/gems/envjs-0.3.6/lib/envjs/env.js:2324:in `__dispatchEvent__' [JavaScript]
/Library/Ruby/Gems/1.8/gems/envjs-0.3.6/lib/envjs/env.js:2324:in `__dispatchEvent__' [JavaScript]
/Library/Ruby/Gems/1.8/gems/envjs-0.3.6/lib/envjs/env.js:2324:in `__dispatchEvent__' [JavaScript]
/Library/Ruby/Gems/1.8/gems/envjs-0.3.6/lib/envjs/env.js:2324:in `__dispatchEvent__' [JavaScript]
/Library/Ruby/Gems/1.8/gems/envjs-0.3.6/lib/envjs/env.js:2324:in `__dispatchEvent__' [JavaScript]
/Library/Ruby/Gems/1.8/gems/envjs-0.3.6/lib/envjs/static.js:1718 [JavaScript]
/Library/Ruby/Gems/1.8/gems/johnson-2.0.0.pre3/lib/johnson/ruby_land_proxy.rb:110:in `method_missing'
...

fix disappear port in window.location =

The Ruby URI class used for parsing uri's in removing explicit ports in urls if it roundtrips. There's no evidence that HTML5 expects this to happen. It seems to in FF but not in Safari.

Probably should ditch the Ruby class and write one in JS to be shared between Johnson and Rhino.

env-js breaks tidy

env-js replaces tidy that comes with OS X and replaces it with a strange one.

It causes some problems. Evernote stops working for example.

Original tidy

db@db-station:~$ tidy --version
HTML Tidy for Mac OS X released on 31 October 2006 - Apple Inc. build 15.3.6

Tidy from envjs gem

db@db-station:~$ tidy --version
/usr/bin/tidy:19:in `load': /Library/Ruby/Gems/1.8/gems/envjs-0.3.8/bin/tidy:1: Invalid char `\376' in expression (SyntaxError)
/Library/Ruby/Gems/1.8/gems/envjs-0.3.8/bin/tidy:1: Invalid char `\355' in expression
/Library/Ruby/Gems/1.8/gems/envjs-0.3.8/bin/tidy:1: Invalid char `\372' in expression
/Library/Ruby/Gems/1.8/gems/envjs-0.3.8/bin/tidy:1: Invalid char `\316' in expression
    from /usr/bin/tidy:19

$w is not defined exception when calling visit a second time

I'm using capybara-0.3.9, capybara-envjs-0.1.6 and envjs-0.3.7. It works perfectly if I have a single test case that only invokes visit once. But if I invoke visit a second time (either in the same test case or in separate ones), I get the following exception:

$ ruby spec/acceptance/raw_javascript_track_spec.rb
WARNIING: [Sat Jul 31 2010 08:41:25 GMT-0700 (PST)] {ENVJS} Exception while loading window: ReferenceError: $w is not defined
F

Johnson::Error in 'Feature name
In order to ...
As a ...
I want to ...
should include bucket javascript on the page'
$w is not defined
vendor/gems/envjs-0.3.7/lib/envjs/static.js:22590 [JavaScript]
vendor/gems/envjs-0.3.7/lib/envjs/static.js:22580 [JavaScript]
vendor/gems/envjs-0.3.7/lib/envjs/static.js:3654 [JavaScript]
vendor/gems/envjs-0.3.7/lib/envjs/env.js:1145 [JavaScript]
vendor/gems/envjs-0.3.7/lib/envjs/env.js:2665 [JavaScript]
vendor/gems/envjs-0.3.7/lib/envjs/env.js:95 [JavaScript]
vendor/gems/envjs-0.3.7/lib/envjs/env.js:2674 [JavaScript]
vendor/gems/envjs-0.3.7/lib/envjs/env.js:6 [JavaScript]
vendor/gems/envjs-0.3.7/lib/envjs/runtime.rb:53:in evaluate' vendor/gems/envjs-0.3.7/lib/envjs/runtime.rb:189:inextended'
vendor/gems/capybara-envjs-0.1.6/lib/capybara/driver/envjs_driver.rb:190:in call' vendor/gems/capybara-envjs-0.1.6/lib/capybara/driver/envjs_driver.rb:190:ininitialize'
vendor/gems/envjs-0.3.7/lib/envjs/env.js:596 [JavaScript]
vendor/gems/envjs-0.3.7/lib/envjs/env.js:606 [JavaScript]
vendor/gems/envjs-0.3.7/lib/envjs/env.js:1887 [JavaScript]
vendor/gems/envjs-0.3.7/lib/envjs/env.js:1936 [JavaScript]
vendor/gems/capybara-envjs-0.1.6/lib/capybara/driver/envjs_driver.rb:254:in visit' vendor/gems/capybara-0.3.9/lib/capybara/dsl.rb:55:invisit'
spec/acceptance/raw_javascript_track_spec.rb:21:

jQuery 1.4 is not currently supported

Support for jQuery 1.4+ is not good.

Per smparkes:
1.4 relies a lot more on event bubbling and that code in env.js (at least the Ruby fork) is not good.

It's not all that terribly hard to fix ... no rocket science ... but it's probably a few hard core days to really get it solid and unfortunately I don't have the right combination of need and time right now.

Wish I did. It's one of the biggest pains in env.js right now since more and more code relies on proper bubbling.

"Then show me the page" behaves erratically

Hi, Steven! I've been trying to use "Then show me the page" to help debug my tests. It should be an invaluable debugging tool. However, it seems to behave really erratically when using XHRs. What I'm seeing is that unless you look for something in the page that was put there as a result of the XHR, you won't see it in the "show me the page" output.

I've got some simple tests in my project here: https://github.com/sbleon/envjs-test
The tests you should check out are in https://github.com/sbleon/envjs-test/blob/master/features/show_me_the_page_test.feature . Please read the comments at the top of that file for a description of what I'm seeing when I run the tests.

Thanks!

PS. This behavior is disturbingly reminiscent of Heisenberg's uncertainty principle and Schroedinger's Cat ;-)

window.location.hash and setHistory error

Hello,

I'm using envjs (with Harmony). But when I define, in my javascript, window.location.hash, I get the following error from envjs :

1)
Johnson::Error in 'MainController should load the record's content'
setHistory is not defined
/usr/lib64/ruby/gems/1.8/gems/envjs-0.2.0/lib/envjs/env.js:1900 [JavaScript]

selectedIndex on options with optgroup

Hello,

I'm testing some events on a select box.

So I define the select's value and then I trigger the event.

js("jQuery('#select')[0].selectedIndex = 1;")
js("jQuery('#select').change();")

But this select box now has some optgroups which it didn't have before.
And with these optgroups, envjs can't define the value (when it works in firebug).

I get the following error :

Johnson::Error in 'MainController should get the multi properties edit page'

this.parentNode.options is undefined
/usr/lib64/ruby/gems/1.8/gems/envjs-0.2.0/lib/envjs/static.js:6779 [JavaScript]
/usr/lib64/ruby/gems/1.8/gems/envjs-0.2.0/lib/envjs/static.js:6815 [JavaScript]
/usr/lib64/ruby/gems/1.8/gems/envjs-0.2.0/lib/envjs/static.js:7108 [JavaScript]
/usr/lib64/ruby/gems/1.8/gems/envjs-0.2.0/lib/envjs/static.js:7047 [JavaScript]
/usr/lib64/ruby/gems/1.8/gems/envjs-0.2.0/lib/envjs/static.js:7076 [JavaScript]
/usr/lib64/ruby/gems/1.8/gems/envjs-0.2.0/lib/envjs/static.js:6775 [JavaScript]
/usr/lib64/ruby/gems/1.8/gems/envjs-0.2.0/lib/envjs/static.js:6815 [JavaScript]
/usr/lib64/ruby/gems/1.8/gems/envjs-0.2.0/lib/envjs/static.js:7108 [JavaScript]
/usr/lib64/ruby/gems/1.8/gems/envjs-0.2.0/lib/envjs/static.js:7047 [JavaScript]
/usr/lib64/ruby/gems/1.8/gems/envjs-0.2.0/lib/envjs/static.js:7076 [JavaScript]
/usr/lib64/ruby/gems/1.8/gems/envjs-0.2.0/lib/envjs/static.js:6786 [JavaScript]
/usr/lib64/ruby/gems/1.8/gems/envjs-0.2.0/lib/envjs/static.js:6815 [JavaScript]
/usr/lib64/ruby/gems/1.8/gems/envjs-0.2.0/lib/envjs/static.js:7108 [JavaScript]
inline:1 [JavaScript]

"$w is not defined" error when setting a cookie with a domain

thanks for the other cookie fix, but I'm having a similar issue when setting cookies now if they have a domain:
document.cookie = 'foo=bar; expires=Mon, 13 Sep 2010 22:14:13 GMT; path=/; domain=baz.com';

gives this error:

envjs-0.3.8/lib/envjs/static.js:23039 [JavaScript]: $w is not defined (Johnson::Error)

I appears to be using the $w static as well, I changed that line to:
cookie['domain']=this._parentWindow.location.domain;

Real edge case, but I thought I'd open a ticket for it.

Thanks for the awesome gem!

Serialize multipart/form-data forms correctly

When serializing multipart/form-data we need to separate the headers for a part from the data value with a blank newline. e.g:

Content-Disposition: form-data; name="username"

jresig

note:

Content-Disposition: form-data; name="username"
jresig

which is what happens currently.

Fix available here: http://github.com/h-lame/env-js/commit/38e63ddf37c980ed323ea27e9df2f62b5f069dfb
Tests available here: http://github.com/h-lame/env-js/commit/87a1728d91aa67cad4e54bf28dcba2a991ff6cec

timer error: TypeError: $events[target.uuid] is undefined

Hello Steven,

First of all thanks for your efforts, I really appreciate being able to do proper integration testing, including JS.

Today, I ran into the following issue with the $events hash:

timer error: TypeError: $events[target.uuid] is undefined
timer error: __removeEventListener__([object Object],"keydown")@/home/orslumen/.bundle/ruby/1.8/gems/envjs-0.3.7/lib/envjs/env.js:2158
("keydown",(function () {return typeof jQuery !== "undefined" && !jQuery.event.triggered ? jQuery.event.handle.apply(eventHandle.elem, arguments) : undefined;}),false)@/home/orslumen/.bundle/ruby/1.8/gems/envjs-0.3.7/lib/envjs/static.js:1714
([object Object],"keydown",(function () {return typeof jQuery !== "undefined" && !jQuery.event.triggered ? jQuery.event.handle.apply(eventHandle.elem, arguments) : undefined;}))@inline:2070
...
()@/home/orslumen/.bundle/ruby/1.8/gems/envjs-0.3.7/lib/envjs/event_loop.js:67
(0)@/home/orslumen/.bundle/ruby/1.8/gems/envjs-0.3.7/lib/envjs/event_loop.js:153
(-1989.672)@/home/orslumen/.bundle/ruby/1.8/gems/envjs-0.3.7/lib/envjs/env.js:2121

In my case this was the result of a jQuery submit handler with a timeout, something like:

$('#my_form_id').submit(function() {
  window.setTimeout(function() {
    $('#some_element_with_bindings').unbind();
  }, 100);
  return true;
});

I think the actual submit clears the $events hash and then, 100 milliseconds later, the $events[target.uuid] can not be found anymore. Probably this behaviour is correct, but I would like env.js not to throw an error at me.

Locally I have fixed this by adding the 3 lines of code to removeEventListener:

function __removeEventListener__(target, type, fn){
  if ( !target.uuid ) {
    target.uuid = $events.length;
    $events[target.uuid] = {};
  }
  // do not throw an error in case an event is removed from a non-existing element
  if (!$events[target.uuid]) {
    return;
  }
  if ( !$events[target.uuid][type] ){
  ...

As I have not spend that much time in env.js I am not sure if this is the right fix (it works for me :) In case the fix can be applied in general, I would appreciate it if you could add it to the codebase for the following release.

PS. I am using:
johnson (2.0.0.pre3)
capybara-envjs (0.1.6)
envjs (0.3.7)

'timer error' raised from event_loop.js

I've got a fairly complete example of the problem in https://github.com/chrisroos/capybara-envjs-rack-test. I haven't had a go at writing a failing test or a fix. The reason is that the rhino version of envjs doesn't suffer from this same problem and I think it'd be a better use of time to bring the two versions back in sync rather than fixing specific problems in this version. I'm going to follow this up on the mailing list too, to see whether I can be of any help in bringing the versions back in sync.

jquery live event with default action

[moving this issue here ...]

Suppose I have a document like this one:

  <html>
    <head>
      <title></title>
      <script src="/javascripts/jquery-1.4.2.js" type="text/javascript"></script>
      <script>
        $(document).ready(function() {
          $('a.clickable').live('click', function(event) {
            document.title = 'live click event triggered';
            return false;
          });
        });
      </script>
    </head>
    <body>
      <a href='/foo' class='clickable'>link</a>
    </body>
  </html>

Then the event handler should be called (i.e. document.title set to 'live click event triggered') and the default action of the link (i.e. the request to /foo) should not happen.

What actually happens is: the request to /foo happens first and the event handler is called afterwards.

Jquery registers a live event handler to the topmost dom node, so the handler will be called after the event has bubbled up the entire tree. In envjs 0.3.4 event bubbling seems to happen at the very end of the __dispatchEvent__ method after default actions have been evaluated.

debug is not defined in $env.log()

I found this when loading a script by inserting a DOM script node, and the script URL gives a 404.

Here's the relevant part of the stack trace:

Exception: TypeError: debug is not a function
/opt/local/lib/ruby/gems/1.8/gems/envjs-0.3.7/lib/envjs/env.js:148 ("could not load script http://localhost/core/javascripts/script-loader-badfile.js: 404 Not Found","...
/opt/local/lib/ruby/gems/1.8/gems/envjs-0.3.7/lib/envjs/env.js:693 ("could not load script http://localhost/core/javascripts/script-loader-badfile.js: 404 Not Found")
/opt/local/lib/ruby/gems/1.8/gems/envjs-0.3.7/lib/envjs/env.js:816 ([object Object],null)

The reason is that $env.log() calls debug() not print()

cannot set readonly attribute: type" when setting innerHtml

Try this out:

  1. Fire up envjsrb
  2. Fill in the following:

newDiv = document.createElement("div");
newDiv.innerHTML = "";

  1. An exception is raised: "cannot set readonly attribute: type"

JQuery sets innerHTML to "" when
updating the options of a select tag using append, so this been a bit
of pain in the heiney.

Unable to visit HTTPS sites

If I try to go to an https-only site in env-js with Ruby 1.8.6, I get an error from Net::HTTP because the connection isn't using SSL. The following simple patch fixes that, though I'm sure there are other, related issues.

diff --git a/src/platform/johnson.js b/src/platform/johnson.js
index 491ad16..4962fb4 100644
--- a/src/platform/johnson.js
+++ b/src/platform/johnson.js
@@ -131,6 +131,7 @@ $env.connection = $master.connection || function(xhr, responseHandler, da
         }
     } else { 
         Ruby.eval("require 'net/http'");
+        Ruby.eval("require 'net/https'");
 
         var req;
         var path;
@@ -160,7 +161,9 @@ $env.connection = $master.connection || function(xhr, responseHandler, da
        }
        
         try {
-            connection = Ruby.Net.HTTP.start( url.host, url.port );
+            connection = Ruby.Net.HTTP.new( url.host, url.port );
+            connection.use_ssl = ( url.scheme == "https" );
+            connection.start();
             resp = connection.request(req);
         } catch(e) {
             $env.warn("XHR net request failed: "+e);

URI.parse breaks using RVM and gemset

As RVM creates folders using the % sign to separate ruby version and gemset, it breakes URI.parse:

~/.rvm/gems/ruby-1.8.7-p249%rails3

I have updated envjs to use URI.escape before parsing the file name, so it will escape the % sign. Tests pass here after this change, but I don't know how I could add a test to it.

I'm sending a pull request with the changes in my fork, please take a look.
Thanks, Carlos

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.