diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml index 8fc842c7..f308280f 100644 --- a/.github/workflows/code-analysis.yml +++ b/.github/workflows/code-analysis.yml @@ -4,6 +4,7 @@ on: branches: - main pull_request: + # types: [opened, synchronize, reopened] branches: - main @@ -14,7 +15,7 @@ jobs: steps: - uses: actions/checkout@v2 with: - fetch-depth: 0 + fetch-depth: 0 - name: Instala dependĂȘncias run: yarn @@ -23,7 +24,7 @@ jobs: run: yarn lint - name: Executa testes e gera cobertura - run: yarn test + run: yarn test:all - name: Executa SonarCloud Scan if: ${{ always() }} @@ -39,4 +40,4 @@ jobs: fail_ci_if_error: true flags: jest name: 2023.2-PrintGo-FrontEnd - verbose: true \ No newline at end of file + verbose: true diff --git a/package-lock.json b/package-lock.json index 7d80a858..1323de1d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,6 +36,9 @@ "eslint-plugin-react": "^7.33.2", "identity-obj-proxy": "^3.0.0", "jest": "^27.5.1", + "jest-mock-extended": "^3.0.5", + "jest-sonar": "^0.2.16", + "jest-sonar-reporter": "^2.0.0", "jsdom": "^22.1.0", "react-router-dom": "^6.17.0", "react-test-renderer": "^18.2.0" @@ -12918,6 +12921,19 @@ "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" } }, + "node_modules/jest-mock-extended": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/jest-mock-extended/-/jest-mock-extended-3.0.5.tgz", + "integrity": "sha512-/eHdaNPUAXe7f65gHH5urc8SbRVWjYxBqmCgax2uqOBJy8UUcCBMN1upj1eZ8y/i+IqpyEm4Kq0VKss/GCCTdw==", + "dev": true, + "dependencies": { + "ts-essentials": "^7.0.3" + }, + "peerDependencies": { + "jest": "^24.0.0 || ^25.0.0 || ^26.0.0 || ^27.0.0 || ^28.0.0 || ^29.0.0", + "typescript": "^3.0.0 || ^4.0.0 || ^5.0.0" + } + }, "node_modules/jest-mock/node_modules/@jest/types": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/@jest/types/-/types-27.5.1.tgz", @@ -14077,6 +14093,40 @@ "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, + "node_modules/jest-sonar": { + "version": "0.2.16", + "resolved": "https://registry.npmjs.org/jest-sonar/-/jest-sonar-0.2.16.tgz", + "integrity": "sha512-ES6Z9BbIVDELtbz+/b6pv41B2qOfp38cQpoCLqei21FtlkG/GzhyQ0M3egEIM+erpJOkpRKM8Tc8/YQtHdiTXA==", + "dev": true, + "dependencies": { + "entities": "4.3.0", + "strip-ansi": "6.0.1" + } + }, + "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-sonar/node_modules/entities": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.3.0.tgz", + "integrity": "sha512-/iP1rZrSEJ0DTlPiX+jbzlA3eVkY/e8L8SozroF395fIqE3TYF/Nz7YOMAawta+vLmyJ/hkGNNPcSbMADCCXbg==", + "dev": true, + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, "node_modules/jest-util": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.7.0.tgz", @@ -19755,6 +19805,15 @@ "resolved": "https://registry.npmjs.org/tryer/-/tryer-1.0.1.tgz", "integrity": "sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA==" }, + "node_modules/ts-essentials": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/ts-essentials/-/ts-essentials-7.0.3.tgz", + "integrity": "sha512-8+gr5+lqO3G84KdiTSMRLtuyJ+nTBVRKuCrK4lidMPdVeEp0uqC875uE5NMcaA7YYMN7XsNiFQuMvasF8HT/xQ==", + "dev": true, + "peerDependencies": { + "typescript": ">=3.7.0" + } + }, "node_modules/ts-interface-checker": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", @@ -21026,6 +21085,12 @@ } } }, + "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/xml-name-validator": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-4.0.0.tgz", diff --git a/scripts/metrics.js b/scripts/metrics.js index aec12f6e..d40a0db1 100644 --- a/scripts/metrics.js +++ b/scripts/metrics.js @@ -1,28 +1,26 @@ const REPO = '2023.2-PrintGo-FrontEnd' -const SONAR_OWNER = 'fga-eps-mds-1' const OWNER = 'fga-eps-mds' const SONAR_ID = 'fga-eps-mds_2023.2-PrintGo-FrontEnd' const METRIC_LIST = [ - 'files', - 'functions', - 'complexity', - 'comment_lines_density', - 'duplicated_lines_density', - 'coverage', - 'ncloc', - 'tests', - 'test_errors', - 'test_failures', - 'test_execution_time', - 'security_rating' -] -const SONAR_URL = `https://sonarcloud.io/api/measures/component_tree?component=${SONAR_ID}&metricKeys=${METRIC_LIST.join( - ',' -)}&ps=500` + 'files', + 'functions', + 'complexity', + 'comment_lines_density', + 'duplicated_lines_density', + 'coverage', + 'ncloc', + 'tests', + 'test_errors', + 'test_failures', + 'test_execution_time', + 'security_rating' +]; + +const SONAR_URL = `https://sonarcloud.io/api/measures/component_tree?component=${SONAR_ID}&metricKeys=${METRIC_LIST.join(',')}&ps=500`; module.exports = { - SONAR_URL, - REPO, - OWNER -} \ No newline at end of file + SONAR_URL, + REPO, + OWNER +}; \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties index 1df2a8d6..db57bb4a 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,5 +1,13 @@ sonar.projectKey=fga-eps-mds_2023.2-PrintGo-FrontEnd sonar.organization=fga-eps-mds-1 sonar.sources=src -sonar.exclusions=node_modules/**, test/**, assets/**, .github/** -sonar.javascript.lcov.reportPaths=coverage/lcov.info \ No newline at end of file +sonar.tests=tests +sonar.language=ts +sonar.typescript.tsconfigPath=./tsconfig.json + +sonar.test.inclusions=**/*.spec.tsx,**/*.spec.ts, **/*.test.ts +sonar.exclusions=node_modules/**, test/**, assets/**, .github/**, scripts/** + + +sonar.javascript.lcov.reportPaths=coverage/lcov.info +sonar.testExecutionReportPaths=reports/sonar-report.xml \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index fa9f91c4..dc0f851c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4213,6 +4213,11 @@ entities@^4.4.0: resolved "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz" integrity sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw== +entities@4.3.0: + version "4.3.0" + resolved "https://registry.npmjs.org/entities/-/entities-4.3.0.tgz" + integrity sha512-/iP1rZrSEJ0DTlPiX+jbzlA3eVkY/e8L8SozroF395fIqE3TYF/Nz7YOMAawta+vLmyJ/hkGNNPcSbMADCCXbg== + error-ex@^1.3.1: version "1.3.2" resolved "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz" @@ -6131,6 +6136,13 @@ jest-message-util@^29.7.0: slash "^3.0.0" stack-utils "^2.0.3" +jest-mock-extended@^3.0.5: + version "3.0.5" + resolved "https://registry.npmjs.org/jest-mock-extended/-/jest-mock-extended-3.0.5.tgz" + integrity sha512-/eHdaNPUAXe7f65gHH5urc8SbRVWjYxBqmCgax2uqOBJy8UUcCBMN1upj1eZ8y/i+IqpyEm4Kq0VKss/GCCTdw== + dependencies: + ts-essentials "^7.0.3" + jest-mock@^27.5.1: version "27.5.1" resolved "https://registry.npmjs.org/jest-mock/-/jest-mock-27.5.1.tgz" @@ -6275,6 +6287,21 @@ jest-snapshot@^27.5.1: pretty-format "^27.5.1" semver "^7.3.2" +jest-sonar-reporter@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/jest-sonar-reporter/-/jest-sonar-reporter-2.0.0.tgz" + integrity sha512-ZervDCgEX5gdUbdtWsjdipLN3bKJwpxbvhkYNXTAYvAckCihobSLr9OT/IuyNIRT1EZMDDwR6DroWtrq+IL64w== + dependencies: + xml "^1.0.1" + +jest-sonar@^0.2.16: + version "0.2.16" + resolved "https://registry.npmjs.org/jest-sonar/-/jest-sonar-0.2.16.tgz" + integrity sha512-ES6Z9BbIVDELtbz+/b6pv41B2qOfp38cQpoCLqei21FtlkG/GzhyQ0M3egEIM+erpJOkpRKM8Tc8/YQtHdiTXA== + dependencies: + entities "4.3.0" + strip-ansi "6.0.1" + jest-util@^27.5.1: version "27.5.1" resolved "https://registry.npmjs.org/jest-util/-/jest-util-27.5.1.tgz" @@ -6400,7 +6427,7 @@ jest-worker@^29.7.0: merge-stream "^2.0.0" supports-color "^8.0.0" -"jest@^27.0.0 || ^28.0.0", jest@^27.4.3, jest@^27.5.1: +"jest@^24.0.0 || ^25.0.0 || ^26.0.0 || ^27.0.0 || ^28.0.0 || ^29.0.0", "jest@^27.0.0 || ^28.0.0", jest@^27.4.3, jest@^27.5.1: version "27.5.1" resolved "https://registry.npmjs.org/jest/-/jest-27.5.1.tgz" integrity sha512-Yn0mADZB89zTtjkPJEXwrac3LHudkQMR+Paqa8uxJHCBr9agxztUifWCyiYrjhMPBoUVBjyny0I7XH6ozDr7QQ== @@ -9014,7 +9041,7 @@ stringify-object@^3.3.0: is-obj "^1.0.1" is-regexp "^1.0.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: +strip-ansi@^6.0.0, strip-ansi@^6.0.1, strip-ansi@6.0.1: version "6.0.1" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -9357,6 +9384,11 @@ tryer@^1.0.1: resolved "https://registry.npmjs.org/tryer/-/tryer-1.0.1.tgz" integrity sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA== +ts-essentials@^7.0.3: + version "7.0.3" + resolved "https://registry.npmjs.org/ts-essentials/-/ts-essentials-7.0.3.tgz" + integrity sha512-8+gr5+lqO3G84KdiTSMRLtuyJ+nTBVRKuCrK4lidMPdVeEp0uqC875uE5NMcaA7YYMN7XsNiFQuMvasF8HT/xQ== + ts-interface-checker@^0.1.9: version "0.1.13" resolved "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz" @@ -9482,7 +9514,7 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -"typescript@^3.2.1 || ^4", "typescript@>= 2.7", "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta": +"typescript@^3.0.0 || ^4.0.0 || ^5.0.0", "typescript@^3.2.1 || ^4", "typescript@>= 2.7", "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta", typescript@>=3.7.0: version "4.9.5" resolved "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz" integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== @@ -10162,6 +10194,11 @@ xml-name-validator@^4.0.0: resolved "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-4.0.0.tgz" integrity sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw== +xml@^1.0.1: + version "1.0.1" + resolved "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz" + integrity sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw== + xmlchars@^2.2.0: version "2.2.0" resolved "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz"