Node.js 开玩笑+;SonarQube-未导入报告
我正在我的NodeJS+Typescript应用程序上运行sonar scanner,并在单元测试中使用Jest。我能够在控制台上看到报告,显示创建的每个模块的覆盖率。然后,我研究了如何使用Jest sonar reporter将Jest与Sonarqube集成,该报告程序按预期生成report.xml 我在获取我运行的jet的覆盖范围时遇到了问题--覆盖范围将显示在sonarqube中 这是我的项目结构Node.js 开玩笑+;SonarQube-未导入报告,node.js,typescript,sonarqube,sonarqube-scan,ts-jest,Node.js,Typescript,Sonarqube,Sonarqube Scan,Ts Jest,我正在我的NodeJS+Typescript应用程序上运行sonar scanner,并在单元测试中使用Jest。我能够在控制台上看到报告,显示创建的每个模块的覆盖率。然后,我研究了如何使用Jest sonar reporter将Jest与Sonarqube集成,该报告程序按预期生成report.xml 我在获取我运行的jet的覆盖范围时遇到了问题--覆盖范围将显示在sonarqube中 这是我的项目结构 ├── babel.config.js ├── coverage │ ├── clov
├── babel.config.js
├── coverage
│ ├── clover.xml
│ ├── coverage-final.json
│ ├── lcov.info
│ ├── lcov-report
│ └── test-reporter.xml
├── Dockerfile
├── ecs-meta.json
├── Jenkinsfile
├── nodemon.json
├── package.json
├── package-lock.json
├── properties
│ ├── application-dev.json
│ ├── application-prd.json
│ ├── application-tst.json
│ └── application-uat.json
├── README.md
├── sonar-project.properties
├── sonarqube.ts
├── src
│ ├── configs
│ ├── controllers
│ │ └── StoreController.ts
│ ├── index.ts
│ ├── models
│ │ ├── consul.model.ts
│ │ └── UserModel.ts
│ ├── routes
│ │ ├── index.ts
│ │ └── StoreRoutes.ts
│ ├── services
│ │ ├── __mocks__
│ │ │ └── Repository.ts
│ │ └── Repository.ts
│ ├── test
│ │ ├── controllers
│ │ │ └── index.test.ts
│ │ └── utils
│ │ └── ExpressResponseMock.ts
│ └── typings.d.ts
├── tsconfig.json
└── tslint.json
My tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
}
},
"include": [
"src"
]
}
{
"name": "core",
"version": "1.0.0",
"scripts": {
"sonar": "npx sonar-scanner",
"test": "jest --collectCoverage",
"start": "echo \"== DO NOT USE START SCRIPT FOR PRODUCTION ==\" && nodemon",
"build": "tsc",
"lint": "tslint --project ./tsconfig.json --config ./tslint.json",
"review": "cross-env CI=true && npm run lint && npm run build",
"prettify": "prettier --write ./src/**/*.ts"
},
"jest": {
"testEnvironment": "node",
"collectCoverage": true,
"verbose": true,
"modulePathIgnorePatterns": [
"src/config/*"
],
"collectCoverageFrom": [
"src/**/*.{ts,tsx}"
],
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"testResultsProcessor": "jest-sonar-reporter"
},
"jestSonar": {
"reportPath": "coverage",
"reportFile": "test-reporter.xml",
"indent": 4
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm run review"
}
},
"lint-staged": {
"*.{js,ts}": [
"npm run lint",
"npm run prettify"
]
},
"prettier": {
"printWidth": 110
},
"dependencies": {
"@types/axios": "^0.14.0",
"@types/consul": "^0.23.34",
"@types/express": "^4.17.6",
"@types/jest": "^26.0.15",
"@types/node": "^13.5.1",
"@types/request": "^2.48.5",
"axios": "^0.19.0",
"body-parser": "^1.19.0",
"consul": "^0.37.0",
"cross-env": "^7.0.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"jest": "^26.6.0",
"node-vault": "^0.9.20",
"nodemon": "^2.0.2",
"request": "^2.88.2",
"ts-node": "^8.6.2",
"tslint": "^6.0.0",
"typescript": "^3.9.7",
"vault-auth-aws": "^0.1.7"
},
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@babel/preset-typescript": "^7.12.1",
"babel-jest": "^26.6.0",
"husky": "^4.2.5",
"jest-sonar-reporter": "^2.0.0",
"lint-staged": "^10.2.9",
"prettier": "^2.0.5",
"pretty-quick": "^2.0.1",
"sonarqube-scanner": "^2.7.0",
"supertest": "^5.0.0",
"ts-jest": "^26.4.1",
"tslint-config-prettier": "^1.18.0"
}
}
My package.json
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
}
},
"include": [
"src"
]
}
{
"name": "core",
"version": "1.0.0",
"scripts": {
"sonar": "npx sonar-scanner",
"test": "jest --collectCoverage",
"start": "echo \"== DO NOT USE START SCRIPT FOR PRODUCTION ==\" && nodemon",
"build": "tsc",
"lint": "tslint --project ./tsconfig.json --config ./tslint.json",
"review": "cross-env CI=true && npm run lint && npm run build",
"prettify": "prettier --write ./src/**/*.ts"
},
"jest": {
"testEnvironment": "node",
"collectCoverage": true,
"verbose": true,
"modulePathIgnorePatterns": [
"src/config/*"
],
"collectCoverageFrom": [
"src/**/*.{ts,tsx}"
],
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"testResultsProcessor": "jest-sonar-reporter"
},
"jestSonar": {
"reportPath": "coverage",
"reportFile": "test-reporter.xml",
"indent": 4
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm run review"
}
},
"lint-staged": {
"*.{js,ts}": [
"npm run lint",
"npm run prettify"
]
},
"prettier": {
"printWidth": 110
},
"dependencies": {
"@types/axios": "^0.14.0",
"@types/consul": "^0.23.34",
"@types/express": "^4.17.6",
"@types/jest": "^26.0.15",
"@types/node": "^13.5.1",
"@types/request": "^2.48.5",
"axios": "^0.19.0",
"body-parser": "^1.19.0",
"consul": "^0.37.0",
"cross-env": "^7.0.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"jest": "^26.6.0",
"node-vault": "^0.9.20",
"nodemon": "^2.0.2",
"request": "^2.88.2",
"ts-node": "^8.6.2",
"tslint": "^6.0.0",
"typescript": "^3.9.7",
"vault-auth-aws": "^0.1.7"
},
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@babel/preset-typescript": "^7.12.1",
"babel-jest": "^26.6.0",
"husky": "^4.2.5",
"jest-sonar-reporter": "^2.0.0",
"lint-staged": "^10.2.9",
"prettier": "^2.0.5",
"pretty-quick": "^2.0.1",
"sonarqube-scanner": "^2.7.0",
"supertest": "^5.0.0",
"ts-jest": "^26.4.1",
"tslint-config-prettier": "^1.18.0"
}
}
我的声纳项目。属性
#sonar.organization=YOUR-ORGANISATION-KEY
# relative paths to source directories. More details and properties are described
# in https://sonarcloud.io/documentation/project-administration/narrowing-the-focus/
sonar.host.url=https://sonarqube.in
sonar.projectKey=**
sonar.sources=src
sonar.tests=src/test
sonar.test.inclusions=src/**/*.spec.js,src/**/*.spec.jsx,src/**/*.test.js,src/**/*.test.jsx,src/**/*.test.ts,src/**/*.test.tsx
sonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar.testExecutionReportPaths=./coverage/test-reporter.xml
sonar.sourceEncoding=UTF-8
这些是jest覆盖和声纳扫描仪的输出:
$jest——覆盖范围
PASS src/test/controllers/index.test.ts
Get
✓ Get Stores (12 ms)
console.log
Starting lookup for store ""
at Object.getStores (src/controllers/StoreController.ts:4:11)
console.info
Success retrieving store based on "" details!
at then.result (src/controllers/StoreController.ts:7:15)
-------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------|---------|----------|---------|---------|-------------------
All files | 17.24 | 0 | 33.33 | 17.24 |
src | 0 | 0 | 0 | 0 |
index.ts | 0 | 0 | 0 | 0 | 8-28
typings.d.ts | 0 | 0 | 0 | 0 |
src/controllers | 66.67 | 100 | 66.67 | 66.67 |
StoreController.ts | 66.67 | 100 | 66.67 | 66.67 | 11-12
src/models | 0 | 0 | 0 | 0 |
UserModel.ts | 0 | 0 | 0 | 0 |
consul.model.ts | 0 | 0 | 0 | 0 |
src/routes | 0 | 100 | 0 | 0 |
StoreRoutes.ts | 0 | 100 | 100 | 0 | 3-5
index.ts | 0 | 100 | 0 | 0 | 5-14
src/services | 0 | 0 | 0 | 0 |
Repository.ts | 0 | 0 | 0 | 0 | 3-16
src/test/utils | 100 | 100 | 100 | 100 |
ExpressResponseMock.ts | 100 | 100 | 100 | 100 |
-------------------------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.995 s
Ran all test suites.
从下面可以看出,它说已成功找到并解析了覆盖率报告,但我在Sonar仪表板上没有看到它:
INFO: Parsing /mnt/86da7b30-23bc-4ecb-a95e-bbeaecd50c7d/Documents/work/projects/stores/coverage/test-reporter.xml
INFO: Imported test execution data for 1 files
INFO: Sensor Generic Test Executions Report (done) | time=16ms
这是报告的内容:
<?xml version="1.0" encoding="UTF-8"?>
<testExecutions version="1">
<file path="/mnt/86da7b30-23bc-4ecb-a95e-bbeaecd50c7d/Documents/work/projects/stores/src/test/controllers/index.test.ts">
<testCase name="Get Get Stores" duration="12"/>
</file>
</testExecutions>
$sonar扫描仪-X
编辑1
SonarQube版本-版本是-社区版7.9.1(build 27448)您使用的是哪个SonarQube版本?这只会影响SonarQube 6.2+功能。版本为-Community EditionVersion 7.9.1(build 27448)sonar.typescript.lcov.reportpath=coverage/lcov.info,因为您的项目中没有.js文件。我看到的配置与您的配置相同:
WARN:无法解析中的103个文件路径[/mnt/ramdisk/agents/agent12/work/dbe8ad65d6f5738a//coverage/lcov.info],第一个未解析的路径:src/app/app.component.html
,但这是直接与jest--coverage
不同的coverage报告,而由jest sonar reporter生成的test reporter.xml
正在导入-我在这里感到困惑