我有一个类型记录项目,它通过Jenkins管道并行进行所有功能测试(在构建主容器之后)。在管道的末尾,我们创建代码覆盖检查,然后将结果发送给声呐。
这是我的package.json:
"test": "npm run test:unit && npm run test:component && npm run test:functional",
"test:component": "mocha --reporter mocha-sonarqube-reporter --reporter-options output=tests/coverage/component/test-xcomponent.xml --recursive -r ts-node/register tests/component/*.ts",
"test:functional": "mocha --reporter mocha-sonarqube-reporter --reporter-options output=tests/coverage/functional/test-xfunctional.xml --recursive -r ts-node/register tests/functional/*.ts",
"test:unit": "mocha --reporter mocha-sonarqube-reporter --reporter-options output=tests/coverage/unit/test-xunit.xml --recursive -r ts-node/register tests/unit/*.ts",
"test:unit:nosq": "mocha --recursive -r ts-node/register tests/unit/*.ts",
"lint": "tslint -t verbose --project tsconfig.json -c tslint.json",
"cover": "nyc --report-dir tests/coverage/all npm run test",
"cover:unit": "nyc --report-dir tests/coverage/unit npm run test:unit",
"cover:functional": "nyc --report-dir tests/coverage/functional -x 'app/repositories' -x 'app/entities' -x 'app/utils' --no-clean npm run test:functional"我的声纳项目。属性如下:
sonar.exclusions=**/node_modules/**,**/*.spec.ts,app/entities/**,dependency-check-report/*,tests/coverage/**/*
sonar.tests=tests
sonar.test.inclusions=tests/**/*
sonar.ts.tslintconfigpath=tslint.json
sonar.typescript.lcov.reportPaths=tests/coverage/all/lcov.info我在这个设置中有两个问题:
nyc merge命令进行组合,但是输出是.json,而sonarqube需要xml。我的代码覆盖率只有一半,因为我只发送一个文件,而不是组合文件。sonar-project.properties文件中,我也将其包含在.gitignore中,但是sonarqube仍然将其报告为代码小。发布于 2019-06-25 18:11:27
SonarQube不需要XML文件来覆盖JavaScript,它要求报表采用lcov格式。请参阅SonarQube的文档:JavaScript覆盖范围结果导入。
为了生成这个lcov报告,您可以执行以下操作:
__coverage__全局写入的内容)放在一个目录中,默认为.nyc_outputnyc report --reporter=lcov --report-dir=.nyc_coveragenyc,您希望使用--report-dir指定的目录中的所有文件(本例中为.nyc_coverage)生成报表,并且希望报表采用--reporter指定的格式(本例中为lcov)。nyc将创建一个文件夹(默认情况下为.nyc_output),并在那里写入lcov文件。如果你愿意,你也可以增加额外的记者为理智。我通常添加--reporter=text,以便它也能打印出覆盖范围。
因此,您的最终命令可能是:
nyc report \
--reporter=lcov \
--reporter=text \
--report-dir=.nyc_coverage=是可选的,命令参数可以放在子命令之前,所以您还可以运行您注意到的命令:
nyc --reporter lcov --reporter text --report-dir .nyc_coverage report此外,通过在命令行上指定报表,告诉SonarQube报表在哪里:
sonar-scanner \
-Dsonar.projectKey=whatever \
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info也可以在项目设置中设置它:
Project -> Administration -> JavaScript -> Tests and Coverage -> LCOV Fileshttps://stackoverflow.com/questions/56755397
复制相似问题