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

Request overrides are disabled #127

Closed
ossistyle opened this issue Nov 4, 2021 · 2 comments
Closed

Request overrides are disabled #127

ossistyle opened this issue Nov 4, 2021 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ossistyle
Copy link

If requests override each other, then the newest matching request should be called.
Somehow this plugin disables this order.

The workaround is to disable/remove 'cy:request' in options.collectTypes

Example:
Add the following overwrite to the /support/commands.js

Cypress.Commands.overwrite('request', (originalFn, ...args) => {
   let options = {};

  if (typeof args[0] === 'object' && args[0] !== null) {
    options = args[0];
  } else if (args.length === 1) {
    [options.url] = args;
  } else if (args.length === 2) {
    [options.method, options.url] = args;
  } else if (args.length === 3) {
    [options.method, options.url, options.body] = args;
  }

  let headers = options.headers || {};
  headers['User-Agent'] = 'Cypress'; 

// ... changing/adding more custom headers
  
  options.headers = headers;

  return originalFn(options);
});

In the real request overwrite we added baseAuth credentials which are not used but the example with the user-agent also works as an example, I hope.

In the request header no "User-Agent" = "Cypress" is shown.

@archfz
Copy link
Owner

archfz commented Nov 7, 2021

So we had a similar issue with cy.intercept, but for that it was the case that the originalFn return value was not returned. See #120

So in case of cy.request we are returning see

return originalFn(...args).catch(async (e) => {
So I am not sure what is going, could use some debugging help here.

@ossistyle
Copy link
Author

Hello,
you can close the issue. After I updated the Cypress version to 9.0.0 I can see the request in the terminal.
Maybe this is not the fix but it works now for me.

If I have again this issue, I will open another ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants