项目作者: tornaia

项目描述 :
一个Karma插件。单元测试SonarQube / Generic Coverage插件的执行报告
高级语言: JavaScript
项目地址: git://github.com/tornaia/karma-sonarqube-unit-reporter.git
创建时间: 2016-01-26T10:13:19Z
项目社区:https://github.com/tornaia/karma-sonarqube-unit-reporter

开源协议:MIT License

下载


karma-sonarqube-unit-reporter

NpmLicense npm NpmVersion

Motivation

This solution is based on https://github.com/karma-runner/karma-junit-reporter .

Issue: https://github.com/karma-runner/karma-junit-reporter/issues/81

How to get

Available on npmjs.org
https://www.npmjs.com/package/karma-sonarqube-unit-reporter

How to use

Sample karma.conf.ci.js

  1. 'use strict';
  2. var path = require('path');
  3. var conf = require('./gulp/conf');
  4. var _ = require('lodash');
  5. var wiredep = require('wiredep');
  6. var pathSrcHtml = [
  7. path.join(conf.paths.src, '/**/*.html'),
  8. path.join(conf.paths.src_test, '/**/*.html')
  9. ];
  10. function listFiles() {
  11. var wiredepOptions = _.extend({}, conf.wiredep, {
  12. dependencies: true,
  13. devDependencies: true
  14. });
  15. return wiredep(wiredepOptions).js
  16. .concat([
  17. path.join(conf.paths.src, '/app/**/*.module.js'),
  18. path.join(conf.paths.src, '/app/**/*.js'),
  19. path.join(conf.paths.src, '/**/*.spec.js'),
  20. path.join(conf.paths.src, '/**/*.mock.js'),
  21. path.join(conf.paths.src_test, '/app/**/*.module.js'),
  22. path.join(conf.paths.src_test, '/app/**/*.js'),
  23. path.join(conf.paths.src_test, '/**/*.spec.js'),
  24. path.join(conf.paths.src_test, '/**/*.mock.js')
  25. ])
  26. .concat(pathSrcHtml);
  27. }
  28. module.exports = function(config) {
  29. var configuration = {
  30. files: listFiles(),
  31. singleRun: true,
  32. colors: false,
  33. autoWatch: false,
  34. ngHtml2JsPreprocessor: {
  35. stripPrefix: conf.paths.src + '/',
  36. moduleName: 'TODO_PUT_HERE_YOUR_MODULE_NAME'
  37. },
  38. logLevel: 'WARN',
  39. frameworks: ['jasmine', 'angular-filesort'],
  40. angularFilesort: {
  41. whitelist: [path.join(conf.paths.src, '/**/!(*.html|*.spec|*.mock).js'), path.join(conf.paths.src_test, '/**/!(*.html|*.spec|*.mock).js')]
  42. },
  43. browsers: ['PhantomJS'],
  44. sonarQubeUnitReporter: {
  45. sonarQubeVersion: 'LATEST',
  46. outputFile: 'reports/ut_report.xml',
  47. useBrowserName: false
  48. },
  49. plugins: [
  50. 'karma-phantomjs-launcher',
  51. 'karma-angular-filesort',
  52. 'karma-coverage',
  53. 'karma-jasmine',
  54. 'karma-ng-html2js-preprocessor',
  55. 'karma-sonarqube-unit-reporter'
  56. ],
  57. coverageReporter: {
  58. type : 'lcov',
  59. dir : 'reports',
  60. subdir : 'coverage'
  61. },
  62. reporters: ['progress', 'sonarqubeUnit', 'coverage'],
  63. preprocessors: {
  64. 'src/**/*.js': ['coverage'],
  65. 'test/**/*.js': ['coverage']
  66. }
  67. };
  68. config.set(configuration);
  69. };

By default, the description of the jasmine tests used as the path attribute in the generated xml. If this is not the case with your tests, you can use the following options to automagically find the right path values. It is the recommended way to use this plugin but to be backward compatible it is not enabled by default.

  1. sonarQubeUnitReporter: {
  2. sonarQubeVersion: 'LATEST',
  3. outputFile: 'reports/ut_report.xml',
  4. overrideTestDescription: true,
  5. testPaths: ['./test', './moreTests'],
  6. testFilePattern: '.spec.js',
  7. useBrowserName: false
  8. },
Prerequisites for development
Build
  • npm install
  • npm build
Additional Arguments
  1. sonarQubeUnitReporter: {
  2. prependTestFileName: 'frontend' # This adds a string to the front of the generated file name in the report
  3. # Useful if you run tests from within a subdirectory
  4. }