Skip to content

Commit

Permalink
fix(driver): add support for alias.all when using dynamic alias (#28352)
Browse files Browse the repository at this point in the history
* add tests for failing instance

* fix: support for dynamic alias.all

* update changelog

* Update cli/CHANGELOG.md

Co-authored-by: Matt Schile <[email protected]>

* move test

* Update cli/CHANGELOG.md

Co-authored-by: Emily Rohrbough <[email protected]>

---------

Co-authored-by: Matt Schile <[email protected]>
Co-authored-by: Emily Rohrbough <[email protected]>
  • Loading branch information
3 people committed Nov 16, 2023
1 parent d6e2a0d commit 02d0493
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ _Released 11/21/2023 (PENDING)_

**Bugfixes:**

- Fixed an issue where [aliasing individual requests](https://docs.cypress.io/api/commands/intercept#Aliasing-individual-requests) with `cy.intercept()` led to an error when retrieving all of the aliases with `cy.get(@alias.all)` . Addresses [#25448](https://github.com/cypress-io/cypress/issues/25448)
- The URL of the application under test and command error "Learn more" links now open externally instead of in the Cypress-launched browser. Fixes [#24572](https://github.com/cypress-io/cypress/issues/24572).

**Misc:**

- Browser tabs and windows other than the Cypress tab are now closed between tests in Chromium-based browsers. Addressed in [#28204](https://github.com/cypress-io/cypress/pull/28204).
- Cypress now ensures the main browser tab is active before running eaech command in Chromium-based browsers. Addressed in [#28334](https://github.com/cypress-io/cypress/pull/28334).
- Cypress now ensures the main browser tab is active before running each command in Chromium-based browsers. Addressed in [#28334](https://github.com/cypress-io/cypress/pull/28334).

## 13.5.1

Expand Down
19 changes: 19 additions & 0 deletions packages/driver/cypress/e2e/commands/net_stubbing.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3732,6 +3732,25 @@ describe('network stubbing', { retries: 15 }, function () {
})
})

// @see https://github.com/cypress-io/cypress/issues/25448
it('gets all aliased Interceptions by alias.all when assigning an alias using req.alias', function () {
const url = uniqueRoute('/foo')

cy.intercept(`${url}*`, (req) => {
req.alias = 'alias'
req.reply({ bar: 'baz' })
})
.then(() => {
$.get(url)
$.get(url)
})
.wait('@alias').wait('@alias')

cy.get('@alias.all').then((interceptions) => {
expect(interceptions).to.have.length(2)
})
})

// TODO: fix+document this behavior
// @see https://github.com/cypress-io/cypress/issues/7663
it.skip('gets indexed Interception by alias.number', function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cy/aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const requestXhrRe = /\.request$/

const reserved = ['test', 'runnable', 'timeout', 'slow', 'skip', 'inspect']

const aliasDisplayName = (name) => {
export const aliasDisplayName = (name) => {
return name.replace(aliasDisplayRe, '')
}

Expand Down
8 changes: 5 additions & 3 deletions packages/driver/src/cy/commands/querying/querying.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import $utils from '../../../cypress/utils'
import type { Log } from '../../../cypress/log'
import { resolveShadowDomInclusion } from '../../../cypress/shadow_dom_utils'
import { getAliasedRequests, isDynamicAliasingPossible } from '../../net-stubbing/aliasing'
import { aliasRe, aliasIndexRe } from '../../aliases'
import { aliasRe, aliasIndexRe, aliasDisplayName } from '../../aliases'

type GetOptions = Partial<Cypress.Loggable & Cypress.Timeoutable & Cypress.Withinable & Cypress.Shadow & {
_log?: Log
Expand Down Expand Up @@ -38,15 +38,17 @@ function getAlias (selector, log, cy) {
aliasObj = cy.getAlias(toSelect)
} catch (err) {
// possibly this is a dynamic alias, check to see if there is a request
const requests = getAliasedRequests(alias, cy.state)
// We need to use the stripped alias
const strippedAlias = aliasDisplayName(toSelect)
const requests = getAliasedRequests(strippedAlias, cy.state)

if (!isDynamicAliasingPossible(cy.state) || !requests.length) {
err.retry = false
throw err
}

aliasObj = {
alias,
alias: strippedAlias,
command: cy.state('routes')[requests[0].routeId].command,
}
}
Expand Down

5 comments on commit 02d0493

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 02d0493 Nov 16, 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.6.0/linux-x64/develop-02d04934725afd4a5b8067c1dd8ec1415e99ed3a/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 02d0493 Nov 16, 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.6.0/linux-arm64/develop-02d04934725afd4a5b8067c1dd8ec1415e99ed3a/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 02d0493 Nov 16, 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.6.0/darwin-x64/develop-02d04934725afd4a5b8067c1dd8ec1415e99ed3a/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 02d0493 Nov 16, 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.6.0/darwin-arm64/develop-02d04934725afd4a5b8067c1dd8ec1415e99ed3a/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 02d0493 Nov 16, 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.6.0/win32-x64/develop-02d04934725afd4a5b8067c1dd8ec1415e99ed3a/cypress.tgz

Please sign in to comment.