From 4a3162444e8b344a389d071af4c1c3ba468d1787 Mon Sep 17 00:00:00 2001 From: Tommy Markley Date: Tue, 19 Apr 2022 16:48:47 -0500 Subject: [PATCH] Adds code coverage reporting (#1478) * Renames build and test workflow to eliminate ambiguity. * Adds coverage generation for jest and mocha tests. * Expands coverage collection for jest tests. * Utilizes `lcov` reporter as well as text summary reporter. Resolves #1339 Prerequisite for #1035 Signed-off-by: Tommy Markley (cherry picked from commit 1caf90752d8e34ceece81d8a69f6ec79aabfa9c1) --- ...rkflow.yml => build_and_test_workflow.yml} | 21 ++++++++++--------- package.json | 6 ++++-- src/dev/jest/config.js | 13 ++---------- 3 files changed, 17 insertions(+), 23 deletions(-) rename .github/workflows/{pr_check_workflow.yml => build_and_test_workflow.yml} (91%) diff --git a/.github/workflows/pr_check_workflow.yml b/.github/workflows/build_and_test_workflow.yml similarity index 91% rename from .github/workflows/pr_check_workflow.yml rename to .github/workflows/build_and_test_workflow.yml index f51255de2948..6fb20afa622d 100644 --- a/.github/workflows/pr_check_workflow.yml +++ b/.github/workflows/build_and_test_workflow.yml @@ -83,18 +83,19 @@ jobs: id: linter run: yarn lint - # Runs unit tests while limiting workers because github actions will spawn more than it can handle and crash - # Continues on error but will create a comment on the pull request if this step failed. - - name: Run unit tests - if: steps.unit_tests_results.outputs.unit_tests_results != 'success' + - name: Run unit tests with coverage id: unit-tests - continue-on-error: true - run: node scripts/jest --ci --colors --maxWorkers=10 - env: - SKIP_BAD_APPLES: true + run: yarn test:jest:ci:coverage + + - name: Run mocha tests with coverage + id: mocha-tests + run: yarn test:mocha:coverage - - run: echo Unit tests completed unsuccessfully. However, unit tests are inconsistent on the CI so please verify locally with `yarn test:jest`. - if: steps.unit_tests_results.outputs.unit_tests_results != 'success' && steps.unit-tests.outcome != 'success' + - name: Upload Code Coverage + id: upload-code-coverage + uses: codecov/codecov-action@v3 + with: + directory: ./target/opensearch-dashboards-coverage - name: Run integration tests if: steps.integration_tests_results.outputs.integration_tests_results != 'success' diff --git a/package.json b/package.json index 517e7927bc7f..ad49d653a81a 100644 --- a/package.json +++ b/package.json @@ -42,13 +42,15 @@ "opensearch": "node scripts/opensearch", "test": "grunt test", "test:jest": "node scripts/jest", + "test:jest:coverage": "node scripts/jest --coverage", + "test:jest:ci": "node scripts/jest --ci --colors --runInBand", + "test:jest:ci:coverage": "node scripts/jest --ci --colors --runInBand --coverage", "test:jest_integration": "node scripts/jest_integration", "test:mocha": "node scripts/mocha", - "test:mocha:coverage": "grunt test:mochaCoverage", + "test:mocha:coverage": "yarn nyc --reporter=text-summary --reporter=lcov --report-dir=./target/opensearch-dashboards-coverage/mocha node scripts/mocha", "test:ftr": "node scripts/functional_tests", "test:ftr:server": "node scripts/functional_tests_server", "test:ftr:runner": "node scripts/functional_test_runner", - "test:coverage": "grunt test:coverage", "checkLicenses": "node scripts/check_licenses --dev", "build-platform": "node scripts/build", "build": "node scripts/build --all-platforms", diff --git a/src/dev/jest/config.js b/src/dev/jest/config.js index 759addb21f48..4e3891f94a6b 100644 --- a/src/dev/jest/config.js +++ b/src/dev/jest/config.js @@ -51,16 +51,6 @@ export default { '/src/test_utils', '/test/functional/services/remote', ], - collectCoverageFrom: [ - 'src/plugins/**/*.{ts,tsx}', - '!src/plugins/**/*.d.ts', - 'packages/osd-ui-framework/src/components/**/*.js', - '!packages/osd-ui-framework/src/components/index.js', - '!packages/osd-ui-framework/src/components/**/*/index.js', - 'packages/osd-ui-framework/src/services/**/*.js', - '!packages/osd-ui-framework/src/services/index.js', - '!packages/osd-ui-framework/src/services/**/*/index.js', - ], moduleNameMapper: { '@elastic/eui$': '/node_modules/@elastic/eui/test-env', '@elastic/eui/lib/(.*)?': '/node_modules/@elastic/eui/test-env/$1', @@ -84,7 +74,8 @@ export default { '/src/dev/jest/setup/react_testing_library.js', ], coverageDirectory: '/target/opensearch-dashboards-coverage/jest', - coverageReporters: ['html', 'text'], + coveragePathIgnorePatterns: ['/node_modules/', '.*\\.d\\.ts'], + coverageReporters: ['lcov', 'text-summary'], moduleFileExtensions: ['js', 'mjs', 'json', 'ts', 'tsx', 'node'], modulePathIgnorePatterns: [ '__fixtures__/',