Mittwoch, 11. Dezember 2013

karma-mocha-reporter - Deutsch


Das Testen von Code ist ein fester Bestandteil in unserem täglichen Arbeitsprozess. Für die client-seitigen JavaScript Tests verwenden wir den karma test runner. Dabei laufen die Tests in einem Browser. Die Ergebnisse werden in die Konsole geschrieben. Dazu sind schon einige reporter in karma integriert. Wir wollten aber eine etwas hübschere Ausgabe. Kein Problem dank der Plugin Architektur in karma. Also haben wir einen eigenen reporter entwickelt.

So sieht das Ergebnis aus




Installation

$ npm install karma-mocha-reporter

Verwendung

Die Konfiguration ist wirklich einfach und wird über die config Datei von karma gemacht. Man fügt 'mocha' in das reporters array und 'karma-mocha-reporter' in das plugins array ein. Hier eine beispielhafte karma config Datei.

// karma.conf.js
module.exports = function(config) {
  config.set({
    frameworks: ['jasmine'],

    // reporters configuration
    reporters: ['mocha'],

    plugins: [
      'karma-jasmine',
      'karma-mocha-reporter'
    ]
  });
};

karma-mocha-reporter - English


Testing is an important task of our daily work. For the client JavaScript tests we use the karma test runner. It runs all the test in a real browser. The results are logged in the console. There are some reporters included, but we would like to have a more ‘fancy’ one. Thanks to the plugin architecture of karma it is an easy task to create a new reporter.

So how does it look like




Install

$ npm install karma-mocha-reporter

Usage

So the configuration is really simple. It is all done in the karma config file. You just add 'mocha' to the reporters array and 'karma-mocha-reporter' to the plugins array. Here is a sample karma config file.

// karma.conf.js
module.exports = function(config) {
  config.set({
    frameworks: ['jasmine'],

    // reporters configuration
    reporters: ['mocha'],

    plugins: [
      'karma-jasmine',
      'karma-mocha-reporter'
    ]
  });
};