Brian M. Hunt Brian M. Hunt - 1 year ago 129
Javascript Question

Add files to watch-list in karma preprocessor

Here is a repository created to demonstrate the issue:


I'm trying to get karma-rollup-preprocessor working with Karma's builtin watch i.e. solve showpad/karma-rollup-preprocessor#3

In other words, in a preprocessor, I want to add files to Karma's watch list.

It's easy to get the list of files Rollup uses to compile. Rollup returns a list of files that it reads (ones one wants to watch), so in the preprocessor I am trying to add files to the list karma watches.

Basically I want to add this (or the working equivalent) to the preprocessor:

bundle.modules.forEach((module) => {
pattern:, /* The full file path, from Rollup */
watched: true,
included: false,
nocache: false,
served: false,

is Karma's
or whatever place one needs to put the files being watched.

Doing the above with
, the files are indeed being added to the watcher, but
fails the

So it looks like the files also (or alternatively) must be added to the

Unfortunately when I try to add the
to the
, I get the error:

Error: Can not resolve circular dependency! (Resolving: preprocess -> preprocessor:rollup -> fileList -> preprocess).

I've looked at basically all the other preprocessors that look like they could also add includes, but I have found no indication of how to do it.

Is there a canonical way to add files Karma should watch from a preprocessor? Or otherwise how might one do this? This seems pretty clutch for a preprocessor in Karma, so it's surprising that it's not documented, apparent, or problematic in the other preprocessors.

EDIT Here's some more attempts:

I tried to add the watched patterns to the

files: [
{pattern:"src/**/*.js", included: false, watched: true}

But the
doesn't recompile when changed. The tests just re-run.

So I tried chokidar like this:

var server = new karma.Server(options)..."src/**/*.js")
.on('add', server.refreshFiles.bind(server))
.on('change', server.refreshFiles.bind(server))

I also tried it with a debounce, in case Karma was slower on the refresh, but it seems the tests won't re-run.

I rooted around karma-browserify for inspiration but it was a bit too convoluted to pick up without delving in.

Answer Source

I've issued a pull request to resolve this.

Until it is merged one can use my repo i.e. put "karma-rollup-preprocessor": "brianmhunt/karma-rollup-preprocessor" in package.json dependencies or devDependencies.

EDIT: Superceded by

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download