2.0.1 • Published 5 years ago

karma-mocha v2.0.1

Weekly downloads
281,046
License
MIT
Repository
github
Last release
5 years ago

karma-mocha

js-standard-style npm version npm downloads

Build Status Dependency Status devDependency Status

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.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`
        ...
      }
      ...
    }
  });
};

If you already have a configuration for Mocha in an opts file, you can use the opts option:

module.exports = function(config) {
  config.set({
    ...
    client: {
      mocha: {
        opts: 'test/mocha.opts' // You can set opts to equal true then plugin will load opts from default location 'test/mocha.opts'
        ...
      }
      ...
    }
  });
};

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.

@tyz-wallet/tyz-wallet-core-build@rock-kit/ui-karma-configmy-gulpak-gulpbitcore-build-polisclying-uikelvin-id-generator-aws-xrayotel-aws-xray-id-generatorsammenpeach-cliclouds-uies6-workflow@temporg/config-karma@temporg/ui-karma-configedui@cvpcasada/nwbforkliftjsjust-bi-toolkityii-vue-uilevibestliblevibestlib2levilibtest19levilibtest24levilibtest25levilibtest26levilibtest27levilibtest28levilibtest29vbtcclibyarntest@everything-registry/sub-chunk-2005tasegirsynaptic-scoutwidecore-buildwl-power-pluginwa.component.validatorwa.validator2web-modules-utilsvusion-cliwebdatabasetest1webdatabasetest10weiler-electrode-archetype-react-app-devxdc-karmaxin-ui20210822xipcodexethya-extension-basesaffron-bundlershenxin-uishowcar-gulpsexcore-buildsg-karmaroc-plugin-test-mocha-karma-webpacksuper-powered-api-testingsumcore-buildseqcore-buildrsc-testrunpackrgui-toolstestweblibapitest_gulu_leetestlib17testfullvue-click-to-editvue-color-tablev-tagsvue-cli-plugin-ui-karmavue-cli-plugin-unit-karmavue-cli-plugin-unit-karmajsvue-cli-plugin-unit-karmajscli3vue-buildveriumcore-buildvoting-appgulp-it@starpack/starpack@aws-crypto/example-browsermilk-devmimosa-karma-enterprisemetal-karma-configlifetioncore-buildlll-ui-1liferay-karma-alloy-configliferay-karma-configliferay-forms-alloy-configliferay-forms-ui-testslc-base-serverhelloxyzklmgix-gix-polar-karmagix-polar-karmagoodeggs-karmajnwbjs-boilerplatejs-build-scriptsjs-stack.taskshyamamoto-job-toolboxicx4icya-uiioncore-buildinterstellariopcore-buildlioncore-build
2.0.1

5 years ago

2.0.0

5 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.10

10 years ago

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.4

10 years ago

0.1.3

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

12 years ago