smparkes / env-js Goto Github PK
View Code? Open in Web Editor NEWThis project forked from thatcher/env-js
A pure-JavaScript browser environment with early rubygem support.
Home Page: http://github.com/smparkes/env-js
This project forked from thatcher/env-js
A pure-JavaScript browser environment with early rubygem support.
Home Page: http://github.com/smparkes/env-js
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'
...
Implement XHR using async i/o, either through EM or through ruby threads.
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 replaces tidy that comes with OS X and replaces it with a strange one.
It causes some problems. Evernote stops working for example.
db@db-station:~$ tidy --version
HTML Tidy for Mac OS X released on 31 October 2006 - Apple Inc. build 15.3.6
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
Is there a way to inspect the cookies set by the application?
Something like browser.cookies[name]
would be nice.
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:in
extended'
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:in
initialize'
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:in
visit'
spec/acceptance/raw_javascript_track_spec.rb:21:
If radio input was used outside form (e.g. in jquery.rating read-only radio
inputs are used outside form to display rating) then parent was null and was
giving exception when accessing tagName property.
Made a patch for it http://github.com/rsim/env-js/commit/3a7335ceeeac55c830702d0ad86f5f236a115f9d
Please merge it in :)
Hello,
I was curious if you'll be merging this particular change in.
http://envjs.lighthouseapp.com/projects/21590/tickets/82-execution-of-scripts-added-after-page-load
I'm hoping it would solve an issue we've encountered within Harmony which uses your gem.
Best,
Trevor
when clicking a link like ... envjs tries to follow the link and fails instead of executing the javascript.
I haven't yet tried to fix this myself, the only reference I could find to so far is http://groups.google.com/group/envjs/browse_thread/thread/7638481239b23fdc
I'm personally just dealing with javascript:void() links so far, so I could work around this, but if i'm not mistaken support is needed to drive things like bookmarklets
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.
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 ;-)
Right now the option defaults may not be the same as the master fork. Revert to that but provide support for an .envjsrc file so that projects can override, rather than having to in every file. Maybe.
This is on envjs version 0.2.0 and johnson 2.0.0.pre3
$ envjsrb
js> load('jquery-1.4.1.js')
=> nil
js> var foo = jQuery("foo");
=> nil
js> JSON.stringify(foo)
Segmentation fault
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]
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]
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!
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
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)
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.
[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.
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()
envjsrb assumes arguments are paths. It should allow URLs.
Try this out:
newDiv = document.createElement("div");
newDiv.innerHTML = "";
JQuery sets innerHTML to "" when
updating the options of a select tag using append, so this been a bit
of pain in the heiney.
Please see the line notes: smparkes/capybara-envjs@077ebab
In Rails 3 master.load was giving exception "ArgumentError: wrong number of
arguments (0 for 1)" - it seems that somehow different #load method definition
was called before method_missing which handles dynamic properties.
Made a patch for it http://github.com/rsim/env-js/commit/46706f1ec0131f972d346077f8bfd8ce6bd45406
Please merge it in :)
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);
When making an xhr request env-js croaks when receiving a non-xml response regardless of content-type headers.
this can be avoided like this: thatcher@a46fe6b#diff-19
Note: that commit contains one error - checking request headers instead of response headers.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.