Skip to content

Support for asynchronous plugins #851

Closed
@caitp

Description

@caitp

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

Activity

caitp

caitp commented on Dec 8, 2013

@caitp
Author

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 node-di to await promise resolution before invoking functions. That's probably only a couple of lines to accomplish, but also leads to dependency on some promise implementation or another, which kind of sucks... I'll raise the issue over there though.

vojtajina

vojtajina commented on Dec 8, 2013

@vojtajina
Contributor

Not sure I understand this correctly. You wanna a single test suite that
tests your project. You can tell Karma to test it with different versions
of Angular and Karma will run the suite multiple times, each time loading a
different version of angular. Is that about right?

On Sat, Dec 7, 2013 at 5:22 PM, Caitlin Potter notifications@github.comwrote:

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


Reply to this email directly or view it on GitHubhttps://github.com//issues/851#issuecomment-30072425
.

caitp

caitp commented on Dec 9, 2013

@caitp
Author

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 config.bower, transforms a list of components into an array of endpoints for bower.commands.install()... Finally, capturing the error and end events would let the injector/karma know that the plugin's work is finished. (in the future, it might be nice to save components to specific subdirectories so that they wouldn't be re-downloaded each time the suite is run..)

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

vojtajina

vojtajina commented on Dec 11, 2013

@vojtajina
Contributor

Well the plugin instantiation can be synchronous. It just needs to delay
the execution, which is doable.

You can hack the global emitter to override "file_list_modified" event. It
gets a promise with all the resolved files, so you need to wrap this
promise and delay it until all the stuff is installed.

Try to hack this then we can change Karma to make this possible without
hacks... How about that?

On Sun, Dec 8, 2013 at 4:43 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.


Reply to this email directly or view it on GitHubhttps://github.com//issues/851#issuecomment-30098187
.

caitp

caitp commented on Dec 11, 2013

@caitp
Author

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

vojtajina

vojtajina commented on Dec 22, 2013

@vojtajina
Contributor

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:

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


Reply to this email directly or view it on GitHubhttps://github.com//issues/851#issuecomment-30290181
.

caitp

caitp commented on Apr 28, 2014

@caitp
Author

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

vojtajina

vojtajina commented on Apr 28, 2014

@vojtajina
Contributor

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.

caitp

caitp commented on May 1, 2014

@caitp
Author

Yeah, I think it should be good enough, so long as different frameworks never need to depend on each other

caitp

caitp commented on May 1, 2014

@caitp
Author

Ignore previous (deleted) comment, I just realized installing q didn't actually add a new package!

added a commit that references this issue on May 1, 2014
d1d5868
added a commit that references this issue on May 1, 2014
adcfb7c

27 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Support for asynchronous plugins · Issue #851 · karma-runner/karma