diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 607d9e70be..a3c68e3a83 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,11 +33,19 @@ jobs: matrix: # syntax inspired from https://github.community/t5/GitHub-Actions/Using-a-matrix-defined-input-for-a-custom-action/m-p/32032/highlight/true#M988 os: - - { name: ubuntu-20.04 } + - { name: ubuntu-20.04, coverage: '-- --coverage' } - { name: macos-10.15 } - { name: windows-2019 } steps: - - uses: actions/checkout@v2 + - name: Checkout with shallow clone + uses: actions/checkout@v2 + if: ${{ !contains(matrix.os.coverage, 'coverage') }} + - name: Checkout without shallow clone + uses: actions/checkout@v2 + if: ${{ contains(matrix.os.coverage, 'coverage') }} + with: + # Disabling shallow clone is recommended for improving relevancy of SonarCloud reporting + fetch-depth: 0 - name: Setup node uses: actions/setup-node@v1 with: @@ -54,7 +62,7 @@ jobs: run: npm run build - name: Test Application id: 'test_unit' - run: npm run test:unit + run: npm run test:unit ${{ matrix.os.coverage }} - name: Upload unit test results if: ${{ failure() && steps.test_unit.outcome == 'failure' }} uses: actions/upload-artifact@v2 @@ -63,7 +71,7 @@ jobs: path: build/test-report/unit - name: Test Application End to End id: 'test_e2e' - run: npm run test:e2e + run: npm run test:e2e ${{ matrix.os.coverage }} - name: Upload e2e test results if: ${{ failure() && steps.test_e2e.outcome == 'failure' }} uses: actions/upload-artifact@v2 @@ -73,3 +81,11 @@ jobs: # Ensure we don't break scripts - name: Build utils run: npm run build-utils + + # No need to run the analysis from all environments + - name: SonarCloud Scan + if: ${{ success() && contains(matrix.os.coverage, 'coverage') }} + uses: SonarSource/sonarcloud-github-action@v1.4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/README.md b/README.md index 26b60b2c12..294fac6606 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,9 @@ Build + + Coverage + Gitpod diff --git a/package-lock.json b/package-lock.json index b0a35978c5..a42a3311c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11821,6 +11821,24 @@ } } }, + "jest-sonar": { + "version": "0.2.11", + "resolved": "https://registry.npmjs.org/jest-sonar/-/jest-sonar-0.2.11.tgz", + "integrity": "sha512-uQej+af8ElXNp6rP5OyjrZraSpbxGwLUuMJIxaBq/dd9V0rP6GCFjUUn35w6oUF5RT8vC8N+gNq1lxrlgpbmUg==", + "dev": true, + "requires": { + "entities": "2.0.3", + "strip-ansi": "6.0.0" + }, + "dependencies": { + "entities": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/entities/-/entities-2.0.3.tgz", + "integrity": "sha512-MyoZ0jgnLvB2X3Lg5HqpFmn1kybDiIfEQmKzTb5apr51Rb+T3KdmMiqa70T+bhGnyv7bQ6WMj2QMHpGMmlrUYQ==", + "dev": true + } + } + }, "jest-util": { "version": "26.6.1", "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-26.6.1.tgz", diff --git a/package.json b/package.json index eead7d2249..9d987898dc 100644 --- a/package.json +++ b/package.json @@ -62,11 +62,11 @@ "lint-check": "tsc --noEmit && eslint \"*/**/*.{js,ts,tsx}\" NOTICE --max-warnings 0", "test": "run-s test:unit test:e2e", "test:unit": "jest --runInBand --config=./test/unit/jest.config.js", - "test:unit:coverage": "jest --runInBand --config=./test/unit/jest.config.js --coverage", - "test:unit:watch": "jest --runInBand --config=./test/unit/jest.config.js --coverage --watchAll", + "test:unit:coverage": "npm run test:unit -- --coverage", + "test:unit:watch": "npm run test:unit:coverage -- --watchAll", "test:e2e": "cross-env DEBUG=test JEST_IMAGE_SNAPSHOT_TRACK_OBSOLETE=1 JEST_PUPPETEER_CONFIG=./test/e2e/jest-puppeteer.config.js jest --runInBand --detectOpenHandles --testPathIgnorePatterns ./test/e2e/performance --config=./test/e2e/jest.config.js", "test:perf": "cd ./test/e2e && jest --runInBand --detectOpenHandles --testNamePattern=performance", - "test:e2e:coverage": "cross-env JEST_IMAGE_SNAPSHOT_TRACK_OBSOLETE=1 jest --runInBand --detectOpenHandles --config=./test/e2e/jest.config.js --coverage" + "test:e2e:coverage": "npm run test:e2e -- --coverage" }, "dependencies": { "entities": "^2.1.0", @@ -103,6 +103,7 @@ "jest-html-reporter": "^3.3.0", "jest-image-snapshot": "^4.2.0", "jest-puppeteer": "^4.4.0", + "jest-sonar": "^0.2.11", "lint-staged": "^10.5.2", "minimist": "^1.2.5", "mxgraph-type-definitions": "^1.0.4", diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000000..0f46ca0135 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,29 @@ +# Organization and project keys are displayed in the right sidebar of the project homepage +sonar.projectKey=process-analytics_bpmn-visualization-js +sonar.organization=process-analytics + +# This is the name and version displayed in the SonarCloud UI. +sonar.projectName=bpmn-visualization +sonar.projectVersion=0.7.0 + +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +sonar.sources=src +sonar.exclusions=src/model/**/*,src/demo/**/*,src/static/**/* +#sonar.inclusions= +# Encoding of the source code. Default is default system encoding +sonar.sourceEncoding=UTF-8 + +# Path to tests +sonar.tests=test +sonar.test.exclusions=**/jest.config.js,**/*.png +#sonar.test.inclusions= + +sonar.javascript.lcov.reportPaths=build/test-report/unit/lcov.info,build/test-report/e2e/lcov.info +sonar.testExecutionReportPaths=build/test-report/unit/sonar-report.xml,build/test-report/e2e/sonar-report.xml + +# The job failed before the sonar analysis, if the lint check failed. So no need to configure eslint for Sonar +#sonar.eslint.reportPaths=build/eslint-reporter.json +sonar.typescript.tsconfigPath=tsconfig.json + +# Exclusions for copy-paste detection +#sonar.cpd.exclusions= diff --git a/test/e2e/jest.config.js b/test/e2e/jest.config.js index 9c6fb4497d..250cf78308 100644 --- a/test/e2e/jest.config.js +++ b/test/e2e/jest.config.js @@ -14,10 +14,11 @@ * limitations under the License. */ module.exports = { + rootDir: '../..', + roots: ['./test/e2e', './src'], preset: 'jest-puppeteer', - roots: ['./'], testMatch: ['**/?(*.)+(spec|test).[t]s'], - testPathIgnorePatterns: ['/node_modules/', 'dist'], + testPathIgnorePatterns: ['/node_modules/', 'dist', 'src'], testTimeout: 200000, transform: { '^.+\\.ts?$': 'ts-jest', @@ -25,9 +26,13 @@ module.exports = { testEnvironment: 'jest-environment-puppeteer-jsdom', globalSetup: 'jest-environment-puppeteer-jsdom/setup', globalTeardown: 'jest-environment-puppeteer-jsdom/teardown', - setupFiles: ['./config/jest.globals.ts'], + collectCoverageFrom: ['**/*.{ts,js}'], + coveragePathIgnorePatterns: ['/node_modules/', 'dist', 'test', 'src/demo', 'src/static', 'src/model'], + coverageReporters: ['lcovonly', 'text', 'text-summary'], + coverageDirectory: 'build/test-report/e2e', + setupFiles: ['./test/e2e/config/jest.globals.ts'], // jest-image-snapshot configuration doesn't work with setupFiles, fix with setupFilesAfterEnv: see https://github.com/testing-library/jest-dom/issues/122#issuecomment-650520461 - setupFilesAfterEnv: ['./config/jest.image.ts'], + setupFilesAfterEnv: ['./test/e2e/config/jest.image.ts'], reporters: [ 'default', [ @@ -39,5 +44,11 @@ module.exports = { includeSuiteFailure: true, }, ], + [ + 'jest-sonar', + { + outputDirectory: 'build/test-report/e2e', + }, + ], ], }; diff --git a/test/unit/jest.config.js b/test/unit/jest.config.js index b11fcd8515..41410e687d 100644 --- a/test/unit/jest.config.js +++ b/test/unit/jest.config.js @@ -14,29 +14,23 @@ * limitations under the License. */ module.exports = { - roots: ['./'], + rootDir: '../..', + roots: ['./test/unit', './src'], moduleNameMapper: { // mock files that jest doesn't support like CSS and SVG files '\\.css$': './../module-mock.js', '\\.svg$': './../module-mock.js', }, testMatch: ['**/?(*.)+(spec|test).[t]s'], - testPathIgnorePatterns: ['/node_modules/', 'dist'], + testPathIgnorePatterns: ['/node_modules/', 'dist', 'src'], transform: { '^.+\\.ts?$': 'ts-jest', }, collectCoverageFrom: ['**/*.{ts,js}'], - coveragePathIgnorePatterns: ['/node_modules/', 'dist', 'test'], - coverageThreshold: { - global: { - branches: 80, - functions: 80, - lines: 80, - statements: 80, - }, - }, - coverageReporters: ['json', 'json-summary', 'lcov', 'text', 'text-summary', 'clover'], - setupFiles: ['./jest.globals.ts'], + coveragePathIgnorePatterns: ['/node_modules/', 'dist', 'test', 'src/demo', 'src/static', 'src/model'], + coverageReporters: ['lcovonly', 'text', 'text-summary'], + coverageDirectory: 'build/test-report/unit', + setupFiles: ['./test/unit/jest.globals.ts'], reporters: [ 'default', [ @@ -48,5 +42,11 @@ module.exports = { includeSuiteFailure: true, }, ], + [ + 'jest-sonar', + { + outputDirectory: 'build/test-report/unit', + }, + ], ], };