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
|
@@ -50,12 +50,12 @@ describe("PresenceChannel", function() {
|
|
|
50
50
|
|
|
51
51
|
beforeEach(function() {
|
|
52
52
|
authorizer = Mocks.getAuthorizer();
|
|
53
|
-
spyOn(Factory, "createAuthorizer").
|
|
53
|
+
spyOn(Factory, "createAuthorizer").and.returnValue(authorizer);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
it("should create and call an authorizer", function() {
|
|
57
57
|
channel.authorize("1.23", function() {});
|
|
58
|
-
expect(Factory.createAuthorizer.calls.
|
|
58
|
+
expect(Factory.createAuthorizer.calls.count()).toEqual(1);
|
|
59
59
|
expect(Factory.createAuthorizer).toHaveBeenCalledWith(
|
|
60
60
|
channel,
|
|
61
61
|
{ foo: "bar" }
|
|
@@ -93,18 +93,7 @@ describe("PresenceChannel", function() {
|
|
|
93
93
|
channel.subscribed = true;
|
|
94
94
|
});
|
|
95
95
|
it("should raise an exception if the event name does not start with client-", function() {
|
|
96
|
-
|
|
97
|
-
// (exception.message || exception) with (expected.message || expected)
|
|
98
|
-
// the thrown exception has a message so it's passed to the matcher. The
|
|
99
|
-
// message is a string, and *not* an instanceof the expected class
|
|
100
|
-
// https://github.com/jasmine/jasmine/blob/v1.3.1/src/core/Matchers.js#L331-L333
|
|
101
|
-
var exception;
|
|
102
|
-
try {
|
|
103
|
-
channel.trigger("whatever", {});
|
|
104
|
-
} catch(e) {
|
|
105
|
-
exception = e;
|
|
106
|
-
}
|
|
107
|
-
expect(exception).toMatch(jasmine.any(Errors.BadEventName));
|
|
96
|
+
expect(() => channel.trigger("whatever", {})).toThrow(jasmine.any(Errors.BadEventName));
|
|
108
97
|
});
|
|
109
98
|
|
|
110
99
|
it("should call send_event on connection", function() {
|
|
@@ -114,12 +103,12 @@ describe("PresenceChannel", function() {
|
|
|
114
103
|
});
|
|
115
104
|
|
|
116
105
|
it("should return true if connection sent the event", function() {
|
|
117
|
-
pusher.send_event.
|
|
106
|
+
pusher.send_event.and.returnValue(true);
|
|
118
107
|
expect(channel.trigger("client-test", {})).toBe(true);
|
|
119
108
|
});
|
|
120
109
|
|
|
121
110
|
it("should return false if connection didn't send the event", function() {
|
|
122
|
-
pusher.send_event.
|
|
111
|
+
pusher.send_event.and.returnValue(false);
|
|
123
112
|
expect(channel.trigger("client-test", {})).toBe(false);
|
|
124
113
|
});
|
|
125
114
|
});
|
|
@@ -129,7 +118,7 @@ describe("PresenceChannel", function() {
|
|
|
129
118
|
|
|
130
119
|
beforeEach(function() {
|
|
131
120
|
authorizer = Mocks.getAuthorizer();
|
|
132
|
-
spyOn(Factory, "createAuthorizer").
|
|
121
|
+
spyOn(Factory, "createAuthorizer").and.returnValue(authorizer);
|
|
133
122
|
channel.authorize("1.23", function() {});
|
|
134
123
|
authorizer._callback(false, {
|
|
135
124
|
foo: "bar",
|
|
@@ -287,7 +276,7 @@ describe("PresenceChannel", function() {
|
|
|
287
276
|
}
|
|
288
277
|
}
|
|
289
278
|
});
|
|
290
|
-
members = callback.calls
|
|
279
|
+
members = callback.calls.first().args[0];
|
|
291
280
|
});
|
|
292
281
|
|
|
293
282
|
it("members should store correct data", function() {
|
|
@@ -298,7 +287,7 @@ describe("PresenceChannel", function() {
|
|
|
298
287
|
var callback = jasmine.createSpy("callback");
|
|
299
288
|
members.each(callback);
|
|
300
289
|
|
|
301
|
-
expect(callback.calls.
|
|
290
|
+
expect(callback.calls.count()).toEqual(3);
|
|
302
291
|
expect(callback).toHaveBeenCalledWith({ id: "A", info: "user A" });
|
|
303
292
|
expect(callback).toHaveBeenCalledWith({ id: "B", info: "user B" });
|
|
304
293
|
expect(callback).toHaveBeenCalledWith({ id: "U", info: "me" });
|
|
@@ -33,12 +33,12 @@ describe("PrivateChannel", function() {
|
|
|
33
33
|
|
|
34
34
|
beforeEach(function() {
|
|
35
35
|
authorizer = Mocks.getAuthorizer();
|
|
36
|
-
factorySpy = spyOn(Factory, "createAuthorizer").
|
|
36
|
+
factorySpy = spyOn(Factory, "createAuthorizer").and.returnValue(authorizer);
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
it("should create and call an authorizer", function() {
|
|
40
40
|
channel.authorize("1.23", function() {});
|
|
41
|
-
expect(Factory.createAuthorizer.calls.
|
|
41
|
+
expect(Factory.createAuthorizer.calls.count()).toEqual(1);
|
|
42
42
|
expect(Factory.createAuthorizer).toHaveBeenCalledWith(
|
|
43
43
|
channel,
|
|
44
44
|
{ foo: "bar" }
|
|
@@ -57,13 +57,13 @@ describe("PrivateChannel", function() {
|
|
|
57
57
|
|
|
58
58
|
describe('with custom authorizer', function() {
|
|
59
59
|
beforeEach(function() {
|
|
60
|
-
pusher = Mocks.getPusher({
|
|
60
|
+
pusher = Mocks.getPusher({
|
|
61
61
|
authorizer: function(channel, options) {
|
|
62
62
|
return authorizer;
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
channel = new PrivateChannel("private-test-custom-auth", pusher);
|
|
66
|
-
factorySpy.
|
|
66
|
+
factorySpy.and.callThrough();
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
it("should call the authorizer", function() {
|
|
@@ -78,20 +78,10 @@ describe("PrivateChannel", function() {
|
|
|
78
78
|
describe("#trigger", function() {
|
|
79
79
|
beforeEach(function() {
|
|
80
80
|
channel.subscribed = true;
|
|
81
|
-
})
|
|
81
|
+
});
|
|
82
|
+
|
|
82
83
|
it("should raise an exception if the event name does not start with client-", function() {
|
|
83
|
-
|
|
84
|
-
// (exception.message || exception) with (expected.message || expected)
|
|
85
|
-
// the thrown exception has a message so it's passed to the matcher. The
|
|
86
|
-
// message is a string, and *not* an instanceof the expected class
|
|
87
|
-
// https://github.com/jasmine/jasmine/blob/v1.3.1/src/core/Matchers.js#L331-L333
|
|
88
|
-
var exception;
|
|
89
|
-
try {
|
|
90
|
-
channel.trigger("whatever", {});
|
|
91
|
-
} catch(e) {
|
|
92
|
-
exception = e;
|
|
93
|
-
}
|
|
94
|
-
expect(exception).toMatch(jasmine.any(Errors.BadEventName));
|
|
84
|
+
expect(() => channel.trigger('whatever', {})).toThrow(jasmine.any(Errors.BadEventName));
|
|
95
85
|
});
|
|
96
86
|
|
|
97
87
|
it("should call send_event on connection", function() {
|
|
@@ -101,12 +91,12 @@ describe("PrivateChannel", function() {
|
|
|
101
91
|
});
|
|
102
92
|
|
|
103
93
|
it("should return true if connection sent the event", function() {
|
|
104
|
-
pusher.send_event.
|
|
94
|
+
pusher.send_event.and.returnValue(true);
|
|
105
95
|
expect(channel.trigger("client-test", {})).toBe(true);
|
|
106
96
|
});
|
|
107
97
|
|
|
108
98
|
it("should return false if connection didn't send the event", function() {
|
|
109
|
-
pusher.send_event.
|
|
99
|
+
pusher.send_event.and.returnValue(false);
|
|
110
100
|
expect(channel.trigger("client-test", {})).toBe(false);
|
|
111
101
|
});
|
|
112
102
|
});
|
|
@@ -7,7 +7,7 @@ var nacl = require('tweetnacl')
|
|
|
7
7
|
describe('Config', function() {
|
|
8
8
|
beforeEach(function() {
|
|
9
9
|
if (TestEnv === 'web') {
|
|
10
|
-
spyOn(Runtime, 'getDocument').
|
|
10
|
+
spyOn(Runtime, 'getDocument').and.returnValue({
|
|
11
11
|
location: {
|
|
12
12
|
protocol: 'http:'
|
|
13
13
|
}
|
|
@@ -80,7 +80,7 @@ describe('Config', function() {
|
|
|
80
80
|
});
|
|
81
81
|
if (TestEnv === 'web') {
|
|
82
82
|
it('should use TLS when using https', function() {
|
|
83
|
-
Runtime.getDocument.
|
|
83
|
+
Runtime.getDocument.and.returnValue({
|
|
84
84
|
location: {
|
|
85
85
|
protocol: 'https:'
|
|
86
86
|
}
|
|
@@ -7,17 +7,23 @@ describe("ConnectionManager", function() {
|
|
|
7
7
|
var connection, strategy, timeline;
|
|
8
8
|
var managerOptions, manager;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
jasmine.
|
|
10
|
+
beforeAll(() => {
|
|
11
|
+
jasmine.clock().install();
|
|
12
|
+
});
|
|
12
13
|
|
|
14
|
+
afterAll(() => {
|
|
15
|
+
jasmine.clock().uninstall();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
beforeEach(function() {
|
|
13
19
|
connection = Mocks.getConnection();
|
|
14
20
|
strategy = Mocks.getStrategy(true);
|
|
15
21
|
timeline = Mocks.getTimeline();
|
|
16
22
|
|
|
17
|
-
spyOn(Network, "isOnline").
|
|
23
|
+
spyOn(Network, "isOnline").and.returnValue(true);
|
|
18
24
|
|
|
19
25
|
managerOptions = {
|
|
20
|
-
getStrategy: jasmine.createSpy("getStrategy").
|
|
26
|
+
getStrategy: jasmine.createSpy("getStrategy").and.returnValue(strategy),
|
|
21
27
|
timeline: timeline,
|
|
22
28
|
activityTimeout: 3456,
|
|
23
29
|
pongTimeout: 2345,
|
|
@@ -29,15 +35,15 @@ describe("ConnectionManager", function() {
|
|
|
29
35
|
|
|
30
36
|
describe("on construction", function() {
|
|
31
37
|
it("should construct a strategy", function() {
|
|
32
|
-
expect(manager.options.getStrategy.calls.
|
|
38
|
+
expect(manager.options.getStrategy.calls.count()).toEqual(1);
|
|
33
39
|
});
|
|
34
40
|
|
|
35
41
|
it("should pass the key to the strategy builder", function() {
|
|
36
|
-
expect(manager.options.getStrategy.calls
|
|
42
|
+
expect(manager.options.getStrategy.calls.first().args[0].key).toEqual("foo");
|
|
37
43
|
});
|
|
38
44
|
|
|
39
45
|
it("should pass a timeline to the strategy builder", function() {
|
|
40
|
-
var getStrategy = jasmine.createSpy("getStrategy").
|
|
46
|
+
var getStrategy = jasmine.createSpy("getStrategy").and.callFake(function(options) {
|
|
41
47
|
expect(options.timeline).toBe(timeline);
|
|
42
48
|
return strategy;
|
|
43
49
|
});
|
|
@@ -74,7 +80,7 @@ describe("ConnectionManager", function() {
|
|
|
74
80
|
describe("#connect", function() {
|
|
75
81
|
it("should not re-build the strategy", function() {
|
|
76
82
|
manager.connect();
|
|
77
|
-
expect(managerOptions.getStrategy.calls.
|
|
83
|
+
expect(managerOptions.getStrategy.calls.count()).toEqual(1);
|
|
78
84
|
});
|
|
79
85
|
|
|
80
86
|
it("should try to connect using the strategy", function() {
|
|
@@ -130,7 +136,7 @@ describe("ConnectionManager", function() {
|
|
|
130
136
|
it("should clear the unavailable timer", function() {
|
|
131
137
|
manager.disconnect();
|
|
132
138
|
|
|
133
|
-
jasmine.
|
|
139
|
+
jasmine.clock().tick(10000);
|
|
134
140
|
// if unavailable timer had worked, it would have transitioned into 'unavailable'
|
|
135
141
|
expect(manager.state).toEqual("disconnected");
|
|
136
142
|
});
|
|
@@ -141,9 +147,9 @@ describe("ConnectionManager", function() {
|
|
|
141
147
|
var onUnavailable = jasmine.createSpy("onUnavailable");
|
|
142
148
|
manager.bind("unavailable", onUnavailable);
|
|
143
149
|
|
|
144
|
-
jasmine.
|
|
150
|
+
jasmine.clock().tick(1233);
|
|
145
151
|
expect(manager.state).toEqual("connecting");
|
|
146
|
-
jasmine.
|
|
152
|
+
jasmine.clock().tick(1);
|
|
147
153
|
expect(manager.state).toEqual("unavailable");
|
|
148
154
|
expect(onUnavailable).toHaveBeenCalled();
|
|
149
155
|
});
|
|
@@ -162,14 +168,14 @@ describe("ConnectionManager", function() {
|
|
|
162
168
|
|
|
163
169
|
beforeEach(function() {
|
|
164
170
|
tlsStrategy = Mocks.getStrategy(true);
|
|
165
|
-
managerOptions.getStrategy.
|
|
171
|
+
managerOptions.getStrategy.and.returnValue(tlsStrategy);
|
|
166
172
|
|
|
167
173
|
handshake = { action: "tls_only" };
|
|
168
174
|
strategy._callback(null, handshake);
|
|
169
175
|
});
|
|
170
176
|
|
|
171
177
|
it("should build a TLS strategy", function() {
|
|
172
|
-
expect(managerOptions.getStrategy.calls.
|
|
178
|
+
expect(managerOptions.getStrategy.calls.count()).toEqual(2);
|
|
173
179
|
expect(managerOptions.getStrategy).toHaveBeenCalledWith({
|
|
174
180
|
key: "foo",
|
|
175
181
|
useTLS: true,
|
|
@@ -179,7 +185,7 @@ describe("ConnectionManager", function() {
|
|
|
179
185
|
|
|
180
186
|
it("should connect using the TLS strategy", function() {
|
|
181
187
|
// connection is retried with a zero delay
|
|
182
|
-
jasmine.
|
|
188
|
+
jasmine.clock().tick(0);
|
|
183
189
|
expect(tlsStrategy.connect).toHaveBeenCalled();
|
|
184
190
|
expect(manager.state).toEqual("connecting");
|
|
185
191
|
});
|
|
@@ -206,7 +212,7 @@ describe("ConnectionManager", function() {
|
|
|
206
212
|
});
|
|
207
213
|
|
|
208
214
|
it("should not reconnect", function() {
|
|
209
|
-
jasmine.
|
|
215
|
+
jasmine.clock().tick(100000);
|
|
210
216
|
expect(manager.state).toEqual("disconnected");
|
|
211
217
|
});
|
|
212
218
|
});
|
|
@@ -220,7 +226,7 @@ describe("ConnectionManager", function() {
|
|
|
220
226
|
});
|
|
221
227
|
|
|
222
228
|
it("should reconnect immediately", function() {
|
|
223
|
-
jasmine.
|
|
229
|
+
jasmine.clock().tick(0);
|
|
224
230
|
expect(manager.state).toEqual("connecting");
|
|
225
231
|
});
|
|
226
232
|
});
|
|
@@ -238,14 +244,14 @@ describe("ConnectionManager", function() {
|
|
|
238
244
|
});
|
|
239
245
|
|
|
240
246
|
it("should reconnect after 1s", function() {
|
|
241
|
-
jasmine.
|
|
242
|
-
expect(strategy.connect.calls.
|
|
243
|
-
jasmine.
|
|
244
|
-
expect(strategy.connect.calls.
|
|
247
|
+
jasmine.clock().tick(999);
|
|
248
|
+
expect(strategy.connect.calls.count()).toEqual(1);
|
|
249
|
+
jasmine.clock().tick(1);
|
|
250
|
+
expect(strategy.connect.calls.count()).toEqual(2);
|
|
245
251
|
});
|
|
246
252
|
|
|
247
253
|
it("should emit 'connecting_in' event", function() {
|
|
248
|
-
expect(onConnectingIn.calls.
|
|
254
|
+
expect(onConnectingIn.calls.count()).toEqual(1);
|
|
249
255
|
expect(onConnectingIn).toHaveBeenCalledWith(1);
|
|
250
256
|
});
|
|
251
257
|
});
|
|
@@ -301,15 +307,15 @@ describe("ConnectionManager", function() {
|
|
|
301
307
|
});
|
|
302
308
|
|
|
303
309
|
it("should clear the unavailable timer", function() {
|
|
304
|
-
jasmine.
|
|
310
|
+
jasmine.clock().tick(1500);
|
|
305
311
|
// if unavailable timer was not cleared, state should be unavailable
|
|
306
312
|
expect(manager.state).toEqual("connected");
|
|
307
313
|
});
|
|
308
314
|
|
|
309
315
|
it("should not try to connect again", function() {
|
|
310
|
-
expect(strategy.connect.calls.
|
|
316
|
+
expect(strategy.connect.calls.count()).toEqual(1);
|
|
311
317
|
manager.connect();
|
|
312
|
-
expect(strategy.connect.calls.
|
|
318
|
+
expect(strategy.connect.calls.count()).toEqual(1);
|
|
313
319
|
});
|
|
314
320
|
|
|
315
321
|
describe("#send", function() {
|
|
@@ -338,7 +344,7 @@ describe("ConnectionManager", function() {
|
|
|
338
344
|
it("should clear the activity check", function() {
|
|
339
345
|
manager.disconnect();
|
|
340
346
|
|
|
341
|
-
jasmine.
|
|
347
|
+
jasmine.clock().tick(10000);
|
|
342
348
|
// if activity check had worked, it would have sent a ping message
|
|
343
349
|
expect(connection.ping).not.toHaveBeenCalled();
|
|
344
350
|
});
|
|
@@ -367,16 +373,16 @@ describe("ConnectionManager", function() {
|
|
|
367
373
|
});
|
|
368
374
|
|
|
369
375
|
it("should transition to 'connecting' after 1s", function() {
|
|
370
|
-
jasmine.
|
|
376
|
+
jasmine.clock().tick(999);
|
|
371
377
|
expect(onConnecting).not.toHaveBeenCalled();
|
|
372
378
|
|
|
373
|
-
jasmine.
|
|
379
|
+
jasmine.clock().tick(1);
|
|
374
380
|
expect(onConnecting).toHaveBeenCalled();
|
|
375
381
|
expect(manager.state).toEqual("connecting");
|
|
376
382
|
});
|
|
377
383
|
|
|
378
384
|
it("should clean up the activity check", function() {
|
|
379
|
-
jasmine.
|
|
385
|
+
jasmine.clock().tick(10000);
|
|
380
386
|
// if activity check had worked, it would have sent a ping message
|
|
381
387
|
expect(connection.ping).not.toHaveBeenCalled();
|
|
382
388
|
});
|
|
@@ -384,38 +390,38 @@ describe("ConnectionManager", function() {
|
|
|
384
390
|
|
|
385
391
|
describe("while reconnecting", function() {
|
|
386
392
|
it("should re-use the strategy", function() {
|
|
387
|
-
expect(managerOptions.getStrategy.calls.
|
|
388
|
-
expect(strategy.connect.calls.
|
|
393
|
+
expect(managerOptions.getStrategy.calls.count()).toEqual(1);
|
|
394
|
+
expect(strategy.connect.calls.count()).toEqual(1);
|
|
389
395
|
|
|
390
396
|
manager.disconnect();
|
|
391
397
|
manager.connect();
|
|
392
398
|
|
|
393
|
-
expect(managerOptions.getStrategy.calls.
|
|
394
|
-
expect(strategy.connect.calls.
|
|
399
|
+
expect(managerOptions.getStrategy.calls.count()).toEqual(1);
|
|
400
|
+
expect(strategy.connect.calls.count()).toEqual(2);
|
|
395
401
|
});
|
|
396
402
|
});
|
|
397
403
|
|
|
398
404
|
describe("on activity timeout", function() {
|
|
399
405
|
it("should send a ping", function() {
|
|
400
|
-
jasmine.
|
|
406
|
+
jasmine.clock().tick(499);
|
|
401
407
|
expect(connection.ping).not.toHaveBeenCalled();
|
|
402
408
|
|
|
403
|
-
jasmine.
|
|
409
|
+
jasmine.clock().tick(1);
|
|
404
410
|
expect(connection.ping).toHaveBeenCalled();
|
|
405
411
|
|
|
406
|
-
jasmine.
|
|
412
|
+
jasmine.clock().tick(999);
|
|
407
413
|
expect(connection.close).not.toHaveBeenCalled();
|
|
408
414
|
|
|
409
415
|
connection.emit("activity");
|
|
410
416
|
// pong received, connection should not get closed
|
|
411
|
-
jasmine.
|
|
417
|
+
jasmine.clock().tick(1000);
|
|
412
418
|
expect(connection.close).not.toHaveBeenCalled();
|
|
413
419
|
});
|
|
414
420
|
|
|
415
421
|
it("should close the connection after pong timeout", function() {
|
|
416
|
-
jasmine.
|
|
422
|
+
jasmine.clock().tick(500);
|
|
417
423
|
expect(connection.close).not.toHaveBeenCalled();
|
|
418
|
-
jasmine.
|
|
424
|
+
jasmine.clock().tick(2346);
|
|
419
425
|
expect(connection.close).toHaveBeenCalled();
|
|
420
426
|
});
|
|
421
427
|
});
|
|
@@ -451,10 +457,10 @@ describe("ConnectionManager", function() {
|
|
|
451
457
|
Network.emit("offline");
|
|
452
458
|
expect(connection.ping).toHaveBeenCalled();
|
|
453
459
|
|
|
454
|
-
jasmine.
|
|
460
|
+
jasmine.clock().tick(2345);
|
|
455
461
|
expect(manager.state).toEqual("connected");
|
|
456
462
|
|
|
457
|
-
jasmine.
|
|
463
|
+
jasmine.clock().tick(1);
|
|
458
464
|
expect(manager.state).toEqual("connecting");
|
|
459
465
|
});
|
|
460
466
|
});
|
|
@@ -477,7 +483,7 @@ describe("ConnectionManager", function() {
|
|
|
477
483
|
it("should emit error and reconnect upon receipt of a tls_only event", function() {
|
|
478
484
|
var error = {code: 4000};
|
|
479
485
|
connection.emit("tls_only", {error: error});
|
|
480
|
-
jasmine.
|
|
486
|
+
jasmine.clock().tick(1);
|
|
481
487
|
expect(manager.state).toEqual("connecting");
|
|
482
488
|
expect(errorHandler).toHaveBeenCalledWith({
|
|
483
489
|
type: 'WebSocketError',
|
|
@@ -487,7 +493,7 @@ describe("ConnectionManager", function() {
|
|
|
487
493
|
it("should emit error and reconnect with backoff upon receipt of a backoff event", function() {
|
|
488
494
|
var error = {code: 4100};
|
|
489
495
|
connection.emit("backoff", {error: error});
|
|
490
|
-
jasmine.
|
|
496
|
+
jasmine.clock().tick(1000);
|
|
491
497
|
expect(manager.state).toEqual("connecting");
|
|
492
498
|
expect(errorHandler).toHaveBeenCalledWith({
|
|
493
499
|
type: 'WebSocketError',
|
|
@@ -497,7 +503,7 @@ describe("ConnectionManager", function() {
|
|
|
497
503
|
it("should emit error and reconnect upon receipt of a retry event", function() {
|
|
498
504
|
var error = {code: 4200};
|
|
499
505
|
connection.emit("retry", {error: error});
|
|
500
|
-
jasmine.
|
|
506
|
+
jasmine.clock().tick(1);
|
|
501
507
|
expect(manager.state).toEqual("connecting");
|
|
502
508
|
expect(errorHandler).toHaveBeenCalledWith({
|
|
503
509
|
type: 'WebSocketError',
|
|
@@ -511,7 +517,7 @@ describe("ConnectionManager", function() {
|
|
|
511
517
|
beforeEach(function() {
|
|
512
518
|
manager.connect();
|
|
513
519
|
connection.id = "123.456";
|
|
514
|
-
connection.handlesActivityChecks.
|
|
520
|
+
connection.handlesActivityChecks.and.returnValue(true);
|
|
515
521
|
strategy._callback(null, {
|
|
516
522
|
action: "connected",
|
|
517
523
|
connection: connection,
|
|
@@ -521,7 +527,7 @@ describe("ConnectionManager", function() {
|
|
|
521
527
|
|
|
522
528
|
describe("on activity timeout", function() {
|
|
523
529
|
it("should not send a ping or close a connection", function() {
|
|
524
|
-
jasmine.
|
|
530
|
+
jasmine.clock().tick(10000);
|
|
525
531
|
expect(connection.ping).not.toHaveBeenCalled();
|
|
526
532
|
expect(connection.close).not.toHaveBeenCalled();
|
|
527
533
|
});
|
|
@@ -531,37 +537,37 @@ describe("ConnectionManager", function() {
|
|
|
531
537
|
describe("on online event", function() {
|
|
532
538
|
it("should retry when in 'connecting' state", function() {
|
|
533
539
|
manager.connect();
|
|
534
|
-
expect(strategy.connect.calls.
|
|
540
|
+
expect(strategy.connect.calls.count()).toEqual(1);
|
|
535
541
|
|
|
536
542
|
Network.emit("online");
|
|
537
|
-
expect(strategy.connect.calls.
|
|
543
|
+
expect(strategy.connect.calls.count()).toEqual(1);
|
|
538
544
|
expect(manager.state).toEqual("connecting");
|
|
539
545
|
|
|
540
|
-
jasmine.
|
|
541
|
-
expect(strategy.connect.calls.
|
|
546
|
+
jasmine.clock().tick(1);
|
|
547
|
+
expect(strategy.connect.calls.count()).toEqual(2);
|
|
542
548
|
});
|
|
543
549
|
|
|
544
550
|
it("should retry when in 'unavailable' state", function() {
|
|
545
551
|
manager.connect();
|
|
546
|
-
expect(strategy.connect.calls.
|
|
552
|
+
expect(strategy.connect.calls.count()).toEqual(1);
|
|
547
553
|
|
|
548
|
-
jasmine.
|
|
549
|
-
expect(strategy.connect.calls.
|
|
554
|
+
jasmine.clock().tick(1234);
|
|
555
|
+
expect(strategy.connect.calls.count()).toEqual(1);
|
|
550
556
|
expect(manager.state).toEqual("unavailable");
|
|
551
557
|
Network.emit("online");
|
|
552
558
|
|
|
553
|
-
jasmine.
|
|
554
|
-
expect(strategy.connect.calls.
|
|
559
|
+
jasmine.clock().tick(1);
|
|
560
|
+
expect(strategy.connect.calls.count()).toEqual(2);
|
|
555
561
|
});
|
|
556
562
|
});
|
|
557
563
|
|
|
558
564
|
describe("on strategy error", function() {
|
|
559
565
|
it("should connect again using the same strategy", function() {
|
|
560
566
|
manager.connect();
|
|
561
|
-
expect(strategy.connect.calls.
|
|
567
|
+
expect(strategy.connect.calls.count()).toEqual(1);
|
|
562
568
|
|
|
563
569
|
strategy._callback(true);
|
|
564
|
-
expect(strategy.connect.calls.
|
|
570
|
+
expect(strategy.connect.calls.count()).toEqual(2);
|
|
565
571
|
expect(manager.state).toEqual("connecting");
|
|
566
572
|
});
|
|
567
573
|
});
|
|
@@ -569,7 +575,7 @@ describe("ConnectionManager", function() {
|
|
|
569
575
|
describe("with unsupported strategy", function() {
|
|
570
576
|
it("should transition to failed on connect", function() {
|
|
571
577
|
strategy.isSupported = jasmine.createSpy("isSupported")
|
|
572
|
-
.
|
|
578
|
+
.and.returnValue(false);
|
|
573
579
|
|
|
574
580
|
var onFailed = jasmine.createSpy("onFailed");
|
|
575
581
|
manager.bind("failed", onFailed);
|
|
@@ -597,10 +603,10 @@ describe("ConnectionManager", function() {
|
|
|
597
603
|
};
|
|
598
604
|
strategy._callback(null, handshake);
|
|
599
605
|
|
|
600
|
-
jasmine.
|
|
606
|
+
jasmine.clock().tick(2665);
|
|
601
607
|
expect(connection.send_event).not.toHaveBeenCalled();
|
|
602
608
|
|
|
603
|
-
jasmine.
|
|
609
|
+
jasmine.clock().tick(1);
|
|
604
610
|
expect(connection.ping).toHaveBeenCalled();
|
|
605
611
|
});
|
|
606
612
|
|
|
@@ -613,10 +619,10 @@ describe("ConnectionManager", function() {
|
|
|
613
619
|
};
|
|
614
620
|
strategy._callback(null, handshake);
|
|
615
621
|
|
|
616
|
-
jasmine.
|
|
622
|
+
jasmine.clock().tick(3399);
|
|
617
623
|
expect(connection.send_event).not.toHaveBeenCalled();
|
|
618
624
|
|
|
619
|
-
jasmine.
|
|
625
|
+
jasmine.clock().tick(1);
|
|
620
626
|
expect(connection.ping).toHaveBeenCalled();
|
|
621
627
|
});
|
|
622
628
|
|
|
@@ -629,10 +635,10 @@ describe("ConnectionManager", function() {
|
|
|
629
635
|
};
|
|
630
636
|
strategy._callback(null, handshake);
|
|
631
637
|
|
|
632
|
-
jasmine.
|
|
638
|
+
jasmine.clock().tick(3455);
|
|
633
639
|
expect(connection.send_event).not.toHaveBeenCalled();
|
|
634
640
|
|
|
635
|
-
jasmine.
|
|
641
|
+
jasmine.clock().tick(1);
|
|
636
642
|
expect(connection.ping).toHaveBeenCalled();
|
|
637
643
|
});
|
|
638
644
|
});
|
|
@@ -28,30 +28,30 @@ describe("Connection", function() {
|
|
|
28
28
|
|
|
29
29
|
describe("#handlesActivityChecks", function() {
|
|
30
30
|
it("should return true if transport handles activity checks by itself", function() {
|
|
31
|
-
transport.handlesActivityChecks.
|
|
31
|
+
transport.handlesActivityChecks.and.returnValue(true);
|
|
32
32
|
expect(connection.handlesActivityChecks()).toBe(true);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
it("should return false if transport does not handle activity checks by itself", function() {
|
|
36
|
-
transport.handlesActivityChecks.
|
|
36
|
+
transport.handlesActivityChecks.and.returnValue(false);
|
|
37
37
|
expect(connection.handlesActivityChecks()).toBe(false);
|
|
38
38
|
});
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
describe("#send", function() {
|
|
42
42
|
it("should pass the data to the transport", function() {
|
|
43
|
-
transport.send.
|
|
43
|
+
transport.send.and.returnValue(true);
|
|
44
44
|
connection.send("proxy");
|
|
45
45
|
expect(transport.send).toHaveBeenCalledWith("proxy");
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
it("should return true if the transport sent the data", function() {
|
|
49
|
-
transport.send.
|
|
49
|
+
transport.send.and.returnValue(true);
|
|
50
50
|
expect(connection.send("proxy")).toBe(true);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
it("should return false if the transport did not send the data", function() {
|
|
54
|
-
transport.send.
|
|
54
|
+
transport.send.and.returnValue(false);
|
|
55
55
|
expect(connection.send("proxy")).toBe(false);
|
|
56
56
|
});
|
|
57
57
|
|
|
@@ -75,18 +75,18 @@ describe("Connection", function() {
|
|
|
75
75
|
|
|
76
76
|
describe("#ping", function() {
|
|
77
77
|
it("should call ping on the transport if it's supported", function() {
|
|
78
|
-
transport.supportsPing.
|
|
78
|
+
transport.supportsPing.and.returnValue(true);
|
|
79
79
|
connection.ping();
|
|
80
80
|
expect(transport.ping).toHaveBeenCalled();
|
|
81
81
|
expect(transport.send).not.toHaveBeenCalled();
|
|
82
82
|
});
|
|
83
83
|
|
|
84
84
|
it("should send a pusher:ping event if ping is not supported", function() {
|
|
85
|
-
transport.supportsPing.
|
|
85
|
+
transport.supportsPing.and.returnValue(false);
|
|
86
86
|
connection.ping();
|
|
87
87
|
|
|
88
88
|
expect(transport.ping).not.toHaveBeenCalled();
|
|
89
|
-
var pingEvent = JSON.parse(transport.send.calls
|
|
89
|
+
var pingEvent = JSON.parse(transport.send.calls.first().args[0]);
|
|
90
90
|
expect(pingEvent).toEqual({
|
|
91
91
|
event: "pusher:ping",
|
|
92
92
|
data: {}
|
|
@@ -115,6 +115,7 @@ describe("Connection", function() {
|
|
|
115
115
|
expect(onMessage).toHaveBeenCalledWith({
|
|
116
116
|
event: "random",
|
|
117
117
|
data: { foo: "bar" },
|
|
118
|
+
channel: undefined,
|
|
118
119
|
});
|
|
119
120
|
});
|
|
120
121
|
|
|
@@ -164,7 +165,7 @@ describe("Connection", function() {
|
|
|
164
165
|
var error = {};
|
|
165
166
|
|
|
166
167
|
var onMessage = jasmine.createSpy("onMessage");
|
|
167
|
-
var onError = jasmine.createSpy("onError").
|
|
168
|
+
var onError = jasmine.createSpy("onError").and.callFake(function(e) {
|
|
168
169
|
error = e;
|
|
169
170
|
});
|
|
170
171
|
connection.bind("message", onMessage);
|
|
@@ -212,8 +213,8 @@ describe("Connection", function() {
|
|
|
212
213
|
it("should emit the action dispatched by protocol", function() {
|
|
213
214
|
var onMockAction = jasmine.createSpy("onMockAction");
|
|
214
215
|
connection.bind("mock_action", onMockAction);
|
|
215
|
-
spyOn(Protocol, "getCloseAction").
|
|
216
|
-
spyOn(Protocol, "getCloseError").
|
|
216
|
+
spyOn(Protocol, "getCloseAction").and.returnValue("mock_action");
|
|
217
|
+
spyOn(Protocol, "getCloseError").and.returnValue(null);
|
|
217
218
|
|
|
218
219
|
transport.emit("closed", { code: 1006, reason: "unknown" });
|
|
219
220
|
|
|
@@ -227,8 +228,8 @@ describe("Connection", function() {
|
|
|
227
228
|
it("should emit the error returned by protocol", function() {
|
|
228
229
|
var onError = jasmine.createSpy("onError");
|
|
229
230
|
connection.bind("error", onError);
|
|
230
|
-
spyOn(Protocol, "getCloseAction").
|
|
231
|
-
spyOn(Protocol, "getCloseError").
|
|
231
|
+
spyOn(Protocol, "getCloseAction").and.returnValue("mock_action");
|
|
232
|
+
spyOn(Protocol, "getCloseError").and.returnValue({
|
|
232
233
|
type: "MockError",
|
|
233
234
|
data: {
|
|
234
235
|
code: 4123,
|