karma-runner/karma

Extract watcher into an injected dependency

Open

#1468 opened on Jun 24, 2015

View on GitHub
 (6 comments) (0 reactions) (0 assignees)JavaScript (11,918 stars) (1,703 forks)batch import
apidiscusshelp wantedtype: feature

Description

I'm writing a plugin that integrates Karma with Broccoli so that it can lean fully on broccoli for all pre-processing, building, etc... The reason being that if you have a Brocfile, then you already have your build toolchain defined in one place, so you might as well utilize it from your test runner. That way, instead of maintaining a parallel build systems: one for your test runner and one for development/production, you can just npm install karma-broccoli and it will know how and when to build, and also which files the build generates. I have the single run use-case working where you invoke karma run. It waits until a build runs (if there is a build), and then executes the test suite.

For the config.autoWatch use-case, I'd like to replace the normal karma watcher with the Broccoli watcher for the same reason I want Broccoli to be responsible for the build, it already knows what to to watch for and consequently, what to build. It would be nice if I could just swap out the broccoli watcher for the bundled karma watcher, but at the moment it is hard coded to the watch function in watcher.js https://github.com/karma-runner/karma/blob/master/lib/server.js#L54

While the dependencies to the watch() function are injected, the watcher itself is not, so I'd like to see if you would be open to extracting the watcher into a first-class injected dependency. If so, I'd be happy to take a stab at implementing it.

Contributor guide