Description
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
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
- feat(async): frameworks can be loaded asynchronouslykarma-runner/karma
- feat(server): wait for frameworks to load via q.all() before starting serverkarma-runner/karma
- [Snyk] Upgrade karma from 4.3.0 to 4.4.1speech4j/web
- Bump karma from ~1.2.0 to ~6.4 in /redpen-serverkarronoli/redpen
- [Snyk] Fix for 2 vulnerabilitiesOmrisnyk/npm-lockfiles
Activity
Returns false instead of null to avoid null.toString().
caitp commentedon Dec 8, 2013
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 commentedon Dec 8, 2013
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:
caitp commentedon Dec 9, 2013
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 theerror
andend
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 commentedon Dec 11, 2013
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:
caitp commentedon Dec 11, 2013
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 commentedon Dec 22, 2013
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:
caitp commentedon Apr 28, 2014
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 commentedon Apr 28, 2014
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 commentedon May 1, 2014
Yeah, I think it should be good enough, so long as different frameworks never need to depend on each other
caitp commentedon May 1, 2014
Ignore previous (deleted) comment, I just realized installing q didn't actually add a new package!
feat(server): wait for frameworks to load via q.all() before starting…
feat(server): wait for frameworks to load via q.all() before starting…
27 remaining items