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()
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')
})
Arguments:
browser
: The browser instance
A new browser was opened, but is not ready yet.
Arguments:
browser
: The browser instanceerror
: The error that occured
There was an error on this browser instance.
Arguments:
browser
: The browser instanceinfo
: Details about the run
A test run is beginning in this browser.
Arguments:
browser
: The browser instanceresult
: Test results
A test run has completed in this browser.
Arguments:
browsers
: A collection of browser instances
The list of browers has changed.
All browsers are ready for execution
Arguments:
browsers
: A collection of browser instances on which tests are excuted
A test run starts.
Arguments:
browsers
: A collection of browser instancesresults
: A list of results
A 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)
})
- If there is an error, the error code will be provided as the second parameter to the error callback.