question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for EventSource

See original GitHub issue

I would like to see the EventSource support because we use it extensively in our app.

Current behavior:

cy.route doesn’t identify EventSource requests and there is no way to watch them reliably now.

Desired behavior:

Either cy.route should support it or we should have another API for EventSource.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:9
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
orjandesmetcommented, May 7, 2019

I’ve come up with a solution to mock EventSources in a Cypress test: You can use a package similar to https://github.com/gcedo/eventsourcemock

In your main file of your application, you can then add:

import EventSource, { sources } from 'eventsourcemock';

if (window['Cypress']) {
  // Add mocked EventSources to Cypress run
  Object.defineProperty(window, 'EventSource', { value: EventSource });
  Object.defineProperty(window, 'mockEventSources', { value: sources });
}

And in your test, you can use:

cy.window().its('mockEventSources' as any).then(mockEventSources => {
  cy.readFile('cypress/fixtures/<your fixture here>').then(fixture => {
    mockEventSources['<your name here>'].emit(
      messageEvent.type,
      messageEvent
    );
  });
});

I hope this helps some people.

EDIT If you don’t want to add to your application’s main file, you can also use the solution from #2349

3reactions
sashashakuncommented, Feb 7, 2019

Same problem here:)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server-sent events | Can I use... Support tables for ... - CanIUse
Method of continuously sending data from a server to the browser, rather than repeatedly requesting it (EventSource interface, used to fall under HTML5)....
Read more >
EventSource - Web APIs | MDN
desktop desktop Chrome Edge EventSource Full support. Chrome6. Toggle history Full support. Edge79. Tog... EventSource() constructor Full support. Chrome6. Toggle history Full support. Edge79. Tog...
Read more >
EventSource client for Node.js and Browser (polyfill) - GitHub
This library is a pure JavaScript implementation of the EventSource client. The API aims to be W3C compatible. You can use it with...
Read more >
EventSource (Jersey 2.34 API)
The EventSource supports automated recuperation from a connection loss, including negotiation of delivery of any missed events based on the last received ...
Read more >
EventSource Class (System.Diagnostics.Tracing)
Attempt to keep EventSource objects backwards compatible and version them appropriately. The default version for an event is 0 . The version can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found