使用SonarTS创建进行typescript代码质量扫描(续):如何设定除外的文件

更新时间:2023-06-13 01:12:26 阅读: 评论:0

使⽤SonarTS创建进⾏typescript代码质量扫描(续):如何设定除外的⽂件
在前⾯的⽂章中介绍了如何使⽤SonarQube结合Karma与Jasmine进⾏前端单元测试并显⽰测试覆盖率,这篇⽂章介绍⼀下如何指定扫描⽬录和除外⽂件。
事前准备
SonarQube环境搭建
可以使⽤SonarQube的各个版本进⾏验证,此处使⽤SonarQube LTS 7.9.1版本 + Postgresql 12版本。详细环境搭建可以参看:
Angular应⽤+Karma+Jasmine
单元测试覆盖率的获取,事前必须需要⾸先执⾏单元测试,然后SonarQube实际上会分析此结果才能进⾏覆盖率的展⽰。⽽这个过程中则需要多种⼯具包括Karma和Jasmine等,⽽由于Angular CLI创建的应⽤框架中已经默认⼏乎配置完毕,⽽且包含⽰例的测试⽂件,所以只需要如下步骤即可:
步骤1: ng new demo --style=less
步骤2: cd demo && npm install
步骤3: 设定karma的配置⽂件
步骤4: ng test --code-coverage
详细的说明和解释可以参看如下内容:
Sonar-Scanner
liumiaocn:~ liumiao$ sonar-scanner --version
INFO: Scanner configuration file: /usr/local/share/sonar/sonar-scanner-3.2.0.1227-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 3.2.0.1227
INFO: Java 1.8.0_191 Oracle Corporation (64-bit)
INFO: Mac OS X 10.14 x86_64
liumiaocn:~ liumiao$
测试执⾏
使⽤ng --code-coverage进⾏测试,并⽣成测试结果⽂件lcov.info,并将此⽂件作为参数传给Sonar-Scanner进⾏覆盖率的确认。
覆盖率信息详细信息如下所⽰:
设定除外⽂件列表
缺省的设定之下,覆盖率为18.5,⽽这个覆盖率的计算是上述7个⽂件的整体单元测试结果。如果将不希望进⾏覆盖率的⽂件进⾏除外,可以使⽤lusions进⾏指定,具体执⾏⽰例如下所⽰:
执⾏⽇志如下所⽰:
liumiaocn:demo liumiao$ sonar-scanner -Dsonar.projectKey=coveragetest \
> -Dsonar.sources=src \
新中式背景墙
> -portPaths=coverage/demo/lcov.info \
> -Dsonar.host.url=192.168.31.242:9001 \
> -Dsonar.login=admin \
> -Dsonar.password=admin \
> -lusions=src/**.spec.ts,src/dule.ts,src/environments/environment*.ts,src/main.ts
INFO: Scanner configuration file: /usr/local/share/sonar/sonar-scanner-3.2.0.1227-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 3.2.0.1227
INFO: Java 1.8.0_191 Oracle Corporation (64-bit)
INFO: Mac OS X 10.14 x86_64
INFO: Ur cache: /Urs/liumiao/.sonar/cache
INFO: SonarQube rver 7.9.1
INFO: Default locale: "en_CN", source code encoding: "UTF-8" (analysis is platform dependent)
WARN: SonarScanner will require Java 11+ to run starting in SonarQube 8.x
INFO: Load global ttings
INFO: Load global ttings (done) | time=457ms
INFO: Server id: 46AF5D23-AW4QVqQKMR98oZUMGunZ
INFO: Ur cache: /Urs/liumiao/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=396ms
INFO: Load/download plugins (done) | time=412ms
INFO: Process project properties
INFO: Project key: coveragetest
INFO: Ba dir: /Urs/liumiao/demo
INFO: Ba dir: /Urs/liumiao/demo
INFO: Working dir: /Urs/liumiao/demo/.scannerwork
INFO: Load project ttings for component key: 'coveragetest'猪脚炖花生的做法
INFO: Load project ttings for component key: 'coveragetest' (done) | time=415ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=477ms
INFO: Load active rules
INFO: Load active rules (done) | time=1033ms
WARN: SCM provider autodetection failed. Plea u "sonar.scm.provider" to define SCM of your project, or disable the SCM Sensor in the project tting s.
关于团结的作文INFO:
INFO: Project configuration:
鼓励孩子自信的话INFO:  Excluded sources: src/**.spec.ts, src/dule.ts, src/environments/environment*.ts, src/main.ts
INFO: 9 files indexed
INFO: 0 files ignored becau of inclusion/exclusion patterns
INFO: Quality profile for ts: Sonar way
西洋参泡酒的功效INFO: ------------- Run nsors on module coveragetest
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=345ms
INFO: Sensor SonarTS [typescript]
INFO: Load project repositories
INFO: Load project repositories (done) | time=393ms
INFO: Analyzing 4 typescript file(s) with the following configuration file /Urs/liumiao/demo/tsconfig.json
INFO: 4 files analyzed out of 4
INFO: Sensor SonarTS [typescript] (done) | time=3122ms
INFO: Sensor SonarTS Coverage [typescript]
INFO: Analysing [/Urs/liumiao/demo/coverage/demo/lcov.info]
INFO: Sensor SonarTS Coverage [typescript] (done) | time=6ms
INFO: ------------- Run nsors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=0ms
INFO: No SCM system was detected. You can u the 'sonar.scm.provider' property to explicitly specify it.
INFO: 2 files had no CPD blocks
INFO: Calculating CPD for 2 files
INFO: CPD calculation finished
INFO: Analysis report generated in 52ms, dir size=16 KB
INFO: Analysis report compresd in 25ms, zip size=8 KB
INFO: Analysis report uploaded in 393ms
INFO: ANALYSIS SUCCESSFUL, you can brow 192.168.31.242:9001/dashboard?id=coveragetest
INFO: Note that you will be able to access the updated dashboard once the rver has procesd the submitted analysis report
INFO: More about the report processing at 192.168.31.242:9001/api/ce/task?id=AW42VurRzxaMqkyn8AZV
INFO: Analysis total time: 7.147 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 8.991s
INFO: Final Memory: 11M/197M
秋天的叶
INFO: ------------------------------------------------------------------------
liumiaocn:demo liumiao$
SonarQube覆盖率确认
整体覆盖率确认:100%写景作文评语
欢迎小雨点
各⽂件测试覆盖率信息列表:2个⽂件,100%
另外使⽤sonar.inclusions也可以根据需要进⾏扫描⽂件的指定,使⽤⽅法类似,不再赘述。

本文发布于:2023-06-13 01:12:26,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/941243.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:覆盖率   需要   扫描   测试   参看   设定   结果   环境
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图