Intercepting ajax request with "async: false" cause cypress to freeze
See original GitHub issueCurrent behavior
We have code (JS/jQuery) invoking the POST request:
$.ajax({
type: 'POST',
url: '/web/api2/v1/term/{0}'.format(tbId),
dataType: 'json',
contentType: 'application/json',
cache: false,
async: false,
data: JSON.stringify({
conceptId: conceptId,
lang: input.attr('name'),
text: input.val()
}),
success: function (data) {
...
},
error: function (req, status) {
...
}
});
When we run tests on production we then intercept all the calls to add additional header and only on the request triggered like this cypress completely freeze. Screenshots and Debug logz are attached. Logs.txt
Desired behavior
Cypress should intercept the request.
Test code to reproduce
application code (JS/jQuery) invoking the POST request
$.ajax({
type: 'POST',
url: '/web/api2/v1/term/{0}'.format(tbId),
dataType: 'json',
contentType: 'application/json',
cache: false,
async: false,
data: JSON.stringify({
conceptId: conceptId,
lang: input.attr('name'),
text: input.val()
}),
success: function (data) {
...
},
error: function (req, status) {
...
}
});
test.spec.js
cy.get('#tb-insert-button').click();
cy.get('#tb-insert-tbody').find(`input[type="text"][name=${targetLang}]`).type(term);
cy.get('#tb-insert-submit').click();`
index.js
`beforeEach('Adds headers to web012 env', () => {
if (Cypress.env('ENVIRONMENT') === 'web012') {
cy.log(Cypress.env('ENVIRONMENT'));
cy.intercept(/^https:\/\/some\.domain\.com\/web\/(?!assets).*/, (req) => {
req.headers['X-Memsource-Web-Canary-Request'] = 'any';
});
}
});
Cypress Version
9.6.2
Other
No response
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Ajax Async False Freeze - Stack Overflow
Here is a solution that will make the uploads one by one without using async: false while still using asynchronous i/o and not...
Read more >Cypress cy.intercept Problems - Gleb Bahmutov
intercept runs, the call is already in progress, and thus not intercepted. Cypress shows XHR calls by default in its Command Log, thus...
Read more >Changelog - Cypress Documentation
testIsolation=false caused invalid configuration validation when running cypress ... Use the cy.intercept() command to stub network responses and requests.
Read more >Synchronous Ajax Call - Magia della Natura
The interception of synchronous requests seems to lock up cypress indefinitely. Asynchronous calls allow the client side process to continue while waiting ...
Read more >Synchronous Ajax Call - Bar Sereno
Intercepting ajax request with "async : false" cause cypress to freeze. gotthard panorama express ticket / fluminense vs palmeiras predictions / like a ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Donaab thank you for the report, I can reproduce this. The interception of synchronous requests seems to lock up cypress indefinitely. If I don’t intercept the synchronous request, the app will hang while the request executes but continues functioning after the request completes. I can also safely intercept the request if I provide a stubbed response.
I also put together a small reproduction as part of my investigation: https://github.com/tbiethman/cypress-test-tiny/tree/sync-request-intercept
As far as I can tell, when the app makes the synchronous request, it’s not able to handle events emitted from the middleware that allow the interception to be possible, which in result never allows the request to complete. More investigation will be required to determine how we should be handling these types of requests; we definitely shouldn’t allow Cypress to get into a scenario that we know will cause a hang.
Is there any way to skip interception of async:false requests? I’m trying to follow this sample code for throttling all requests, but I keep getting stuck with pending requests and Cypress frozen. https://docs.cypress.io/api/commands/intercept#Throttle-or-delay-response-all-incoming-responses