question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Show dynamic request aliases in the command log

See original GitHub issue

What would you like?

When I assign an alias from my cy.intercept() route handler, I want it to show up in the command log just as if I had aliased the route using cy.intercept().as().

Why is this needed?

The command log is extremely useful to understanding test execution and control flow, and without a clear link between the route table and an XHR made by my app, it can be difficult for developers to understand what happened.

Other

To reproduce the issue, you can run this standalone test:

describe("Dynamic aliasing", function () {
  it("test", () => {
    cy.visit("https://jsonplaceholder.cypress.io/");
    cy.intercept('/todos/1', req => {
      req.alias = 'dynamic';
      req.continue();
    });
    cy.contains('button', 'Try it').click();
    cy.contains('#result', 'delectus aut autem');
  });
});

Which results in the XHR having “no alias” in the command log, even though I clearly gave it an alias: image

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:11
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
ekeijlcommented, Sep 20, 2021

It seems I can neither use cy.wait('@test') on the dynamic alias.

2reactions
ShaunWangGocommented, Oct 6, 2022

Here’s a workaround: Use Cypress.log in the cy.intercept. Cypress.log runs syncrounously, so the log appears directly below the request, which is good enough for identifying which graphql request is which. https://docs.cypress.io/api/cypress-api/cypress-log#Syntax

cy.intercept("POST", {graphql url}, (req) => {
    const { body } = req;
    if (body.hasOwnProperty("operationName")) {
      Cypress.log({
        name: "Log GraphQL Request",
        message: body.operationName,
      });
    }
  });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Db2 11 - Data sharing - Member-specific location aliases - IBM
You can use the MODIFY DDF command with the ALIAS option to define and manage as many as 40 location aliases dynamically. You...
Read more >
Linux dynamic alias - Super User
The alias command is for making shortcuts for regularly issued commands ... This function will look for the logfile in the directory passed....
Read more >
Variables and Aliases - Cypress Documentation
To alias something you'd like to share use the .as() command. Let's look at our previous example with aliases. beforeEach(() ...
Read more >
alias command in Linux with Examples - GeeksforGeeks
–help option : It displays help Information. Syntax: alias --help. How to remove an alias? We use unalias command for this purpose.
Read more >
Linux: 70 commands aliases for everyday life
Aliases are a very dynamic way to add power to the command terminal ... This way you can type less to request the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found