diff --git a/src/collector/LogCollectCypressFetch.js b/src/collector/LogCollectCypressFetch.js index ba7e097..ba3c593 100644 --- a/src/collector/LogCollectCypressFetch.js +++ b/src/collector/LogCollectCypressFetch.js @@ -46,8 +46,8 @@ module.exports = class LogCollectCypressFetch { if (statusCode) { log += `\nStatus: ${statusCode}`; } - if (options.err && options.err.message.match(/abort/)) { - log += ' - ABORTED'; + if (options.err && options.err.message) { + log += ' - ' + options.err.message; } if ( diff --git a/test/cypress/integration/fetchApi.spec.js b/test/cypress/integration/fetchApi.spec.js index a37821a..f99dacd 100644 --- a/test/cypress/integration/fetchApi.spec.js +++ b/test/cypress/integration/fetchApi.spec.js @@ -24,7 +24,70 @@ describe('Fetch Api', () => { cy.wait('@putComment'); cy.get('.breaking-get', {timeout: 1}); + }) + + context('Timeout', () => { + + it('forceNetworkError ', () => { + cy.visit('/commands/network-requests'); + + cy.intercept( + { + method: 'PUT', + url: 'comments/*', + + }, + { + forceNetworkError: true, + } + ).as('putComment'); + + cy.window().then((w) => { + fetch('/comments/10', { + method: 'PUT', + body: 'test', + }); + }); + + cy.wait('@putComment'); + + cy.get('.breaking-get', {timeout: 1}); + }); + + // Currently Cypress can't handle fetch Abort properly. It produces an unhandled entry, while the request remains "pending": + // cy:command ✘ uncaught exception AbortError: The user aborted a request. + it('timeout using AbortController', () => { + cy.visit('/commands/network-requests'); + + cy.intercept( + { + method: 'PUT', + url: 'comments/*', + + }, + { + delay: 500, + } + ).as('putComment'); + + cy.window().then((w) => { + + const controller = new AbortController(); + setTimeout(() => controller.abort(), 100); + + fetch('/comments/10', { + method: 'PUT', + body: 'test', + signal: controller.signal + }); + }); + + cy.wait('@putComment'); + + cy.get('.breaking-get', {timeout: 1}); + }); }); + context('Real Fetch Requests', () => { const testRealFetchRequest = (options) => { diff --git a/test/specs/commandsLogging.spec.js b/test/specs/commandsLogging.spec.js index 339771a..064e887 100755 --- a/test/specs/commandsLogging.spec.js +++ b/test/specs/commandsLogging.spec.js @@ -141,6 +141,12 @@ describe('Commands logging.', () => { expect(stdout).to.contain(`Status: 404\n`); expect(stdout).to.contain(`Response body: {\n${PADDING} "error": "Test message."\n${PADDING}}\n`); + // timeouts / abort + expect(cleanStdout).to.contain( + `(putComment) STUBBED PUT https://example.cypress.io/comments/10 - forceNetworkError called`, + 'network failed request contains failure message' + ); + // test real fetch requests expect(cleanStdout).to.contain( `cy:fetch ${ICONS.route} GET https://jsonplaceholder.cypress.io/comments/1\n${PADDING} Status: 200\n`,