Originally posted here, March 2015
I got tired of building my Angular project and having to rerun all the tests whenever I touched some code. Realizing that I could monitor the changed files, I could also feed Karma the tests I wanted to run. I'm sure this can be improved upon. I took one of my projects and ripped out most of the things not related to running tests. In a nutshell, when the tests run:
gulp testAll the tests are run, and then the watcher task is called. When something changes, the gulp-changed plug-in the watcher task knows what files have been changed. This list can be parsed and matching test cases are passed to the karma task. The process relies on consistent naming conventions so when a source file changes, the corresponding unit test file can be found. The name gulp-test-watcher is unfortunate, as it implies this is a gulp npm module (hint: nope). Hope you find it useful.