-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible to run jsdom in a worker #711
Comments
Wow, this is great. I think the path these days is to use browserify. So that should eliminate the need to provide pure-JS implementations of the node dependencies, since browserify comes with those; it may also solve the node dependencies that cannot be met. And should obviate the need to use AMD at all; just produce a browserify UMD bundle, which last I heard are worker compatible (or if they're not, that should be an easy PR to get accepted). The other thing that gives you is the ability to use the
I'd prefer not to add the Subclass.prototype = Object.create(Superclass.prototype, {
constructor: {
value: Subclass,
writable: true,
configurable: true
}
});
Yes please!
Hopefully not necessary, but if we can figure it out, I don't see a real problem with it. |
Ok, great! Thanks for the feedback, @domenic. I'm going to do the switch to |
Yeah sounds good! I'll merge as things come in. |
Replace all instances of `__defineGetter__` and `__defineSetter__` with the respective method from `jsdom/utils`. This is work toward jsdom#711. For posterity, the vim regex I used is: `\(\s*\)\([^_]\+\)\.__\([^_]\+\)__(\([^,]\+\),/\1\3(\2, \4,`
Replace all instances of `__defineGetter__` and `__defineSetter__` with the respective method from `jsdom/utils`. This is work toward #711. For posterity, the vim regex I used is: `\(\s*\)\([^_]\+\)\.__\([^_]\+\)__(\([^,]\+\),/\1\3(\2, \4,`
Ok, I've surveyed all external dependencies and tried requiring them in a worker via browserify. The following don't work and will likely never work:
The following don't work but can likely be fixed:
|
Ok, it looks like we may be able to use iriscouch/browser-request instead of mikeal/request. |
@domenic, do you have any preference for how I should accomplish the browserify build? I could just add an entry to |
🎆 🍻 I can build a browserify bundle that works with this worker (in Chrome Stable latest): var jsdom = require('../lib/jsdom');
jsdom.env({
url: 'http://example.com',
html: '<p><a class="the-link" href="https://github.com/tmpvar/jsdom">jsdom\'s Homepage</a></p>',
done: function (errors, window) {
var link = window.document.querySelector('a.the-link');
postMessage(link.innerHTML);
}
}); That was fun. Next step is to get the tests running in a worker and find out how many we fail. |
Woah, nice!
What kind of build is required? I was kind of hoping we'd just use the |
Yep! That's how it works. The only real wrinkle is that OS X needs the maximum number of files bumped up. It's possible we will need something more advanced in the future, but adding a |
Ok, I hacked on a copy of
|
The tests fail for a variety of reasons, most of which I have not diagnosed. Use of |
Great! In that case I don't think a
brfs might help here. |
This reply references the problem: The following don't work and will likely never work: the exact error I receive is: and thankfully I see that at least you all know about it. what do I do about it? |
Actually, the canvas error is from: |
@andrew-luhring You'll need to make a fake |
its all good. where would i put the fake canvas module? |
@lawnsea +1 |
+2 |
For jsdom#711, the test runner will execute in a web worker, but test results will be displayed in the parent page or a shell. So, it is convenient to break the options parsing, test running, and results display into their own modules for reuse by other runners.
For #711, the test runner will execute in a web worker, but test results will be displayed in the parent page or a shell. So, it is convenient to break the options parsing, test running, and results display into their own modules for reuse by other runners.
It's been a long time coming, but I finally have a PR that adds experimental support for running jsdom browserified in a Web Worker. See #849 for details. |
For my research project Treehouse, I forked jsdom and got it to run in a web worker. This was two years ago. I'm interested in doing this again, but in a way that is maintainable, rather than just a proof-of-concept.
At a high level, this is what was necessary to get jsdom 0.2.4 running in a worker:
fs
, e.g.)*url
, e.g.)*util.inherits
instead of assigning to__proto__
Object.defineProperty
instead of__defineSetter__
/Getter__
window
anddocument
withwin
anddoc
**I also refactored the code to use AMD and build with RequireJS. I don't think this is necessary now (and may not have been necessary then): it should be possible to use the
cjsTranslate
method to build for the browser.I would like to keep the diff from my fork to the original as minimal as possible. So, I'd like to upstream those changes that support browser compatibility in a non-breaking way. Would y'all be open to that?
* browserify may help with these
** I'm embarrassed to admit I don't remember why this was necessary
EDIT: I'm aware of this thread and #245
The text was updated successfully, but these errors were encountered: