MCPcopy Create free account
hub / github.com/Yaffle/EventSource / mainTests

Function mainTests

tests/tests.js:20–381  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18 "Cache-Control: no-store\n";
19
20 var mainTests = function () {
21 // Opera bug with "XMLHttpRequest#onprogress"
22 asyncTest("EventSource: 3 messages with small delay", function () {
23 var body = "data\n\n<delay(25)>data\n\n<delay(25)>data\n\n<delay(10000)>";
24 var es = new EventSource(url + "?estest=" + encodeURIComponent(commonHeaders + "\n\n" + body));
25 var n = 0;
26 es.onmessage = function () {
27 n += 1;
28 };
29 es.onerror = es.onopen = function () {
30 es.onerror = es.onopen = undefined;
31 setTimeout(function () {
32 es.close();
33 ok(n === 3, "failed, n = " + n);
34 start();
35 }, 1000);
36 };
37 });
38
39 asyncTest("EventSource: ping-pong", function () {
40 var n = 0;
41 var timeStamp = new Date().getTime();
42 var es = undefined;
43 var timer = 0;
44 var onTimeout = undefined;
45 var body = "retry: 500\n" +
46 "data: " + Math.random() + "\n\n" +
47 "<delay(1500)>" +
48 "data: " + Math.random() + "\n\n" +
49 "<delay(1500)>" +
50 "data: " + Math.random() + "\n\n" +
51 "<delay(10000)>";
52 if (global.XDomainRequest != undefined) {
53 body = new Array(2048).join(" ") + body;
54 }
55 es = new EventSource(url + "?estest=" + encodeURIComponent(commonHeaders + "\n\n" + body));
56 es.onmessage = function () {
57 ++n;
58 clearTimeout(timer);
59 if (n === 3) {
60 es.close();
61 ok(true, "test 0, duration: " + (new Date().getTime() - timeStamp));
62 start();
63 } else {
64 timer = setTimeout(onTimeout, 2000);
65 }
66 };
67 onTimeout = function () {
68 es.close();
69 ok(false, "failed, n = " + n);
70 start();
71 };
72 timer = setTimeout(onTimeout, 1000);
73 });
74
75 asyncTest("Last event id test with custom query name", function () {
76 var body = "retry: 500\n" +
77 "id: <lastEventId(1)>\n" +

Callers 1

tests.jsFile · 0.85

Calls 2

startFunction · 0.70
fFunction · 0.70

Tested by

no test coverage detected