Transition from contextWindow to postMessage#1984
Transition from contextWindow to postMessage#1984dignifiedquire merged 1 commit intokarma-runner:masterfrom
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
|
I signed it! |
|
CLAs look good, thanks! |
static/context.html
Outdated
| } else { | ||
| window.parent.karma.setupContext(window); | ||
| } | ||
| (function () { |
There was a problem hiding this comment.
All this code should still be in a separate file rather than inlined here.
There was a problem hiding this comment.
Yea, definitely. This was mostly to get the proof of concept up and out the door =)
|
Hey, first thanks for all this work! In general I like the idea of using |
|
The polyfill would be less of an actual polyfill and more of a fallback implementation for Electron: // Define a remote call method for Karma
var parentWindow = window.opener || window.parent;
var callParentKarma = function (method, args) {
parentWindow.karma[method].apply(parentWindow.karma, args);
};
// If we don't have access to the window, then use `postMessage`
// DEV: In Electron, we don't have access to the parent window due to it being in a separate process
// DEV: We avoid using this in Internet Explorer as they only support strings
// http://caniuse.com/#search=postmessage
if (!parentWindow.window) {
callParentKarma = function (method, args) {
parentWindow.postMessage({method: method, arguments: args}, window.location.origin);
};
}I think the next iteration of this PR won't be a fully polished product but another proof of concept demonstrating the concept works in other browsers |
76e8d9f to
a073481
Compare
|
Alright, I was able to make a clean transition for everything (or at least I think it's clean). There are still some rough edges in this PR (e.g. lingering TODOs, using PhantomJS over Chrome/FF so I can dev faster) but the majority of it is here. I know that a large PR can be frustrating as a reviewer. As a result, I had some interim branches for you to glance over: twolfson/karma@87c56e3...twolfson:dev/postmessage.work Also, here was my initial game plan although I derailed from the path at some point: https://gist.github.com/twolfson/f7d257966d7cdafdf30c |
a073481 to
b1e23fa
Compare
|
@dignifiedquire Would it be possible to get a review on this PR? I'm more than happy to break it down into smaller pieces if that helps |
|
@twolfson yes I will try to get to it tomorrow |
| sudo: false | ||
| language: node_js | ||
| node_js: | ||
| - "0.10" |
There was a problem hiding this comment.
We need to pass our tests on all these platforms, please leave them in here
There was a problem hiding this comment.
These were removed for local development. I will restore them
|
Alright this is starting to take nice form, I left some smaller comments inline. Could you also do a rebase please of latest master so it merges cleanly? |
|
Hooray, thanks for the review =) Most of the comments were on files/edits that were done for local development (i.e. make everything headless/simple to make iterations as fast as possible). They were left in due to this PR still being up in the air. Now that it sounds like this will eventually be landed, then I agree that it's best to take them out and add finishing polish. With respect to before/after 1.0, it's prob best to hold this off until after 1.0. I suggest shipping this feature as standalone as possible since it could break builds (unlikely but plausible) and we want to be easily revertable. With respect to the requested changes in this PR, I will take care of them by the end of the weekend. |
.travis.yml
Outdated
| recipients: | ||
| - todd@twolfson.com | ||
| on_success: change | ||
| on_failure: change |
There was a problem hiding this comment.
Note to self: Remove these edits as well
|
Not sure if you caught this but what were your thoughts on the folder structure (i.e. relocating some I know that some developers like to keep the top level folder as clean as possible so an alternative might be a |
|
I'm realizing that when we introduce |
|
Nice! I will be travelling the next week, so I might be slow to respond, but going to test this out and see how it works :) |
…ularity BREAKING CHANGE: Our `context.html` and `debug.html` structures have changed to lean on `context.js` and `debug.js`. This is in preparation for deeper `context.js` changes in karma-runner#1984. As a result, all `customContextFile` and `customDebugFile` options much update their format to match this new format.
…ularity BREAKING CHANGE: Our `context.html` and `debug.html` structures have changed to lean on `context.js` and `debug.js`. This is in preparation for deeper `context.js` changes in karma-runner#1984. As a result, all `customContextFile` and `customDebugFile` options much update their format to match this new format.
7efa81d to
7dd2aeb
Compare
|
Bump on this PR and its related PRs =/ |
…ularity BREAKING CHANGE: Our `context.html` and `debug.html` structures have changed to lean on `context.js` and `debug.js`. This is in preparation for deeper `context.js` changes in karma-runner#1984. As a result, all `customContextFile` and `customDebugFile` options much update their format to match this new format.
489a921 to
19d81d0
Compare
|
This PR should be good to review now as well 👍 |
|
Bump on this issue again =/ |
|
Bump on this issue again =/ |
|
@twolfson I finally got around to releasing 1.0. Sorry for the massive delay on this but I had a lot to do on my day job. Reviewing this now, in the meantime could you please rebase this onto the latest master? |
… Electron support via postMessage
19d81d0 to
81b1f04
Compare
|
I have rebased the commit to the latest master |
|
Thanks a lot @twolfson, going to merge this and put it into the new release |
|
@twolfson released as 1.1.0 |
|
woot, awesome. Thanks =D |
I am currently attempting to get Karma running with Electron. There are a lot of benefits to this:
requireUnfortunately, the current Karma implementation is incompatible with Electron.
If we use an iframe, we lose the Node.js integration and must polyfill it via
window.parent. This works great for top level modules but submodules have their global context executed in thewindow.parentwhich makes usingmochaimpossible =/Other alternatives from an iframe for Electron are
window.open,<webview>, and launching multipleBrowserWindowinstances. Unfortunately, these options are executed in separate processes so we cannot usewindow.openeras per usual.window.opendefines a proxy where we can runevalandpostMessage<webview>definesexecuteJavaScriptandsendwindow.openexcept they can receive responses whereas neitherevalnorpostMessagecan directly receive responses (although we can send a correspondingpostMessagereply or build a bridge library to match requests/responses)BrowserWindowvia Electron seems too custom to Electron to be reusable elsewheresendSyncin the browser which allows for synchronous function calls and responses but this only works when sending fromrenderertomainprocessesI decided to use
window.opensince it doesn't require any duplicate logic for other browsers and is easily polyfilled for older browsers to usecontextWindow.In this PR, I have a proof of concept working with the
karma-electrontest suite but the PR is far from done.Matching test suite: https://github.com/twolfson/karma-electron/tree/ba7d54bf4d941200c9c15d94ebf0cbfd7546d5c7
What are your thoughts on this PR?