diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 1456c03f4..9de2a0da1 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -75,6 +75,14 @@ jobs: * [The example site](https://designsystem-dev.cancer.gov/${ process.env.BUILD_NAME }/example-site/) ` }) + - name: Create Code Coverage Placeholder + uses: marocchino/sticky-pull-request-comment@v2 + if: startsWith(github.repository, 'NCIOCPL') && github.event_name == 'pull_request' + with: + header: code coverage + message: | + ## Code Coverage + Please wait for build to complete. ## This clones and checks out. - name: Checkout branch uses: actions/checkout@v3 @@ -115,6 +123,21 @@ jobs: run: yarn test env: CI: true + - name: Generate Code Coverage Report + uses: irongut/CodeCoverageSummary@v1.3.0 + with: + filename: 'reports/coverage/**/cobertura-coverage.xml' + badge: true + format: markdown + output: both + - name: Update Code Coverage Comment + uses: marocchino/sticky-pull-request-comment@v2 + if: startsWith(github.repository, 'NCIOCPL') && github.event_name == 'pull_request' + with: + header: code coverage + path: code-coverage-results.md + - name: Output Summary + run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY ## Build all the things for publishing. This is a proxy for testing. - name: Build Doc Site run: yarn docs-artifact diff --git a/.gitignore b/.gitignore index cfebeb61c..d30c073a0 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ pids lib-cov # Coverage directory used by tools like istanbul +/reports coverage *.lcov diff --git a/docs/jest.config.js b/docs/jest.config.js index 42fb1cf8c..a23c7b31f 100644 --- a/docs/jest.config.js +++ b/docs/jest.config.js @@ -1,5 +1,19 @@ +const path = require('path'); module.exports = { collectCoverage: true, + // This needs to be turned on and the coverage + // improved. + // collectCoverageFrom: [ + // 'src/**/*.{js,jsx,ts,tsx}', + // '!src/**/*.test.{js,jsx,ts,tsx}', + // '!**/__tests__/**', + // '!src/**/*.d.ts', + // '!src/**/*.mock.ts', + // '!src/**/index.ts', + // '!src/index.ts', + // ], + coverageReporters: ['cobertura', 'lcov', 'text'], + coverageDirectory: path.join(__dirname, '..', 'reports', 'coverage', 'docs'), coverageThreshold: { global: { branches: 85, diff --git a/packages/ncids-js/jest.config.ts b/packages/ncids-js/jest.config.ts index 075ec2110..ec6ea8144 100644 --- a/packages/ncids-js/jest.config.ts +++ b/packages/ncids-js/jest.config.ts @@ -1,3 +1,4 @@ +import path from 'path'; import type { Config } from '@jest/types'; const config: Config.InitialOptions = { @@ -26,5 +27,14 @@ const config: Config.InitialOptions = { lines: 85, }, }, + coverageReporters: ['cobertura', 'lcov', 'text'], + coverageDirectory: path.join( + __dirname, + '..', + '..', + 'reports', + 'coverage', + 'ncids-js' + ), }; export default config; diff --git a/packages/ncids-react/jest.config.js b/packages/ncids-react/jest.config.js index 0632086d6..aaab7dc00 100644 --- a/packages/ncids-react/jest.config.js +++ b/packages/ncids-react/jest.config.js @@ -1,3 +1,5 @@ +const path = require('path'); + module.exports = { setupFilesAfterEnv: ["./rtl.setup.js"], collectCoverage: true, @@ -8,4 +10,22 @@ module.exports = { lines: 85, }, }, + collectCoverageFrom: [ + 'src/**/*.{js,jsx,ts,tsx}', + '!src/**/*.test.{js,jsx,ts,tsx}', + '!**/__tests__/**', + '!src/**/*.d.ts', + '!src/**/*.mock.ts', + '!src/**/index.ts', + '!src/index.ts', + ], + coverageReporters: ['cobertura', 'lcov', 'text'], + coverageDirectory: path.join( + __dirname, + '..', + '..', + 'reports', + 'coverage', + 'ncids-react' + ), };