简体   繁体   English

业力声纳单元记者输出xml路径

[英]karma sonarqube unit reporter output xml path

I have integrated the sonar-cube report with my deployment pipeline.我已将声纳立方体报告与我的部署管道集成。

My Project structure is as Project 1) AWS/Lammbda (containing all aws lambda python code) 2) Web (Containing angular project)我的项目结构为项目1) AWS/Lammbda (包含所有 aws lambda python 代码) 2) Web (包含 Angular 项目)

In my CI pipeline, I have implemented tasks as在我的 CI 管道中,我将任务实现为

- task: SonarSource.sonarqube.15B84CA1-B62F-4A2A-A403-89B77A063157.SonarQubePrepare@5
        displayName: 'Prepare analysis on SonarQube'
        inputs:
          SonarQube: SonarQube
          scannerMode: CLI
          configMode: manual
          cliProjectKey: 'ABCD-UI'
          cliProjectName: 'ABCD-UI'
          cliSources: Web
          extraProperties: |
            sonar.sourceEncoding=UTF-8
            sonar.exclusions=**/app-config/**/*, **/dist/**/*, **/e2e/**/*, **/coverage/**/*, **/assets/**/*, **/legacyDependency/**/* , **/node_modules/**/* , **/third-party-deps/**/*
            sonar.verbose=true
            sonar.ts.tslint.configpath=tslint.json
            sonar.buildbreaker.skip=true
            sonar.sources=$(Build.SourcesDirectory)/Web/src
            sonar.tests=$(Build.SourcesDirectory)/Web/src
            sonar.test.inclusions=**/*.spec.ts
            sonar.javascript.lcov.reportPaths=$(Build.SourcesDirectory)/Web/coverage/rollback/lcov.info
            sonar.testExecutionReportPaths=$(Build.SourcesDirectory)/Web/unit-test-results/sonar-unit-test-report.xml
  

My karma.conf.js configuration is as -:我的karma.conf.js配置为-:

process.env.CHROME_BIN = require('puppeteer').executablePath()

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-coverage'),
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jsonsummary-reporter'),
      require('karma-htmlfile-reporter'),
      require('karma-sonarqube-unit-reporter'),
      require('karma-jasmine-html-reporter'),
      //require('karma-spec-reporter'),
      require('karma-junit-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false, // leave Jasmine Spec Runner output visible in browser
      jasmine: {
        failSpecWithNoExpectations: true
      }
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, './coverage/rollback'),
      reports: ['html', 'lcovonly', 'text-summary', 'cobertura'],
      fixWebpackSourcePaths: true
    },
    files: [
      { pattern: 'src/api/**/*.json', watched: false, included: false, served: true }
    ],
    reporters: ['jsonsummary', 'junit', 'kjhtml', 'coverage', 'html', 'progress', 'coverage-istanbul', 'sonarqubeUnit'],//, 'spec'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['ChromeHeadless'],
    browserDisconnectTimeout: 10000,
    browserDisconnectTolerance: 3,
    browserNoActivityTimeout: 60000,
    flags: [
      '--disable-gpu',
      '--no-sandbox',
      '--no-proxy-server'
    ],
    singleRun: true,
    restartOnFileChange: true,
    htmlReporter: {
      outputFile: 'unit-test-results/index.html',
      // Optional
      pageTitle: 'Buy-side Web',
      subPageTitle: 'Unit test results',
      groupSuites: true,
      useCompactStyle: true,
      useLegacyStyle: false
    },
    jsonReporter: {
      stdout: false,
      outputFile: 'unit-test-results/results.json'
    },
    junitReporter: {
      outputDir: 'unit-test-results', // results will be saved as $outputDir/$browserName.xml
      outputFile: 'results-junit.xml', // if included, results will be saved as $outputDir/$browserName/$outputFile
      suite: '', // suite will become the package name attribute in xml testsuite element
      useBrowserName: false, // add browser name to report and classes names
      nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
      classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
      properties: {} // key value pair of properties to add to the <properties> section of the report
    },
    sonarQubeUnitReporter: {
      sonarQubeVersion: 'LATEST',
      outputFile: 'unit-test-results/sonar-unit-test-report.xml',
      useBrowserName: false,
      overrideTestDescription: true
    }
  });
};

I am able to get all the sonar scan results and coverage part but unable to get the test result, I analyzed the issue and I find the sonar-unit-test-report.xml path is not correct.我能够获得所有声纳扫描结果和覆盖部分,但无法获得测试结果,我分析了问题,发现sonar-unit-test-report.xml路径不正确。

it is generating like它正在生成

<testExecutions version="1">
  <file path="src/app/modules/feature-compliance/compliance/components/compliance-results-grid/compliance-results-grid.component.spec.ts">
    <testCase name="Compliance Results Grid Component should create" duration="588"/>
</file>
</testExecutions>

but it should be like -但它应该像 -

<testExecutions version="1">
  <file path="Web/src/app/modules/feature-compliance/compliance/components/compliance-results-grid/compliance-results-grid.component.spec.ts">
    <testCase name="Compliance Results Grid Component should create" duration="588"/>
</file>
</testExecutions>

I have tried to provide a hardcode xml and was able to get all the test results, so can anyone suggest to me what changes I need to do in karma.conf.js or sonar configuration .我试图提供一个硬编码 xml 并且能够获得所有测试结果,所以任何人都可以向我建议我需要在karma.conf.jssonar configuration中进行哪些更改。

声纳仪表板

I resolved it by adding a new property prependTestFileName我通过添加一个新属性prependTestFileName解决了它

sonarQubeUnitReporter: {
     sonarQubeVersion: "LATEST",
     outputDir: "coverage/",
     outputFile: "test-report.xml",
     useBrowserName: false,
     overrideTestDescription: true,
     prependTestFileName: "apps/portal"
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM