Skip to content

Commit

Permalink
fix: only ask for server-side coverage when there is url to ask (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov authored Jul 23, 2019
1 parent 19f81e7 commit 5d829a9
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions support.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,32 @@ afterEach(() => {
after(() => {
// there might be server-side code coverage information
// we should grab it once after all tests finish
const url = Cypress._.get(Cypress.env('codeCoverage'), 'url', '/__coverage__')
cy.request({
url,
log: false,
failOnStatusCode: false
})
.then(r => Cypress._.get(r, 'body.coverage', null), { log: false })
.then(coverage => {
if (!coverage) {
// we did not get code coverage - this is the
// original failed request
return
}
cy.task('combineCoverage', coverage)
const baseUrl = Cypress.config('baseUrl') || cy.state('window').origin
const runningEndToEndTests = baseUrl !== Cypress.config('proxyUrl')
if (runningEndToEndTests) {
// we can only request server-side code coverage
// if we are running end-to-end tests,
// otherwise where do we send the request?
const url = Cypress._.get(
Cypress.env('codeCoverage'),
'url',
'/__coverage__'
)
cy.request({
url,
log: false,
failOnStatusCode: false
})
.then(r => Cypress._.get(r, 'body.coverage', null), { log: false })
.then(coverage => {
if (!coverage) {
// we did not get code coverage - this is the
// original failed request
return
}
cy.task('combineCoverage', coverage)
})
}

// collect and merge frontend coverage
const specFolder = Cypress.config('integrationFolder')
Expand Down

0 comments on commit 5d829a9

Please sign in to comment.