Most of the time, you will be using Karma directly from the command line. You can, however, call Karma programmatically from your node module. Here is the public API.
var Server = require('karma').Server
var server = new Server({port: 9876}, function(exitCode) {
console.log('Karma has exited with ' + exitCode)
process.exit(exitCode)
})
Equivalent of karma start
.
server.start()
Trigger a file list refresh. Returns a promise.
server.refreshFiles()
The server
object is an EventEmitter
. You can simply listen to events like this:
server.on('browser_register', function (browser) {
console.log('A new browser was registered')
})
browser_register
#Arguments:
browser
: The browser instanceA new browser was opened, but is not ready yet.
browser_error
#Arguments:
browser
: The browser instanceerror
: The error that occurredThere was an error on this browser instance.
browser_start
#Arguments:
browser
: The browser instanceinfo
: Details about the runA test run is beginning in this browser.
browser_complete
#Arguments:
browser
: The browser instanceresult
: Test resultsA test run has completed in this browser.
browsers_change
#Arguments:
browsers
: A collection of browser instancesThe list of browsers has changed.
browsers_ready
#All browsers are ready for execution
run_start
#Arguments:
browsers
: A collection of browser instances on which tests are executedA test run starts.
run_complete
#Arguments:
browsers
: A collection of browser instancesresults
: A list of resultsA test run was completed.
Equivalent of karma run
.
var runner = require('karma').runner
runner.run({port: 9876}, function(exitCode) {
console.log('Karma has exited with ' + exitCode)
process.exit(exitCode)
})