Skip to content

Commit

Permalink
Merge branch 'develop' into feature/experimental-retries
Browse files Browse the repository at this point in the history
  • Loading branch information
cacieprins authored Oct 26, 2023
2 parents 5e85168 + 80cc83d commit d66f980
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 23 deletions.
5 changes: 5 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->

## 13.4.0

_Released 10/25/2023 (PENDING)_
Expand All @@ -7,6 +8,10 @@ _Released 10/25/2023 (PENDING)_

- Introduced experimental configuration options for advanced retry logic: adds `experimentalStrategy` and `experimentalOptions` keys to the `retry` configuration key. See [Experimental Flake Detection Features](https://docs.cypress.io/guides/references/experiments/#Experimental-Flake-Detection-Features) in the documentation. Addressed in [#27930](https://github.com/cypress-io/cypress/pull/27930).

**Bugfixes:**

- Fixed a regression in [`13.3.2`](https://docs.cypress.io/guides/references/changelog/13.3.2) where loading a service worker and immediately reloading the page can cause a crash. Fixes [#28141](https://github.com/cypress-io/cypress/issues/28141).

## 13.3.3

_Released 10/24/2023_
Expand Down
2 changes: 1 addition & 1 deletion cli/__snapshots__/build_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports['package.json build outputs expected properties 1'] = {
'version': 'x.y.z',
'buildInfo': 'replaced by normalizePackageJson',
'description': 'Cypress is a next generation front end testing tool built for the modern web',
'homepage': 'https://github.com/cypress-io/cypress',
'homepage': 'https://cypress.io',
'license': 'MIT',
'bugs': {
'url': 'https://github.com/cypress-io/cypress/issues',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
"type": "git",
"url": "https://github.com/cypress-io/cypress.git"
},
"homepage": "https://github.com/cypress-io/cypress",
"homepage": "https://cypress.io",
"bugs": {
"url": "https://github.com/cypress-io/cypress/issues"
},
Expand Down
15 changes: 10 additions & 5 deletions packages/server/lib/browsers/browser-cri-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,17 @@ export class BrowserCriClient {
// The basic approach here is we attach to targets and enable network traffic
// We must attach in a paused state so that we can enable network traffic before the target starts running.
browserClient.on('Target.attachedToTarget', async (event) => {
if (event.targetInfo.type !== 'page') {
await browserClient.send('Network.enable', protocolManager?.networkEnableOptions ?? DEFAULT_NETWORK_ENABLE_OPTIONS, event.sessionId)
}
try {
if (event.targetInfo.type !== 'page') {
await browserClient.send('Network.enable', protocolManager?.networkEnableOptions ?? DEFAULT_NETWORK_ENABLE_OPTIONS, event.sessionId)
}

if (event.waitingForDebugger) {
await browserClient.send('Runtime.runIfWaitingForDebugger', undefined, event.sessionId)
if (event.waitingForDebugger) {
await browserClient.send('Runtime.runIfWaitingForDebugger', undefined, event.sessionId)
}
} catch (error) {
// it's possible that the target was closed before we could enable network and continue, in that case, just ignore
debug('error attaching to target browser', error)
}
})

Expand Down
19 changes: 12 additions & 7 deletions packages/server/lib/browsers/cri-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,18 @@ export const create = async ({

if (fullyManageTabs) {
cri.on('Target.attachedToTarget', async (event) => {
// Service workers get attached at the page and browser level. We only want to handle them at the browser level
if (event.targetInfo.type !== 'service_worker' && event.targetInfo.type !== 'page') {
await cri.send('Network.enable', protocolManager?.networkEnableOptions ?? DEFAULT_NETWORK_ENABLE_OPTIONS, event.sessionId)
}

if (event.waitingForDebugger) {
await cri.send('Runtime.runIfWaitingForDebugger', undefined, event.sessionId)
try {
// Service workers get attached at the page and browser level. We only want to handle them at the browser level
if (event.targetInfo.type !== 'service_worker' && event.targetInfo.type !== 'page') {
await cri.send('Network.enable', protocolManager?.networkEnableOptions ?? DEFAULT_NETWORK_ENABLE_OPTIONS, event.sessionId)
}

if (event.waitingForDebugger) {
await cri.send('Runtime.runIfWaitingForDebugger', undefined, event.sessionId)
}
} catch (error) {
// it's possible that the target was closed before we could enable network and continue, in that case, just ignore
debug('error attaching to target cri', error)
}
})

Expand Down
3 changes: 2 additions & 1 deletion packages/server/test/integration/http_requests_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ describe('Routes', () => {
this.networkProxy.setPreRequestTimeout(50)
// If this takes longer than the Promise.delay and the prerequest timeout then the second
// call has hit the prerequest timeout which is a problem
this.timeout(150)
this.timeout(900)

nock(this.server.remoteStates.current().origin)
.get('/')
Expand All @@ -1057,6 +1057,7 @@ describe('Routes', () => {

// Wait 100 ms to make sure the request times out
return Promise.delay(100).then(() => {
this.networkProxy.setPreRequestTimeout(1000)
nock(this.server.remoteStates.current().origin)
.get('/')
.once()
Expand Down
25 changes: 25 additions & 0 deletions packages/server/test/unit/browsers/browser-cri-client_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,31 @@ describe('lib/browsers/cri-client', function () {
expect(protocolManager.connectToBrowser).to.be.calledWith(client)
})

it('creates a page client when the passed in url is found and notifies the protocol manager and fully managed tabs and attaching to target throws', async function () {
const mockPageClient = {}
const protocolManager: any = {
connectToBrowser: sinon.stub().resolves(),
}

send.withArgs('Target.getTargets').resolves({ targetInfos: [{ targetId: '1', url: 'http://foo.com' }, { targetId: '2', url: 'http://bar.com' }] })
send.withArgs('Target.setDiscoverTargets', { discover: true })
on.withArgs('Target.targetDestroyed', sinon.match.func)

send.withArgs('Network.enable').throws(new Error('ProtocolError: Inspected target navigated or closed'))

criClientCreateStub.withArgs({ target: '1', onAsynchronousError: onError, host: HOST, port: PORT, protocolManager, fullyManageTabs: true, browserClient: { on, send, close } }).resolves(mockPageClient)

const browserClient = await getClient({ protocolManager, fullyManageTabs: true })

const client = await browserClient.attachToTargetUrl('http://foo.com')

expect(client).to.be.equal(mockPageClient)
expect(protocolManager.connectToBrowser).to.be.calledWith(client)

// This would throw if the error was not caught
await on.withArgs('Target.attachedToTarget').args[0][1]({ targetInfo: { type: 'worker' } })
})

it('retries when the passed in url is not found', async function () {
sinon.stub(protocol, '_getDelayMsForRetry')
.onFirstCall().returns(100)
Expand Down
8 changes: 8 additions & 0 deletions packages/server/test/unit/browsers/cri-client_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ describe('lib/browsers/cri-client', function () {
await expect(client.send(command, { depth: -1 })).to.be.rejectedWith(`${command} will not run as the target browser or tab CRI connection has crashed`)
})

it('does not reject if attachToTarget work throws', async function () {
criStub.send.withArgs('Network.enable').throws(new Error('ProtocolError: Inspected target navigated or closed'))
await getClient({ host: '127.0.0.1', fullyManageTabs: true })

// This would throw if the error was not caught
await criStub.on.withArgs('Target.attachedToTarget').args[0][1]({ targetInfo: { type: 'worker' } })
})

context('retries', () => {
([
'WebSocket is not open',
Expand Down
10 changes: 5 additions & 5 deletions system-tests/projects/e2e/shared-worker.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// eslint-disable-next-line no-undef
importScripts('/sw.js')

self.addEventListener('connect', (event) => {
self.onconnect = (event) => {
const port = event.ports[0]

port.onmessage = (e) => {
// eslint-disable-next-line no-undef
importScripts('/sw.js')

if (e.data.foo === 'baz') {
port.postMessage({
foo: 'baz2',
})
}
}
})
}
6 changes: 3 additions & 3 deletions system-tests/projects/e2e/web-worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line no-undef
importScripts('/ww.js')

onmessage = (e) => {
// eslint-disable-next-line no-undef
importScripts('/ww.js')

if (e.data.foo === 'bar') {
postMessage({
foo: 'bar2',
Expand Down

5 comments on commit d66f980

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on d66f980 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.4.0/linux-x64/feature/experimental-retries-d66f9804e00297b375058fa0ae6ada5e4799366c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on d66f980 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.4.0/linux-arm64/feature/experimental-retries-d66f9804e00297b375058fa0ae6ada5e4799366c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on d66f980 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.4.0/darwin-x64/feature/experimental-retries-d66f9804e00297b375058fa0ae6ada5e4799366c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on d66f980 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.4.0/darwin-arm64/feature/experimental-retries-d66f9804e00297b375058fa0ae6ada5e4799366c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on d66f980 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.4.0/win32-x64/feature/experimental-retries-d66f9804e00297b375058fa0ae6ada5e4799366c/cypress.tgz

Please sign in to comment.