Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

47 lines (38 sloc) 1.205 kb
{ assert, brains, Browser } = require("./helpers")
describe "EventSource", ->
before (done)->
brains.get "/streaming", (req, res)->
res.send """
<html>
<head>
<script>
var source = new EventSource("/stream");
window.events = [];
source.addEventListener("test", function(event) {
window.events.push(event.data)
});
</script>
</head>
</html>
"""
brains.get "/stream", (req, res)->
res.writeHead 200,
"Content-Type": "text/event-stream; charset=utf-8"
"Cache-Control": "no-cache"
"Connection": "keep-alive"
res.write "event: test\nid: 1\ndata: first\n\n"
setTimeout ->
res.write "event: test\nid: 2\ndata: second\n\n"
res.end()
, 100
brains.ready done
before (done)->
browser = new Browser()
browser.visit("http://localhost:3003/streaming")
browser.wait (window)->
return window.events && window.events.length == 2
, =>
@events = browser.evaluate("window.events")
done()
it "should stream to browser", ->
assert.deepEqual @events, ["first", "second"]
Jump to Line
Something went wrong with that request. Please try again.