From 48cd34807d0882767192c0f4bc610600bd111166 Mon Sep 17 00:00:00 2001 From: Ramon Blanquer Date: Wed, 26 Mar 2025 02:48:27 +0545 Subject: [PATCH] feat: add explicit check against codeCoverage.expectFrontendCoverageOnly before attempting to collect backend coverage (#555) Co-authored-by: Jennifer Shehane Co-authored-by: AtofStryker --- README.md | 15 +++++++++++++++ support.js | 11 ++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b11182b1..f13892ae8 100644 --- a/README.md +++ b/README.md @@ -251,6 +251,21 @@ After: ![Cypress knows to expect the backend code coverage only](./images/expect-backend.png) +### expectFrontendCoverageOnly + +If there is ONLY frontend code coverage, set `expectFrontendCoverageOnly: true` in the `cypress.json` file. Otherwise, Cypress complains that it cannot find the frontend code coverage. + +```json +{ + "env": { + "codeCoverage": { + "url": "http://localhost:3003/__coverage__", + "expectFrontendCoverageOnly": true + } + } +} +``` + ## Custom report folder You can specify a custom report folder by adding `nyc` object to the `package.json` file. For example, to save reports to `cypress-coverage` folder, use: diff --git a/support.js b/support.js index dcec20929..b35bd802e 100644 --- a/support.js +++ b/support.js @@ -178,10 +178,19 @@ const registerHooks = () => { const baseUrl = Cypress.config('baseUrl') || cy.state('window').origin // @ts-ignore const runningEndToEndTests = baseUrl !== Cypress.config('proxyUrl') + const expectFrontendCoverageOnly = Cypress._.get( + Cypress.env('codeCoverage'), + 'expectFrontendCoverageOnly', + false + ) const specType = Cypress._.get(Cypress.spec, 'specType', 'integration') const isIntegrationSpec = specType === 'integration' - if (runningEndToEndTests && isIntegrationSpec) { + if ( + !expectFrontendCoverageOnly && + runningEndToEndTests && + isIntegrationSpec + ) { // we can only request server-side code coverage // if we are running end-to-end tests, // otherwise where do we send the request?