karma-mocha
Adapter for the Mocha testing framework.
Installation
Install karma-mocha
and mocha
into to your project via npm
:
$ npm install karma-mocha mocha --save-dev
karma-mocha
should work with any version of mocha
.
Since karma-mocha
is an adapter for Karma, you likely have it installed already, but in case you don't:
$ npm install karma --save-dev
If you're having trouble, Karma provides detailed instructions on installation.
Configuration
Following code shows the default configuration...
// karma.conf.jsmodule { config;};
If you want to pass configuration options directly to mocha you can do this in the following way
// karma.conf.jsmodule { config;};
If you want run only some tests matching a given pattern you can do this in the following way
karma start &karma run -- --grep=<pattern>
or
module { config;};
If you want to expose test properties specific to mocha
, you can use the expose
option:
module { config;};
If you already have a configuration for Mocha in an opts file, you can use the opts
option:
module { config;};
Internals
On the end of each test karma-mocha
passes to karma
result object with fields:
description
Test title.suite
List of titles of test suites.success
True if test is succeed, false otherwise.skipped
True if test is skipped.time
Test duration.log
List of errors.startTime
Milliseconds since epoch that the test startedendTime
Milliseconds since epoch that the test endedassertionErrors
List of additional error info:name
Error name.message
Error message.actual
Actual data in assertion, serialized to string.expected
Expected data in assertion, serialized to string.showDiff
True if it is configured by assertion to show diff.
mocha
An optional object listed if you use theexpose
option
This object will be passed to test reporter.
NB. the start and end times are added by the adapter whereas the duration is calculated by Mocha - as such they probably will not match arithmetically. Ie. endTime - startTime !== duration
. These fields have been added so that timestamped reports can be matched up with other timestamped reports from the target device (eg. memory profiling data collected outside the browser)
For more information on Karma see the homepage.