From 1ce2b3a75d4ce18d38a2afa61e934069a276b381 Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Fri, 17 Sep 2021 11:27:25 -0400 Subject: [PATCH 1/6] chore(tests): fix flake in proxy-logging-spec --- .../integration/cypress/proxy-logging-spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/driver/cypress/integration/cypress/proxy-logging-spec.ts b/packages/driver/cypress/integration/cypress/proxy-logging-spec.ts index de9c73a2e522..06394c185840 100644 --- a/packages/driver/cypress/integration/cypress/proxy-logging-spec.ts +++ b/packages/driver/cypress/integration/cypress/proxy-logging-spec.ts @@ -80,11 +80,8 @@ describe('Proxy Logging', () => { expect(log.consoleProps).to.not.have.property('Matched `cy.intercept()`') // trigger: .snapshot('request') - cy.once('log:changed', (log) => { - expect(log.snapshots.map((v) => v.name)).to.deep.eq(['request']) - - // trigger: .snapshot('response') - cy.once('log:changed', (log) => { + cy.on('log:changed', (log) => { + try { expect(log.snapshots.map((v) => v.name)).to.deep.eq(['request', 'response']) expect(log.consoleProps['Response Headers']).to.include({ 'x-powered-by': 'Express', @@ -101,7 +98,10 @@ describe('Proxy Logging', () => { ) done() - }) + } catch (err) { + // eslint-disable-next-line no-console + console.log('assertion error, retrying', err) + } }) }) }) From ef0c055a7eaf53f0292423290ba3d91c6ca79b0d Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Mon, 20 Sep 2021 11:29:18 -0400 Subject: [PATCH 2/6] chore(tests): address flake in xhr_spec --- .../cypress/integration/commands/xhr_spec.js | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/packages/driver/cypress/integration/commands/xhr_spec.js b/packages/driver/cypress/integration/commands/xhr_spec.js index 54f99145c020..00213f67363a 100644 --- a/packages/driver/cypress/integration/commands/xhr_spec.js +++ b/packages/driver/cypress/integration/commands/xhr_spec.js @@ -1026,14 +1026,25 @@ describe('src/cy/commands/xhr', () => { }) it('sets err on log when caused by code errors', function (done) { - cy.on('fail', (err) => { + done = _.once(done) + cy.once('fail', (err) => { + // suppress failure + }) + + cy.on('log:changed', () => { const { lastLog } = this - expect(this.logs.length).to.eq(1) - expect(lastLog.get('name')).to.eq('request') - expect(lastLog.get('error').message).contain('foo is not defined') + if (!lastLog || lastLog.get('name') !== 'request') return - done() + try { + expect(this.logs.length).to.eq(1) + expect(lastLog.get('error').message).contain('foo is not defined') + + done() + } catch (err) { + // eslint-disable-next-line no-console + console.log('assertion failure', err) + } }) cy.window().then((win) => { @@ -1047,17 +1058,27 @@ describe('src/cy/commands/xhr', () => { }) it('causes errors caused by onreadystatechange callback function', function (done) { + done = _.once(done) const e = new Error('onreadystatechange caused this error') - cy.on('fail', (err) => { + cy.once('fail', (err) => { + // suppress failure + }) + + cy.on('log:changed', () => { const { lastLog } = this - expect(this.logs.length).to.eq(1) - expect(lastLog.get('name')).to.eq('request') - expect(err.message).to.include(lastLog.get('error').message) - expect(err.message).to.include(e.message) + if (!lastLog || lastLog.get('name') !== 'request') return - done() + try { + expect(this.logs.length).to.eq(1) + expect(lastLog.get('name')).to.eq('request') + expect(e.message).to.include(lastLog.get('error').message) + done() + } catch (err) { + // eslint-disable-next-line no-console + console.log('assertion failure', err) + } }) cy @@ -2563,7 +2584,9 @@ describe('src/cy/commands/xhr', () => { xhr.open('GET', '/timeout?ms=999') xhr.send() - xhr.abort() + + // allow the request time to make it out of the browser so proxy logging has a chance to see it + requestAnimationFrame(() => xhr.abort()) cy.wrap(null).should(() => { expect(log.get('state')).to.eq('failed') From df8aad586d47ee3ba3fcef17ca3ae7fc1d53a1be Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Mon, 20 Sep 2021 12:14:28 -0400 Subject: [PATCH 3/6] chore: fix constant 1/3 flake caused by AUT unhandled exception --- .../cypress/integration/commands/net_stubbing_spec.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/driver/cypress/integration/commands/net_stubbing_spec.ts b/packages/driver/cypress/integration/commands/net_stubbing_spec.ts index de9fe72aa0e6..e0d82962d5ee 100644 --- a/packages/driver/cypress/integration/commands/net_stubbing_spec.ts +++ b/packages/driver/cypress/integration/commands/net_stubbing_spec.ts @@ -1638,12 +1638,10 @@ describe('network stubbing', { retries: 2 }, function () { delay: 5000, }).as('create') - cy.window().then((win) => { - win.eval( - `fetch("/post-only", { - method: 'POST', // *GET, POST, PUT, DELETE, etc. - });`, - ) + cy.then(() => { + fetch('/post-only', { + method: 'POST', // *GET, POST, PUT, DELETE, etc. + }) }) cy.wait('@create', { timeout: 500 }) From 4854597115223d60380363b55a4bd6a9834aa881 Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Mon, 20 Sep 2021 12:19:47 -0400 Subject: [PATCH 4/6] fix waiting/aliasing flake --- .../driver/cypress/integration/commands/net_stubbing_spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/driver/cypress/integration/commands/net_stubbing_spec.ts b/packages/driver/cypress/integration/commands/net_stubbing_spec.ts index e0d82962d5ee..cce78060a6f0 100644 --- a/packages/driver/cypress/integration/commands/net_stubbing_spec.ts +++ b/packages/driver/cypress/integration/commands/net_stubbing_spec.ts @@ -3127,7 +3127,7 @@ describe('network stubbing', { retries: 2 }, function () { }) }) - context('waiting and aliasing', function () { + context('waiting and aliasing', { defaultCommandTimeout: 10000 }, function () { const testFailWaiting = (cb) => testFail(cb, 'https://on.cypress.io/wait') it('can wait on a single response using "alias"', function () { From cfe98cc96f8983b8bd6849b6acf001765aa9870c Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Mon, 20 Sep 2021 13:23:43 -0400 Subject: [PATCH 5/6] fix forceNetworkError flake --- .../cypress/integration/cypress/proxy-logging-spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/driver/cypress/integration/cypress/proxy-logging-spec.ts b/packages/driver/cypress/integration/cypress/proxy-logging-spec.ts index 06394c185840..1119689e5ceb 100644 --- a/packages/driver/cypress/integration/cypress/proxy-logging-spec.ts +++ b/packages/driver/cypress/integration/cypress/proxy-logging-spec.ts @@ -230,15 +230,15 @@ describe('Proxy Logging', () => { } }) - cy.intercept('/foo', { forceNetworkError: true }).as('alias') + cy.intercept('/foo*', { forceNetworkError: true }).as('alias') .then(() => { - return fetch('/foo') + return fetch(`/foo?${Date.now()}`) .catch(() => {}) }) .wrap(logs) .should((logs) => { // retries... - expect(logs).to.have.length.greaterThan(2) + expect(logs).to.have.length.greaterThan(0) for (const log of logs) { expect(log.err).to.include({ name: 'Error' }) From 409f19905cd761abce7719c7e56f2d725ec9078a Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Mon, 20 Sep 2021 14:13:03 -0400 Subject: [PATCH 6/6] minimize diff --- .../driver/cypress/integration/cypress/proxy-logging-spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/driver/cypress/integration/cypress/proxy-logging-spec.ts b/packages/driver/cypress/integration/cypress/proxy-logging-spec.ts index 1119689e5ceb..d84a86954087 100644 --- a/packages/driver/cypress/integration/cypress/proxy-logging-spec.ts +++ b/packages/driver/cypress/integration/cypress/proxy-logging-spec.ts @@ -230,9 +230,9 @@ describe('Proxy Logging', () => { } }) - cy.intercept('/foo*', { forceNetworkError: true }).as('alias') + cy.intercept('/foo', { forceNetworkError: true }).as('alias') .then(() => { - return fetch(`/foo?${Date.now()}`) + return fetch('/foo') .catch(() => {}) }) .wrap(logs)