Brian M. Hunt
Brian M. Hunt

Reputation: 83868

Persistent Karma test runner with autoWatch=false

I am trying to run Karma via node (gulp, specifically) persistently in the background but to manually re-run the tests i.e. I have autoWatch set to false. I start the server with something like:

karma_server = new karma.Server(config.karma)
karma_server.start()

Then elsewhere I would like to trigger the tests running when files are updated outside Karma. The API method that one would expect might work is server.refreshFiles(), but it does not do this.

Internally it seems like executor.schedule() might do the trick, but it seems to be undocumented, private, and inaccessible.

So when autoWatch is turned off, how does one trigger Karma testing with an existing server? I'm sure I must be missing something obvious as otherwise the autoWatch option would always need to be true for the server to be useful.

Upvotes: 1

Views: 394

Answers (1)

4lejandrito
4lejandrito

Reputation: 182

If you have a server already running you can use the karma runner to communicate with it:

var runner = require('karma').runner,
    karmaConfig = {/* The karma config here */};

runner.run(karmaConfig, callback);

The grunt-karma plugin works like this, you can check it out for more info: https://github.com/karma-runner/grunt-karma/blob/master/tasks/grunt-karma.js

Upvotes: 2

Related Questions