Skip to content

Commit

Permalink
test: report merged tests coverage (#656)
Browse files Browse the repository at this point in the history
* test: merge tests coverage

* test: use coverage:report run script

* ci: add job to collect & publish coverage results

* ci: add coverage dir to codecov action

* test: create lcov merged report for Codecov

* ci: keep old component tests job name

* ci: use previous unit tests name
  • Loading branch information
davidlj95 authored Jul 7, 2024
1 parent 6541176 commit 6a96bad
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
uses: ./.github/workflows/reusable-test.yml
permissions:
checks: write
secrets:
codecov-token: ${{ secrets.CODECOV_TOKEN }}
lint:
name: Lint
uses: ./.github/workflows/reusable-lint.yml
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
test:
name: Test
uses: ./.github/workflows/reusable-test.yml
secrets:
codecov-token: ${{ secrets.CODECOV_TOKEN }}
lint:
name: Lint
uses: ./.github/workflows/reusable-lint.yml
Expand Down
50 changes: 45 additions & 5 deletions .github/workflows/reusable-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ on:
type: string
required: false
default: ''
secrets:
codecov-token:
description: Token to use to upload coverage to Codecov. Can be empty for forks https://about.codecov.io/blog/january-product-update-updating-the-codecov-ci-uploaders-to-the-codecov-cli/
required: true

# Add those permissions if reporting test results
# https://github.com/dorny/test-reporter/issues/229
# permissions:
# checks: write

env:
COVERAGE_ARTIFACT_NAME_PREFIX: coverage-
COVERAGE_DIR: coverage

jobs:
templates-have-been-rendered:
name: Templated files are rendered
Expand Down Expand Up @@ -49,12 +57,12 @@ jobs:
name: Test results
path: '*.xml'
reporter: java-junit
- name: Report coverage
# noinspection SpellCheckingInspection
uses: livewing/lcov-job-summary@0a9952db27f98def2ba2de3189c6b24acc4c5501 # v1.1.0
if: success() || failure()
- name: Upload coverage results
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
with:
lcov: coverage/davidlj95/website/lcov.info
name: ${{ env.COVERAGE_ARTIFACT_NAME_PREFIX }}${{ github.job }}
path: ${{ env.COVERAGE_DIR }}
retention-days: 5

component-test:
name: Component tests
Expand Down Expand Up @@ -102,3 +110,35 @@ jobs:
# Given we're doing caching manually, installing apart to leverage cache
install: false
component: true
- name: Upload coverage results
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
with:
name: ${{ env.COVERAGE_ARTIFACT_NAME_PREFIX }}${{ github.job }}
path: ${{ env.COVERAGE_DIR }}
retention-days: 5

coverage:
name: Coverage
needs: [test, component-test]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
ref: ${{ inputs.ref }}
- name: Setup
uses: ./.github/actions/setup
- name: Download code coverage reports
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4
with:
pattern: ${{ env.COVERAGE_ARTIFACT_NAME_PREFIX }}*
path: ${{ env.COVERAGE_DIR }}
merge-multiple: true
- name: Merge coverage reports
run: pnpm run coverage:report:all
- name: Upload to Codecov
uses: codecov/[email protected]
with:
directory: ${{ env.COVERAGE_DIR }}
token: ${{ secrets.codecov-token }}
2 changes: 1 addition & 1 deletion .idea/runConfigurations/Cypress__all_component_tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ module.exports = function (config) {
suppressAll: true, // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, './coverage/davidlj95/website'),
dir: require('path').join(__dirname, './coverage'),
subdir: '.',
reporters: [{ type: 'text-summary' }, { type: 'lcov' }],
reporters: [
{ type: 'text-summary' },
{ type: 'json', file: 'unit-testing.json' },
],
check: {
global: {
statements: 80,
Expand Down
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"build:pullRequest": "pnpm run build --configuration pullRequest,production",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"test:coverage": "ng test --code-coverage --watch false",
"//0": "👇 Can't be 'coverage:report', look for that run script comments for reason",
"coverage:report:all": "pnpm run coverage:move-to-nyc-output && nyc report --reporter lcov --report-dir coverage",
"coverage:move-to-nyc-output": "rm -rf .nyc_output && mkdir .nyc_output && cp -f coverage/*.json .nyc_output",
"security-txt": "tsm scripts/src/generate-security-txt.ts",
"lint": "ng lint",
"lint-staged": "lint-staged",
Expand All @@ -36,7 +40,11 @@
"e2e": "ng e2e",
"cypress:open": "cypress open",
"cypress:run": "cypress run",
"cypress:run-ct": "cypress run --component"
"cypress:run:ct": "cypress run --component",
"//2": "👇 Cypress executes it to perform custom reporting. With this:",
"//3": " - **same filename for local/CI**: the 'mv' command is run in both local & CI, so JSON coverage filename is the same",
"//4": " - **.nycrc* config files avoided:** could be mistakenly used by other tools",
"coverage:report": "nyc report --reporter json --report-dir coverage && mv -f coverage/coverage-final.json coverage/component-testing.json"
},
"dependencies": {
"@angular/animations": "18.0.5",
Expand Down Expand Up @@ -106,6 +114,7 @@
"lint-staged": "15.2.7",
"liquidjs": "10.14.0",
"ng-mocks": "14.13.0",
"nyc": "17.0.0",
"prettier": "3.3.2",
"semantic-release": "24.0.0",
"subset-font": "2.3.0",
Expand Down
48 changes: 44 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6a96bad

Please sign in to comment.