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
|
@@ -13,7 +13,7 @@ describe("TransportStrategy", function() {
|
|
|
13
13
|
transport = Mocks.getTransport(true);
|
|
14
14
|
transportClass = Mocks.getTransportClass(true, transport);
|
|
15
15
|
|
|
16
|
-
spyOn(Factory, 'createHandshake').
|
|
16
|
+
spyOn(Factory, 'createHandshake').and.callFake(function(transport, callback) {
|
|
17
17
|
handshake = Mocks.getHandshake(transport, callback);
|
|
18
18
|
return handshake;
|
|
19
19
|
});
|
|
@@ -42,6 +42,14 @@ describe("TransportStrategy", function() {
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
describe("#connect", function() {
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
jasmine.clock().install();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
jasmine.clock().uninstall();
|
|
51
|
+
});
|
|
52
|
+
|
|
45
53
|
it("should pass key and options to the transport", function() {
|
|
46
54
|
var options = {
|
|
47
55
|
key: "asdf",
|
|
@@ -129,32 +137,22 @@ describe("TransportStrategy", function() {
|
|
|
129
137
|
});
|
|
130
138
|
|
|
131
139
|
it("should call back with an error if transport's priority is too low", function() {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}, "callback to be called");
|
|
138
|
-
runs(function() {
|
|
139
|
-
expect(callback).toHaveBeenCalledWith(
|
|
140
|
-
jasmine.any(Errors.TransportPriorityTooLow)
|
|
141
|
-
);
|
|
142
|
-
});
|
|
140
|
+
strategy.connect(2, callback);
|
|
141
|
+
|
|
142
|
+
jasmine.clock().tick(100);
|
|
143
|
+
|
|
144
|
+
expect(callback).toHaveBeenCalledWith(jasmine.any(Errors.TransportPriorityTooLow));
|
|
143
145
|
});
|
|
144
146
|
|
|
145
147
|
it("should call back with an error if transport is not supported", function() {
|
|
146
|
-
transportClass.isSupported.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
expect(callback).toHaveBeenCalledWith(
|
|
155
|
-
jasmine.any(Errors.UnsupportedStrategy)
|
|
156
|
-
);
|
|
157
|
-
});
|
|
148
|
+
transportClass.isSupported.and.returnValue(false);
|
|
149
|
+
|
|
150
|
+
strategy.connect(0, callback);
|
|
151
|
+
|
|
152
|
+
jasmine.clock().tick(100);
|
|
153
|
+
|
|
154
|
+
expect(callback.calls.count()).toBeGreaterThan(0);
|
|
155
|
+
expect(callback).toHaveBeenCalledWith(jasmine.any(Errors.UnsupportedStrategy));
|
|
158
156
|
});
|
|
159
157
|
});
|
|
160
158
|
|
|
@@ -49,7 +49,7 @@ describe("Timeline", function() {
|
|
|
49
49
|
|
|
50
50
|
describe("on send", function() {
|
|
51
51
|
beforeEach(function() {
|
|
52
|
-
spyOn(Network, "isOnline").
|
|
52
|
+
spyOn(Network, "isOnline").and.returnValue(true);
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
it("should include key, session id, cluster, features, version and params", function() {
|
|
@@ -84,21 +84,25 @@ describe("Timeline", function() {
|
|
|
84
84
|
it("should include pushed events", function() {
|
|
85
85
|
spyOn(util, "now");
|
|
86
86
|
|
|
87
|
-
util.now.
|
|
87
|
+
util.now.and.returnValue(1000);
|
|
88
88
|
timeline.log(2, {a: 1});
|
|
89
|
-
util.now.
|
|
89
|
+
util.now.and.returnValue(2000);
|
|
90
90
|
timeline.error({ b: 2.2 });
|
|
91
|
-
util.now.
|
|
91
|
+
util.now.and.returnValue(100000);
|
|
92
92
|
timeline.info({ foo: "bar" });
|
|
93
|
-
util.now.
|
|
93
|
+
util.now.and.returnValue(100001);
|
|
94
94
|
timeline.debug({ debug: true });
|
|
95
95
|
|
|
96
96
|
expect(timeline.send(sendJSONP, onSend)).toBe(true);
|
|
97
97
|
expect(sendJSONP).toHaveBeenCalledWith(
|
|
98
|
-
{
|
|
99
|
-
|
|
98
|
+
{
|
|
99
|
+
bundle: 1,
|
|
100
|
+
key: 'foo',
|
|
100
101
|
session: 666,
|
|
101
|
-
lib:
|
|
102
|
+
lib: 'js',
|
|
103
|
+
version: undefined,
|
|
104
|
+
cluster: undefined,
|
|
105
|
+
features: undefined,
|
|
102
106
|
timeline: [
|
|
103
107
|
{ timestamp: 1000, a: 1 },
|
|
104
108
|
{ timestamp: 2000, b: 2.2 },
|
|
@@ -117,7 +121,7 @@ describe("Timeline", function() {
|
|
|
117
121
|
});
|
|
118
122
|
|
|
119
123
|
it("should respect the size limit", function() {
|
|
120
|
-
spyOn(util, "now").
|
|
124
|
+
spyOn(util, "now").and.returnValue(123);
|
|
121
125
|
|
|
122
126
|
var timeline = new Timeline("bar", 123, {
|
|
123
127
|
level: TimelineLevel.INFO,
|
|
@@ -133,6 +137,9 @@ describe("Timeline", function() {
|
|
|
133
137
|
key: "bar",
|
|
134
138
|
session: 123,
|
|
135
139
|
lib: "js",
|
|
140
|
+
version: undefined,
|
|
141
|
+
cluster: undefined,
|
|
142
|
+
features: undefined,
|
|
136
143
|
timeline: [
|
|
137
144
|
{ timestamp: 123, i: 2},
|
|
138
145
|
{ timestamp: 123, i: 3},
|
|
@@ -7,8 +7,8 @@ describe("AssistantToTheTransportManager", function() {
|
|
|
7
7
|
var manager;
|
|
8
8
|
|
|
9
9
|
beforeEach(function() {
|
|
10
|
-
jasmine.
|
|
11
|
-
spyOn(Util, "now").
|
|
10
|
+
jasmine.clock().install();
|
|
11
|
+
spyOn(Util, "now").and.returnValue(1);
|
|
12
12
|
|
|
13
13
|
transport = Mocks.getTransport(true);
|
|
14
14
|
transportManager = Mocks.getTransportManager();
|
|
@@ -21,6 +21,10 @@ describe("AssistantToTheTransportManager", function() {
|
|
|
21
21
|
);
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
+
afterEach(function() {
|
|
25
|
+
jasmine.clock().uninstall();
|
|
26
|
+
});
|
|
27
|
+
|
|
24
28
|
describe("#isSupported", function() {
|
|
25
29
|
it("should return true when transport is supported", function() {
|
|
26
30
|
var assistant = new AssistantToTheTransportManager(
|
|
@@ -41,12 +45,12 @@ describe("AssistantToTheTransportManager", function() {
|
|
|
41
45
|
});
|
|
42
46
|
|
|
43
47
|
it("should return true if transport is alive", function() {
|
|
44
|
-
transportManager.isAlive.
|
|
48
|
+
transportManager.isAlive.and.returnValue(true);
|
|
45
49
|
expect(assistant.isSupported()).toBe(true);
|
|
46
50
|
});
|
|
47
51
|
|
|
48
52
|
it("should return false if transport is not alive", function() {
|
|
49
|
-
transportManager.isAlive.
|
|
53
|
+
transportManager.isAlive.and.returnValue(false);
|
|
50
54
|
expect(assistant.isSupported()).toBe(false);
|
|
51
55
|
});
|
|
52
56
|
});
|
|
@@ -54,8 +58,12 @@ describe("AssistantToTheTransportManager", function() {
|
|
|
54
58
|
describe("#createConnection", function() {
|
|
55
59
|
it("should pass parameters to the transport", function() {
|
|
56
60
|
assistant.createConnection("foo", 66, "abc", { test: true });
|
|
57
|
-
expect(transportClass.createConnection)
|
|
58
|
-
|
|
61
|
+
expect(transportClass.createConnection).toHaveBeenCalledWith(
|
|
62
|
+
'foo',
|
|
63
|
+
66,
|
|
64
|
+
'abc',
|
|
65
|
+
{ test: true, activityTimeout: undefined }
|
|
66
|
+
);
|
|
59
67
|
});
|
|
60
68
|
|
|
61
69
|
it("should return the transport instance", function() {
|
|
@@ -69,9 +77,9 @@ describe("AssistantToTheTransportManager", function() {
|
|
|
69
77
|
|
|
70
78
|
beforeEach(function() {
|
|
71
79
|
connection = assistant.createConnection("x", 1, "a", {});
|
|
72
|
-
Util.now.
|
|
80
|
+
Util.now.and.returnValue(1);
|
|
73
81
|
connection.emit("open");
|
|
74
|
-
Util.now.
|
|
82
|
+
Util.now.and.returnValue(100001);
|
|
75
83
|
connection.emit("closed", { wasClean: true, code: 1002 });
|
|
76
84
|
});
|
|
77
85
|
|
|
@@ -85,9 +93,9 @@ describe("AssistantToTheTransportManager", function() {
|
|
|
85
93
|
|
|
86
94
|
beforeEach(function() {
|
|
87
95
|
connection = assistant.createConnection("x", 1, "a", {});
|
|
88
|
-
Util.now.
|
|
96
|
+
Util.now.and.returnValue(1);
|
|
89
97
|
connection.emit("open");
|
|
90
|
-
Util.now.
|
|
98
|
+
Util.now.and.returnValue(100001);
|
|
91
99
|
connection.emit("closed", { wasClean: true, code: 1003 });
|
|
92
100
|
});
|
|
93
101
|
|
|
@@ -107,14 +115,14 @@ describe("AssistantToTheTransportManager", function() {
|
|
|
107
115
|
{ minPingDelay: 10000, maxPingDelay: 100000 }
|
|
108
116
|
);
|
|
109
117
|
connection = assistant.createConnection("x", 1, "a", {});
|
|
110
|
-
Util.now.
|
|
118
|
+
Util.now.and.returnValue(1);
|
|
111
119
|
connection.emit("open");
|
|
112
|
-
Util.now.
|
|
120
|
+
Util.now.and.returnValue(190001);
|
|
113
121
|
connection.emit("closed", { wasClean: false });
|
|
114
122
|
});
|
|
115
123
|
|
|
116
124
|
it("should report its death once to the manager", function() {
|
|
117
|
-
expect(transportManager.reportDeath.calls.
|
|
125
|
+
expect(transportManager.reportDeath.calls.count()).toEqual(1);
|
|
118
126
|
});
|
|
119
127
|
|
|
120
128
|
it("should set the activity timeout on the next connection to lifetime/2 ms", function() {
|
|
@@ -136,9 +144,9 @@ describe("AssistantToTheTransportManager", function() {
|
|
|
136
144
|
{ minPingDelay: 10000, maxPingDelay: 50000 }
|
|
137
145
|
);
|
|
138
146
|
connection = assistant.createConnection("x", 1, "a", {});
|
|
139
|
-
Util.now.
|
|
147
|
+
Util.now.and.returnValue(1);
|
|
140
148
|
connection.emit("open");
|
|
141
|
-
Util.now.
|
|
149
|
+
Util.now.and.returnValue(100002);
|
|
142
150
|
connection.emit("closed", { wasClean: false });
|
|
143
151
|
});
|
|
144
152
|
|
|
@@ -149,7 +157,10 @@ describe("AssistantToTheTransportManager", function() {
|
|
|
149
157
|
it("should not set the activity timeout on the next connection", function() {
|
|
150
158
|
var connection = assistant.createConnection("x", 1, "a", {});
|
|
151
159
|
expect(transportClass.createConnection).toHaveBeenCalledWith(
|
|
152
|
-
|
|
160
|
+
'x',
|
|
161
|
+
1,
|
|
162
|
+
'a',
|
|
163
|
+
{ activityTimeout: undefined }
|
|
153
164
|
);
|
|
154
165
|
});
|
|
155
166
|
});
|
|
@@ -165,14 +176,14 @@ describe("AssistantToTheTransportManager", function() {
|
|
|
165
176
|
{ minPingDelay: 20000, maxPingDelay: 100000 }
|
|
166
177
|
);
|
|
167
178
|
connection = assistant.createConnection("x", 1, "a", {});
|
|
168
|
-
Util.now.
|
|
179
|
+
Util.now.and.returnValue(1);
|
|
169
180
|
connection.emit("open");
|
|
170
|
-
Util.now.
|
|
181
|
+
Util.now.and.returnValue(32001);
|
|
171
182
|
connection.emit("closed", { wasClean: false });
|
|
172
183
|
});
|
|
173
184
|
|
|
174
185
|
it("should report its death once to the manager", function() {
|
|
175
|
-
expect(transportManager.reportDeath.calls.
|
|
186
|
+
expect(transportManager.reportDeath.calls.count()).toEqual(1);
|
|
176
187
|
});
|
|
177
188
|
|
|
178
189
|
it("should set the activity timeout on the next connection to minPingDelay ms", function() {
|
|
@@ -188,9 +199,9 @@ describe("AssistantToTheTransportManager", function() {
|
|
|
188
199
|
|
|
189
200
|
beforeEach(function() {
|
|
190
201
|
connection = assistant.createConnection("x", 1, "a", {});
|
|
191
|
-
Util.now.
|
|
202
|
+
Util.now.and.returnValue(1);
|
|
192
203
|
connection.emit("open");
|
|
193
|
-
Util.now.
|
|
204
|
+
Util.now.and.returnValue(100001);
|
|
194
205
|
connection.emit("closed", { wasClean: true });
|
|
195
206
|
});
|
|
196
207
|
|
|
@@ -201,7 +212,10 @@ describe("AssistantToTheTransportManager", function() {
|
|
|
201
212
|
it("should not set the activity timeout on the next connection", function() {
|
|
202
213
|
var connection = assistant.createConnection("x", 1, "a", {});
|
|
203
214
|
expect(transportClass.createConnection).toHaveBeenCalledWith(
|
|
204
|
-
|
|
215
|
+
'x',
|
|
216
|
+
1,
|
|
217
|
+
'a',
|
|
218
|
+
{ activityTimeout: undefined }
|
|
205
219
|
);
|
|
206
220
|
});
|
|
207
221
|
});
|
|
@@ -15,13 +15,13 @@ describe("Host/Port Configuration", function() {
|
|
|
15
15
|
var Transports;
|
|
16
16
|
|
|
17
17
|
beforeEach(function() {
|
|
18
|
-
spyOn(Runtime, 'getNetwork').
|
|
18
|
+
spyOn(Runtime, 'getNetwork').and.callFake(function(){
|
|
19
19
|
var network = new NetInfo();
|
|
20
20
|
network.isOnline = jasmine.createSpy("isOnline")
|
|
21
|
-
.
|
|
21
|
+
.and.returnValue(true);
|
|
22
22
|
return network;
|
|
23
23
|
});
|
|
24
|
-
spyOn(Runtime, "getLocalStorage").
|
|
24
|
+
spyOn(Runtime, "getLocalStorage").and.returnValue({});
|
|
25
25
|
Transports = Runtime.Transports;
|
|
26
26
|
});
|
|
27
27
|
|
|
@@ -33,16 +33,16 @@ describe("Host/Port Configuration", function() {
|
|
|
33
33
|
var _WebSocket;
|
|
34
34
|
|
|
35
35
|
beforeEach(function() {
|
|
36
|
-
spyOn(Runtime, 'createWebSocket').
|
|
36
|
+
spyOn(Runtime, 'createWebSocket').and.returnValue(Mocks.getTransport());
|
|
37
37
|
|
|
38
|
-
spyOn(Transports.ws.hooks, "isInitialized").
|
|
39
|
-
spyOn(Transports.ws, "isSupported").
|
|
40
|
-
spyOn(Transports.xhr_streaming, "isSupported").
|
|
41
|
-
spyOn(Transports.xhr_polling, "isSupported").
|
|
38
|
+
spyOn(Transports.ws.hooks, "isInitialized").and.returnValue(true);
|
|
39
|
+
spyOn(Transports.ws, "isSupported").and.returnValue(true);
|
|
40
|
+
spyOn(Transports.xhr_streaming, "isSupported").and.returnValue(false);
|
|
41
|
+
spyOn(Transports.xhr_polling, "isSupported").and.returnValue(false);
|
|
42
42
|
|
|
43
43
|
if (TestEnv == "web") {
|
|
44
|
-
spyOn(Transports.xdr_streaming, "isSupported").
|
|
45
|
-
spyOn(Transports.xdr_polling, "isSupported").
|
|
44
|
+
spyOn(Transports.xdr_streaming, "isSupported").and.returnValue(false);
|
|
45
|
+
spyOn(Transports.xdr_polling, "isSupported").and.returnValue(false);
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
const TestEnv = require('testenv');
|
|
2
|
+
const Mocks = require('mocks');
|
|
3
|
+
const TransportConnection = require('core/transports/transport_connection').default;
|
|
4
|
+
const Collections = require('core/utils/collections');
|
|
5
|
+
const OneOffTimer = require('core/utils/timers').OneOffTimer;
|
|
6
|
+
const Dependencies = require('dom/dependencies').Dependencies;
|
|
7
|
+
const waitsFor = require('../../../helpers/waitsFor');
|
|
7
8
|
|
|
8
9
|
describe("TransportConnection", function() {
|
|
9
10
|
function getTransport(hooks, key, options) {
|
|
@@ -36,7 +37,7 @@ describe("TransportConnection", function() {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
timeline = Mocks.getTimeline();
|
|
39
|
-
timeline.generateUniqueID.
|
|
40
|
+
timeline.generateUniqueID.and.returnValue(667);
|
|
40
41
|
|
|
41
42
|
urls = {
|
|
42
43
|
getInitial: function(key, params) {
|
|
@@ -47,8 +48,8 @@ describe("TransportConnection", function() {
|
|
|
47
48
|
hooks = {
|
|
48
49
|
urls: urls,
|
|
49
50
|
supportsPing: false,
|
|
50
|
-
isInitialized: jasmine.createSpy().
|
|
51
|
-
getSocket: jasmine.createSpy().
|
|
51
|
+
isInitialized: jasmine.createSpy().and.returnValue(true),
|
|
52
|
+
getSocket: jasmine.createSpy().and.returnValue(socket)
|
|
52
53
|
};
|
|
53
54
|
|
|
54
55
|
transport = getTransport(hooks, "foo", {
|
|
@@ -110,7 +111,7 @@ describe("TransportConnection", function() {
|
|
|
110
111
|
beforeEach(function() {
|
|
111
112
|
hooks = {
|
|
112
113
|
supportsPing: false,
|
|
113
|
-
isInitialized: jasmine.createSpy().
|
|
114
|
+
isInitialized: jasmine.createSpy().and.returnValue(true)
|
|
114
115
|
};
|
|
115
116
|
transport = getTransport(hooks, "foo", {
|
|
116
117
|
timeline: timeline
|
|
@@ -134,8 +135,8 @@ describe("TransportConnection", function() {
|
|
|
134
135
|
beforeEach(function() {
|
|
135
136
|
hooks = {
|
|
136
137
|
file: "test",
|
|
137
|
-
isInitialized: jasmine.createSpy().
|
|
138
|
-
getSocket: jasmine.createSpy().
|
|
138
|
+
isInitialized: jasmine.createSpy().and.returnValue(false),
|
|
139
|
+
getSocket: jasmine.createSpy().and.returnValue(socket)
|
|
139
140
|
};
|
|
140
141
|
transport = getTransport(hooks, "foo", {
|
|
141
142
|
timeline: timeline
|
|
@@ -154,7 +155,7 @@ describe("TransportConnection", function() {
|
|
|
154
155
|
|
|
155
156
|
it("should load the resource file (useTLS=false)", function() {
|
|
156
157
|
transport.initialize();
|
|
157
|
-
expect(Dependencies.load.calls.
|
|
158
|
+
expect(Dependencies.load.calls.count()).toEqual(1);
|
|
158
159
|
expect(Dependencies.load).toHaveBeenCalledWith(
|
|
159
160
|
"test", { useTLS: false }, jasmine.any(Function)
|
|
160
161
|
);
|
|
@@ -167,7 +168,7 @@ describe("TransportConnection", function() {
|
|
|
167
168
|
});
|
|
168
169
|
|
|
169
170
|
transport.initialize();
|
|
170
|
-
expect(Dependencies.load.calls.
|
|
171
|
+
expect(Dependencies.load.calls.count()).toEqual(1);
|
|
171
172
|
expect(Dependencies.load).toHaveBeenCalledWith(
|
|
172
173
|
"test", { useTLS: true }, jasmine.any(Function)
|
|
173
174
|
);
|
|
@@ -184,9 +185,9 @@ describe("TransportConnection", function() {
|
|
|
184
185
|
|
|
185
186
|
transport.initialize();
|
|
186
187
|
// after loading the resource, isInitialized will return true
|
|
187
|
-
hooks.isInitialized.
|
|
188
|
+
hooks.isInitialized.and.returnValue(true);
|
|
188
189
|
// fire the callback for the resource file load
|
|
189
|
-
Dependencies.load.calls
|
|
190
|
+
Dependencies.load.calls.first().args[2](null, loadCallback);
|
|
190
191
|
});
|
|
191
192
|
|
|
192
193
|
it("should transition to 'initialized'", function() {
|
|
@@ -210,9 +211,9 @@ describe("TransportConnection", function() {
|
|
|
210
211
|
|
|
211
212
|
transport.initialize();
|
|
212
213
|
// after loading the resource, isInitialized will return true
|
|
213
|
-
hooks.isInitialized.
|
|
214
|
+
hooks.isInitialized.and.returnValue(false);
|
|
214
215
|
// fire the callback for the resource file load
|
|
215
|
-
Dependencies.load.calls
|
|
216
|
+
Dependencies.load.calls.first().args[2](null, loadCallback);
|
|
216
217
|
});
|
|
217
218
|
|
|
218
219
|
it("should transition to 'closed'", function() {
|
|
@@ -271,7 +272,7 @@ describe("TransportConnection", function() {
|
|
|
271
272
|
transport.initialize();
|
|
272
273
|
transport.connect();
|
|
273
274
|
expect(transport.state).toEqual("connecting");
|
|
274
|
-
expect(onConnecting.calls.
|
|
275
|
+
expect(onConnecting.calls.count()).toEqual(1);
|
|
275
276
|
});
|
|
276
277
|
|
|
277
278
|
it("should transition to 'open' after connection is established", function() {
|
|
@@ -283,55 +284,53 @@ describe("TransportConnection", function() {
|
|
|
283
284
|
socket.onopen();
|
|
284
285
|
|
|
285
286
|
expect(transport.state).toEqual("open");
|
|
286
|
-
expect(onOpen.calls.
|
|
287
|
+
expect(onOpen.calls.count()).toEqual(1);
|
|
287
288
|
});
|
|
288
289
|
|
|
289
|
-
it("should emit the error raised by getSocket", function() {
|
|
290
|
-
hooks.getSocket.
|
|
290
|
+
it("should emit the error raised by getSocket", async function() {
|
|
291
|
+
hooks.getSocket.and.throwError("test exception");
|
|
291
292
|
|
|
292
293
|
var onError = jasmine.createSpy("onError");
|
|
293
294
|
transport.bind("error", onError);
|
|
294
295
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
return onError.calls.length > 0;
|
|
296
|
+
transport.initialize();
|
|
297
|
+
transport.connect();
|
|
298
|
+
|
|
299
|
+
await waitsFor(function() {
|
|
300
|
+
return onError.calls.count();
|
|
301
301
|
}, "error to be emitted", 50);
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
302
|
+
|
|
303
|
+
expect(onError.calls.count()).toBeGreaterThan(0);
|
|
304
|
+
expect(onError.calls.count()).toEqual(1);
|
|
305
|
+
expect(onError).toHaveBeenCalledWith({
|
|
306
|
+
type: "WebSocketError",
|
|
307
|
+
error: new Error ("test exception")
|
|
308
308
|
});
|
|
309
309
|
});
|
|
310
310
|
|
|
311
|
-
it("should transition to 'closed' when getSocket raises an error", function() {
|
|
312
|
-
hooks.getSocket.
|
|
311
|
+
it("should transition to 'closed' when getSocket raises an error", async function() {
|
|
312
|
+
hooks.getSocket.and.throwError("test exception");
|
|
313
313
|
|
|
314
314
|
var onClosed = jasmine.createSpy("onClosed");
|
|
315
315
|
transport.bind("closed", onClosed);
|
|
316
316
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
return onClosed.calls.length > 0;
|
|
317
|
+
transport.initialize();
|
|
318
|
+
transport.connect();
|
|
319
|
+
|
|
320
|
+
await waitsFor(function () {
|
|
321
|
+
return onClosed.calls.count();
|
|
323
322
|
}, "transitioning to 'closed'", 50);
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
323
|
+
|
|
324
|
+
expect(onClosed.calls.count()).toBeGreaterThan(0);
|
|
325
|
+
expect(onClosed.calls.count()).toEqual(1);
|
|
326
|
+
expect(transport.state).toEqual("closed");
|
|
328
327
|
});
|
|
329
328
|
|
|
330
329
|
it("should be idempotent", function() {
|
|
331
330
|
transport.initialize();
|
|
332
331
|
|
|
333
332
|
transport.connect();
|
|
334
|
-
expect(hooks.getSocket.calls.
|
|
333
|
+
expect(hooks.getSocket.calls.count()).toEqual(1);
|
|
335
334
|
expect(transport.state).toEqual("connecting");
|
|
336
335
|
|
|
337
336
|
var onConnecting = jasmine.createSpy("onConnecting");
|
|
@@ -339,7 +338,7 @@ describe("TransportConnection", function() {
|
|
|
339
338
|
|
|
340
339
|
transport.connect();
|
|
341
340
|
expect(transport.state).toEqual("connecting");
|
|
342
|
-
expect(hooks.getSocket.calls.
|
|
341
|
+
expect(hooks.getSocket.calls.count()).toEqual(1);
|
|
343
342
|
expect(onConnecting).not.toHaveBeenCalled();
|
|
344
343
|
});
|
|
345
344
|
});
|
|
@@ -351,35 +350,29 @@ describe("TransportConnection", function() {
|
|
|
351
350
|
socket.onopen();
|
|
352
351
|
});
|
|
353
352
|
|
|
354
|
-
it("should defer sending data to the socket", function() {
|
|
355
|
-
|
|
356
|
-
socket.send = jasmine.createSpy("send").andCallFake(function() {
|
|
357
|
-
sendCalled = true;
|
|
358
|
-
});
|
|
353
|
+
it("should defer sending data to the socket", async function() {
|
|
354
|
+
socket.send.calls.reset();
|
|
359
355
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
waitsFor(function () {
|
|
365
|
-
return
|
|
356
|
+
expect(socket.send).not.toHaveBeenCalled();
|
|
357
|
+
|
|
358
|
+
let sendCall = transport.send('foobar');
|
|
359
|
+
|
|
360
|
+
await waitsFor(function () {
|
|
361
|
+
return socket.send.calls.count();
|
|
366
362
|
}, "socket.send to be called", 50);
|
|
367
|
-
runs(function() {
|
|
368
|
-
expect(socket.send).toHaveBeenCalledWith("foobar");
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
363
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
364
|
+
expect(sendCall).toBe(true);
|
|
365
|
+
expect(socket.send.calls.count()).toEqual(1);
|
|
366
|
+
expect(socket.send).toHaveBeenCalledWith("foobar");
|
|
367
|
+
});
|
|
376
368
|
|
|
377
|
-
|
|
378
|
-
|
|
369
|
+
it("should not crash when socket is closed before next tick (will log to console only)", async function() {
|
|
370
|
+
transport.send("foobar");
|
|
371
|
+
transport.close();
|
|
372
|
+
socket.onclose({ wasClean: true });
|
|
373
|
+
var timer = new OneOffTimer(100, function() {});
|
|
379
374
|
|
|
380
|
-
|
|
381
|
-
});
|
|
382
|
-
waitsFor(function () {
|
|
375
|
+
await waitsFor(function () {
|
|
383
376
|
return !timer.isRunning();
|
|
384
377
|
}, "timer to run", 500);
|
|
385
378
|
});
|
|
@@ -393,8 +386,8 @@ describe("TransportConnection", function() {
|
|
|
393
386
|
var hooks = {
|
|
394
387
|
urls: urls,
|
|
395
388
|
supportsPing: true,
|
|
396
|
-
isInitialized: jasmine.createSpy().
|
|
397
|
-
getSocket: jasmine.createSpy().
|
|
389
|
+
isInitialized: jasmine.createSpy().and.returnValue(true),
|
|
390
|
+
getSocket: jasmine.createSpy().and.returnValue(socket)
|
|
398
391
|
};
|
|
399
392
|
var transport = getTransport(hooks, "foo", {
|
|
400
393
|
timeline: timeline
|
|
@@ -414,8 +407,8 @@ describe("TransportConnection", function() {
|
|
|
414
407
|
var hooks = {
|
|
415
408
|
urls: urls,
|
|
416
409
|
supportsPing: false,
|
|
417
|
-
isInitialized: jasmine.createSpy().
|
|
418
|
-
getSocket: jasmine.createSpy().
|
|
410
|
+
isInitialized: jasmine.createSpy().and.returnValue(true),
|
|
411
|
+
getSocket: jasmine.createSpy().and.returnValue(socket)
|
|
419
412
|
};
|
|
420
413
|
var transport = getTransport(hooks, "foo", {
|
|
421
414
|
timeline: timeline
|
|
@@ -443,7 +436,7 @@ describe("TransportConnection", function() {
|
|
|
443
436
|
expect(onClosed).not.toHaveBeenCalled();
|
|
444
437
|
|
|
445
438
|
socket.onclose({ wasClean: true });
|
|
446
|
-
expect(onClosed).toHaveBeenCalledWith({ wasClean: true });
|
|
439
|
+
expect(onClosed).toHaveBeenCalledWith({ wasClean: true, code: undefined, reason: undefined });
|
|
447
440
|
});
|
|
448
441
|
|
|
449
442
|
it("should not fail if not open", function() {
|
|
@@ -477,8 +470,8 @@ describe("TransportConnection", function() {
|
|
|
477
470
|
hooks = {
|
|
478
471
|
urls: urls,
|
|
479
472
|
supportsPing: true,
|
|
480
|
-
isInitialized: jasmine.createSpy().
|
|
481
|
-
getSocket: jasmine.createSpy().
|
|
473
|
+
isInitialized: jasmine.createSpy().and.returnValue(true),
|
|
474
|
+
getSocket: jasmine.createSpy().and.returnValue(socket)
|
|
482
475
|
};
|
|
483
476
|
transport = getTransport(hooks, "foo", {
|
|
484
477
|
timeline: timeline
|
|
@@ -517,7 +510,7 @@ describe("TransportConnection", function() {
|
|
|
517
510
|
test: "We're doomed"
|
|
518
511
|
}
|
|
519
512
|
});
|
|
520
|
-
expect(onError.calls.
|
|
513
|
+
expect(onError.calls.count()).toEqual(1);
|
|
521
514
|
});
|
|
522
515
|
|
|
523
516
|
it("should emit a closed event with correct params", function() {
|
|
@@ -536,7 +529,7 @@ describe("TransportConnection", function() {
|
|
|
536
529
|
reason: "testing",
|
|
537
530
|
wasClean: true
|
|
538
531
|
});
|
|
539
|
-
expect(onClosed.calls.
|
|
532
|
+
expect(onClosed.calls.count()).toEqual(1);
|
|
540
533
|
expect(transport.state).toEqual("closed");
|
|
541
534
|
});
|
|
542
535
|
|
|
@@ -547,7 +540,7 @@ describe("TransportConnection", function() {
|
|
|
547
540
|
socket.onclose();
|
|
548
541
|
|
|
549
542
|
expect(onClosed).toHaveBeenCalled();
|
|
550
|
-
expect(onClosed.calls.
|
|
543
|
+
expect(onClosed.calls.count()).toEqual(1);
|
|
551
544
|
});
|
|
552
545
|
|
|
553
546
|
it("should log an error as a string to timeline", function() {
|
|
@@ -563,22 +556,24 @@ describe("TransportConnection", function() {
|
|
|
563
556
|
it("should log the new state to timeline", function() {
|
|
564
557
|
transport.initialize();
|
|
565
558
|
|
|
566
|
-
expect(timeline.info.calls.
|
|
559
|
+
expect(timeline.info.calls.count()).toEqual(2);
|
|
567
560
|
expect(timeline.info).toHaveBeenCalledWith({
|
|
568
561
|
cid: 667,
|
|
569
562
|
transport: "test"
|
|
570
563
|
});
|
|
571
564
|
expect(timeline.info).toHaveBeenCalledWith({
|
|
572
565
|
cid: 667,
|
|
573
|
-
state: "initialized"
|
|
566
|
+
state: "initialized",
|
|
567
|
+
params: undefined,
|
|
574
568
|
});
|
|
575
569
|
|
|
576
570
|
transport.connect();
|
|
577
571
|
|
|
578
|
-
expect(timeline.info.calls.
|
|
572
|
+
expect(timeline.info.calls.count()).toEqual(3);
|
|
579
573
|
expect(timeline.info).toHaveBeenCalledWith({
|
|
580
574
|
cid: 667,
|
|
581
|
-
state: "connecting"
|
|
575
|
+
state: "connecting",
|
|
576
|
+
params: undefined,
|
|
582
577
|
});
|
|
583
578
|
});
|
|
584
579
|
});
|