Open ChenKuanSun opened 1 year ago
Hi @ChenKuanSun can you please create a reproducible example suing Cypress Test Tiny and update this ticket with that example?
Hi @ChenKuanSun can you please create a reproducible example suing Cypress Test Tiny and update this ticket with that example?
Hello @nagash77 I have created repo from template.
https://github.com/ChenKuanSun/cypress-test-tiny-issue-sample
Note: we are disabling the testIsolation to keep context between tests.
Before each test, we are mocking all the API call and change the response in setup function. But if there is some api calls in the background like something service, the intercept will fail due to Cypress's netStubbingState reset.
Thanks for providing a reproducible example, @ChenKuanSun. I have replicated your problem in the latest version of Cypress and will forward this ticket to the appropriate team. They will evaluate the priority of this ticket and consider their capacity to pick it up. Please note that this does not guarantee that this issue will be resolved. The ticket will indicate status changes during evaluation, so we ask that you please refrain from asking for updates. Thanks!
I think we are having a flavour of this problem as well which has cost significant time and frustration debugging before finding this Github issue. It seems like it is the same problem as we're defining an intercept with the same url between tests and waiting on it in each test:
const login = ({ email, password }) => {
cy.intercept('POST', `${apiUrl}/login`).as('postLogin')
cy.visit(loginUrl)
cy.get("[name='login']").type(email)
cy.get("[type='password']").type(password)
cy.get('button').contains('Log in').click()
cy.wait(`@postLogin`, { timeout: 30000 })
.then((result) => {
// result is undefined when the test fails
cy.task('log', JSON.stringify(result))
cy.wrap(result)
})
.its('response.statusCode')
.should('eq', 200)
}
describe('auth', () => {
it('should be sent to xxx', () => {
login({ email, password })
cy.url().should('eq', `xxx`)
})
it('should be sent to yyy', () => {
login({ email, password })
cy.url().should('eq', `yyy`)
})
it('should be sent to zzz', () => {
login({ email, password })
cy.url().should('eq', 'zzz')
})
})
It consistently works in the first xxx test but then randomly fails in the 2nd or 3rd tests with the cy.wait
returning undefined immediately - i.e. it does not wait 30000ms.
Do you know what version of Cypress this was introduced in @ChenKuanSun as I'd like to consider rolling back until this is fixed? If not I will try to determine this for myself.
Current behavior
In our team, we want to maintain the test context and continue with the next test after one test has ended while Test isolation is disabled.
However, if we have some background services like the User data service, they might make some API calls between each test. If we use a setup to mock our API calls, and if the service issues an API call after the previous 'it' scope test ends but before the next mock API function is set up, then this API call will not be intercepted.
Desired behavior
If Test isolation is disabled, the API requests that were originally set up with an interceptor should still be intercepted as expected.
Test code to reproduce
Sample repo
Sample code
Cypress Version
12.8.1
Node version
v18.15.0
Operating System
macOS 13.3.1
Debug Logs
Other
No response