如何为基于 Typescript 的 AngularJS 项目配置 SonarQube?

问题描述 投票:0回答:1

我已经设置了 SonarQube 和 SonarScanner 并设法扫描了我的项目。我可以在屏幕上看到指标,但代码覆盖率始终为 0%。我错过了什么?

#----- Default SonarQube server
sonar.host.url=http://localhost:9000/sonar

#----- Default source code encoding
#sonar.sourceEncoding=UTF-8

# must be unique in a given SonarQube instance
sonar.projectKey=pwta
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=PWTA
sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set. 
sonar.sources=client

sonar.language=ts
sonar.exclusions=**/node_modules/**
sonar.typescript.lcov.reportPaths=coverage/lcov.info

以上是sonar-project.properties文件的摘录。位于 coverage/lcov.info 的 LCOV 文件是使用 nyc 库生成的。

来自命令提示符的日志:

INFO: Scanner configuration file: NONE
INFO: Project root configuration file: C:\Repos\pwta-desktop\ui\sonar-project.properties
INFO: SonarQube Scanner 3.3.0.1492
INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
INFO: Windows 10 10.0 amd64
INFO: User cache: C:\Users\koklliew\.sonar\cache
INFO: SonarQube server 7.6.0
INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=90ms
INFO: Server id: 9CFC3560-AWmQJqPmStMXNHgIIeVs
INFO: User cache: C:\Users\koklliew\.sonar\cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=166ms
INFO: Load/download plugins (done) | time=223ms
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=4ms
INFO: Project key: pwta
INFO: Base dir: C:\Repos\pwta-desktop\ui
INFO: Working dir: C:\Repos\pwta-desktop\ui\.scannerwork
INFO: Load project settings
INFO: Load project settings (done) | time=49ms
INFO: Load project repositories
INFO: Load project repositories (done) | time=156ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=46ms
INFO: Load active rules
INFO: Load active rules (done) | time=802ms
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=36ms
INFO: Language is forced to ts
INFO: Indexing files...
INFO: Project configuration:
INFO:   Excluded sources: **/node_modules/**, *.spec.ts
INFO:   Included tests: *.spec.ts
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\app.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\app.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\backend\database\seeders\guiSettings.json' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\display-settings\display-settings-group\display-settings-group.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\display-settings\display-settings-tabs\display-settings-tabs.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\display-settings\display-settings.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\display-settings\display-settings.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\external-params\external-params-editor\external-params-editor.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\external-params\external-params-editor\external-params-editor.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\external-params\external-params.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\external-params\external-params.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\external-params\merge-external-params\merge-external-params.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\external-params\merge-external-params\merge-external-params.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\external-params\_external-params-global.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\external-params\_mixins.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\external-params\_variables.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\hidden-elements\hidden-elements.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\hidden-elements\hidden-elements.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\incompatible-testPlan-dialog\incompatible-testPlan-dialog.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\incompatible-testPlan-dialog\incompatible-testPlan-dialog.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\interaction-dialog\interaction-dialog.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\interaction-dialog\interaction-dialog.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\menu\menu.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\menu\menu.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\navigation-bar\navigation-bar.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\navigation-bar\navigation-bar.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\notification-area\notification-area.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\notification-area\notification-area.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\notifications-resource\notifications-resource.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\notifications-resource\notifications-resource.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\notifications-resource\overlay\overlay.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\notifications-resource\overlay\overlay.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\notifications-toolbar\filter\notification-filter.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\notifications-toolbar\filter\notification-filter.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\notifications-toolbar\notifications-toolbar.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\notifications-toolbar\notifications-toolbar.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\notifications-toolbar\search\notifications-search.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\notifications-toolbar\search\notifications-search.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\package-manager-dialog\directives\pm-extended.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\package-manager-dialog\package-manager-dialog.component.html' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\package-manager-dialog\package-manager-dialog.component.scss' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\property-editor\DisplayForProps.tsd.json' is ignored because it doesn't belong to the forced language 'ts'
WARN: File 'C:\Repos\pwta-desktop\ui\client\app\components\property-editor\DisplayForPropsTree.json' is ignored because it doesn't belong to the forced language 'ts'

...继续...

INFO: 343 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: Quality profile for ts: Sonar way
INFO: ------------- Run sensors on module PWTA
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=12ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=9ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=20ms
INFO: Sensor SonarTS [typescript]
INFO: Analyzing 343 typescript file(s) with the following configuration file C:\Repos\pwta-desktop\ui\tsconfig.json
INFO: 145 files analyzed out of 343. Current file: C:\Repos\pwta-desktop\ui\client\app\components\sequence-viewer\services\results-utility.service.spec.ts
INFO: 343 files analyzed out of 343
INFO: Sensor SonarTS [typescript] (done) | time=38926ms
INFO: Sensor SonarTS Coverage [typescript]
INFO: Analysing [C:\Repos\pwta-desktop\ui\coverage\lcov.info]
WARN: Could not resolve 1 file paths in [C:\Repos\pwta-desktop\ui\coverage\lcov.info], first unresolved path: c:\repos\pwta-desktop\ui\karma.conf.js
INFO: Sensor SonarTS Coverage [typescript] (done) | time=14ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=248ms
INFO: ------------- Run sensors on project
INFO: SCM provider for this project is: git
INFO: 1 files to be analyzed
INFO: 0/1 files analyzed
WARN: Missing blame information for the following files:
WARN:   * client/version.ts
WARN: This may lead to missing/broken features in SonarQube
INFO: 43 files had no CPD blocks
INFO: Calculating CPD for 300 files
INFO: CPD calculation finished
INFO: Analysis report generated in 3904ms, dir size=2 MB
INFO: Analysis report compressed in 3421ms, zip size=1 MB
INFO: Analysis report uploaded in 145ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/sonar/dashboard?id=pwta
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://localhost:9000/sonar/api/ce/task?id=AWmkhBxOhYEp7lx6Lmb2
INFO: Analysis total time: 1:01.823 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 1:04.060s
INFO: Final Memory: 19M/407M
INFO: ------------------------------------------------------------------------

日志显示可以找到lcov文件。

而且,似乎在上面的日志中提到了有关路径的投诉。这可能是问题所在吗?

angularjs typescript sonarqube sonarqube-scan sonarscanner
1个回答
0
投票

我认为你的 lcov.info 路径在你的 sonar-project.properties 中是错误的。这是我的:

# TypeScript specific config
sonar.typescript.lcov.reportPaths=coverage/my-project/lcov.info
sonar.test.inclusions=**/*.spec.ts
© www.soinside.com 2019 - 2024. All rights reserved.