MCPcopy Create free account
hub / github.com/cypress-io/code-coverage / captureCoverage

Function captureCoverage

lib/support.ts:218–247  ·  view source on GitHub ↗
(url: string, suffix = '')

Source from the content-addressed store, hash-verified

216 '/__coverage__'
217 )
218 function captureCoverage(url: string, suffix = ''): void {
219 cy.request({
220 url,
221 log: false,
222 failOnStatusCode: false
223 })
224 .then((r) => {
225 return Cypress._.get(r, 'body.coverage', null)
226 })
227 .then((coverage) => {
228 if (!coverage) {
229 // we did not get code coverage - this is the
230 // original failed request
231 const expectBackendCoverageOnly = Cypress._.get(
232 Cypress.expose('codeCoverage'),
233 'expectBackendCoverageOnly',
234 false
235 )
236 if (expectBackendCoverageOnly) {
237 throw new Error(
238 `Expected to collect backend code coverage from ${url}`
239 )
240 } else {
241 // we did not really expect to collect the backend code coverage
242 return
243 }
244 }
245 sendCoverage(coverage, `backend${suffix}`)
246 })
247 }
248
249 if (Array.isArray(captureUrls)) {
250 for (const [index, url] of captureUrls.entries()) {

Callers 1

registerHooksFunction · 0.85

Calls 1

sendCoverageFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…