From b4a9ff397a75df0808393f59095740eb8954becd Mon Sep 17 00:00:00 2001 From: rohanm-crest Date: Wed, 16 Apr 2025 12:29:35 +0530 Subject: [PATCH 01/10] feat: added script for ui test case coverage --- .github/scripts/ui-code-coverage.mjs | 124 +++++++++++++++++++++++++++ .github/workflows/ui-cod-cov.yml | 54 ++++++++++++ ui/jest.config.ts | 1 + 3 files changed, 179 insertions(+) create mode 100644 .github/scripts/ui-code-coverage.mjs create mode 100644 .github/workflows/ui-cod-cov.yml diff --git a/.github/scripts/ui-code-coverage.mjs b/.github/scripts/ui-code-coverage.mjs new file mode 100644 index 000000000..5566d5f72 --- /dev/null +++ b/.github/scripts/ui-code-coverage.mjs @@ -0,0 +1,124 @@ +import fs from "fs"; + +const readJson = (filePath) => { + return JSON.parse(fs.readFileSync(filePath, "utf-8")); +}; + +const getTotals = (rawData) => { + let totalLineCovered = 0; + let totalLineTotal = 0; + let totalBranchCovered = 0; + let totalBranchTotal = 0; + + for (const [filename, data] of Object.entries(rawData)) { + const lineData = data.lines; + const branchData = data.branches; + const linePct = + lineData.total === 0 ? 100 : (lineData.covered / lineData.total) * 100; + const branchPct = + branchData.total === 0 + ? 100 + : (branchData.covered / branchData.total) * 100; + + totalLineCovered += lineData.covered; + totalLineTotal += lineData.total; + + totalBranchCovered += branchData.covered; + totalBranchTotal += branchData.total; + } + + const totalLinePct = + totalLineTotal === 0 ? 100 : (totalLineCovered / totalLineTotal) * 100; + const totalBranchPct = + totalBranchTotal === 0 + ? 100 + : (totalBranchCovered / totalBranchTotal) * 100; + + console.log("๐Ÿ“Š Total Coverage Summary"); + console.log("--------------------------"); + console.log(`โœ… Line Coverage: ${totalLinePct.toFixed(2)}%`); + console.log(`โœ… Branch Coverage: ${totalBranchPct.toFixed(2)}%`); + return [totalLinePct, totalBranchPct]; +}; + +/** + * @param {import('@actions/github-script').AsyncFunctionArguments} args + */ +export default async ({ github, context, core }) => { + const developCoveragePath = "/tmp/pr-coverage.json"; + const prCoveragePath = "/tmp/develop-coverage.json"; + // const developCoveragePath = '../../ui/coverage/coverage-summary.json'; + // const prCoveragePath = '../../ui/coverage/coverage-summary.json'; + + // const prCoverage = JSON.parse(fs.readFileSync('/tmp/pr-coverage.json', 'utf8')); + // const devCoverage = JSON.parse(fs.readFileSync('/tmp/develop-coverage.json', 'utf8')); + + const developCoverage = readJson(developCoveragePath); + const prCoverage = readJson(prCoveragePath); + + const [prLinePct, prBranchPct] = getTotals(prCoverage); + const [developLinePct, developBranchPct] = getTotals(developCoverage); + + const lineDiff = prLinePct - developLinePct; + const branchDiff = prBranchPct - developBranchPct; + + let status = 'unchanged'; + if (lineDiff > 0 || branchDiff > 0) { + status = 'increased'; + } else if (lineDiff < 0 || branchDiff < 0) { + status = 'decreased'; + } + + const lineStatus = + lineDiff > 0 + ? "๐ŸŸข Increased" + : lineDiff < 0 + ? "๐Ÿ”ด Decreased" + : "โšช Unchanged"; + const branchStatus = + branchDiff > 0 + ? "๐ŸŸข Increased" + : branchDiff < 0 + ? "๐Ÿ”ด Decreased" + : "โšช Unchanged"; + + const message = ` + ## ๐Ÿงช Frontend Code Coverage Report ${status === 'increased' ? '๐ŸŽ‰' : status === 'decreased' ? 'โš ๏ธ' : '๐Ÿ”„'}\n\n + + | Metric | PR | Base (develop) | Change | Status | + |--------|----|----------------|--------|--------| + | Line Coverage | ${prLinePct.toFixed(2)}% | ${developLinePct.toFixed(2)}% | ${lineDiff.toFixed(2)}% | ${lineStatus} | + | Branch Coverage | ${prBranchPct.toFixed(2)}% | ${developBranchPct.toFixed(2)}% | ${branchDiff.toFixed(2)}% | ${branchStatus} | + `; + + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + const oldComment = comments.find( + (c) => + c.user.login === "github-actions[bot]" && + c.body.startsWith("## ๐Ÿงช Frontend Code Coverage Report") + ); + + if (oldComment) { + await github.rest.issues.deleteComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: oldComment.id, + }); + } + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: message.trim(), + }); + + if (lineDiff < 0 || branchDiff < 0) { + core.setFailed("Coverage has decreased. Please improve test coverage."); + } +}; diff --git a/.github/workflows/ui-cod-cov.yml b/.github/workflows/ui-cod-cov.yml new file mode 100644 index 000000000..ac5742ee7 --- /dev/null +++ b/.github/workflows/ui-cod-cov.yml @@ -0,0 +1,54 @@ +name: Frontend Code Coverage + +on: + pull_request: + branches: + - develop + paths: + - 'src/**' + - 'tests/**' + types: [opened, synchronize, reopened] + +jobs: + compare-frontend-coverage: + runs-on: ubuntu-22.04 + permissions: + pull-requests: write + contents: read + + steps: + - name: Checkout develop branch + uses: actions/checkout@v4 + with: + ref: develop + + - name: Install Node + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install dependencies + run: npm ci + + - name: Generate coverage for develop branch + run: | + npx jest --coverage --coverageReporters=json-summary + cp coverage/coverage-summary.json /tmp/develop-coverage.json + + - name: Checkout PR branch + uses: actions/checkout@v4 + + - name: Install dependencies again + run: npm ci + + - name: Generate coverage for PR branch + run: | + npx jest --coverage --coverageReporters=json-summary + cp coverage/coverage-summary.json /tmp/pr-coverage.json + + - name: Compare and comment coverage + uses: actions/github-script@v7 + with: + script: | + const { default: compareDiff } = await import('${{ github.workspace }}/.github/scripts/ui-code-coverage.mjs') + await compareDiff({ github, context, core }) diff --git a/ui/jest.config.ts b/ui/jest.config.ts index fd5584f3c..3e4e20e6c 100644 --- a/ui/jest.config.ts +++ b/ui/jest.config.ts @@ -11,6 +11,7 @@ export default { restoreMocks: true, // Coverage collectCoverage: true, + coverageReporters: ['json', 'text', 'lcov', 'json-summary'], collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], coveragePathIgnorePatterns: [ '/node_modules/', From b86cd98b7e54b6daa9db38d0be48a9bd0f338256 Mon Sep 17 00:00:00 2001 From: rohanm-crest Date: Wed, 16 Apr 2025 12:41:45 +0530 Subject: [PATCH 02/10] test: trigger CI From bbf1564a57e017870afd3a8499b9bf98765ebd61 Mon Sep 17 00:00:00 2001 From: rohanm-crest Date: Wed, 16 Apr 2025 12:43:50 +0530 Subject: [PATCH 03/10] test: trigger CI From 71e5ad26b4e60dae894430acb7c8142bb4bf667d Mon Sep 17 00:00:00 2001 From: rohanm-crest Date: Wed, 16 Apr 2025 14:35:39 +0530 Subject: [PATCH 04/10] refactor yml --- .github/scripts/ui-code-coverage.mjs | 208 ++++++++++++++------------- .github/workflows/ui-cod-cov.yml | 2 +- 2 files changed, 108 insertions(+), 102 deletions(-) diff --git a/.github/scripts/ui-code-coverage.mjs b/.github/scripts/ui-code-coverage.mjs index 5566d5f72..0efa2438c 100644 --- a/.github/scripts/ui-code-coverage.mjs +++ b/.github/scripts/ui-code-coverage.mjs @@ -1,86 +1,92 @@ import fs from "fs"; const readJson = (filePath) => { - return JSON.parse(fs.readFileSync(filePath, "utf-8")); -}; - -const getTotals = (rawData) => { - let totalLineCovered = 0; - let totalLineTotal = 0; - let totalBranchCovered = 0; - let totalBranchTotal = 0; - - for (const [filename, data] of Object.entries(rawData)) { - const lineData = data.lines; - const branchData = data.branches; - const linePct = - lineData.total === 0 ? 100 : (lineData.covered / lineData.total) * 100; - const branchPct = - branchData.total === 0 - ? 100 - : (branchData.covered / branchData.total) * 100; - - totalLineCovered += lineData.covered; - totalLineTotal += lineData.total; - - totalBranchCovered += branchData.covered; - totalBranchTotal += branchData.total; + try { + return JSON.parse(fs.readFileSync(filePath, "utf-8")); + } catch (e) { + throw new Error(`Failed to read or parse JSON at ${filePath}: ${e.message}`); } + }; + - const totalLinePct = - totalLineTotal === 0 ? 100 : (totalLineCovered / totalLineTotal) * 100; - const totalBranchPct = - totalBranchTotal === 0 - ? 100 - : (totalBranchCovered / totalBranchTotal) * 100; - - console.log("๐Ÿ“Š Total Coverage Summary"); - console.log("--------------------------"); - console.log(`โœ… Line Coverage: ${totalLinePct.toFixed(2)}%`); - console.log(`โœ… Branch Coverage: ${totalBranchPct.toFixed(2)}%`); - return [totalLinePct, totalBranchPct]; +const getTotals = (rawData) => { + let totalLineCovered = 0; + let totalLineTotal = 0; + let totalBranchCovered = 0; + let totalBranchTotal = 0; + + for (const [filename, data] of Object.entries(rawData)) { + const lineData = data.lines; + const branchData = data.branches; + const linePct = + lineData.total === 0 ? 100 : (lineData.covered / lineData.total) * 100; + const branchPct = + branchData.total === 0 + ? 100 + : (branchData.covered / branchData.total) * 100; + + totalLineCovered += lineData.covered; + totalLineTotal += lineData.total; + + totalBranchCovered += branchData.covered; + totalBranchTotal += branchData.total; + } + + const totalLinePct = + totalLineTotal === 0 ? 100 : (totalLineCovered / totalLineTotal) * 100; + const totalBranchPct = + totalBranchTotal === 0 + ? 100 + : (totalBranchCovered / totalBranchTotal) * 100; + + core.info("๐Ÿ“Š Total Coverage Summary"); + core.info("--------------------------"); + core.info(`โœ… Line Coverage: ${totalLinePct.toFixed(2)}%`); + core.info(`โœ… Branch Coverage: ${totalBranchPct.toFixed(2)}%`); + return [totalLinePct, totalBranchPct]; }; /** * @param {import('@actions/github-script').AsyncFunctionArguments} args */ export default async ({ github, context, core }) => { - const developCoveragePath = "/tmp/pr-coverage.json"; - const prCoveragePath = "/tmp/develop-coverage.json"; - // const developCoveragePath = '../../ui/coverage/coverage-summary.json'; - // const prCoveragePath = '../../ui/coverage/coverage-summary.json'; - - // const prCoverage = JSON.parse(fs.readFileSync('/tmp/pr-coverage.json', 'utf8')); - // const devCoverage = JSON.parse(fs.readFileSync('/tmp/develop-coverage.json', 'utf8')); - - const developCoverage = readJson(developCoveragePath); - const prCoverage = readJson(prCoveragePath); - - const [prLinePct, prBranchPct] = getTotals(prCoverage); - const [developLinePct, developBranchPct] = getTotals(developCoverage); - - const lineDiff = prLinePct - developLinePct; - const branchDiff = prBranchPct - developBranchPct; - - let status = 'unchanged'; - if (lineDiff > 0 || branchDiff > 0) { - status = 'increased'; - } else if (lineDiff < 0 || branchDiff < 0) { - status = 'decreased'; - } - - const lineStatus = - lineDiff > 0 - ? "๐ŸŸข Increased" - : lineDiff < 0 - ? "๐Ÿ”ด Decreased" - : "โšช Unchanged"; - const branchStatus = - branchDiff > 0 - ? "๐ŸŸข Increased" - : branchDiff < 0 - ? "๐Ÿ”ด Decreased" - : "โšช Unchanged"; + const prCoveragePath = "/tmp/pr-coverage.json"; + const developCoveragePath = "/tmp/develop-coverage.json"; + + // const developCoveragePath = '../../ui/coverage/coverage-summary.json'; + // const prCoveragePath = '../../ui/coverage/coverage-summary.json'; + + // const prCoverage = JSON.parse(fs.readFileSync('/tmp/pr-coverage.json', 'utf8')); + // const devCoverage = JSON.parse(fs.readFileSync('/tmp/develop-coverage.json', 'utf8')); + + const developCoverage = readJson(developCoveragePath); + const prCoverage = readJson(prCoveragePath); + + const [prLinePct, prBranchPct] = getTotals(prCoverage); + const [developLinePct, developBranchPct] = getTotals(developCoverage); + + const lineDiff = prLinePct - developLinePct; + const branchDiff = prBranchPct - developBranchPct; + + let status = "unchanged"; + if (lineDiff > 0 || branchDiff > 0) { + status = "increased"; + } else if (lineDiff < 0 || branchDiff < 0) { + status = "decreased"; + } + + const lineStatus = + lineDiff > 0 + ? "๐ŸŸข Increased" + : lineDiff < 0 + ? "๐Ÿ”ด Decreased" + : "โšช Unchanged"; + const branchStatus = + branchDiff > 0 + ? "๐ŸŸข Increased" + : branchDiff < 0 + ? "๐Ÿ”ด Decreased" + : "โšช Unchanged"; const message = ` ## ๐Ÿงช Frontend Code Coverage Report ${status === 'increased' ? '๐ŸŽ‰' : status === 'decreased' ? 'โš ๏ธ' : '๐Ÿ”„'}\n\n @@ -91,34 +97,34 @@ export default async ({ github, context, core }) => { | Branch Coverage | ${prBranchPct.toFixed(2)}% | ${developBranchPct.toFixed(2)}% | ${branchDiff.toFixed(2)}% | ${branchStatus} | `; - const { data: comments } = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - }); - - const oldComment = comments.find( - (c) => - c.user.login === "github-actions[bot]" && - c.body.startsWith("## ๐Ÿงช Frontend Code Coverage Report") - ); - - if (oldComment) { - await github.rest.issues.deleteComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: oldComment.id, - }); - } - - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: message.trim(), + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + const oldComment = comments.find( + (c) => + c.user.login === "github-actions[bot]" && + c.body.startsWith("## ๐Ÿงช Frontend Code Coverage Report") + ); + + if (oldComment) { + await github.rest.issues.deleteComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: oldComment.id, }); - - if (lineDiff < 0 || branchDiff < 0) { - core.setFailed("Coverage has decreased. Please improve test coverage."); - } + } + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: message.trim(), + }); + + if (lineDiff < 0 || branchDiff < 0) { + core.setFailed("Coverage has decreased. Please improve test coverage."); + } }; diff --git a/.github/workflows/ui-cod-cov.yml b/.github/workflows/ui-cod-cov.yml index ac5742ee7..c2f85f2f1 100644 --- a/.github/workflows/ui-cod-cov.yml +++ b/.github/workflows/ui-cod-cov.yml @@ -1,4 +1,4 @@ -name: Frontend Code Coverage +name: UI Code Coverage on: pull_request: From 7238b597367adbe42076e939f1e2d34715c3e0b9 Mon Sep 17 00:00:00 2001 From: rohanm-crest Date: Wed, 16 Apr 2025 15:53:01 +0530 Subject: [PATCH 05/10] refactor: yml file --- .github/workflows/ui-cod-cov.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ui-cod-cov.yml b/.github/workflows/ui-cod-cov.yml index c2f85f2f1..806ed5ada 100644 --- a/.github/workflows/ui-cod-cov.yml +++ b/.github/workflows/ui-cod-cov.yml @@ -5,8 +5,8 @@ on: branches: - develop paths: - - 'src/**' - - 'tests/**' + - 'ui/src/**' + - 'tests/ui/**' types: [opened, synchronize, reopened] jobs: From 287ea9d5a4ca5c6cdd0ef15ace1367a5006a3740 Mon Sep 17 00:00:00 2001 From: rohanm-crest Date: Wed, 16 Apr 2025 15:53:43 +0530 Subject: [PATCH 06/10] refactor: yml file --- ui/src/components/CheckboxTree/CheckboxTree.test.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/src/components/CheckboxTree/CheckboxTree.test.tsx b/ui/src/components/CheckboxTree/CheckboxTree.test.tsx index be6439513..28ce5f424 100644 --- a/ui/src/components/CheckboxTree/CheckboxTree.test.tsx +++ b/ui/src/components/CheckboxTree/CheckboxTree.test.tsx @@ -83,6 +83,7 @@ describe('CheckboxTree Component', () => { expect(screen.getByLabelText('Row without group')).toBeInTheDocument(); expect(screen.getByLabelText('Row under Group 1')).toBeInTheDocument(); expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); + expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); expect(screen.getByLabelText('Second row under Group 3')).toBeInTheDocument(); }); From 6d8b52d3254f14fa1d142d40beb2c9c59d7fc65c Mon Sep 17 00:00:00 2001 From: rohanm-crest Date: Wed, 16 Apr 2025 16:02:57 +0530 Subject: [PATCH 07/10] test: ci trigger --- .github/workflows/ui-cod-cov.yml | 21 +++++++------------ .../CheckboxTree/CheckboxTree.test.tsx | 1 + 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ui-cod-cov.yml b/.github/workflows/ui-cod-cov.yml index 806ed5ada..b419a8097 100644 --- a/.github/workflows/ui-cod-cov.yml +++ b/.github/workflows/ui-cod-cov.yml @@ -17,34 +17,29 @@ jobs: contents: read steps: - - name: Checkout develop branch - uses: actions/checkout@v4 - with: - ref: develop - name: Install Node uses: actions/setup-node@v4 with: node-version: '20' - - name: Install dependencies - run: npm ci - - - name: Generate coverage for develop branch + - name: Generate coverage for PR branch run: | npx jest --coverage --coverageReporters=json-summary - cp coverage/coverage-summary.json /tmp/develop-coverage.json + cp coverage/coverage-summary.json /tmp/pr-coverage.json - - name: Checkout PR branch + - name: Checkout develop branch uses: actions/checkout@v4 + with: + ref: develop - - name: Install dependencies again + - name: Install dependencies run: npm ci - - name: Generate coverage for PR branch + - name: Generate coverage for develop branch run: | npx jest --coverage --coverageReporters=json-summary - cp coverage/coverage-summary.json /tmp/pr-coverage.json + cp coverage/coverage-summary.json /tmp/develop-coverage.json - name: Compare and comment coverage uses: actions/github-script@v7 diff --git a/ui/src/components/CheckboxTree/CheckboxTree.test.tsx b/ui/src/components/CheckboxTree/CheckboxTree.test.tsx index 28ce5f424..8479f67e8 100644 --- a/ui/src/components/CheckboxTree/CheckboxTree.test.tsx +++ b/ui/src/components/CheckboxTree/CheckboxTree.test.tsx @@ -84,6 +84,7 @@ describe('CheckboxTree Component', () => { expect(screen.getByLabelText('Row under Group 1')).toBeInTheDocument(); expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); + expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); expect(screen.getByLabelText('Second row under Group 3')).toBeInTheDocument(); }); From 1cf65ade77974255cdc1b848ad8b31044b8cb963 Mon Sep 17 00:00:00 2001 From: rohanm-crest Date: Thu, 17 Apr 2025 12:04:00 +0530 Subject: [PATCH 08/10] chore: empty commit to trigger workflow --- .github/scripts/ui-code-coverage.mjs | 41 ++++++++++--------- .github/workflows/ui-cod-cov.yml | 19 +++++++-- .../CheckboxTree/CheckboxTree.test.tsx | 1 + 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/.github/scripts/ui-code-coverage.mjs b/.github/scripts/ui-code-coverage.mjs index 0efa2438c..5e4dd7079 100644 --- a/.github/scripts/ui-code-coverage.mjs +++ b/.github/scripts/ui-code-coverage.mjs @@ -9,21 +9,15 @@ const readJson = (filePath) => { }; -const getTotals = (rawData) => { +const findTotalPercentage = (rawData) => { let totalLineCovered = 0; let totalLineTotal = 0; let totalBranchCovered = 0; let totalBranchTotal = 0; - for (const [filename, data] of Object.entries(rawData)) { + for (const [, data] of Object.entries(rawData)) { const lineData = data.lines; const branchData = data.branches; - const linePct = - lineData.total === 0 ? 100 : (lineData.covered / lineData.total) * 100; - const branchPct = - branchData.total === 0 - ? 100 - : (branchData.covered / branchData.total) * 100; totalLineCovered += lineData.covered; totalLineTotal += lineData.total; @@ -39,20 +33,19 @@ const getTotals = (rawData) => { ? 100 : (totalBranchCovered / totalBranchTotal) * 100; - core.info("๐Ÿ“Š Total Coverage Summary"); - core.info("--------------------------"); - core.info(`โœ… Line Coverage: ${totalLinePct.toFixed(2)}%`); - core.info(`โœ… Branch Coverage: ${totalBranchPct.toFixed(2)}%`); + return [totalLinePct, totalBranchPct]; }; -/** - * @param {import('@actions/github-script').AsyncFunctionArguments} args - */ -export default async ({ github, context, core }) => { + +// @ts-check +/** @param {import('@actions/github-script').AsyncFunctionArguments} AsyncFunctionArguments */ +export default async ({ github, context }) => { const prCoveragePath = "/tmp/pr-coverage.json"; const developCoveragePath = "/tmp/develop-coverage.json"; + console.log("๐Ÿงช Loaded latest ui-code-coverage.mjs script version"); + // const developCoveragePath = '../../ui/coverage/coverage-summary.json'; // const prCoveragePath = '../../ui/coverage/coverage-summary.json'; @@ -62,8 +55,18 @@ export default async ({ github, context, core }) => { const developCoverage = readJson(developCoveragePath); const prCoverage = readJson(prCoveragePath); - const [prLinePct, prBranchPct] = getTotals(prCoverage); - const [developLinePct, developBranchPct] = getTotals(developCoverage); + const [prLinePct, prBranchPct] = findTotalPercentage(prCoverage); + const [developLinePct, developBranchPct] = findTotalPercentage(developCoverage); + + // core.info("๐Ÿ“Š Total Coverage Summary For PR"); + // core.info("--------------------------"); + // core.info(`โœ… Line Coverage: ${prLinePct.toFixed(2)}%`); + // core.info(`โœ… Branch Coverage: ${prBranchPct.toFixed(2)}%`); + + // core.info("๐Ÿ“Š Total Coverage Summary For Develop"); + // core.info("--------------------------"); + // core.info(`โœ… Line Coverage: ${developLinePct.toFixed(2)}%`); + // core.info(`โœ… Branch Coverage: ${developBranchPct.toFixed(2)}%`); const lineDiff = prLinePct - developLinePct; const branchDiff = prBranchPct - developBranchPct; @@ -125,6 +128,6 @@ export default async ({ github, context, core }) => { }); if (lineDiff < 0 || branchDiff < 0) { - core.setFailed("Coverage has decreased. Please improve test coverage."); + // core.setFailed("Coverage has decreased. Please improve test coverage."); } }; diff --git a/.github/workflows/ui-cod-cov.yml b/.github/workflows/ui-cod-cov.yml index b419a8097..0d27a07c9 100644 --- a/.github/workflows/ui-cod-cov.yml +++ b/.github/workflows/ui-cod-cov.yml @@ -17,14 +17,20 @@ jobs: contents: read steps: + - name: Checkout PR + uses: actions/checkout@v4 - name: Install Node uses: actions/setup-node@v4 with: node-version: '20' + - name: install UI deps + uses: ./.github/actions/cached-ui-deps + - name: Generate coverage for PR branch run: | + cd ui npx jest --coverage --coverageReporters=json-summary cp coverage/coverage-summary.json /tmp/pr-coverage.json @@ -33,17 +39,22 @@ jobs: with: ref: develop - - name: Install dependencies - run: npm ci + - name: install UI deps + uses: ./.github/actions/cached-ui-deps - name: Generate coverage for develop branch run: | + cd ui npx jest --coverage --coverageReporters=json-summary cp coverage/coverage-summary.json /tmp/develop-coverage.json + - name: Bust import cache + run: cp .github/scripts/ui-code-coverage.mjs /tmp/ui-code-coverage-${{ github.run_id }}.mjs + - name: Compare and comment coverage uses: actions/github-script@v7 with: script: | - const { default: compareDiff } = await import('${{ github.workspace }}/.github/scripts/ui-code-coverage.mjs') - await compareDiff({ github, context, core }) + const ts = Date.now(); + const { default: compareDiff } = await import(`/tmp/ui-code-coverage-${process.env.GITHUB_RUN_ID}.mjs`); + await compareDiff({ github, context }); diff --git a/ui/src/components/CheckboxTree/CheckboxTree.test.tsx b/ui/src/components/CheckboxTree/CheckboxTree.test.tsx index 8479f67e8..1989a9aa9 100644 --- a/ui/src/components/CheckboxTree/CheckboxTree.test.tsx +++ b/ui/src/components/CheckboxTree/CheckboxTree.test.tsx @@ -85,6 +85,7 @@ describe('CheckboxTree Component', () => { expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); + expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); expect(screen.getByLabelText('Second row under Group 3')).toBeInTheDocument(); }); From 5fdadf02bb651953835437b89c59e560a2127ac5 Mon Sep 17 00:00:00 2001 From: rohanm-crest Date: Thu, 17 Apr 2025 12:13:00 +0530 Subject: [PATCH 09/10] chore: empty commit to trigger workflow --- .github/workflows/ui-cod-cov.yml | 8 ++------ ui/src/components/CheckboxTree/CheckboxTree.test.tsx | 1 + 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ui-cod-cov.yml b/.github/workflows/ui-cod-cov.yml index 0d27a07c9..9925aaff3 100644 --- a/.github/workflows/ui-cod-cov.yml +++ b/.github/workflows/ui-cod-cov.yml @@ -48,13 +48,9 @@ jobs: npx jest --coverage --coverageReporters=json-summary cp coverage/coverage-summary.json /tmp/develop-coverage.json - - name: Bust import cache - run: cp .github/scripts/ui-code-coverage.mjs /tmp/ui-code-coverage-${{ github.run_id }}.mjs - - name: Compare and comment coverage uses: actions/github-script@v7 with: script: | - const ts = Date.now(); - const { default: compareDiff } = await import(`/tmp/ui-code-coverage-${process.env.GITHUB_RUN_ID}.mjs`); - await compareDiff({ github, context }); + const { default: compareDiff } = await import('${{ github.workspace }}/.github/scripts/ui-code-coverage.mjs') + await compareDiff({ github, context }) diff --git a/ui/src/components/CheckboxTree/CheckboxTree.test.tsx b/ui/src/components/CheckboxTree/CheckboxTree.test.tsx index 1989a9aa9..c67b5ed37 100644 --- a/ui/src/components/CheckboxTree/CheckboxTree.test.tsx +++ b/ui/src/components/CheckboxTree/CheckboxTree.test.tsx @@ -86,6 +86,7 @@ describe('CheckboxTree Component', () => { expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); + expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); expect(screen.getByLabelText('Second row under Group 3')).toBeInTheDocument(); }); From c87358b9de2d9c2f7824897033336c0cd0c30f0c Mon Sep 17 00:00:00 2001 From: rohanm-crest Date: Thu, 17 Apr 2025 12:27:10 +0530 Subject: [PATCH 10/10] chore: empty commit to trigger workflow --- .github/workflows/ui-cod-cov.yml | 2 +- ui/src/components/CheckboxTree/CheckboxTree.test.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ui-cod-cov.yml b/.github/workflows/ui-cod-cov.yml index 9925aaff3..690d03b03 100644 --- a/.github/workflows/ui-cod-cov.yml +++ b/.github/workflows/ui-cod-cov.yml @@ -52,5 +52,5 @@ jobs: uses: actions/github-script@v7 with: script: | - const { default: compareDiff } = await import('${{ github.workspace }}/.github/scripts/ui-code-coverage.mjs') + const { default: compareDiff } = await import('.github/scripts/ui-code-coverage.mjs') await compareDiff({ github, context }) diff --git a/ui/src/components/CheckboxTree/CheckboxTree.test.tsx b/ui/src/components/CheckboxTree/CheckboxTree.test.tsx index c67b5ed37..0d14457d5 100644 --- a/ui/src/components/CheckboxTree/CheckboxTree.test.tsx +++ b/ui/src/components/CheckboxTree/CheckboxTree.test.tsx @@ -87,6 +87,7 @@ describe('CheckboxTree Component', () => { expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); + expect(screen.getByLabelText('First row under Group 3')).toBeInTheDocument(); expect(screen.getByLabelText('Second row under Group 3')).toBeInTheDocument(); });