-
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
Support for asynchronous plugins #851
Support for asynchronous plugins #851
Comments
Hmm, actually this might already be possible... it's really hard to tell, but I'll close this issue if it turns out to be already ... So this doesn't appear to be doable just yet. The simplest solution that I can think of is to modify |
Not sure I understand this correctly. You wanna a single test suite that On Sat, Dec 7, 2013 at 5:22 PM, Caitlin Potter notifications@github.comwrote:
|
Yes, that's right... So, I realize that this can be worked around with multiple karma configurations + external components checked into the tree, but my goal is to be able to do this from a plugin where it's easily reusable, and doesn't require components to be checked in. The bar to this is, as stated, the Bower api is entirely asynchronous, and there seems to be no support for asynchronous injection in node-di/karma. I think there are probably other use cases for an asynchronous plugin mechanism as well, though. The basic idea is to simply run the bower installation command during framework setup time, before the test suite actually begins So like, I have a factory which injects The issue is that there's no way for the injector itself to support objects created asynchronously at this point, and currently no way (that I can tell) to tell Karma itself that the plugin is finished doing its work. Correcting the latter thing may be easier to do, however karma is a much more complicated piece of code than the injector itself, so I'm not quite sure where I'd begin to try and do that. I was just thinking this might be worth looking at, plugins might in some cases need to perform some asynchronous work |
Well the plugin instantiation can be synchronous. It just needs to delay You can hack the global emitter to override "file_list_modified" event. It Try to hack this then we can change Karma to make this possible without On Sun, Dec 8, 2013 at 4:43 PM, Caitlin Potter notifications@github.comwrote:
|
That sounds like a good plan, I'll see how that works --- But what if multiple plugins wanted to do that? Seems like it would become problematic in that case |
Yeah, it's pretty nasty, but I think it should work... On Tue, Dec 10, 2013 at 7:01 PM, Caitlin Potter notifications@github.comwrote:
|
Re: vojtajina/node-di#8 (comment) --- @vojtajina if you want to assign this to me I can try to work on it this week, seems like a good thing to have |
So would async framework init (in Karma) be sufficient for your use case? In that case, the change is simple - you even don't need to change node-di, just change Karma to wait for all frameworks to finish. |
Yeah, I think it should be good enough, so long as different frameworks never need to depend on each other |
Ignore previous (deleted) comment, I just realized installing q didn't actually add a new package! |
… server The API is to simply return a promise from a factory function, or use a promise as a value. The server will wait for the collection of frameworks to resolve before carrying on starting the server. This is useful for when setup requires some asynchronous startup. Currently, any Promise api which is interoperable with q may be used. In addition to this feature, this CL also adds a set of callbacks to the server, via an object for the 3rd parameter. This is useful for test purposes, and enables the test case to run faster, by not waiting for the server to shut down via the second parameter. Closes karma-runner#851
… server The API is to simply return a promise from a factory function, or use a promise as a value. The server will wait for the collection of frameworks to resolve before carrying on starting the server. This is useful for when setup requires some asynchronous startup. Currently, any Promise api which is interoperable with q may be used. In addition to this feature, this CL also adds a set of callbacks to the server, via an object for the 3rd parameter. This is useful for test purposes, and enables the test case to run faster, by not waiting for the server to shut down via the second parameter. Closes karma-runner#851
… server The API is to simply return a promise from a factory function, or use a promise as a value. The server will wait for the collection of frameworks to resolve before carrying on starting the server. This is useful for when setup requires some asynchronous startup. Currently, any Promise api which is interoperable with q may be used. In addition to this feature, this CL also adds a set of callbacks to the server, via an object for the 3rd parameter. This is useful for test purposes, and enables the test case to run faster, by not waiting for the server to shut down via the second parameter. Closes karma-runner#851
… server The API is to simply return a promise from a factory function, or use a promise as a value. The server will wait for the collection of frameworks to resolve before carrying on starting the server. This is useful for when setup requires some asynchronous startup. Currently, any Promise api which is interoperable with q may be used. In addition to this feature, this CL also adds a set of callbacks to the server, via an object for the 3rd parameter. This is useful for test purposes, and enables the test case to run faster, by not waiting for the server to shut down via the second parameter. Closes karma-runner#851
FYI - I had a similar requirement - I wanted to do some action with the list of resolved files and have the result of that action available to the test code, so needed to be able to hold off initialising my framework until the file list was ready. I followed @vojtajina's suggestion to hack the emitter - it's pretty nasty, but it works for my purposes. Here's the rough pattern I used in my plugin factory function - the placeholder here is just a 5s timeout to demonstrate that it's working: var originalEmit = emitter.emit;
emitter.emit = function (event, arg) {
if (event === 'file_list_modified') {
var originalPromise = arg;
var defer = q.defer();
originalPromise.then(function (files) {
setTimeout(function () {
defer.resolve(files);
}, 5000);
});
originalEmit.call(emitter, event, defer.promise);
} else {
originalEmit.apply(emitter, arguments);
}
}; |
Just a warning, this hack won't work in 0.13 any more as the I'm closing this issue for now as there hasn't been much activity lately. |
@dignifiedquire I haven't had a chance to look yet — do you know if Karma has introduced any kind of real support for asynchronous plugins yet? If not, any plugin using this trick will probably be SOL until they remedy that. |
No we haven't yet. I'll reopen this, as it seems there is a need for supporting this properly. |
It would be really good to support this feature please. I want to write a framework which would start a certain server, but I don't have a way of making Karma wait before it is initialised. I could register it as pre-processor I suppose, but that's quite hackish. |
Is this even possible yet? I tied returning a promise in the factory function, but it doesn't seem to wait for it to resolve before moving onto tests. This is extremely annoying to say the least. |
git clone git@github.com:material-foundation/material-remixer-remote-web.git |
Use case:
Looking to test an AngularJS module (angular-ui/ui-router) against several versions of AngularJS, with and without specific plugins (angular-animate).
So, rather than making a big ugly grunt task to manage all of this, I thought it would be nice to write a karma plugin to simplify this.
The goal is this: interface with the bower API to install modules before a test suite is run (by injecting config.bower into the framework factory)
The problem I run into is that I can't seem to find a way to have a plugin treated as asynchronous, so that it can wait for installation to complete.
This would be a super-awesome plugin (I think), and it would depend on a super-awesome feature of Karma.
I could look at implementing this, but I am not aware of all of the finer points of the karma-runner, so it would be really nice if someone could give this some consideration
The text was updated successfully, but these errors were encountered: