pusher-js 7.0.2 → 7.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/stale.yml +2 -2
- package/.github/workflows/release.yml +112 -0
- package/.github/workflows/release_pr.yml +42 -0
- package/.github/workflows/run-tests.yml +38 -0
- package/CHANGELOG.md +26 -0
- package/Makefile +17 -12
- package/README.md +28 -0
- package/dist/node/pusher.js +85 -44
- package/dist/node/pusher.js.map +1 -0
- package/dist/react-native/pusher.js +3 -2
- package/dist/react-native/pusher.js.map +1 -0
- package/dist/web/pusher-with-encryption.js +7 -5
- package/dist/web/pusher-with-encryption.js.map +1 -0
- package/dist/web/pusher-with-encryption.min.js +3 -2
- package/dist/web/pusher-with-encryption.min.js.map +1 -0
- package/dist/web/pusher.js +7 -5
- package/dist/web/pusher.js.map +1 -0
- package/dist/web/pusher.min.js +3 -2
- package/dist/web/pusher.min.js.map +1 -0
- package/dist/worker/pusher-with-encryption.worker.js +19 -7
- package/dist/worker/pusher-with-encryption.worker.js.map +1 -0
- package/dist/worker/pusher-with-encryption.worker.min.js +3 -2
- package/dist/worker/pusher-with-encryption.worker.min.js.map +1 -0
- package/dist/worker/pusher.worker.js +19 -7
- package/dist/worker/pusher.worker.js.map +1 -0
- package/dist/worker/pusher.worker.min.js +3 -2
- package/dist/worker/pusher.worker.min.js.map +1 -0
- package/package.json +17 -15
- package/spec/config/jasmine/helpers/reporter.js +14 -0
- package/spec/config/jasmine/integration.json +13 -0
- package/spec/config/jasmine/unit.json +13 -0
- package/spec/config/{jasmine-node → jasmine}/webpack.integration.js +4 -4
- package/spec/config/{jasmine-node → jasmine}/webpack.unit.js +4 -6
- package/spec/config/karma/config.common.js +10 -4
- package/spec/config/karma/config.integration.js +4 -4
- package/spec/config/karma/config.unit.js +5 -7
- package/spec/config/karma/integration.js +3 -3
- package/spec/config/karma/unit.js +2 -2
- package/spec/javascripts/helpers/mocks.js +18 -18
- package/spec/javascripts/helpers/waitsFor.js +37 -0
- package/spec/javascripts/integration/core/cluster_config_spec.js +45 -34
- package/spec/javascripts/integration/core/falling_back_spec.js +124 -127
- package/spec/javascripts/integration/core/pusher_spec/test_builder.js +264 -284
- package/spec/javascripts/integration/core/timeout_configuration_spec.js +24 -22
- package/spec/javascripts/integration/core/transport_lists_spec.js +8 -8
- package/spec/javascripts/integration/web/dom/jsonp_spec.js +67 -69
- package/spec/javascripts/integration/web/dom/script_request_spec.js +44 -52
- package/spec/javascripts/unit/core/channels/channel_spec.js +11 -21
- package/spec/javascripts/unit/core/channels/encrypted_channel_spec.js +9 -17
- package/spec/javascripts/unit/core/channels/presence_channel_spec.js +8 -19
- package/spec/javascripts/unit/core/channels/private_channel_spec.js +9 -19
- package/spec/javascripts/unit/core/config_spec.js +2 -2
- package/spec/javascripts/unit/core/connection/connection_manager_spec.js +69 -63
- package/spec/javascripts/unit/core/connection/connection_spec.js +14 -13
- package/spec/javascripts/unit/core/connection/handshake_spec.js +14 -12
- package/spec/javascripts/unit/core/connection/protocol_spec.js +9 -4
- package/spec/javascripts/unit/core/defaults_spec.js +1 -1
- package/spec/javascripts/unit/core/events_dispatcher_spec.js +20 -20
- package/spec/javascripts/unit/core/http/http_polling_socket_spec.js +4 -4
- package/spec/javascripts/unit/core/http/http_request_spec.js +20 -17
- package/spec/javascripts/unit/core/http/http_socket_spec.js +35 -32
- package/spec/javascripts/unit/core/http/http_streaming_socket_spec.js +4 -4
- package/spec/javascripts/unit/core/http/http_xhr_request_spec.js +13 -13
- package/spec/javascripts/unit/core/pusher_authorizer_spec.js +11 -11
- package/spec/javascripts/unit/core/pusher_spec.js +31 -27
- package/spec/javascripts/unit/core/strategies/best_connected_ever_strategy_spec.js +5 -5
- package/spec/javascripts/unit/core/strategies/cached_strategy_spec.js +17 -13
- package/spec/javascripts/unit/core/strategies/delayed_strategy_spec.js +12 -8
- package/spec/javascripts/unit/core/strategies/sequential_strategy_spec.js +23 -19
- package/spec/javascripts/unit/core/strategies/transport_strategy_spec.js +22 -24
- package/spec/javascripts/unit/core/timeline/timeline_spec.js +16 -9
- package/spec/javascripts/unit/core/transports/assistant_to_the_transport_manager_spec.js +36 -22
- package/spec/javascripts/unit/core/transports/hosts_and_ports_spec.js +10 -10
- package/spec/javascripts/unit/core/transports/transport_connection_spec.js +81 -86
- package/spec/javascripts/unit/core/transports/transport_manager_spec.js +1 -1
- package/spec/javascripts/unit/core/utils/periodic_timer_spec.js +17 -16
- package/spec/javascripts/unit/core/utils/timers_spec.js +32 -26
- package/spec/javascripts/unit/isomorphic/transports/hosts_and_ports_spec.js +12 -8
- package/spec/javascripts/unit/isomorphic/transports/transports_spec.js +7 -7
- package/spec/javascripts/unit/node/timeline_sender_spec.js +5 -5
- package/spec/javascripts/unit/web/dom/dependency_loader_spec.js +30 -30
- package/spec/javascripts/unit/web/dom/jsonp_request_spec.js +7 -7
- package/spec/javascripts/unit/web/http/http_xdomain_request_spec.js +22 -22
- package/spec/javascripts/unit/web/pusher_authorizer_spec.js +3 -3
- package/spec/javascripts/unit/web/timeline/timeline_sender_spec.js +12 -12
- package/spec/javascripts/unit/web/transports/hosts_and_ports_spec.js +15 -12
- package/spec/javascripts/unit/web/transports/transports_spec.js +24 -26
- package/spec/javascripts/unit/worker/pusher_authorizer_spec.js +2 -2
- package/spec/javascripts/unit/worker/timeline_sender_spec.js +2 -2
- package/src/core/auth/options.ts +1 -0
- package/types/src/core/auth/options.d.ts +1 -0
- package/webpack/config.node.js +2 -2
- package/webpack/config.react-native.js +2 -2
- package/webpack/config.shared.js +9 -1
- package/webpack/config.web.js +2 -2
- package/webpack/config.worker.js +5 -3
- package/worker/index.d.ts +15 -0
- package/worker/index.js +1 -0
- package/worker/with-encryption/index.d.ts +15 -0
- package/worker/with-encryption/index.js +1 -0
- package/.travis.build +0 -22
- package/.travis.yml +0 -7
- package/spec/config/jasmine-node/config.js +0 -10
|
@@ -18,7 +18,7 @@ describe("Handshake", function() {
|
|
|
18
18
|
|
|
19
19
|
describe("after a successful handshake", function() {
|
|
20
20
|
beforeEach(function() {
|
|
21
|
-
Protocol.processHandshake.
|
|
21
|
+
Protocol.processHandshake.and.returnValue({
|
|
22
22
|
action: "connected",
|
|
23
23
|
id: "9.9"
|
|
24
24
|
});
|
|
@@ -29,9 +29,10 @@ describe("Handshake", function() {
|
|
|
29
29
|
expect(callback).toHaveBeenCalledWith({
|
|
30
30
|
action: "connected",
|
|
31
31
|
transport: transport,
|
|
32
|
+
activityTimeout: undefined,
|
|
32
33
|
connection: jasmine.any(Connection)
|
|
33
34
|
});
|
|
34
|
-
expect(callback.calls
|
|
35
|
+
expect(callback.calls.first().args[0].connection.id).toEqual("9.9");
|
|
35
36
|
});
|
|
36
37
|
|
|
37
38
|
it("should not call close on the transport", function() {
|
|
@@ -41,7 +42,7 @@ describe("Handshake", function() {
|
|
|
41
42
|
|
|
42
43
|
describe("after a handshake with other action", function() {
|
|
43
44
|
beforeEach(function() {
|
|
44
|
-
Protocol.processHandshake.
|
|
45
|
+
Protocol.processHandshake.and.returnValue({
|
|
45
46
|
action: "boom",
|
|
46
47
|
error: "BOOM"
|
|
47
48
|
});
|
|
@@ -63,7 +64,7 @@ describe("Handshake", function() {
|
|
|
63
64
|
|
|
64
65
|
describe("after a handshake raising an exception", function() {
|
|
65
66
|
beforeEach(function() {
|
|
66
|
-
Protocol.processHandshake.
|
|
67
|
+
Protocol.processHandshake.and.throwError("Invalid handshake");
|
|
67
68
|
transport.emit("message", { data: "dummy "});
|
|
68
69
|
});
|
|
69
70
|
|
|
@@ -71,7 +72,7 @@ describe("Handshake", function() {
|
|
|
71
72
|
expect(callback).toHaveBeenCalledWith({
|
|
72
73
|
action: "error",
|
|
73
74
|
transport: transport,
|
|
74
|
-
error: "Invalid handshake"
|
|
75
|
+
error: new Error("Invalid handshake")
|
|
75
76
|
});
|
|
76
77
|
});
|
|
77
78
|
|
|
@@ -85,15 +86,15 @@ describe("Handshake", function() {
|
|
|
85
86
|
var finishSpy = spyOn(handshake, 'finish');
|
|
86
87
|
var error = new Error("some exception");
|
|
87
88
|
|
|
88
|
-
finishSpy.
|
|
89
|
+
finishSpy.and.callFake(function(action, params){
|
|
89
90
|
if (action === "connected") {
|
|
90
91
|
throw error
|
|
91
92
|
} else {
|
|
92
|
-
finishSpy.
|
|
93
|
+
finishSpy.and.callThrough();
|
|
93
94
|
}
|
|
94
95
|
});
|
|
95
96
|
|
|
96
|
-
Protocol.processHandshake.
|
|
97
|
+
Protocol.processHandshake.and.returnValue({
|
|
97
98
|
action: "connected",
|
|
98
99
|
id: "9.9"
|
|
99
100
|
});
|
|
@@ -107,7 +108,7 @@ describe("Handshake", function() {
|
|
|
107
108
|
describe("after receiving a 'closed' event from transport", function() {
|
|
108
109
|
describe("with defined action", function() {
|
|
109
110
|
beforeEach(function() {
|
|
110
|
-
spyOn(Protocol, "getCloseAction").
|
|
111
|
+
spyOn(Protocol, "getCloseAction").and.returnValue("boo");
|
|
111
112
|
spyOn(Protocol, "getCloseError");
|
|
112
113
|
|
|
113
114
|
transport.emit("closed", {
|
|
@@ -119,7 +120,8 @@ describe("Handshake", function() {
|
|
|
119
120
|
it("should call back with correct action and error", function() {
|
|
120
121
|
expect(callback).toHaveBeenCalledWith({
|
|
121
122
|
action: "boo",
|
|
122
|
-
transport: transport
|
|
123
|
+
transport: transport,
|
|
124
|
+
error: undefined,
|
|
123
125
|
});
|
|
124
126
|
});
|
|
125
127
|
|
|
@@ -137,8 +139,8 @@ describe("Handshake", function() {
|
|
|
137
139
|
|
|
138
140
|
describe("with null action", function() {
|
|
139
141
|
beforeEach(function() {
|
|
140
|
-
spyOn(Protocol, "getCloseAction").
|
|
141
|
-
spyOn(Protocol, "getCloseError").
|
|
142
|
+
spyOn(Protocol, "getCloseAction").and.returnValue(null);
|
|
143
|
+
spyOn(Protocol, "getCloseError").and.returnValue("???");
|
|
142
144
|
|
|
143
145
|
transport.emit("closed", {
|
|
144
146
|
code: 4321,
|
|
@@ -15,6 +15,7 @@ describe("Protocol", function() {
|
|
|
15
15
|
data: {
|
|
16
16
|
foo: "bar"
|
|
17
17
|
},
|
|
18
|
+
channel: undefined,
|
|
18
19
|
});
|
|
19
20
|
});
|
|
20
21
|
|
|
@@ -29,6 +30,7 @@ describe("Protocol", function() {
|
|
|
29
30
|
expect(Protocol.decodeMessage(message)).toEqual({
|
|
30
31
|
event: "raw",
|
|
31
32
|
data: "just a string",
|
|
33
|
+
channel: undefined,
|
|
32
34
|
});
|
|
33
35
|
});
|
|
34
36
|
|
|
@@ -46,6 +48,7 @@ describe("Protocol", function() {
|
|
|
46
48
|
x: "y",
|
|
47
49
|
z: 1
|
|
48
50
|
},
|
|
51
|
+
channel: undefined
|
|
49
52
|
});
|
|
50
53
|
});
|
|
51
54
|
it("should parse user_id message with user_id", function() {
|
|
@@ -54,13 +57,15 @@ describe("Protocol", function() {
|
|
|
54
57
|
event: "raw",
|
|
55
58
|
data: "just a string",
|
|
56
59
|
user_id: "abc-def",
|
|
57
|
-
})
|
|
60
|
+
}),
|
|
61
|
+
channel: undefined,
|
|
58
62
|
};
|
|
59
63
|
|
|
60
64
|
expect(Protocol.decodeMessage(message)).toEqual({
|
|
61
|
-
event:
|
|
62
|
-
data:
|
|
63
|
-
user_id:
|
|
65
|
+
event: 'raw',
|
|
66
|
+
data: 'just a string',
|
|
67
|
+
user_id: 'abc-def',
|
|
68
|
+
channel: undefined
|
|
64
69
|
});
|
|
65
70
|
});
|
|
66
71
|
|
|
@@ -8,7 +8,7 @@ describe("Default", function() {
|
|
|
8
8
|
function buildTest(ws) {
|
|
9
9
|
it("should be supported when ws=" + ws, function() {
|
|
10
10
|
if (ws) {
|
|
11
|
-
spyOn(WSTransport, "isSupported").
|
|
11
|
+
spyOn(WSTransport, "isSupported").and.returnValue(true);
|
|
12
12
|
}
|
|
13
13
|
var strategy = Runtime.getDefaultStrategy(
|
|
14
14
|
Config.getConfig({}),
|
|
@@ -17,7 +17,7 @@ describe("EventsDispatcher", function() {
|
|
|
17
17
|
dispatcher.emit("boop", "nope");
|
|
18
18
|
|
|
19
19
|
expect(onEvent).toHaveBeenCalledWith("test");
|
|
20
|
-
expect(onEvent.calls.
|
|
20
|
+
expect(onEvent.calls.count()).toEqual(1);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
it("should add the same listener to a specific event several times", function() {
|
|
@@ -28,7 +28,7 @@ describe("EventsDispatcher", function() {
|
|
|
28
28
|
dispatcher.emit("event", "test");
|
|
29
29
|
|
|
30
30
|
expect(onEvent).toHaveBeenCalledWith("test");
|
|
31
|
-
expect(onEvent.calls.
|
|
31
|
+
expect(onEvent.calls.count()).toEqual(2);
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
it("should add the listener with different contexts", function() {
|
|
@@ -40,7 +40,7 @@ describe("EventsDispatcher", function() {
|
|
|
40
40
|
dispatcher.emit("event", "test");
|
|
41
41
|
|
|
42
42
|
expect(onEvent).toHaveBeenCalledWith("test");
|
|
43
|
-
expect(onEvent.calls.
|
|
43
|
+
expect(onEvent.calls.count()).toEqual(3);
|
|
44
44
|
});
|
|
45
45
|
});
|
|
46
46
|
|
|
@@ -54,7 +54,7 @@ describe("EventsDispatcher", function() {
|
|
|
54
54
|
|
|
55
55
|
expect(onAll).toHaveBeenCalledWith("event", "test");
|
|
56
56
|
expect(onAll).toHaveBeenCalledWith("boop", []);
|
|
57
|
-
expect(onAll.calls.
|
|
57
|
+
expect(onAll.calls.count()).toEqual(2);
|
|
58
58
|
});
|
|
59
59
|
});
|
|
60
60
|
|
|
@@ -70,7 +70,7 @@ describe("EventsDispatcher", function() {
|
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
it("should remove the listener while emitting events (regression)", function() {
|
|
73
|
-
var onEvent1 = jasmine.createSpy("onEvent1").
|
|
73
|
+
var onEvent1 = jasmine.createSpy("onEvent1").and.callFake(function() {
|
|
74
74
|
dispatcher.unbind("event", onEvent1);
|
|
75
75
|
});
|
|
76
76
|
var onEvent2 = jasmine.createSpy("onEvent2");
|
|
@@ -79,12 +79,12 @@ describe("EventsDispatcher", function() {
|
|
|
79
79
|
dispatcher.bind("event", onEvent2);
|
|
80
80
|
|
|
81
81
|
dispatcher.emit("event");
|
|
82
|
-
expect(onEvent1.calls.
|
|
83
|
-
expect(onEvent2.calls.
|
|
82
|
+
expect(onEvent1.calls.count()).toEqual(1);
|
|
83
|
+
expect(onEvent2.calls.count()).toEqual(1);
|
|
84
84
|
|
|
85
85
|
dispatcher.emit("event");
|
|
86
|
-
expect(onEvent1.calls.
|
|
87
|
-
expect(onEvent2.calls.
|
|
86
|
+
expect(onEvent1.calls.count()).toEqual(1);
|
|
87
|
+
expect(onEvent2.calls.count()).toEqual(2);
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
it("should not remove the last callback if unbinding a function that was not bound (regression)", function() {
|
|
@@ -95,7 +95,7 @@ describe("EventsDispatcher", function() {
|
|
|
95
95
|
dispatcher.unbind("event", otherCallback);
|
|
96
96
|
|
|
97
97
|
dispatcher.emit("event");
|
|
98
|
-
expect(onEvent.calls.
|
|
98
|
+
expect(onEvent.calls.count()).toEqual(1);
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
it("should remove all listeners on omitted arguments", function() {
|
|
@@ -127,7 +127,7 @@ describe("EventsDispatcher", function() {
|
|
|
127
127
|
|
|
128
128
|
expect(onEvent1).not.toHaveBeenCalled();
|
|
129
129
|
expect(onEvent2).not.toHaveBeenCalled();
|
|
130
|
-
expect(onOther.calls.
|
|
130
|
+
expect(onOther.calls.count()).toEqual(1);
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
it("should remove all listeners with given callback", function() {
|
|
@@ -143,7 +143,7 @@ describe("EventsDispatcher", function() {
|
|
|
143
143
|
dispatcher.emit("event2");
|
|
144
144
|
|
|
145
145
|
expect(onEvent).not.toHaveBeenCalled();
|
|
146
|
-
expect(onOther.calls.
|
|
146
|
+
expect(onOther.calls.count()).toEqual(1);
|
|
147
147
|
});
|
|
148
148
|
|
|
149
149
|
it("should remove all event's listeners with given callback", function() {
|
|
@@ -156,7 +156,7 @@ describe("EventsDispatcher", function() {
|
|
|
156
156
|
dispatcher.emit("event");
|
|
157
157
|
expect(onEvent).not.toHaveBeenCalled();
|
|
158
158
|
dispatcher.emit("event2");
|
|
159
|
-
expect(onEvent.calls.
|
|
159
|
+
expect(onEvent.calls.count()).toEqual(1);
|
|
160
160
|
});
|
|
161
161
|
|
|
162
162
|
it("should remove all event's listeners with given context", function() {
|
|
@@ -174,7 +174,7 @@ describe("EventsDispatcher", function() {
|
|
|
174
174
|
|
|
175
175
|
expect(onEvent1).not.toHaveBeenCalled();
|
|
176
176
|
expect(onEvent2).not.toHaveBeenCalled();
|
|
177
|
-
expect(onEvent3.calls.
|
|
177
|
+
expect(onEvent3.calls.count()).toEqual(1);
|
|
178
178
|
});
|
|
179
179
|
|
|
180
180
|
it("should remove all listeners with given context", function() {
|
|
@@ -194,7 +194,7 @@ describe("EventsDispatcher", function() {
|
|
|
194
194
|
|
|
195
195
|
expect(onEvent1).not.toHaveBeenCalled();
|
|
196
196
|
expect(onEvent2).not.toHaveBeenCalled();
|
|
197
|
-
expect(onEvent3.calls.
|
|
197
|
+
expect(onEvent3.calls.count()).toEqual(1);
|
|
198
198
|
});
|
|
199
199
|
|
|
200
200
|
it("should remove all event's listeners with given callback and context", function() {
|
|
@@ -209,7 +209,7 @@ describe("EventsDispatcher", function() {
|
|
|
209
209
|
expect(onEvent).not.toHaveBeenCalled();
|
|
210
210
|
|
|
211
211
|
dispatcher.emit("event2");
|
|
212
|
-
expect(onEvent.calls.
|
|
212
|
+
expect(onEvent.calls.count()).toEqual(1);
|
|
213
213
|
});
|
|
214
214
|
|
|
215
215
|
it("should remove all listeners with given callback and context", function() {
|
|
@@ -228,10 +228,10 @@ describe("EventsDispatcher", function() {
|
|
|
228
228
|
expect(onEvent).not.toHaveBeenCalled();
|
|
229
229
|
|
|
230
230
|
dispatcher.emit("event3");
|
|
231
|
-
expect(onEvent.calls.
|
|
231
|
+
expect(onEvent.calls.count()).toEqual(1);
|
|
232
232
|
|
|
233
233
|
dispatcher.emit("other");
|
|
234
|
-
expect(onOther.calls.
|
|
234
|
+
expect(onOther.calls.count()).toEqual(1);
|
|
235
235
|
});
|
|
236
236
|
});
|
|
237
237
|
|
|
@@ -292,10 +292,10 @@ describe("EventsDispatcher", function() {
|
|
|
292
292
|
var context = {};
|
|
293
293
|
var boundContext, unboundContext;
|
|
294
294
|
|
|
295
|
-
var onEventBound = jasmine.createSpy("onEventBound").
|
|
295
|
+
var onEventBound = jasmine.createSpy("onEventBound").and.callFake(function(){
|
|
296
296
|
boundContext = this;
|
|
297
297
|
});
|
|
298
|
-
var onEventUnbound = jasmine.createSpy("onEventUnbound").
|
|
298
|
+
var onEventUnbound = jasmine.createSpy("onEventUnbound").and.callFake(function(){
|
|
299
299
|
unboundContext = this;
|
|
300
300
|
});
|
|
301
301
|
|
|
@@ -7,7 +7,7 @@ describe("HTTP.createPollingSocket", function() {
|
|
|
7
7
|
var socket;
|
|
8
8
|
|
|
9
9
|
beforeEach(function() {
|
|
10
|
-
spyOn(HTTPFactory, "createSocket").
|
|
10
|
+
spyOn(HTTPFactory, "createSocket").and.callFake(function(h, u) {
|
|
11
11
|
socket = Mocks.getHTTPSocket();
|
|
12
12
|
hooks = h;
|
|
13
13
|
url = u;
|
|
@@ -41,12 +41,12 @@ describe("HTTP.createPollingSocket", function() {
|
|
|
41
41
|
it("#sendHeartbeat should send an '[]' frame", function() {
|
|
42
42
|
hooks.sendHeartbeat(socket);
|
|
43
43
|
expect(socket.sendRaw).toHaveBeenCalledWith("[]");
|
|
44
|
-
expect(socket.sendRaw.calls.
|
|
44
|
+
expect(socket.sendRaw.calls.count()).toEqual(1);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
it("#onFinished with status 200 should reconnect the socket", function() {
|
|
48
48
|
hooks.onFinished(socket, 200);
|
|
49
|
-
expect(socket.reconnect.calls.
|
|
49
|
+
expect(socket.reconnect.calls.count()).toEqual(1);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
it("#onFinished with non-200 status should close the socket", function() {
|
|
@@ -54,7 +54,7 @@ describe("HTTP.createPollingSocket", function() {
|
|
|
54
54
|
expect(socket.onClose).toHaveBeenCalledWith(
|
|
55
55
|
1006, "Connection interrupted (500)", false
|
|
56
56
|
);
|
|
57
|
-
expect(socket.onClose.calls.
|
|
57
|
+
expect(socket.onClose.calls.count()).toEqual(1);
|
|
58
58
|
});
|
|
59
59
|
});
|
|
60
60
|
});
|
|
@@ -12,7 +12,7 @@ describe("HTTPRequest", function() {
|
|
|
12
12
|
|
|
13
13
|
beforeEach(function() {
|
|
14
14
|
hooks = {
|
|
15
|
-
getRequest: jasmine.createSpy().
|
|
15
|
+
getRequest: jasmine.createSpy().and.callFake(function() {
|
|
16
16
|
lastXHR = Mocks.getXHR();
|
|
17
17
|
return lastXHR;
|
|
18
18
|
}),
|
|
@@ -28,7 +28,7 @@ describe("HTTPRequest", function() {
|
|
|
28
28
|
describe("#start", function() {
|
|
29
29
|
it("should create a request using the getRequest hook", function() {
|
|
30
30
|
request.start("test");
|
|
31
|
-
expect(hooks.getRequest.calls.
|
|
31
|
+
expect(hooks.getRequest.calls.count()).toEqual(1);
|
|
32
32
|
expect(hooks.getRequest).toHaveBeenCalledWith(request);
|
|
33
33
|
});
|
|
34
34
|
|
|
@@ -52,23 +52,23 @@ describe("HTTPRequest", function() {
|
|
|
52
52
|
it("raised by XMLHttpRequest#open", function() {
|
|
53
53
|
hooks.getRequest = function() {
|
|
54
54
|
xhr = Mocks.getXHR();
|
|
55
|
-
xhr.open.
|
|
55
|
+
xhr.open.and.throwError("open exception");
|
|
56
56
|
return xhr;
|
|
57
57
|
};
|
|
58
58
|
expect(function() {
|
|
59
59
|
request.start();
|
|
60
|
-
}).toThrow(
|
|
60
|
+
}).toThrow(new Error('open exception'));
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
it("should re-throw the exception raised by XMLHttpRequest#send", function() {
|
|
64
64
|
hooks.getRequest = function() {
|
|
65
65
|
xhr = Mocks.getXHR();
|
|
66
|
-
xhr.send.
|
|
66
|
+
xhr.send.and.throwError("send exception");
|
|
67
67
|
return xhr;
|
|
68
68
|
};
|
|
69
69
|
expect(function() {
|
|
70
70
|
request.start();
|
|
71
|
-
}).toThrow(
|
|
71
|
+
}).toThrow(new Error('send exception'));
|
|
72
72
|
});
|
|
73
73
|
});
|
|
74
74
|
|
|
@@ -79,12 +79,12 @@ describe("HTTPRequest", function() {
|
|
|
79
79
|
|
|
80
80
|
it("should abort the request using the abortRequest hook", function() {
|
|
81
81
|
request.close();
|
|
82
|
-
expect(hooks.abortRequest.calls.
|
|
82
|
+
expect(hooks.abortRequest.calls.count()).toEqual(1);
|
|
83
83
|
expect(hooks.abortRequest).toHaveBeenCalledWith(lastXHR);
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
it("should unregister the unloader", function() {
|
|
87
|
-
var unloader = Runtime.addUnloadListener.calls
|
|
87
|
+
var unloader = Runtime.addUnloadListener.calls.first().args[0];
|
|
88
88
|
request.close();
|
|
89
89
|
expect(Runtime.removeUnloadListener).toHaveBeenCalledWith(unloader);
|
|
90
90
|
});
|
|
@@ -106,20 +106,23 @@ describe("HTTPRequest", function() {
|
|
|
106
106
|
|
|
107
107
|
it("should emit two chunks received one after another", function() {
|
|
108
108
|
request.onChunk(201, "c1\n");
|
|
109
|
-
expect(onChunk.calls.
|
|
109
|
+
expect(onChunk.calls.count()).toEqual(1);
|
|
110
110
|
expect(onChunk).toHaveBeenCalledWith({ status: 201, data: "c1" });
|
|
111
111
|
|
|
112
112
|
request.onChunk(201, "c1\nc2\n");
|
|
113
|
-
expect(onChunk.calls.
|
|
113
|
+
expect(onChunk.calls.count()).toEqual(2);
|
|
114
114
|
expect(onChunk).toHaveBeenCalledWith({ status: 201, data: "c2" });
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
it("should emit all chunks send in one batch", function() {
|
|
118
118
|
request.onChunk(200, "c1\nc2\nc3\n");
|
|
119
|
-
expect(onChunk.calls.
|
|
120
|
-
expect(onChunk.calls
|
|
121
|
-
expect(onChunk.calls
|
|
122
|
-
|
|
119
|
+
expect(onChunk.calls.count()).toEqual(3);
|
|
120
|
+
expect(onChunk.calls.first().args[0]).toEqual({ status: 200, data: "c1" });
|
|
121
|
+
expect(onChunk.calls.argsFor(1)[0]).toEqual({
|
|
122
|
+
status: 200,
|
|
123
|
+
data: 'c2'
|
|
124
|
+
});
|
|
125
|
+
expect(onChunk.calls.argsFor(2)[0]).toEqual({ status: 200, data: "c3" });
|
|
123
126
|
});
|
|
124
127
|
|
|
125
128
|
it("should not emit an unfinished chunk", function() {
|
|
@@ -156,7 +159,7 @@ describe("HTTPRequest", function() {
|
|
|
156
159
|
200,
|
|
157
160
|
new Array(256).join(kilobyteChunk + "\n") + kilobyteChunk + "x" + "\n"
|
|
158
161
|
); // 256KB + 1B
|
|
159
|
-
expect(onChunk.calls.
|
|
162
|
+
expect(onChunk.calls.count()).toEqual(256);
|
|
160
163
|
});
|
|
161
164
|
});
|
|
162
165
|
|
|
@@ -171,12 +174,12 @@ describe("HTTPRequest", function() {
|
|
|
171
174
|
|
|
172
175
|
beforeEach(function() {
|
|
173
176
|
request.start("test payload");
|
|
174
|
-
unloader = Runtime.addUnloadListener.calls
|
|
177
|
+
unloader = Runtime.addUnloadListener.calls.first().args[0];
|
|
175
178
|
});
|
|
176
179
|
|
|
177
180
|
it("should abort the request using the abortRequest hook", function() {
|
|
178
181
|
unloader();
|
|
179
|
-
expect(hooks.abortRequest.calls.
|
|
182
|
+
expect(hooks.abortRequest.calls.count()).toEqual(1);
|
|
180
183
|
expect(hooks.abortRequest).toHaveBeenCalledWith(lastXHR);
|
|
181
184
|
});
|
|
182
185
|
|
|
@@ -15,25 +15,25 @@ describe("HTTP.Socket", function() {
|
|
|
15
15
|
|
|
16
16
|
beforeEach(function() {
|
|
17
17
|
HTTPFactory = require('runtime').default.HTTPFactory;
|
|
18
|
-
jasmine.
|
|
18
|
+
jasmine.clock().install();
|
|
19
19
|
|
|
20
|
-
spyOn(HTTPFactory, "createXHR").
|
|
20
|
+
spyOn(HTTPFactory, "createXHR").and.callFake(function(method, url) {
|
|
21
21
|
lastXHR = Mocks.getHTTPRequest(method, url);
|
|
22
22
|
return lastXHR;
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
if (TestEnv === "web") {
|
|
26
|
-
spyOn(HTTPFactory, "createXDR").
|
|
26
|
+
spyOn(HTTPFactory, "createXDR").and.callFake(function(method, url) {
|
|
27
27
|
lastXHR = Mocks.getHTTPRequest(method, url);
|
|
28
28
|
return lastXHR;
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
spyOn(Runtime, "isXHRSupported").
|
|
33
|
-
if (TestEnv === "web") spyOn(Runtime, "isXDRSupported").
|
|
32
|
+
spyOn(Runtime, "isXHRSupported").and.returnValue(true);
|
|
33
|
+
if (TestEnv === "web") spyOn(Runtime, "isXDRSupported").and.returnValue(false);
|
|
34
34
|
|
|
35
35
|
hooks = {
|
|
36
|
-
getReceiveURL: jasmine.createSpy().
|
|
36
|
+
getReceiveURL: jasmine.createSpy().and.callFake(function(url, session) {
|
|
37
37
|
return url.base + "/" + session + url.queryString;
|
|
38
38
|
}),
|
|
39
39
|
onHeartbeat: jasmine.createSpy(),
|
|
@@ -55,11 +55,12 @@ describe("HTTP.Socket", function() {
|
|
|
55
55
|
|
|
56
56
|
afterEach(function() {
|
|
57
57
|
socket.close();
|
|
58
|
+
jasmine.clock().uninstall();
|
|
58
59
|
});
|
|
59
60
|
|
|
60
61
|
it("should use XHR if it's supported", function() {
|
|
61
|
-
Runtime.isXHRSupported.
|
|
62
|
-
if (TestEnv === "web" ) Runtime.isXDRSupported.
|
|
62
|
+
Runtime.isXHRSupported.and.returnValue(true);
|
|
63
|
+
if (TestEnv === "web" ) Runtime.isXDRSupported.and.returnValue(false);
|
|
63
64
|
|
|
64
65
|
var socket = new HTTPSocket(hooks, "http://example.com");
|
|
65
66
|
expect(HTTPFactory.createXHR).toHaveBeenCalled();
|
|
@@ -68,8 +69,8 @@ describe("HTTP.Socket", function() {
|
|
|
68
69
|
|
|
69
70
|
if (TestEnv === "web") {
|
|
70
71
|
it("should use XDR if it's supported", function() {
|
|
71
|
-
Runtime.isXHRSupported.
|
|
72
|
-
Runtime.isXDRSupported.
|
|
72
|
+
Runtime.isXHRSupported.and.returnValue(false);
|
|
73
|
+
Runtime.isXDRSupported.and.returnValue(true);
|
|
73
74
|
|
|
74
75
|
var socket = new HTTPSocket(hooks, "http://example.com");
|
|
75
76
|
expect(HTTPFactory.createXDR).toHaveBeenCalled();
|
|
@@ -110,9 +111,9 @@ describe("HTTP.Socket", function() {
|
|
|
110
111
|
// close the default socket
|
|
111
112
|
socket.close();
|
|
112
113
|
|
|
113
|
-
HTTPFactory.createXHR.
|
|
114
|
+
HTTPFactory.createXHR.and.callFake(function() {
|
|
114
115
|
stream = Mocks.getHTTPRequest();
|
|
115
|
-
stream.start.
|
|
116
|
+
stream.start.and.throwError("start exception");
|
|
116
117
|
return stream;
|
|
117
118
|
});
|
|
118
119
|
|
|
@@ -126,13 +127,15 @@ describe("HTTP.Socket", function() {
|
|
|
126
127
|
|
|
127
128
|
it("should raise an error", function() {
|
|
128
129
|
expect(onError).not.toHaveBeenCalled();
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
|
|
131
|
+
jasmine.clock().tick(1);
|
|
132
|
+
|
|
133
|
+
expect(onError).toHaveBeenCalledWith(new Error('start exception'));
|
|
131
134
|
});
|
|
132
135
|
|
|
133
136
|
it("should close itself with code 1006", function() {
|
|
134
137
|
expect(onClose).not.toHaveBeenCalled();
|
|
135
|
-
jasmine.
|
|
138
|
+
jasmine.clock().tick(1);
|
|
136
139
|
expect(onClose).toHaveBeenCalledWith({
|
|
137
140
|
code: 1006,
|
|
138
141
|
reason: "Could not start streaming",
|
|
@@ -142,12 +145,12 @@ describe("HTTP.Socket", function() {
|
|
|
142
145
|
|
|
143
146
|
it("should unbind all listeners from the stream", function() {
|
|
144
147
|
spyOn(stream, "unbind_all");
|
|
145
|
-
jasmine.
|
|
148
|
+
jasmine.clock().tick(1);
|
|
146
149
|
expect(stream.unbind_all).toHaveBeenCalled();
|
|
147
150
|
});
|
|
148
151
|
|
|
149
152
|
it("should close the stream", function() {
|
|
150
|
-
jasmine.
|
|
153
|
+
jasmine.clock().tick(1);
|
|
151
154
|
expect(stream.close).toHaveBeenCalled();
|
|
152
155
|
});
|
|
153
156
|
});
|
|
@@ -189,9 +192,9 @@ describe("HTTP.Socket", function() {
|
|
|
189
192
|
});
|
|
190
193
|
|
|
191
194
|
it("should not trigger any HTTP requests", function() {
|
|
192
|
-
expect(HTTPFactory.createXHR.calls.
|
|
195
|
+
expect(HTTPFactory.createXHR.calls.count()).toEqual(1);
|
|
193
196
|
socket.send("test");
|
|
194
|
-
expect(HTTPFactory.createXHR.calls.
|
|
197
|
+
expect(HTTPFactory.createXHR.calls.count()).toEqual(1);
|
|
195
198
|
});
|
|
196
199
|
});
|
|
197
200
|
});
|
|
@@ -199,9 +202,9 @@ describe("HTTP.Socket", function() {
|
|
|
199
202
|
describe("when connecting", function() {
|
|
200
203
|
describe("before the open frame", function() {
|
|
201
204
|
it("should ignore heartbeat frames", function() {
|
|
202
|
-
var requestCount = HTTPFactory.createXHR.calls.
|
|
205
|
+
var requestCount = HTTPFactory.createXHR.calls.count();
|
|
203
206
|
lastXHR.emit("chunk", { status: 200, data: "hhhhhhhhhhh" });
|
|
204
|
-
expect(HTTPFactory.createXHR.calls.
|
|
207
|
+
expect(HTTPFactory.createXHR.calls.count()).toEqual(requestCount);
|
|
205
208
|
});
|
|
206
209
|
});
|
|
207
210
|
|
|
@@ -221,10 +224,10 @@ describe("HTTP.Socket", function() {
|
|
|
221
224
|
|
|
222
225
|
describe("#send", function() {
|
|
223
226
|
it("should send an HTTP request to a correct URL", function() {
|
|
224
|
-
expect(HTTPFactory.createXHR.calls.
|
|
227
|
+
expect(HTTPFactory.createXHR.calls.count()).toEqual(1);
|
|
225
228
|
socket.send("test");
|
|
226
229
|
|
|
227
|
-
expect(HTTPFactory.createXHR.calls.
|
|
230
|
+
expect(HTTPFactory.createXHR.calls.count()).toEqual(2);
|
|
228
231
|
expect(lastXHR.method).toEqual("POST");
|
|
229
232
|
expect(lastXHR.url).toMatch(
|
|
230
233
|
new RegExp(
|
|
@@ -238,19 +241,19 @@ describe("HTTP.Socket", function() {
|
|
|
238
241
|
it("should send a string payload", function() {
|
|
239
242
|
var data = "test";
|
|
240
243
|
socket.send(data);
|
|
241
|
-
expect(JSON.parse(lastXHR.start.calls
|
|
244
|
+
expect(JSON.parse(lastXHR.start.calls.first().args[0])).toEqual([data]);
|
|
242
245
|
});
|
|
243
246
|
|
|
244
247
|
it("should send an array payload", function() {
|
|
245
248
|
var data = ["test", 1, { foo: "bar" }];
|
|
246
249
|
socket.send(data);
|
|
247
|
-
expect(JSON.parse(lastXHR.start.calls
|
|
250
|
+
expect(JSON.parse(lastXHR.start.calls.first().args[0])).toEqual([data]);
|
|
248
251
|
});
|
|
249
252
|
|
|
250
253
|
it("should send an object payload", function() {
|
|
251
254
|
var data = { num: 1, str: "data", arr: [1, 2, 3]};
|
|
252
255
|
socket.send(data);
|
|
253
|
-
expect(JSON.parse(lastXHR.start.calls
|
|
256
|
+
expect(JSON.parse(lastXHR.start.calls.first().args[0])).toEqual([data]);
|
|
254
257
|
});
|
|
255
258
|
|
|
256
259
|
it("should return true if the request did not raise an exception", function() {
|
|
@@ -258,9 +261,9 @@ describe("HTTP.Socket", function() {
|
|
|
258
261
|
});
|
|
259
262
|
|
|
260
263
|
it("should return false if the request raised an exception", function() {
|
|
261
|
-
HTTPFactory.createXHR.
|
|
264
|
+
HTTPFactory.createXHR.and.callFake(function() {
|
|
262
265
|
var request = Mocks.getHTTPRequest();
|
|
263
|
-
request.start.
|
|
266
|
+
request.start.and.throwError("exception");
|
|
264
267
|
return request;
|
|
265
268
|
});
|
|
266
269
|
|
|
@@ -291,9 +294,9 @@ describe("HTTP.Socket", function() {
|
|
|
291
294
|
describe("on a multi-message frame", function() {
|
|
292
295
|
it("should emit all messages if status is 200", function() {
|
|
293
296
|
lastXHR.emit("chunk", { status: 200, data: 'a[1,2,3]' });
|
|
294
|
-
expect(onMessage.calls
|
|
295
|
-
expect(onMessage.calls
|
|
296
|
-
expect(onMessage.calls
|
|
297
|
+
expect(onMessage.calls.first().args[0]).toEqual({ data: 1 });
|
|
298
|
+
expect(onMessage.calls.argsFor(1)[0]).toEqual({ data: 2 });
|
|
299
|
+
expect(onMessage.calls.argsFor(2)[0]).toEqual({ data: 3 });
|
|
297
300
|
});
|
|
298
301
|
|
|
299
302
|
it("should not emit any messages if status is not 200", function() {
|
|
@@ -351,7 +354,7 @@ describe("HTTP.Socket", function() {
|
|
|
351
354
|
it("should send an HTTP request to the updated host", function() {
|
|
352
355
|
socket.send("test");
|
|
353
356
|
// opening the connection sends the first request
|
|
354
|
-
expect(HTTPFactory.createXHR.calls.
|
|
357
|
+
expect(HTTPFactory.createXHR.calls.count()).toEqual(2);
|
|
355
358
|
expect(lastXHR.method).toEqual("POST");
|
|
356
359
|
expect(lastXHR.url).toMatch(
|
|
357
360
|
new RegExp(
|
|
@@ -7,7 +7,7 @@ describe("HTTP.getStreamingSocket", function() {
|
|
|
7
7
|
var socket;
|
|
8
8
|
|
|
9
9
|
beforeEach(function() {
|
|
10
|
-
spyOn(HTTPFactory, "createSocket").
|
|
10
|
+
spyOn(HTTPFactory, "createSocket").and.callFake(function(h, u) {
|
|
11
11
|
socket = Mocks.getHTTPSocket();
|
|
12
12
|
hooks = h;
|
|
13
13
|
url = u;
|
|
@@ -36,13 +36,13 @@ describe("HTTP.getStreamingSocket", function() {
|
|
|
36
36
|
it("#onHeartbeat should send an '[]' frame", function() {
|
|
37
37
|
hooks.onHeartbeat(socket);
|
|
38
38
|
expect(socket.sendRaw).toHaveBeenCalledWith("[]");
|
|
39
|
-
expect(socket.sendRaw.calls.
|
|
39
|
+
expect(socket.sendRaw.calls.count()).toEqual(1);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
it("#sendHeartbeat should send an '[]' frame", function() {
|
|
43
43
|
hooks.sendHeartbeat(socket);
|
|
44
44
|
expect(socket.sendRaw).toHaveBeenCalledWith("[]");
|
|
45
|
-
expect(socket.sendRaw.calls.
|
|
45
|
+
expect(socket.sendRaw.calls.count()).toEqual(1);
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
it("#onFinished should close the socket", function() {
|
|
@@ -50,7 +50,7 @@ describe("HTTP.getStreamingSocket", function() {
|
|
|
50
50
|
expect(socket.onClose).toHaveBeenCalledWith(
|
|
51
51
|
1006, "Connection interrupted (200)", false
|
|
52
52
|
);
|
|
53
|
-
expect(socket.onClose.calls.
|
|
53
|
+
expect(socket.onClose.calls.count()).toEqual(1);
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
56
|
});
|