karma-mocha-exposed

1.1.2 • Public • Published

karma-mocha

A temporary fork until the next version of karma-mocha is released, including karma-runner/karma-mocha#115

js-standard-style npm version npm downloads

Build Status Dependency Status devDependency Status

Adapter for the Mocha testing framework.

Installation

The easiest way is to keep karma-mocha as a devDependency in your package.json.

{
  "devDependencies": {
    "karma-mocha": "~0.1"
  }
}

You can simple do it by:

npm install karma-mocha --save-dev

Instructions on how to install karma can be found here.

Configuration

Following code shows the default configuration...

// karma.conf.js
module.exports = function(config) {
  config.set({
    frameworks: ['mocha'],
 
    files: [
      '*.js'
    ]
  });
};

If you want to pass configuration options directly to mocha you can do this in the following way

// karma.conf.js
module.exports = function(config) {
  config.set({
    frameworks: ['mocha'],
 
    files: [
      '*.js'
    ],
 
    client: {
      mocha: {
        // change Karma's debug.html to the mocha web reporter
        reporter: 'html',
 
        // require specific files after Mocha is initialized
        require: [require.resolve('bdd-lazy-var/bdd_lazy_var_global')],
 
        // custom ui, defined in required file above
        ui: 'bdd-lazy-var/global',
      }
    }
  });
};

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.exports = function(config) {
  config.set({
    ...
    client: {
      mocha: {
        grep: '<pattern>', // passed directly to mocha
        ...
      }
      ...
    }
  });
};

If you want to expose test properties specific to mocha, you can use the expose option:

module.exports = function(config) {
  config.set({
    ...
    client: {
      mocha: {
        expose: ['body'] // This will be exposed in a reporter as `result.mocha.body`
        ...
      }
      ...
    }
  });
};

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 started
  • endTime Milliseconds since epoch that the test ended
  • assertionErrors 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 the expose 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.

Package Sidebar

Install

npm i karma-mocha-exposed

Weekly Downloads

1

Version

1.1.2

License

MIT

Last publish

Collaborators

  • danthareja