diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 42cc41c..a3ce086 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -36,4 +36,3 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - diff --git a/.github/workflows/sonarpush.yml b/.github/workflows/sonarpush.yml new file mode 100644 index 0000000..f47830a --- /dev/null +++ b/.github/workflows/sonarpush.yml @@ -0,0 +1,30 @@ +name: Sonar push +on: + push: + branches: + - develop + pull_request: + types: [opened, synchronize, reopened] +jobs: + sonarcloud: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: actions/setup-node@v1 + with: + node-version: "18.12.1" + - name: Install dependencies + run: npm install + - name: Install Jest globally + run: sudo npm install -g jest + - name: Run Tests + env: + SECRET: mockSecret + run: npm run test + - name: SonarCloud Scan + uses: sonarsource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.gitignore b/.gitignore index e546391..1db7980 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,5 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* + +test-report.xml diff --git a/jest.config.js b/jest.config.js index c67782b..afe2c66 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,6 +3,11 @@ module.exports = { testEnvironment: 'node', cacheDirectory: '.tmp/jestCache', collectCoverage: true, - collectCoverageFrom: ['/src/**/*.ts'], coverageDirectory: '/coverage', + collectCoverageFrom: ['/src/**/*.ts'], + watchPathIgnorePatterns: ["/test-report.json"], + reporters: ["default"], + testResultsProcessor: "jest-sonar-reporter", + coverageReporters: ["text", "html", "lcov", "clover"], + coveragePathIgnorePatterns: ["/node_modules/", "/test/"] }; diff --git a/package-lock.json b/package-lock.json index e4f031c..1707455 100644 --- a/package-lock.json +++ b/package-lock.json @@ -39,6 +39,7 @@ "eslint": "^8.49.0", "husky": "^8.0.3", "jest": "^29.7.0", + "jest-sonar-reporter": "^2.0.0", "lcov-result-merger": "^4.1.0", "lint-staged": "10.5.4", "madge": "^6.1.0", @@ -5949,6 +5950,18 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-sonar-reporter": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/jest-sonar-reporter/-/jest-sonar-reporter-2.0.0.tgz", + "integrity": "sha512-ZervDCgEX5gdUbdtWsjdipLN3bKJwpxbvhkYNXTAYvAckCihobSLr9OT/IuyNIRT1EZMDDwR6DroWtrq+IL64w==", + "dev": true, + "dependencies": { + "xml": "^1.0.1" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/jest-util": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.7.0.tgz", @@ -9272,6 +9285,12 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/xml": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", + "integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==", + "dev": true + }, "node_modules/xmlbuilder": { "version": "15.1.1", "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-15.1.1.tgz", @@ -13836,6 +13855,15 @@ "semver": "^7.5.3" } }, + "jest-sonar-reporter": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/jest-sonar-reporter/-/jest-sonar-reporter-2.0.0.tgz", + "integrity": "sha512-ZervDCgEX5gdUbdtWsjdipLN3bKJwpxbvhkYNXTAYvAckCihobSLr9OT/IuyNIRT1EZMDDwR6DroWtrq+IL64w==", + "dev": true, + "requires": { + "xml": "^1.0.1" + } + }, "jest-util": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.7.0.tgz", @@ -16265,6 +16293,12 @@ "signal-exit": "^3.0.7" } }, + "xml": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", + "integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==", + "dev": true + }, "xmlbuilder": { "version": "15.1.1", "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-15.1.1.tgz", diff --git a/package.json b/package.json index bd37032..d76bc53 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "merge-coverage": "lcov-result-merger 'coverage/lcov.info' -o 'coverage/lcov-merged.info'", "pre-commit": "lint-staged", "test": "npm run test:unit && npm run test:features && npm run merge-coverage", + "test:ci": "jest --ci --forceExit --reporters='default' --reporters='./github-actions-reporter'", "test:features": "cross-env NODE_ENV=test cucumber-js -p apiApp_backend", "test:unit": "cross-env NODE_ENV=test jest --detectOpenHandles --forceExit --coverage" }, @@ -70,7 +71,7 @@ "eslint": "^8.49.0", "husky": "^8.0.3", "jest": "^29.7.0", - "lcov-result-merger": "^4.1.0", + "jest-sonar-reporter": "^2.0.0", "lint-staged": "10.5.4", "madge": "^6.1.0", "prettier": "^2.8.8",