-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
File watching does not execute actual code changes when site under test utilizes Service Workers. #702
Comments
Additionally seeing problems with ServiceWorkers caching the |
Another potential lifecycle command we could add at the beginning of each test, and then subsequently at the end of all tests is something like: The implementation for that might look something like: window.navigator.serviceWorker.getRegistrations()
.then(function(registrations) {
return Promise.map(registrations, function(registration) {
return registration.unregister()
})
}) |
We could even indefinitely prevent service workers from ever being registered by doing: cy.visit("https://testy.gift/", {
onBeforeLoad: function(win) {
const promise = new Promise(function(resolve) {});
return win.navigator.serviceWorker.register = function() {
return promise;
}
}
}) |
We need to make a decision here. Currently ServiceWorkers end up generating very confusing behavior in Cypress which is hard for new (and even old) users to debug. Proposal
When we enable lifecycle events this could potentially conflict... |
so as a workaround as long as it doesn't cache the stuff at |
Yes, you could. That is the only request of Cypress' that you are caching accidentally. |
The workaround does not work for me:
The test files only update, when i close cypress or when i manually clear the cache through the Chrome settings. Did not found a way to solve it or another workaround. |
I want to be able to e2e test my serviceworker's behavior, so I'd hate to see this happen. I'd love to see an API to clear the caches before each test run though! |
@mxstbr What behavior of the service worker are you testing? We'd like to hear your more about your use case so we can properly address our side. |
Caching of frontend assets and potentially web push notifications? |
another hack i used was to have my web-app detect cypress. my CSP is already no-frame, so, in dev mode w/ the csp off, i can sniff for |
I solved the issues I was having by updating my navigation fallback config in
|
Still no workaround to clear service worker? |
@mackelito I've managed to unregister all service workers before each test in one of my specs like this: beforeEach(() => {
if (window.navigator && navigator.serviceWorker) {
navigator.serviceWorker.getRegistrations()
.then((registrations) => {
registrations.forEach((registration) => {
registration.unregister()
})
})
}
}) |
@abigailcauchi This snippet helped me, thank you. The application I'm working heavily relies on service workers. I noticed my cypress spec files would pass when run independently, but when I chose to run all specs the browser launched by cypress would fail to load some pages (resulting in failed assertions!). After unregistering service workers in my before hooks, my specs are running much faster and passing consistently. Thank you again. |
I have disabled the service workers when 'window.Cypress' but still it is not working. Anything on this yet. |
I came across this issue yesterday. I found I could get around it in Chrome by going to Dev Tools->Application->Service Workers and checking the 'Bypass for network' checkbox. Not ideal but it got me moving again so I could see changes I made to my test. Changing "watchForFileChanges" did not affect this issue. Not an issue when running from the command line. Only from the test runner. App is React/Gatsby/PWA using gatsby-plugin-offline (a workbox wrapper) |
Same here. Just spent the better part of two days figuring out the root cause of our Cypress/Lighthouse tests failing. (using https://github.com/mfrachet/cypress-audit). We have to manually checkbox |
I'm using a service worker to handle authentication by intercepting Currently during development, I always open up developer tools and check the "Allow service workers over HTTP" box like so: With Cypress, I can do the same thing when running Any suggestions for how to ensure that service workers are allowed over HTTP in the headless browser that |
Nevermind, I seem to have fixed my own issue by serving to |
Hi, any update on this? |
Related to #15670. |
Related: #16192 |
There doesn't seem to be a workaround for this for me... Cypress.on('window:before:load', win => {
if (window.navigator && 'serviceWorker' in window.navigator) {
window.navigator.serviceWorker.getRegistrations().then(registrations => {
registrations.forEach(r => r.unregister());
});
}
// @ts-ignore
delete win.navigator.__proto__.ServiceWorker;
// @ts-ignore
delete win.navigator.serviceWorker;
}); but the service worker still registers |
Hello, I am a little junior and I've been struggling with this a lot, the solution is simple - clear cache in a browser that Cypress is using. Version Cypress 12.7.0 hope that helps :) |
Prevent unexpected behaviour with service workers. See: cypress-io/cypress#702
I have encountered this just now. Cypress version 13.5.0. |
Related to #686.
It's possible the application under test ends up using Server Workers to inadvertently cache the files Cypress uses to serve spec files. This prevents changes to the spec files from ever being updated.
Prior to the beginning of all tests we should clear the Service Worker cache and then add a new cy command and add this to lifecycle rules
cy.clearServiceWorkerCache()
.We could make this command print out all the cache keys it cleared.
Workaround:
The text was updated successfully, but these errors were encountered: