I developed some service workers but when the complex of the service workers (SW) is getting higher I want to create a tests battery to check it out regularly.
I decided to use Cypress in first instance. But I struggle with some problems that dont let me handle the situation.
- Offline mode. Cypress has no native use case but has a recipe for Chrome (it doesnt matter if it works only in a unique browser)
- When offline mode recipe is active the fetch doesn't work properly on the test.
Cypress Open Issues - Simulate offline mode #235
Cypress Offline Mode Recipe for Chrome
The same web works on the browser but not in the cypress test.
Cypress test code
it('can load if sw registered and try to visit', () => {
cy.visit(folder)
cy.contains('#sw-status', 'SW not registered')
cy.get('#register').click().wait(1000)
Cypress.goOffline()
Cypress.assertOffline()
cy.get('#fetch').click()
cy.contains('#fetch-response', '200')
})
Exception catched on cypress - Failed to fetch

No internet. Firefox can use the fetch

No internet. Chrome can use the fetch

Something weird. With no internet Chrome said window.navigator.onLine is true

Any suggestion? Try with another testing framework?
I think the explanation of the problem is full and complete, but if someone thinks could be useful I can share code without problems