Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fetch through webworker are not handled by cypress resulting in wait() timeout #7840

Closed
gamegee opened this issue Jun 29, 2020 · 5 comments
Closed
Labels
stale no activity on this issue for a long period topic: network

Comments

@gamegee
Copy link

gamegee commented Jun 29, 2020

Current behavior:

The wait() command will not be triggered if a fetch is done through webworkers.
Because the request is never handled, the test will fail because of timeout.

Desired behavior:

Trigger wait when a fetch is done through webworkers, indeed in an other thread.

Test code to reproduce

If the browser support webworkers I use specific function fetchResourceWithWorker

import { fetchResource } from './api.fetch'
import { fetchResourceWithWorker } from './api.worker'

const fetchFn = window.Worker ? fetchResourceWithWorker : fetchResource

/**
 * Calls the given URL and returns the json object
 */
export const call = (...args) => {
  const [path, options] = args
  return fetchFn(path, { ...options })
}

My only alternative for now is to do something like this:

const fetchFn = window.Worker || process.env.CI === 'true' ? fetchResourceWithWorker : fetchResource

It is not really useful to provide cypress specs code sample, because all my specs using wait() are failing since webworkers are used in the codebase.

Versions

Chrome: Version 83.0.4103.116
MacOS: 10.15.5
Cypress: 4.3.0

@kamranayub
Copy link

I am pretty certain this isn't possible yet, because Service Workers and Web Workers use different scopes. Cypress can indeed stub/spy on fetch with experimentalFetchPolyfill: true in 4.9.0 but it only works on the Window scope, where it will force the use of XHR. Worker scopes will continue to use fetch, so you can't wait/spy/stub those calls.

In my app, I also workaround it by disabling service worker fetching using routing (e.g. /path?sw_ignore). I think you'll have to workaround it like you're doing until stubbing/spying on fetch is enabled for worker scopes.

Related to #687 I think.

@nicholaschiang
Copy link

I'm experiencing the same thing using the new cy.intercept command. I have a service worker that intercepts all requests and adds authentication headers; Cypress seems unable to detect them with the new cy.intercept command when they worked fine with cy.route. I'm not sure why.

@cwirz
Copy link

cwirz commented Mar 7, 2022

I have the same issue as @nicholaschiang. For me the cy.route function can actually intercept these service worker handled requests.
Screenshot 2022-03-07 at 21 02 06

I can also see that if you use a cy.intercept('*') to intercept all requests they are also not captured but everything else is.

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label May 17, 2023
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 2, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
stale no activity on this issue for a long period topic: network
Projects
None yet
Development

No branches or pull requests

6 participants