Git Product home page Git Product logo

grunt-karma-sonar's Introduction

grunt-karma-sonar Build Status

Grunt plugin for integrating karma reports with sonar

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-karma-sonar --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-karma-sonar');

The "karma_sonar" task

Overview

In your project's Gruntfile, add a section named karma_sonar to the data object passed into grunt.initConfig().

grunt.initConfig({
  karma_sonar: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
})

Options

options.dynamicAnalysis

Type: String Default: 'reuseReports'

Should be the sonar.property dynamicAnalysis

options.sourceEncoding

Type: String Default: 'UTF-8'

Should be the sonar.property sourceEncoding

options.language

Type: String Default: 'js'

Should be the sonar.property language (Starting with SonarQube 4.2, multi-language projects are supported. To enable this, set the value to null)

options.scmDisabled

Type: String Default: 'true'

Should be the sonar.property scmDisabled

options.defaultOutputDir

Type: String Default: '.tmp/sonar/'

Should be the location where the karmaSonar plugin will put it's temporary files.

options.excludedProperties

Type: Array Default: []

Should be a list of sonar properties to exclude

options.instance.hostUrl

Type: String Default: 'http://localhost:9000'

Should be the sonar.property host.url

options.instance.jdbcUrl

Type: String Default: 'jdbc:h2:tcp://localhost:9092/sonar'

Should be the sonar.property jdbc.url

options.instance.jdbcUsername

Type: String Default: 'sonar'

Should be the sonar.property jdbc.username

options.instance.jdbcPassword

Type: String Default: 'sonar'

Should be the sonar.property jdbc.password

options.instance.login

Type: String Default: 'admin'

Should be the sonar.property login

options.instance.password

Type: String Default: 'admin'

Should be the sonar.property password

options.instance.runnerProperties

Type: Object

Should be the list of key(sonar key) value pairs.

runnerProperties: {
    'sonar.links.homepage': 'https://github.com/mdasberg/grunt-karma-sonar',
    'sonar.branch': 'master'
}

project

Type: Object, Mandatory: true

Should be the project information for sonar

project.key

Type: String Mandatory: true`

Should be the project key for sonar

project.name

Type: String Mandatory: true`

Should be the project name for sonar

project.version

Type: String

Should be the project version for sonar

paths

Type: Array

Should be the paths that contain the code, tests and results

paths[].cwd

Type: String Default: '.'

Should be the current working directory that contain the source, tests and results folders are located

paths[].src

Type: String

Should be the directory containing the sources within the cwd.

paths[].test

Type: String

Should be the directory containing the tests within the cwd.

paths[].reports

Type: Object

Should be the object containing the reports.

paths[].reports.unit

Type: String

Should be the location of the karma-junit-reporter report within the cwd.

paths[].reports.coverage

Type: String

Should be the glob for the lcov.info files within the cwd.

paths[].reports.itCoverage

Type: String

Should be the glob for the integration test lcov.info files within the cwd.

Usage Examples

Default Options

grunt.initConfig({
  karmaSonar: {
    options: {
    
    },
    your_target: {
      project: {
        key: 'grunt-sonar',
        name: 'Grunt sonar plugin',
        version: '0.2.13'
      },
      paths: [
        {
          cwd: '...', // the current working directory'
          src: '...', // the source directory within the cwd
          test: '...', // the test directory within the cwd
          reports: {
              unit: '../path/result.xml', // the result file within the cwd
              coverage: '../path/**/lcov.info', // the glob for lcov files'
              itCoverage: '../path/**/lcov.info' // the glob for integration lcov files'
          }
        },
        {
          cwd: '...', // the current working directory'
          src: '...', // the source directory within the cwd
          test: '...', // the test directory within the cwd
          reports: {
              unit: '../path/result.xml', // the result file within the cwd
              coverage: '../path/**/lcov.info', // the glob for lcov files'
              itCoverage: '../path/**/lcov.info' // the glob for integration lcov files'
          }
      ],
      exclusions: []
    }
  }
})

Custom Options

In this example, custom options are used to do something else with whatever else. So if the testing file has the content Testing and the 123 file had the content 1 2 3, the generated result in this case would be Testing: 1 2 3 !!!

grunt.initConfig({
  karmaSonar: {
    options: {
      defaultOutputDir: '.tmp/sonar/custom_options/',
      instance: {
        hostUrl : 'http://localhost:20001',
        jdbcUrl : 'jdbc:h2:tcp://localhost:20003/sonar',
        login: 'admin',
        password: 'admin'
      }
    },
    your_target: {
      project: {
        key: 'grunt-sonar',
        name: 'Grunt sonar plugin',
        version: '0.2.13'
      },
      paths: [...],
      exclusions: []
    }
  }
})

Deciding Where To Get Sonar-runner from

By default, this package will download sonar-runner from https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.codehaus.sonar.runner&a=sonar-runner-dist&v=LATEST&p=zip, but only when sonar-runner is not available on the path.

Downloading from a custom URL

If for some reason sonatype is down, or the Great Firewall is blocking sonatype, you may need to use a download mirror url. To set a mirror, set npm config property sonarrunner_cdnurl. Default is ``.

npm install grunt-karma-sonar --sonarrunner_cdnurl=http://some-mirror.org/path/to/downloads

Or add property into your .npmrc file (https://www.npmjs.org/doc/files/npmrc.html)

sonarrunner_cdnurl=http://some-mirror.org/path/to/downloads

Another option is to use PATH variable SONARRUNNER_CDNURL.

SONARRUNNER_CDNURL=http://some-mirror.org/path/to/downloads npm install grunt-karma-sonar

Note: It will try to find sonar-runner-dist.zip in the cdn url.

Downloading from a custom Dir

If for some reason sonatype is down, or the Great Firewall is blocking sonatype, you may need to use a download mirror directory. To set a mirror, set npm config property sonarrunner_cdndir. Default is ``.

npm install grunt-karma-sonar --sonarrunner_cdndir=/some/path/downloads

Or add property into your .npmrc file (https://www.npmjs.org/doc/files/npmrc.html)

sonarrunner_cdndir=/some/path/downloads

Another option is to use PATH variable SONARRUNNER_CDNDIR.

SONARRUNNER_CDNDIR=/some/path/downloads npm install grunt-karma-sonar

Note: It can be the case that there are multiple versions available at the download mirror. If this is the case the latest version will be used.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

(Nothing yet)

grunt-karma-sonar's People

Contributors

mdasberg avatar jeinnovate avatar mrhus avatar nchase avatar tnguyen1 avatar pgokul avatar

Watchers

James Cloos avatar Bart 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.