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 24, 2023
2 parents 1a17cad + 058f3a8 commit 0ca0b19
Show file tree
Hide file tree
Showing 28 changed files with 569 additions and 96 deletions.
12 changes: 11 additions & 1 deletion cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
## 13.4.0

_Released 10/24/2023 (PENDING)_
_Released 10/25/2023 (PENDING)_

**Features:**

- 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).

## 13.3.3

_Released 10/24/2023_

**Bugfixes:**

- Fixed a performance regression in `13.3.1` with proxy correlation timeouts and requests issued from web and shared workers. Fixes [#28104](https://github.com/cypress-io/cypress/issues/28104).
- Fixed a performance problem with proxy correlation when requests get aborted and then get miscorrelated with follow up requests. Addressed in [#28094](https://github.com/cypress-io/cypress/pull/28094).
- Fixed a regression in [10.0.0](#10.0.0), where search would not find a spec if the file name contains "-" or "\_", but search prompt contains " " instead (e.g. search file "spec-file.cy.ts" with prompt "spec file"). Fixes [#25303](https://github.com/cypress-io/cypress/issues/25303).

## 13.3.2

_Released 10/18/2023_
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cypress",
"version": "13.3.2",
"version": "13.3.3",
"description": "Cypress is a next generation front end testing tool built for the modern web",
"private": true,
"scripts": {
Expand Down
60 changes: 60 additions & 0 deletions packages/app/cypress/e2e/specs_list_e2e.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,66 @@ describe('App: Spec List (E2E)', () => {
cy.findByText('No specs matched your search:').should('not.be.visible')
})

it('searches specs with "-" or "_" when search contains space', function () {
clearSearchAndType('accounts list')

cy.findAllByTestId('spec-item')
.should('have.length', 1)
.and('contain', 'accounts_list.spec.js')

cy.findByText('No specs matched your search:').should('not.be.visible')
})

it('searches specs with "-" or "_" when search contains "-"', function () {
clearSearchAndType('accounts-list')

cy.findAllByTestId('spec-item')
.should('have.length', 1)
.and('contain', 'accounts_list.spec.js')

cy.findByText('No specs matched your search:').should('not.be.visible')
})

it('searches specs with "-" or "_" when search contains "_"', function () {
clearSearchAndType('accounts_list')

cy.findAllByTestId('spec-item')
.should('have.length', 1)
.and('contain', 'accounts_list.spec.js')

cy.findByText('No specs matched your search:').should('not.be.visible')
})

it('searches folders with "-" or "_" when search contains space', function () {
clearSearchAndType('a b c')

cy.findAllByTestId('spec-list-directory')
.should('have.length', 1)
.and('contain', 'a-b_c')

cy.findByText('No specs matched your search:').should('not.be.visible')
})

it('searches folders with "-" or "_" when search contains "-"', function () {
clearSearchAndType('a-b-c')

cy.findAllByTestId('spec-list-directory')
.should('have.length', 1)
.and('contain', 'a-b_c')

cy.findByText('No specs matched your search:').should('not.be.visible')
})

it('searches folders with "-" or "_" when search contains "_"', function () {
clearSearchAndType('a_b_c')

cy.findAllByTestId('spec-list-directory')
.should('have.length', 1)
.and('contain', 'a-b_c')

cy.findByText('No specs matched your search:').should('not.be.visible')
})

it('saves the filter when navigating to a spec and back', function () {
const targetSpecFile = 'accounts_list.spec.js'

Expand Down
15 changes: 13 additions & 2 deletions packages/app/src/specs/spec-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import _ from 'lodash'
import { FuzzyFoundSpec, getPlatform } from './tree/useCollapsibleTree'

export function fuzzySortSpecs <T extends FuzzyFoundSpec> (specs: T[], searchValue: string) {
const normalizedSearchValue = getPlatform() === 'win32' ? searchValue.replaceAll('/', '\\') : searchValue
const normalizedSearchValue = normalizeSpecValue(searchValue)

const fuzzySortResult = fuzzySort
.go(normalizedSearchValue, specs, { keys: ['relative', 'baseName'], allowTypo: false, threshold: -3000 })
.go(normalizedSearchValue, specs, { keys: ['normalizedRelative', 'normalizedBaseName'], allowTypo: false, threshold: -3000 })
.map((result) => {
const [relative, baseName] = result

Expand All @@ -24,9 +24,20 @@ export function fuzzySortSpecs <T extends FuzzyFoundSpec> (specs: T[], searchVal
return fuzzySortResult
}

function normalizeSpecValue (name: string) {
const escapedPath = getPlatform() === 'win32' ? name.replaceAll('/', '\\') : name
// replace dash, underscore and space with common character (in this case dash)
// they are replaced and not removed to preserve string length (so highlighting works correctly)
const normalizedSymbols = escapedPath.replace(/[-_\s]/g, '-')

return normalizedSymbols
}

export function makeFuzzyFoundSpec (spec: FoundSpec): FuzzyFoundSpec {
return {
...spec,
normalizedBaseName: normalizeSpecValue(spec.baseName),
normalizedRelative: normalizeSpecValue(spec.relative),
fuzzyIndexes: {
relative: [],
baseName: [],
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/specs/tree/useCollapsibleTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export type RawNode <T> = {
}

export type FuzzyFoundSpec<T = FoundSpec> = T & {
normalizedBaseName: string
normalizedRelative: string
fuzzyIndexes: {
relative: number[]
baseName: number[]
Expand Down
20 changes: 16 additions & 4 deletions packages/proxy/lib/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ErrorMiddleware from './error-middleware'
import RequestMiddleware from './request-middleware'
import ResponseMiddleware from './response-middleware'
import { HttpBuffers } from './util/buffers'
import { GetPreRequestCb, PreRequests } from './util/prerequests'
import { GetPreRequestCb, PendingRequest, PreRequests } from './util/prerequests'

import type EventEmitter from 'events'
import type CyServer from '@packages/server'
Expand Down Expand Up @@ -63,10 +63,12 @@ type HttpMiddlewareCtx<T> = {
stage: HttpStages
debug: Debug.Debugger
middleware: HttpMiddlewareStacks
pendingRequest: PendingRequest | undefined
getCookieJar: () => CookieJar
deferSourceMapRewrite: (opts: { js: string, url: string }) => string
getPreRequest: (cb: GetPreRequestCb) => void
getPreRequest: (cb: GetPreRequestCb) => PendingRequest | undefined
addPendingUrlWithoutPreRequest: (url: string) => void
removePendingRequest: (pendingRequest: PendingRequest) => void
getAUTUrl: Http['getAUTUrl']
setAUTUrl: Http['setAUTUrl']
simulatedCookies: SerializableAutomationCookie[]
Expand Down Expand Up @@ -325,15 +327,25 @@ export class Http {
getAUTUrl: this.getAUTUrl,
setAUTUrl: this.setAUTUrl,
getPreRequest: (cb) => {
this.preRequests.get(ctx.req, ctx.debug, cb)
return this.preRequests.get(ctx.req, ctx.debug, cb)
},
addPendingUrlWithoutPreRequest: (url) => {
this.preRequests.addPendingUrlWithoutPreRequest(url)
},
removePendingRequest: (pendingRequest: PendingRequest) => {
this.preRequests.removePendingRequest(pendingRequest)
},
protocolManager: this.protocolManager,
}

const onError = (error: Error): Promise<void> => {
const pendingRequest = ctx.pendingRequest as PendingRequest | undefined

if (pendingRequest) {
delete ctx.pendingRequest
ctx.removePendingRequest(pendingRequest)
}

ctx.error = error
if (ctx.req.browserPreRequest && !ctx.req.browserPreRequest.errorHandled) {
ctx.req.browserPreRequest.errorHandled = true
Expand Down Expand Up @@ -427,7 +439,7 @@ export class Http {
}

removePendingBrowserPreRequest (requestId: string) {
this.preRequests.removePending(requestId)
this.preRequests.removePendingPreRequest(requestId)
}

addPendingUrlWithoutPreRequest (url: string) {
Expand Down
9 changes: 8 additions & 1 deletion packages/proxy/lib/http/request-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const CorrelateBrowserPreRequest: RequestMiddleware = async function () {
}

this.debug('waiting for prerequest')
this.getPreRequest((({ browserPreRequest, noPreRequestExpected }) => {
this.pendingRequest = this.getPreRequest((({ browserPreRequest, noPreRequestExpected }) => {
this.req.browserPreRequest = browserPreRequest
this.req.noPreRequestExpected = noPreRequestExpected
copyResourceTypeAndNext()
Expand Down Expand Up @@ -455,6 +455,13 @@ const SendRequestOutgoing: RequestMiddleware = function () {
this.debug('request aborted')
// if the request is aborted, close out the middleware span and http span. the response middleware did not run

const pendingRequest = this.pendingRequest

if (pendingRequest) {
delete this.pendingRequest
this.removePendingRequest(pendingRequest)
}

this.reqMiddlewareSpan?.setAttributes({
requestAborted: true,
})
Expand Down
22 changes: 17 additions & 5 deletions packages/proxy/lib/http/util/prerequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export type CorrelationInformation = {

export type GetPreRequestCb = (correlationInformation: CorrelationInformation) => void

type PendingRequest = {
export type PendingRequest = {
key: string
ctxDebug
callback?: GetPreRequestCb
timeout: NodeJS.Timeout
Expand Down Expand Up @@ -74,10 +75,12 @@ class QueueMap<T> {
})
}
removeExact (queueKey: string, value: T) {
const i = this.queues[queueKey].findIndex((v) => v === value)
const i = this.queues[queueKey]?.findIndex((v) => v === value)

this.queues[queueKey].splice(i, 1)
if (this.queues[queueKey].length === 0) delete this.queues[queueKey]
if (i > -1) {
this.queues[queueKey].splice(i, 1)
if (this.queues[queueKey].length === 0) delete this.queues[queueKey]
}
}

forEach (fn: (value: T) => void) {
Expand Down Expand Up @@ -210,7 +213,7 @@ export class PreRequests {
})
}

removePending (requestId: string) {
removePendingPreRequest (requestId: string) {
this.pendingPreRequests.removeMatching(({ browserPreRequest }) => {
return (browserPreRequest.requestId.includes('-retry-') && !browserPreRequest.requestId.startsWith(`${requestId}-`)) || (!browserPreRequest.requestId.includes('-retry-') && browserPreRequest.requestId !== requestId)
})
Expand Down Expand Up @@ -267,6 +270,7 @@ export class PreRequests {
}

const pendingRequest: PendingRequest = {
key,
ctxDebug,
callback,
proxyRequestReceivedTimestamp: performance.now() + performance.timeOrigin,
Expand All @@ -283,6 +287,8 @@ export class PreRequests {
}

this.pendingRequests.push(key, pendingRequest)

return pendingRequest
}

setProtocolManager (protocolManager: ProtocolManagerShape) {
Expand All @@ -293,6 +299,12 @@ export class PreRequests {
this.requestTimeout = requestTimeout
}

removePendingRequest (pendingRequest: PendingRequest) {
this.pendingRequests.removeExact(pendingRequest.key, pendingRequest)
clearTimeout(pendingRequest.timeout)
delete pendingRequest.callback
}

reset () {
this.pendingPreRequests = new QueueMap<PendingPreRequest>()

Expand Down
25 changes: 23 additions & 2 deletions packages/proxy/test/unit/http/util/prerequests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe('http/util/prerequests', () => {

expectPendingCounts(0, 3)

preRequests.removePending('1235')
preRequests.removePendingPreRequest('1235')

expectPendingCounts(0, 2)
})
Expand All @@ -222,7 +222,7 @@ describe('http/util/prerequests', () => {

expectPendingCounts(0, 6)

preRequests.removePending('1235')
preRequests.removePendingPreRequest('1235')

expectPendingCounts(0, 2)
})
Expand All @@ -236,6 +236,27 @@ describe('http/util/prerequests', () => {
expect(cbServiceWorker).to.be.calledWith()
})

it('removes a pending request', () => {
const cb = sinon.stub()

const firstPreRequest = preRequests.get({ proxiedUrl: 'foo', method: 'GET', headers: {} } as CypressIncomingRequest, () => {}, cb)
const secondPreRequest = preRequests.get({ proxiedUrl: 'foo', method: 'GET', headers: {} } as CypressIncomingRequest, () => {}, cb)

expectPendingCounts(2, 0)

preRequests.removePendingRequest(firstPreRequest!)

expectPendingCounts(1, 0)

preRequests.removePendingRequest(firstPreRequest!)

expectPendingCounts(1, 0)

preRequests.removePendingRequest(secondPreRequest!)

expectPendingCounts(0, 0)
})

it('resets the queues', () => {
let callbackCalled = false

Expand Down
Loading

5 comments on commit 0ca0b19

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0ca0b19 Oct 24, 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.3.3/linux-arm64/feature/experimental-retries-0ca0b194920ceca2b69ad11969f849225f035447/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0ca0b19 Oct 24, 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.3.3/linux-x64/feature/experimental-retries-0ca0b194920ceca2b69ad11969f849225f035447/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0ca0b19 Oct 24, 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.3.3/darwin-arm64/feature/experimental-retries-0ca0b194920ceca2b69ad11969f849225f035447/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0ca0b19 Oct 24, 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.3.3/darwin-x64/feature/experimental-retries-0ca0b194920ceca2b69ad11969f849225f035447/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0ca0b19 Oct 24, 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.3.3/win32-x64/feature/experimental-retries-0ca0b194920ceca2b69ad11969f849225f035447/cypress.tgz

Please sign in to comment.