GithubHelp home page GithubHelp logo

kohei-takata / mocha-sonar-reporter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pghalliday/mocha-sonar-reporter

0.0 2.0 0.0 23 KB

Sonar friendly xunit reporter

License: MIT License

Ruby 0.71% JavaScript 97.78% Batchfile 1.51%

mocha-sonar-reporter's Introduction

mocha-sonar-reporter

Build Status Coverage Status Dependency Status devDependency Status

Sonar friendly xunit reporter.

This is a modification of the existing xunit reporter that ships with Mocha. There are 2 problems that become apparent when standard xunit reports are submitted to Sonar using the sonar javascript plugin.

  • Sonar will reject reports that have a classname that mirrors a source file, eg. if you have a source file called MyClass.js then you cannot have a test with a classname of MyClass
  • Sonar interprets the classname field as a filename resulting in hard to read test reports in the Sonar UI (this is probably also the cause of the first issue)

This reporter will generate xunit output that uses the concatenation of the suite and test titles as the test name and set the classname to:

  • if testdir is defined in config, the test file relative path
  • else a configurable constant so that name collisions can be avoided. If no classname is configured it will default to Test.

Usage

Install and save to your devDependencies

npm install --save-dev mocha-sonar-reporter

Configure the classname in package.json (optional)

  ...
  "config": {
    "mocha-sonar-reporter": {
      "classname": "Test"
    }
  },
  ...

Configure the testdir in package.json (optional)

  ...
  "config": {
    "mocha-sonar-reporter": {
      "testdir": "tests",
      // Optionally configure a suffix for the extracted class names.
      // It has been reported that some versions of the sonar javascript
      // plugin require class names to have a `.js` suffix
      "classnameSuffix": ".js"
    }
  },
  ...

Configure the outputfile in package.json, to generate data in file instead of stdout (optional)

  ...
  "config": {
    "mocha-sonar-reporter": {
      "outputfile": "test/TEST-all.xml"
    }
  },
  ...

Add the following to your /sonar-project.properties file

sonar.javascript.jstestdriver.reportsPath=reports

Specify the mocha-sonar-reporter when running mocha

mocha -r mocha-sonar-reporter

NB. feel free to change paths and file names above ;)

NNB. Although not documented here, you may also like to use Grunt and the grunt-mocha-test plugin to do this and get coverage data, etc

A note on use outside of npm

The options for the reporter are added to package.json. This means that they are only loaded if mocha is run via npm (eg. via npm test). If you wish to use the reporter without npm then the options can still be specified in environment variables using the naming conventions that npm uses internally. ie:

npm_package_config_mocha_sonar_reporter_outputfile
npm_package_config_mocha_sonar_reporter_classname
npm_package_config_mocha_sonar_reporter_testdir
npm_package_config_mocha_sonar_reporter_classnameSuffix

Contributing

Add tests for changes and run

npm test

LICENSE

Copyright © 2015 Peter Halliday
Licensed under the MIT license.

Donate Bitcoins

17LtnRG4WxRLYBWzrBoEKP3F7fZx8vcAsK

mocha-sonar-reporter's People

Contributors

heldinz avatar pghalliday avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.