Template for a good new topic, formatted with Markdown:
- ALM used Bitbucket Cloud
- CI system used Bitbucket Cloud
- Languages of the repository - Nodejs
Here’s my bitbucket pipeline.
image: node:18.7.0-alpine
clone:
depth: 1
definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
pipelines:
default:
- step:
name: Test and Publish Report
caches:
- node
script:
- npm install
- npm run coverage
artifacts:
- test-report.xml
- step:
name: Analyze with SonarCloud
script:
- pipe: sonarsource/sonarcloud-scan:1.4.0
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
EXTRA_ARGS: -Dsonar.exclusions=node_modules/** -Dsonar.coverage.jacoco.xmlReportPaths=$BITBUCKET_CLONE_DIR/test-report.xml -Dsonar.projectDescription="Project with sonarcloud-scan pipe"
SONAR_SCANNER_OPTS: -Xmx512m -Dsonar.scanner.maxParallelThreads=8
I generate the report at the root directly of the project as an xml file and the rest of it is in reports/coverage/* . however, no test coverage reports reflect, even though a report is generated
Here’s the important part of my package.json
"scripts": {
"start": "pm2 start ecosystem.config.json --no-daemon && exit 0",
"dev": "cross-env NODE_ENV=development nodemon src/index.js && exit 0",
"test": "jest -i --colors --verbose --detectOpenHandles",
"test2": "jest -i --colors --verbose --detectOpenHandles tests/integration/calculations.test.js",
"test:watch": "jest -i --watchAll",
"coverage": "jest -i --coverage",
"coverage:coveralls": "jest -i --coverage --coverageReporters=text-lcov | coveralls",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prettier": "prettier --check **/*.js",
"prettier:fix": "prettier --write **/*.js",
"docker:prod": "docker-compose -f docker-compose.yml -f docker-compose.prod.yml up",
"docker:dev": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml up",
"docker:test": "docker-compose -f docker-compose.yml -f docker-compose.test.yml up"
},
"devDependencies": {
"coveralls": "^3.0.7",
"eslint": "^7.0.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^24.0.1",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-security": "^1.4.0",
"faker": "^5.1.0",
"jest": "^26.0.1",
"jest-sonar-reporter": "^2.0.0",
"lint-staged": "^11.0.0",
"node-mocks-http": "^1.8.0",
"nodemon": "^2.0.0",
"prettier": "^2.0.5",
"supertest": "^6.0.1"
}
}
And here’s a jest.config.js file:
module.exports = {
testEnvironment: 'node',
testEnvironmentOptions: {
NODE_ENV: 'test',
},
restoreMocks: true,
coveragePathIgnorePatterns: ['node_modules', 'src/config', 'src/app.js', 'tests'],
collectCoverage: true,
testResultsProcessor: 'jest-sonar-reporter',
coverageReporters: ['text', 'lcov', 'json', 'jest-sonar-reporter'],
};
Help is greatly appreciated!!