From f2c2394cea045cd49328060ab2876a4a5f73b26b Mon Sep 17 00:00:00 2001 From: swadeley Date: Tue, 10 Feb 2026 12:29:09 +0800 Subject: [PATCH] Run Integration project in code coverage check --- .github/scripts/merge-ctrf.js | 52 ++++++++++++++++++++++++ .github/workflows/playwright-actions.yml | 18 +++++++- playwright.config.ts | 7 +++- 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 .github/scripts/merge-ctrf.js diff --git a/.github/scripts/merge-ctrf.js b/.github/scripts/merge-ctrf.js new file mode 100644 index 000000000..3795c1f7d --- /dev/null +++ b/.github/scripts/merge-ctrf.js @@ -0,0 +1,52 @@ +#!/usr/bin/env node +/** + * Merges UI and Integration CTRF JSON reports into a single playwright-ctrf.json + * for GitHub test reporting. Run after both Playwright test steps in CI. + */ +const fs = require('fs'); +const path = require('path'); + +const dir = path.join(__dirname, '../../playwright-ctrf'); +const uiPath = path.join(dir, 'playwright-ctrf-ui.json'); +const integrationPath = path.join(dir, 'playwright-ctrf-integration.json'); +const outPath = path.join(dir, 'playwright-ctrf.json'); + +function loadJson(filePath) { + const raw = fs.readFileSync(filePath, 'utf8'); + return JSON.parse(raw); +} + +function mergeSummary(a, b) { + const sum = (x, y) => (x ?? 0) + (y ?? 0); + return { + tests: sum(a.tests, b.tests), + passed: sum(a.passed, b.passed), + failed: sum(a.failed, b.failed), + pending: sum(a.pending, b.pending), + skipped: sum(a.skipped, b.skipped), + other: sum(a.other, b.other), + start: Math.min(a.start ?? Infinity, b.start ?? Infinity), + stop: Math.max(a.stop ?? 0, b.stop ?? 0), + }; +} + +const ui = loadJson(uiPath); +const integration = loadJson(integrationPath); + +const r1 = ui.results; +const r2 = integration.results; + +const merged = { + results: { + tool: r1.tool ?? r2.tool, + summary: mergeSummary(r1.summary ?? {}, r2.summary ?? {}), + tests: [...(r1.tests ?? []), ...(r2.tests ?? [])], + environment: r1.environment ?? r2.environment ?? {}, + }, +}; + +fs.mkdirSync(dir, { recursive: true }); +fs.writeFileSync(outPath, JSON.stringify(merged, null, 0), 'utf8'); +console.log( + `Merged CTRF: ${(r1.tests ?? []).length} UI + ${(r2.tests ?? []).length} Integration tests -> ${outPath}`, +); diff --git a/.github/workflows/playwright-actions.yml b/.github/workflows/playwright-actions.yml index 342823675..524f963b9 100644 --- a/.github/workflows/playwright-actions.yml +++ b/.github/workflows/playwright-actions.yml @@ -205,8 +205,22 @@ jobs: working-directory: content-sources-backend run: while [[ "$(curl http://localhost:8000/api/content-sources/v1.0/repositories/ -H "$( ./scripts/header.sh 9999 1111)" | jq '.data | all(.status == "Valid")')" == "false" ]]; do sleep 5; done; - - name: Run front-end Playwright tests - run: CURRENTS_PROJECT_ID=mMVOFH CURRENTS_RECORD_KEY=$CURRENTS_RECORD_KEY CURRENTS_CI_BUILD_ID="${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt }}" yarn playwright test + - name: Run front-end Playwright tests (UI) + run: yarn playwright test + env: + CURRENTS_PROJECT_ID: ${{ secrets.CURRENTS_PROJECT_ID }} + CURRENTS_RECORD_KEY: ${{ secrets.CURRENTS_RECORD_KEY }} + CURRENTS_CI_BUILD_ID: ${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt }} + + - name: Run front-end Playwright tests (Integration) + run: INTEGRATION=true yarn playwright test + env: + CURRENTS_PROJECT_ID: ${{ secrets.CURRENTS_PROJECT_ID }} + CURRENTS_RECORD_KEY: ${{ secrets.CURRENTS_RECORD_KEY }} + CURRENTS_CI_BUILD_ID: ${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt }} + + - name: Merge CTRF reports + run: node .github/scripts/merge-ctrf.js - name: Publish front-end Test Report uses: ctrf-io/github-test-reporter@v1 diff --git a/playwright.config.ts b/playwright.config.ts index d4bf2a1ff..7f3279810 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -22,7 +22,12 @@ export default defineConfig({ ['html', { outputFolder: 'playwright-report' }], [ 'playwright-ctrf-json-reporter', - { outputDir: 'playwright-ctrf', outputFile: 'playwright-ctrf.json' }, + { + outputDir: 'playwright-ctrf', + outputFile: process.env.INTEGRATION + ? 'playwright-ctrf-integration.json' + : 'playwright-ctrf-ui.json', + }, ], ['@currents/playwright'], ]