Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(driver): dynamic intercept aliases shown with name instead of no alias #28326

Merged
merged 12 commits into from
Nov 20, 2023

Conversation

S-Tornqvist
Copy link
Contributor

@S-Tornqvist S-Tornqvist commented Nov 13, 2023

Additional details

Previously, dynamic aliases added using cy.intercept (documentation) would not show up in the app. cy.wait would still work for them, but the aliases incorrectly renamed to "no alias" in the output confused users. See #24653.

Sample spec for reproduction:

const URL = "https://example.cypress.io"

describe('sample spec', () => {

  // Works before and after.
  it('static alias works', () => {
    cy.intercept('GET', URL).as("sampleRequest");

    cy.visit(URL)
    cy.wait('@sampleRequest')
  })

  // Did not work before. Works after.
  it('dynamic alias works', () => {
    cy.intercept('GET', URL, (req) => {
      req.alias = 'sampleRequest';
    });

    cy.visit(URL)
    cy.wait('@sampleRequest')
  })
})

Steps to test

@jordanpowell88 provided testing through a fixture in dynamic-route-aliases.runner.cy.js that uses a dynamic alias and verifying the behavior in the test aliases.cy.ts. Thanks!

How has the user experience changed?

Sample spec output before and after changes:
before after

PR Tasks

@cypress-app-bot
Copy link
Collaborator

@S-Tornqvist
Copy link
Contributor Author

S-Tornqvist commented Nov 13, 2023

How to test cy.intercept request alias matcher gui label? (solved)

I'm unsure how to test this part of the driver:
paint

The intercept matcher previously worked functionally, it was only the visual part that was previously incorrect.

Fixed by @jordanpowell88 in c4e82bb

@S-Tornqvist S-Tornqvist marked this pull request as ready for review November 13, 2023 18:54
@jordanpowell88 jordanpowell88 changed the title fix: dynamic intercept aliases shown with name instead of "no alias" #24653 fix: dynamic intercept aliases shown with name instead of "no alias" Nov 16, 2023
@jordanpowell88 jordanpowell88 changed the title fix: dynamic intercept aliases shown with name instead of "no alias" fix(driver): dynamic intercept aliases shown with name instead of "no alias" Nov 16, 2023
@jordanpowell88 jordanpowell88 changed the title fix(driver): dynamic intercept aliases shown with name instead of "no alias" fix(driver): dynamic intercept aliases shown with name instead of no alias Nov 16, 2023
cli/CHANGELOG.md Outdated Show resolved Hide resolved
@@ -0,0 +1,15 @@
import { loadSpec } from './support/spec-loader'

describe('Aliases', () => {
Copy link
Member

Choose a reason for hiding this comment

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

This test is pretty heavy when we could be validating log attributes within a driver test

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not super familiar with the driver but the way I understand it, the run time aliases that are set in the callback of intercept can't be triggered via a command? Am I missing something @emilyrohrbough ?

Copy link
Member

@emilyrohrbough emilyrohrbough Nov 20, 2023

Choose a reason for hiding this comment

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

You can pull it from the log list and execute the renderProps function to pull the value. Intercepts is a tricker command, I was playing with it and noticed we already have a test for dynamic aliases here, and we can add this to verify the alias renders correctly:

https://github.com/cypress-io/cypress/blob/develop/packages/driver/cypress/e2e/commands/net_stubbing.cy.ts#L3802

      it('can dynamically alias the request', function () {
        const url = uniqueRoute('/foo')

        cy.intercept(`${url}*`, (req) => {
          req.alias = 'fromInterceptor'
        })
        .then(() => {
          $.get(url)
        })
        .wait('@fromInterceptor')
+       .then(() => {
+         const log = cy.queue.logs({
+            displayName: 'xhr',
+         })[0]

+         const renderProps = log.get('renderProps')()

+         expect(renderProps.interceptions).to.have.length(1)
+         expect(renderProps.interceptions[0]).to.have.property('alias')
+         expect(renderProps.interceptions[0].alias).to.eq('fromInterceptor')
+        })
      })

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you! Just pushed a change

Copy link
Member

@emilyrohrbough emilyrohrbough left a comment

Choose a reason for hiding this comment

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

This test should be in the driver package

@jennifer-shehane jennifer-shehane merged commit 2041c69 into cypress-io:develop Nov 20, 2023
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 21, 2023

Released in 13.6.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v13.6.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Nov 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Individual requests aliases not working
5 participants