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
|
@@ -23,23 +23,25 @@ module.exports = function() {
|
|
|
23
23
|
var pusher;
|
|
24
24
|
|
|
25
25
|
beforeEach(function() {
|
|
26
|
-
|
|
26
|
+
jasmine.clock().install();
|
|
27
27
|
|
|
28
|
-
spyOn(
|
|
29
|
-
spyOn(transports[BASE_FALLBACK], "isSupported").andReturn(false);
|
|
28
|
+
spyOn(Network, "isOnline").and.returnValue(true);
|
|
30
29
|
|
|
31
|
-
spyOn(
|
|
30
|
+
spyOn(transports.ws, "isSupported").and.returnValue(true);
|
|
31
|
+
spyOn(transports[BASE_FALLBACK], "isSupported").and.returnValue(false);
|
|
32
32
|
|
|
33
|
-
spyOn(
|
|
33
|
+
spyOn(Runtime, "getLocalStorage").and.returnValue({});
|
|
34
|
+
|
|
35
|
+
spyOn(transports.ws, "createConnection").and.callFake(function() {
|
|
34
36
|
transport = Mocks.getTransport(true);
|
|
35
|
-
transport.supportsPing.
|
|
37
|
+
transport.supportsPing.and.returnValue(false);
|
|
36
38
|
return transport;
|
|
37
39
|
});
|
|
38
|
-
jasmine.Clock.useMock();
|
|
39
40
|
});
|
|
40
41
|
|
|
41
42
|
afterEach(function() {
|
|
42
43
|
pusher.disconnect();
|
|
44
|
+
jasmine.clock().uninstall();
|
|
43
45
|
});
|
|
44
46
|
|
|
45
47
|
it("should transition to unavailable after default timeout", function() {
|
|
@@ -49,9 +51,9 @@ module.exports = function() {
|
|
|
49
51
|
pusher.connect();
|
|
50
52
|
pusher.connection.bind("unavailable", onUnavailable);
|
|
51
53
|
|
|
52
|
-
jasmine.
|
|
54
|
+
jasmine.clock().tick(Defaults.unavailableTimeout - 1);
|
|
53
55
|
expect(onUnavailable).not.toHaveBeenCalled();
|
|
54
|
-
jasmine.
|
|
56
|
+
jasmine.clock().tick(1);
|
|
55
57
|
expect(onUnavailable).toHaveBeenCalled();
|
|
56
58
|
});
|
|
57
59
|
|
|
@@ -62,9 +64,9 @@ module.exports = function() {
|
|
|
62
64
|
pusher.connect();
|
|
63
65
|
pusher.connection.bind("unavailable", onUnavailable);
|
|
64
66
|
|
|
65
|
-
jasmine.
|
|
67
|
+
jasmine.clock().tick(2344);
|
|
66
68
|
expect(onUnavailable).not.toHaveBeenCalled();
|
|
67
|
-
jasmine.
|
|
69
|
+
jasmine.clock().tick(1);
|
|
68
70
|
expect(onUnavailable).toHaveBeenCalled();
|
|
69
71
|
});
|
|
70
72
|
|
|
@@ -89,14 +91,14 @@ module.exports = function() {
|
|
|
89
91
|
});
|
|
90
92
|
|
|
91
93
|
expect(pusher.connection.state).toEqual("connected");
|
|
92
|
-
jasmine.
|
|
94
|
+
jasmine.clock().tick(12000 - 1);
|
|
93
95
|
expect(firstTransport.send).not.toHaveBeenCalled();
|
|
94
|
-
jasmine.
|
|
96
|
+
jasmine.clock().tick(1);
|
|
95
97
|
expect(firstTransport.send).toHaveBeenCalled();
|
|
96
98
|
|
|
97
|
-
jasmine.
|
|
99
|
+
jasmine.clock().tick(Defaults.pongTimeout - 1);
|
|
98
100
|
expect(firstTransport.close).not.toHaveBeenCalled();
|
|
99
|
-
jasmine.
|
|
101
|
+
jasmine.clock().tick(2);
|
|
100
102
|
expect(firstTransport.close).toHaveBeenCalled();
|
|
101
103
|
});
|
|
102
104
|
|
|
@@ -124,9 +126,9 @@ module.exports = function() {
|
|
|
124
126
|
});
|
|
125
127
|
|
|
126
128
|
expect(pusher.connection.state).toEqual("connected");
|
|
127
|
-
jasmine.
|
|
129
|
+
jasmine.clock().tick(15000 - 1);
|
|
128
130
|
expect(firstTransport.send).not.toHaveBeenCalled();
|
|
129
|
-
jasmine.
|
|
131
|
+
jasmine.clock().tick(1);
|
|
130
132
|
expect(firstTransport.send).toHaveBeenCalled();
|
|
131
133
|
});
|
|
132
134
|
|
|
@@ -154,9 +156,9 @@ module.exports = function() {
|
|
|
154
156
|
});
|
|
155
157
|
|
|
156
158
|
expect(pusher.connection.state).toEqual("connected");
|
|
157
|
-
jasmine.
|
|
159
|
+
jasmine.clock().tick(15555 - 1);
|
|
158
160
|
expect(firstTransport.send).not.toHaveBeenCalled();
|
|
159
|
-
jasmine.
|
|
161
|
+
jasmine.clock().tick(1);
|
|
160
162
|
expect(firstTransport.send).toHaveBeenCalled();
|
|
161
163
|
});
|
|
162
164
|
|
|
@@ -183,11 +185,11 @@ module.exports = function() {
|
|
|
183
185
|
});
|
|
184
186
|
|
|
185
187
|
// first, send the ping
|
|
186
|
-
jasmine.
|
|
188
|
+
jasmine.clock().tick(120000);
|
|
187
189
|
// wait for the pong timeout
|
|
188
|
-
jasmine.
|
|
190
|
+
jasmine.clock().tick(2221);
|
|
189
191
|
expect(firstTransport.close).not.toHaveBeenCalled();
|
|
190
|
-
jasmine.
|
|
192
|
+
jasmine.clock().tick(2);
|
|
191
193
|
expect(firstTransport.close).toHaveBeenCalled();
|
|
192
194
|
});
|
|
193
195
|
});
|
|
@@ -20,18 +20,18 @@ module.exports = function() {
|
|
|
20
20
|
var _isReady = Pusher.isReady;
|
|
21
21
|
|
|
22
22
|
beforeEach(function() {
|
|
23
|
-
spyOn(transports.ws, "isSupported").
|
|
24
|
-
spyOn(transports.xhr_streaming, "isSupported").
|
|
25
|
-
spyOn(transports[BASE_FALLBACK], "isSupported").
|
|
23
|
+
spyOn(transports.ws, "isSupported").and.returnValue(true);
|
|
24
|
+
spyOn(transports.xhr_streaming, "isSupported").and.returnValue(true);
|
|
25
|
+
spyOn(transports[BASE_FALLBACK], "isSupported").and.returnValue(true);
|
|
26
26
|
|
|
27
27
|
spyOn(transports.ws, "createConnection")
|
|
28
|
-
.
|
|
28
|
+
.and.callFake(Mocks.getTransport);
|
|
29
29
|
spyOn(transports.xhr_streaming, "createConnection")
|
|
30
|
-
.
|
|
30
|
+
.and.callFake(Mocks.getTransport);
|
|
31
31
|
spyOn(transports[BASE_FALLBACK], "createConnection")
|
|
32
|
-
.
|
|
32
|
+
.and.callFake(Mocks.getTransport);
|
|
33
33
|
|
|
34
|
-
spyOn(Runtime, "getDefaultStrategy").
|
|
34
|
+
spyOn(Runtime, "getDefaultStrategy").and.callFake(function(config) {
|
|
35
35
|
return new BestConnectedEverStrategy([
|
|
36
36
|
defineTransport(config, 'a', 'ws', 1, {}),
|
|
37
37
|
defineTransport(config, 'b', 'xhr_streaming', 2, {}),
|
|
@@ -39,7 +39,7 @@ module.exports = function() {
|
|
|
39
39
|
]);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
spyOn(Network, "isOnline").
|
|
42
|
+
spyOn(Network, "isOnline").and.returnValue(true);
|
|
43
43
|
Pusher.isReady = true;
|
|
44
44
|
});
|
|
45
45
|
|
|
@@ -1,99 +1,97 @@
|
|
|
1
|
-
|
|
1
|
+
const Pusher = require('pusher_integration');
|
|
2
2
|
window.Pusher = Pusher;
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const Integration = require('integration');
|
|
5
|
+
const JSONPRequest = require('dom/jsonp_request').default;
|
|
6
|
+
const waitsFor = require('../../../helpers/waitsFor');
|
|
6
7
|
|
|
7
8
|
Integration.describe("JSONP", function() {
|
|
8
|
-
it("should send a request and receive a correct response", function() {
|
|
9
|
+
it("should send a request and receive a correct response", async function() {
|
|
9
10
|
var callback = jasmine.createSpy();
|
|
10
11
|
var receiver = Pusher.ScriptReceivers.create(callback);
|
|
11
12
|
var url = Integration.API_URL + "/v2/jsonp/echo";
|
|
12
13
|
var request;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
]
|
|
31
|
-
});
|
|
32
|
-
request.send(receiver);
|
|
15
|
+
request = new JSONPRequest(url, {
|
|
16
|
+
"session": 2289545,
|
|
17
|
+
"features": ["ws", "sockjs"],
|
|
18
|
+
"version": "1.13.0",
|
|
19
|
+
"t0": 1355850357911,
|
|
20
|
+
"timeline": [
|
|
21
|
+
{ t: 0, e: 2 },
|
|
22
|
+
{ t: 2, e: 2, type: "ws" },
|
|
23
|
+
{ t: 1001, e: 4, type: "ws" },
|
|
24
|
+
{ t: 1001, e: 0, type: "sockjs" },
|
|
25
|
+
{ t: 2000, e: 5 },
|
|
26
|
+
{ t: 2158, e: 1, type: "sockjs" },
|
|
27
|
+
{ t: 2378, e: 2, type: "sockjs" },
|
|
28
|
+
{ t: 3892, e: 3, type: "sockjs" },
|
|
29
|
+
{ t: 3892, e: 3 }
|
|
30
|
+
]
|
|
33
31
|
});
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
request.send(receiver);
|
|
33
|
+
|
|
34
|
+
await waitsFor(function() {
|
|
35
|
+
return callback.calls.count() > 0;
|
|
36
36
|
}, "JSONP to respond", 5000);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
request.cleanup()
|
|
37
|
+
|
|
38
|
+
expect(callback.calls.count()).toEqual(1);
|
|
39
|
+
expect(callback).toHaveBeenCalledWith(null, {
|
|
40
|
+
"session": "2289545",
|
|
41
|
+
"features": ["ws", "sockjs"],
|
|
42
|
+
"version": "1.13.0",
|
|
43
|
+
"t0": "1355850357911",
|
|
44
|
+
"timeline": [
|
|
45
|
+
{ t: 0, e: 2 },
|
|
46
|
+
{ t: 2, e: 2, type: "ws" },
|
|
47
|
+
{ t: 1001, e: 4, type: "ws" },
|
|
48
|
+
{ t: 1001, e: 0, type: "sockjs" },
|
|
49
|
+
{ t: 2000, e: 5 },
|
|
50
|
+
{ t: 2158, e: 1, type: "sockjs" },
|
|
51
|
+
{ t: 2378, e: 2, type: "sockjs" },
|
|
52
|
+
{ t: 3892, e: 3, type: "sockjs" },
|
|
53
|
+
{ t: 3892, e: 3 }
|
|
54
|
+
]
|
|
57
55
|
});
|
|
56
|
+
|
|
57
|
+
request.cleanup()
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
it("should call back without a result on 404 response", function() {
|
|
60
|
+
it("should call back without a result on 404 response", async function() {
|
|
61
61
|
var callback = jasmine.createSpy();
|
|
62
62
|
var receiver = Pusher.ScriptReceivers.create(callback);
|
|
63
63
|
var url = Integration.API_URL + "/jsonp/404";
|
|
64
64
|
var request;
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return callback.calls.length > 0;
|
|
66
|
+
request = new JSONPRequest(url, {});
|
|
67
|
+
request.send(receiver);
|
|
68
|
+
|
|
69
|
+
await waitsFor(function() {
|
|
70
|
+
return callback.calls.count() > 0;
|
|
72
71
|
}, "JSONP to respond", 5000);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
|
|
73
|
+
expect(callback.calls.count()).toEqual(1);
|
|
74
|
+
expect(callback.calls.first().args[1]).toBe(undefined);
|
|
75
|
+
|
|
76
|
+
request.cleanup();
|
|
78
77
|
});
|
|
79
78
|
|
|
80
|
-
it("should call back without a result on 500 response", function() {
|
|
79
|
+
it("should call back without a result on 500 response", async function() {
|
|
81
80
|
var callback = jasmine.createSpy();
|
|
82
81
|
var receiver = Pusher.ScriptReceivers.create(callback);
|
|
83
82
|
var url = Integration.API_URL + "/jsonp/500";
|
|
84
83
|
var request;
|
|
85
84
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return callback.calls.length > 0;
|
|
85
|
+
request = new JSONPRequest(url, {});
|
|
86
|
+
request.send(receiver);
|
|
87
|
+
|
|
88
|
+
await waitsFor(function() {
|
|
89
|
+
return callback.calls.count() > 0;
|
|
92
90
|
}, "JSONP to respond", 5000);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
|
|
92
|
+
expect(callback.calls.count()).toEqual(1);
|
|
93
|
+
expect(callback.calls.first().args[1]).toBe(undefined);
|
|
94
|
+
|
|
95
|
+
request.cleanup();
|
|
98
96
|
});
|
|
99
97
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
const Pusher = require('pusher_integration');
|
|
2
2
|
window.Pusher = Pusher;
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const Integration = require('integration');
|
|
5
|
+
const ScriptRequest = require('dom/script_request').default;
|
|
6
|
+
const waitsFor = require('../../../helpers/waitsFor');
|
|
7
7
|
|
|
8
8
|
Integration.describe("ScriptRequest", function() {
|
|
9
9
|
var callback, receiver;
|
|
@@ -23,20 +23,18 @@ Integration.describe("ScriptRequest", function() {
|
|
|
23
23
|
request.cleanup();
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
it("should send a request and receive a correct response", function() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return callback.calls.length > 0;
|
|
26
|
+
it("should send a request and receive a correct response", async function() {
|
|
27
|
+
request.send(receiver);
|
|
28
|
+
|
|
29
|
+
await waitsFor(function() {
|
|
30
|
+
return callback.calls.count() > 0;
|
|
32
31
|
}, "endpoint to respond", 5000);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
32
|
+
|
|
33
|
+
expect(callback.calls.count()).toEqual(1);
|
|
34
|
+
expect(callback).toHaveBeenCalledWith(null, { param: "test" });
|
|
37
35
|
});
|
|
38
36
|
|
|
39
|
-
it("should allow cleaning up", function() {
|
|
37
|
+
it("should allow cleaning up", async function() {
|
|
40
38
|
var callback = jasmine.createSpy();
|
|
41
39
|
var receiver = Pusher.Integration.ScriptReceivers.create(callback);
|
|
42
40
|
var query = "receiver=" + receiver.name;
|
|
@@ -44,55 +42,49 @@ Integration.describe("ScriptRequest", function() {
|
|
|
44
42
|
|
|
45
43
|
var request = new ScriptRequest(url);
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return callback.calls.length > 0;
|
|
45
|
+
expect(document.getElementById(receiver.id)).toBe(null);
|
|
46
|
+
expect(document.getElementById(receiver.id + "_error")).toBe(null);
|
|
47
|
+
request.send(receiver);
|
|
48
|
+
// we don't test for the _error tag, because it's Opera-specific
|
|
49
|
+
expect(document.getElementById(receiver.id)).not.toBe(null);
|
|
50
|
+
|
|
51
|
+
await waitsFor(function() {
|
|
52
|
+
return callback.calls.count() > 0;
|
|
56
53
|
}, "endpoint to respond", 5000);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
54
|
+
|
|
55
|
+
expect(document.getElementById(receiver.id)).not.toBe(null);
|
|
56
|
+
request.cleanup();
|
|
57
|
+
expect(document.getElementById(receiver.id)).toBe(null);
|
|
58
|
+
expect(document.getElementById(receiver.id + "_error")).toBe(null);
|
|
63
59
|
});
|
|
64
60
|
|
|
65
|
-
it("should call back without result on a 404 response", function() {
|
|
61
|
+
it("should call back without result on a 404 response", async function() {
|
|
66
62
|
var url = Integration.API_URL + "/jsonp/404/" + receiver.number;
|
|
67
63
|
var request = new ScriptRequest(url);
|
|
68
64
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return callback.calls.length > 0;
|
|
65
|
+
request.send(receiver);
|
|
66
|
+
|
|
67
|
+
await waitsFor(function() {
|
|
68
|
+
return callback.calls.count() > 0;
|
|
74
69
|
}, "endpoint to respond", 5000);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
70
|
+
|
|
71
|
+
expect(callback.calls.count()).toEqual(1);
|
|
72
|
+
expect(callback.calls.first().args[1]).toBe(undefined);
|
|
73
|
+
request.cleanup();
|
|
80
74
|
});
|
|
81
75
|
|
|
82
|
-
it("should call back without result on a 500 response", function() {
|
|
76
|
+
it("should call back without result on a 500 response", async function() {
|
|
83
77
|
var url = Integration.API_URL + "/jsonp/500/" + receiver.number;
|
|
84
78
|
var request = new ScriptRequest(url);
|
|
85
79
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return callback.calls.length > 0;
|
|
80
|
+
request.send(receiver);
|
|
81
|
+
|
|
82
|
+
await waitsFor(function() {
|
|
83
|
+
return callback.calls.count() > 0;
|
|
91
84
|
}, "endpoint to respond", 5000);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
85
|
+
|
|
86
|
+
expect(callback.calls.count()).toEqual(1);
|
|
87
|
+
expect(callback.calls.first().args[1]).toBe(undefined);
|
|
88
|
+
request.cleanup();
|
|
97
89
|
});
|
|
98
90
|
});
|
|
@@ -38,19 +38,9 @@ describe("Channel", function() {
|
|
|
38
38
|
beforeEach(function() {
|
|
39
39
|
channel.subscribed = true;
|
|
40
40
|
});
|
|
41
|
+
|
|
41
42
|
it("should raise an exception if the event name does not start with client-", function() {
|
|
42
|
-
|
|
43
|
-
// (exception.message || exception) with (expected.message || expected)
|
|
44
|
-
// the thrown exception has a message so it's passed to the matcher. The
|
|
45
|
-
// message is a string, and *not* an instanceof the expected class
|
|
46
|
-
// https://github.com/jasmine/jasmine/blob/v1.3.1/src/core/Matchers.js#L331-L333
|
|
47
|
-
var exception;
|
|
48
|
-
try {
|
|
49
|
-
channel.trigger("whatever", {});
|
|
50
|
-
} catch(e) {
|
|
51
|
-
exception = e;
|
|
52
|
-
}
|
|
53
|
-
expect(exception).toMatch(jasmine.any(Errors.BadEventName))
|
|
43
|
+
expect(() => channel.trigger('whatever', {})).toThrow(jasmine.any(Errors.BadEventName));
|
|
54
44
|
});
|
|
55
45
|
|
|
56
46
|
it("should call send_event on connection", function() {
|
|
@@ -60,12 +50,12 @@ describe("Channel", function() {
|
|
|
60
50
|
});
|
|
61
51
|
|
|
62
52
|
it("should return true if connection sent the event", function() {
|
|
63
|
-
pusher.send_event.
|
|
53
|
+
pusher.send_event.and.returnValue(true);
|
|
64
54
|
expect(channel.trigger("client-test", {})).toBe(true);
|
|
65
55
|
});
|
|
66
56
|
|
|
67
57
|
it("should return false if connection didn't send the event", function() {
|
|
68
|
-
pusher.send_event.
|
|
58
|
+
pusher.send_event.and.returnValue(false);
|
|
69
59
|
expect(channel.trigger("client-test", {})).toBe(false);
|
|
70
60
|
});
|
|
71
61
|
});
|
|
@@ -81,7 +71,7 @@ describe("Channel", function() {
|
|
|
81
71
|
|
|
82
72
|
it("should set subscriptionPending to false", function() {
|
|
83
73
|
channel.subscriptionPending = true;
|
|
84
|
-
|
|
74
|
+
|
|
85
75
|
channel.disconnect();
|
|
86
76
|
|
|
87
77
|
expect(channel.subscriptionPending).toEqual(false);
|
|
@@ -216,10 +206,10 @@ describe("Channel", function() {
|
|
|
216
206
|
});
|
|
217
207
|
|
|
218
208
|
it("should authorize the connection first", function() {
|
|
219
|
-
expect(channel.authorize.calls.
|
|
209
|
+
expect(channel.authorize.calls.count()).toEqual(0);
|
|
220
210
|
channel.subscribe();
|
|
221
211
|
|
|
222
|
-
expect(channel.authorize.calls.
|
|
212
|
+
expect(channel.authorize.calls.count()).toEqual(1);
|
|
223
213
|
expect(channel.authorize).toHaveBeenCalledWith(
|
|
224
214
|
"9.37", jasmine.any(Function)
|
|
225
215
|
);
|
|
@@ -229,7 +219,7 @@ describe("Channel", function() {
|
|
|
229
219
|
expect(pusher.send_event).not.toHaveBeenCalled();
|
|
230
220
|
|
|
231
221
|
channel.subscribe();
|
|
232
|
-
var authorizeCallback = channel.authorize.calls
|
|
222
|
+
var authorizeCallback = channel.authorize.calls.first().args[1];
|
|
233
223
|
authorizeCallback(false, {
|
|
234
224
|
auth: "one",
|
|
235
225
|
channel_data: "two"
|
|
@@ -246,7 +236,7 @@ describe("Channel", function() {
|
|
|
246
236
|
channel.bind("pusher:subscription_error", onSubscriptionError);
|
|
247
237
|
|
|
248
238
|
channel.subscribe();
|
|
249
|
-
var authorizeCallback = channel.authorize.calls
|
|
239
|
+
var authorizeCallback = channel.authorize.calls.first().args[1];
|
|
250
240
|
authorizeCallback(new Error("test error"), {auth: ""})
|
|
251
241
|
|
|
252
242
|
expect(onSubscriptionError).toHaveBeenCalledWith(
|
|
@@ -270,7 +260,7 @@ describe("Channel", function() {
|
|
|
270
260
|
expect(channel.subscriptionPending).toEqual(false);
|
|
271
261
|
|
|
272
262
|
channel.subscribe();
|
|
273
|
-
var authorizeCallback = channel.authorize.calls
|
|
263
|
+
var authorizeCallback = channel.authorize.calls.first().args[1];
|
|
274
264
|
authorizeCallback(new Error("test error"), {auth: ""})
|
|
275
265
|
|
|
276
266
|
expect(channel.subscriptionPending).toEqual(false);
|
|
@@ -280,7 +270,7 @@ describe("Channel", function() {
|
|
|
280
270
|
expect(channel.subscriptionPending).toEqual(false);
|
|
281
271
|
|
|
282
272
|
channel.subscribe();
|
|
283
|
-
var authorizeCallback = channel.authorize.calls
|
|
273
|
+
var authorizeCallback = channel.authorize.calls.first().args[1];
|
|
284
274
|
authorizeCallback(false, {
|
|
285
275
|
auth: "one",
|
|
286
276
|
channel_data: "two"
|
|
@@ -28,7 +28,7 @@ describe("EncryptedChannel", function() {
|
|
|
28
28
|
pusher = Mocks.getPusher({ foo: "bar" });
|
|
29
29
|
channel = new EncryptedChannel("private-encrypted-test", pusher, nacl);
|
|
30
30
|
authorizer = Mocks.getAuthorizer();
|
|
31
|
-
factorySpy = spyOn(Factory, "createAuthorizer").
|
|
31
|
+
factorySpy = spyOn(Factory, "createAuthorizer").and.returnValue(authorizer);
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
describe("after construction", function() {
|
|
@@ -48,7 +48,7 @@ describe("EncryptedChannel", function() {
|
|
|
48
48
|
describe("#authorize", function() {
|
|
49
49
|
it("should create and call an authorizer", function() {
|
|
50
50
|
channel.authorize("1.23", function() {});
|
|
51
|
-
expect(Factory.createAuthorizer.calls.
|
|
51
|
+
expect(Factory.createAuthorizer.calls.count()).toEqual(1);
|
|
52
52
|
expect(Factory.createAuthorizer).toHaveBeenCalledWith(channel, {
|
|
53
53
|
foo: "bar"
|
|
54
54
|
});
|
|
@@ -73,8 +73,9 @@ describe("EncryptedChannel", function() {
|
|
|
73
73
|
});
|
|
74
74
|
// For some reason comparing the Error types doesn't work properly in
|
|
75
75
|
// Safari on Mojave. Manually check the arguments.
|
|
76
|
-
expect(callback.calls.
|
|
77
|
-
let args = callback.calls
|
|
76
|
+
expect(callback.calls.count()).toEqual(1)
|
|
77
|
+
let args = callback.calls.first().args;
|
|
78
|
+
|
|
78
79
|
expect(args.length).toEqual(2)
|
|
79
80
|
expect(args[0]).toEqual(jasmine.any(Error))
|
|
80
81
|
expect(args[0].message).toEqual(
|
|
@@ -91,7 +92,7 @@ describe("EncryptedChannel", function() {
|
|
|
91
92
|
}
|
|
92
93
|
});
|
|
93
94
|
channel = new EncryptedChannel("private-test-custom-auth", pusher, nacl);
|
|
94
|
-
factorySpy.
|
|
95
|
+
factorySpy.and.callThrough();
|
|
95
96
|
});
|
|
96
97
|
|
|
97
98
|
it("should call the authorizer", function() {
|
|
@@ -112,18 +113,9 @@ describe("EncryptedChannel", function() {
|
|
|
112
113
|
channel.authorize("1.23", callback);
|
|
113
114
|
});
|
|
114
115
|
it("should raise an exception if called", function() {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// message is a string, and *not* an instanceof the expected class
|
|
119
|
-
// https://github.com/jasmine/jasmine/blob/v1.3.1/src/core/Matchers.js#L331-L333
|
|
120
|
-
var exception;
|
|
121
|
-
try {
|
|
122
|
-
channel.trigger("whatever", {});
|
|
123
|
-
} catch(e) {
|
|
124
|
-
exception = e;
|
|
125
|
-
}
|
|
126
|
-
expect(exception).toMatch(jasmine.any(Errors.UnsupportedFeature));
|
|
116
|
+
expect(() => channel.trigger('whatever', {})).toThrow(
|
|
117
|
+
jasmine.any(Errors.UnsupportedFeature)
|
|
118
|
+
);
|
|
127
119
|
});
|
|
128
120
|
});
|
|
129
121
|
|