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
|
@@ -10,9 +10,9 @@ describe("HTTP.getXHR", function() {
|
|
|
10
10
|
beforeEach(function() {
|
|
11
11
|
HTTPFactory = require('runtime').default.HTTPFactory;
|
|
12
12
|
|
|
13
|
-
spyOn(Runtime, 'getXHRAPI').
|
|
13
|
+
spyOn(Runtime, 'getXHRAPI').and.returnValue(Mocks.getXHR);
|
|
14
14
|
|
|
15
|
-
spyOn(HTTPFactory, "createRequest").
|
|
15
|
+
spyOn(HTTPFactory, "createRequest").and.callFake(function(h, m, u) {
|
|
16
16
|
hooks = h;
|
|
17
17
|
return Mocks.getHTTPRequest(m, u);
|
|
18
18
|
});
|
|
@@ -64,7 +64,7 @@ describe("HTTP.getXHR", function() {
|
|
|
64
64
|
xhr.responseText = "asdf";
|
|
65
65
|
|
|
66
66
|
xhr.onreadystatechange();
|
|
67
|
-
expect(socket.onChunk.calls.
|
|
67
|
+
expect(socket.onChunk.calls.count()).toEqual(1);
|
|
68
68
|
expect(socket.onChunk).toHaveBeenCalledWith(201, "asdf");
|
|
69
69
|
});
|
|
70
70
|
|
|
@@ -73,12 +73,12 @@ describe("HTTP.getXHR", function() {
|
|
|
73
73
|
xhr.responseText = "asdf";
|
|
74
74
|
|
|
75
75
|
xhr.onreadystatechange();
|
|
76
|
-
expect(socket.onChunk.calls.
|
|
76
|
+
expect(socket.onChunk.calls.count()).toEqual(1);
|
|
77
77
|
expect(socket.onChunk).toHaveBeenCalledWith(201, "asdf");
|
|
78
78
|
|
|
79
79
|
xhr.responseText = "asdfghjkl";
|
|
80
80
|
xhr.onreadystatechange();
|
|
81
|
-
expect(socket.onChunk.calls.
|
|
81
|
+
expect(socket.onChunk.calls.count()).toEqual(2);
|
|
82
82
|
expect(socket.onChunk).toHaveBeenCalledWith(201, "asdfghjkl");
|
|
83
83
|
});
|
|
84
84
|
});
|
|
@@ -93,7 +93,7 @@ describe("HTTP.getXHR", function() {
|
|
|
93
93
|
xhr.responseText = "";
|
|
94
94
|
|
|
95
95
|
xhr.onreadystatechange();
|
|
96
|
-
expect(socket.close.calls.
|
|
96
|
+
expect(socket.close.calls.count()).toEqual(1);
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
it("should not call socket.onChunk if there is no responseText", function() {
|
|
@@ -116,8 +116,8 @@ describe("HTTP.getXHR", function() {
|
|
|
116
116
|
xhr.status = 234;
|
|
117
117
|
xhr.responseText = "12356890";
|
|
118
118
|
|
|
119
|
-
socket.close.
|
|
120
|
-
expect(socket.onChunk.calls.
|
|
119
|
+
socket.close.and.callFake(function() {
|
|
120
|
+
expect(socket.onChunk.calls.count()).toEqual(1);
|
|
121
121
|
expect(socket.onChunk).toHaveBeenCalledWith(234, "12356890");
|
|
122
122
|
});
|
|
123
123
|
|
|
@@ -131,8 +131,8 @@ describe("HTTP.getXHR", function() {
|
|
|
131
131
|
var onFinished = jasmine.createSpy();
|
|
132
132
|
socket.bind("finished", onFinished);
|
|
133
133
|
|
|
134
|
-
socket.close.
|
|
135
|
-
expect(onFinished.calls.
|
|
134
|
+
socket.close.and.callFake(function() {
|
|
135
|
+
expect(onFinished.calls.count()).toEqual(1);
|
|
136
136
|
expect(onFinished).toHaveBeenCalledWith(404);
|
|
137
137
|
});
|
|
138
138
|
|
|
@@ -145,15 +145,15 @@ describe("HTTP.getXHR", function() {
|
|
|
145
145
|
it("should abort the passed request", function() {
|
|
146
146
|
var xhr = Mocks.getXHR();
|
|
147
147
|
|
|
148
|
-
expect(xhr.abort.calls.
|
|
148
|
+
expect(xhr.abort.calls.count()).toEqual(0);
|
|
149
149
|
hooks.abortRequest(xhr);
|
|
150
|
-
expect(xhr.abort.calls.
|
|
150
|
+
expect(xhr.abort.calls.count()).toEqual(1);
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
it("should set the onreadystatechange listener to null before calling abort", function() {
|
|
154
154
|
var xhr = Mocks.getXHR();
|
|
155
155
|
xhr.onreadystatechange = function() {};
|
|
156
|
-
xhr.abort.
|
|
156
|
+
xhr.abort.and.callFake(function() {
|
|
157
157
|
expect(xhr.onreadystatechange).toBe(null);
|
|
158
158
|
});
|
|
159
159
|
|
|
@@ -52,9 +52,9 @@ if (TestEnv !== "worker") {
|
|
|
52
52
|
xhr = new Mocks.getXHR();
|
|
53
53
|
|
|
54
54
|
if (TestEnv === "web" && !window.XMLHttpRequest) {
|
|
55
|
-
spyOn(Runtime, "createMicrosoftXHR").
|
|
55
|
+
spyOn(Runtime, "createMicrosoftXHR").and.returnValue(xhr);
|
|
56
56
|
} else {
|
|
57
|
-
spyOn(Runtime, "createXHR").
|
|
57
|
+
spyOn(Runtime, "createXHR").and.returnValue(xhr);
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
|
|
@@ -70,7 +70,7 @@ if (TestEnv !== "worker") {
|
|
|
70
70
|
);
|
|
71
71
|
authorizer.authorize("1.23", function() {});
|
|
72
72
|
|
|
73
|
-
expect(xhr.setRequestHeader.calls.
|
|
73
|
+
expect(xhr.setRequestHeader.calls.count()).toEqual(3);
|
|
74
74
|
expect(xhr.setRequestHeader).toHaveBeenCalledWith(
|
|
75
75
|
"Content-Type", "application/x-www-form-urlencoded"
|
|
76
76
|
);
|
|
@@ -90,7 +90,7 @@ if (TestEnv !== "worker") {
|
|
|
90
90
|
);
|
|
91
91
|
authorizer.authorize("1.23", function() {});
|
|
92
92
|
|
|
93
|
-
expect(xhr.send.calls.
|
|
93
|
+
expect(xhr.send.calls.count()).toEqual(1);
|
|
94
94
|
expect(xhr.send).toHaveBeenCalledWith(
|
|
95
95
|
"socket_id=1.23&channel_name=chan&a=1&b=2"
|
|
96
96
|
);
|
|
@@ -109,9 +109,9 @@ if (TestEnv !== "worker") {
|
|
|
109
109
|
authorizer.authorize("1.23", callback);
|
|
110
110
|
|
|
111
111
|
if (TestEnv === "web" && !window.XMLHttpRequest) {
|
|
112
|
-
expect(Runtime.createMicrosoftXHR.calls.
|
|
112
|
+
expect(Runtime.createMicrosoftXHR.calls.count()).toEqual(1);
|
|
113
113
|
} else {
|
|
114
|
-
expect(Runtime.createXHR.calls.
|
|
114
|
+
expect(Runtime.createXHR.calls.count()).toEqual(1);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
xhr.readyState = 4;
|
|
@@ -119,7 +119,7 @@ if (TestEnv !== "worker") {
|
|
|
119
119
|
xhr.responseText = dataJSON;
|
|
120
120
|
xhr.onreadystatechange();
|
|
121
121
|
|
|
122
|
-
expect(callback.calls.
|
|
122
|
+
expect(callback.calls.count()).toEqual(1);
|
|
123
123
|
expect(callback).toHaveBeenCalledWith(null, data);
|
|
124
124
|
});
|
|
125
125
|
|
|
@@ -133,9 +133,9 @@ if (TestEnv !== "worker") {
|
|
|
133
133
|
authorizer.authorize("1.23", callback);
|
|
134
134
|
|
|
135
135
|
if (TestEnv === "web" && !window.XMLHttpRequest) {
|
|
136
|
-
expect(Runtime.createMicrosoftXHR.calls.
|
|
136
|
+
expect(Runtime.createMicrosoftXHR.calls.count()).toEqual(1);
|
|
137
137
|
} else {
|
|
138
|
-
expect(Runtime.createXHR.calls.
|
|
138
|
+
expect(Runtime.createXHR.calls.count()).toEqual(1);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
xhr.readyState = 4;
|
|
@@ -143,10 +143,10 @@ if (TestEnv !== "worker") {
|
|
|
143
143
|
xhr.responseText = invalidJSON;
|
|
144
144
|
xhr.onreadystatechange();
|
|
145
145
|
|
|
146
|
-
expect(callback.calls.
|
|
146
|
+
expect(callback.calls.count()).toEqual(1);
|
|
147
147
|
// For some reason comparing the Error types doesn't work properly in
|
|
148
148
|
// Safari on Mojave. Manually check the arguments.
|
|
149
|
-
let args = callback.calls
|
|
149
|
+
let args = callback.calls.first().args;
|
|
150
150
|
expect(args.length).toEqual(2)
|
|
151
151
|
expect(args[0]).toEqual(jasmine.any(Error))
|
|
152
152
|
expect(args[0].message).toEqual(
|
|
@@ -32,23 +32,23 @@ describe("Pusher", function() {
|
|
|
32
32
|
Pusher.isReady = false;
|
|
33
33
|
Pusher.instances = [];
|
|
34
34
|
|
|
35
|
-
spyOn(Runtime, "getDefaultStrategy").
|
|
35
|
+
spyOn(Runtime, "getDefaultStrategy").and.callFake(function() {
|
|
36
36
|
return Mocks.getStrategy(true);
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
spyOn(Factory, "createConnectionManager").
|
|
39
|
+
spyOn(Factory, "createConnectionManager").and.callFake(function(key, options, config) {
|
|
40
40
|
var manager = Mocks.getConnectionManager();
|
|
41
41
|
manager.key = key;
|
|
42
42
|
manager.options = options;
|
|
43
43
|
manager.config = config;
|
|
44
44
|
return manager;
|
|
45
45
|
});
|
|
46
|
-
spyOn(Factory, "createChannel").
|
|
46
|
+
spyOn(Factory, "createChannel").and.callFake(function(name, _) {
|
|
47
47
|
return Mocks.getChannel(name);
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
if (TestEnv === "web") {
|
|
51
|
-
spyOn(Runtime, "getDocument").
|
|
51
|
+
spyOn(Runtime, "getDocument").and.returnValue({
|
|
52
52
|
location: {
|
|
53
53
|
protocol: "http:"
|
|
54
54
|
}
|
|
@@ -116,7 +116,7 @@ describe("Pusher", function() {
|
|
|
116
116
|
});
|
|
117
117
|
|
|
118
118
|
it("should pass a feature list to the timeline", function() {
|
|
119
|
-
spyOn(Pusher, "getClientFeatures").
|
|
119
|
+
spyOn(Pusher, "getClientFeatures").and.returnValue(["foo", "bar"]);
|
|
120
120
|
var pusher = new Pusher("foo");
|
|
121
121
|
expect(pusher.timeline.options.features).toEqual(["foo", "bar"]);
|
|
122
122
|
});
|
|
@@ -154,7 +154,7 @@ describe("Pusher", function() {
|
|
|
154
154
|
|
|
155
155
|
if (TestEnv === "web") {
|
|
156
156
|
it("should be on when using https", function() {
|
|
157
|
-
Runtime.getDocument.
|
|
157
|
+
Runtime.getDocument.and.returnValue({
|
|
158
158
|
location: {
|
|
159
159
|
protocol: "https:"
|
|
160
160
|
}
|
|
@@ -455,16 +455,20 @@ describe("Pusher", function() {
|
|
|
455
455
|
var timelineSender;
|
|
456
456
|
|
|
457
457
|
beforeEach(function() {
|
|
458
|
-
jasmine.
|
|
458
|
+
jasmine.clock().install();
|
|
459
459
|
|
|
460
460
|
timelineSender = Mocks.getTimelineSender();
|
|
461
|
-
spyOn(Factory, "createTimelineSender").
|
|
461
|
+
spyOn(Factory, "createTimelineSender").and.returnValue(timelineSender);
|
|
462
462
|
|
|
463
463
|
});
|
|
464
464
|
|
|
465
|
+
afterEach(function() {
|
|
466
|
+
jasmine.clock().uninstall();
|
|
467
|
+
});
|
|
468
|
+
|
|
465
469
|
it("should be sent to stats.pusher.com", function() {
|
|
466
470
|
var pusher = new Pusher("foo", { enableStats: true });
|
|
467
|
-
expect(Factory.createTimelineSender.calls.
|
|
471
|
+
expect(Factory.createTimelineSender.calls.count()).toEqual(1);
|
|
468
472
|
expect(Factory.createTimelineSender).toHaveBeenCalledWith(
|
|
469
473
|
pusher.timeline, { host: "stats.pusher.com", path: "/timeline/v2/" + timelineTransport }
|
|
470
474
|
);
|
|
@@ -484,15 +488,15 @@ describe("Pusher", function() {
|
|
|
484
488
|
var pusher = new Pusher("foo");
|
|
485
489
|
pusher.connect();
|
|
486
490
|
pusher.connection.options.timeline.info({});
|
|
487
|
-
jasmine.
|
|
488
|
-
expect(timelineSender.send.calls.
|
|
491
|
+
jasmine.clock().tick(1000000);
|
|
492
|
+
expect(timelineSender.send.calls.count()).toEqual(0);
|
|
489
493
|
});
|
|
490
494
|
|
|
491
495
|
it("should be sent if disableStats set to false", function() {
|
|
492
496
|
var pusher = new Pusher("foo", { disableStats: false });
|
|
493
497
|
pusher.connect();
|
|
494
498
|
pusher.connection.options.timeline.info({});
|
|
495
|
-
expect(Factory.createTimelineSender.calls.
|
|
499
|
+
expect(Factory.createTimelineSender.calls.count()).toEqual(1);
|
|
496
500
|
expect(Factory.createTimelineSender).toHaveBeenCalledWith(
|
|
497
501
|
pusher.timeline, { host: "stats.pusher.com", path: "/timeline/v2/" + timelineTransport }
|
|
498
502
|
);
|
|
@@ -502,7 +506,7 @@ describe("Pusher", function() {
|
|
|
502
506
|
var pusher = new Pusher("foo", { disableStats: true, enableStats: true });
|
|
503
507
|
pusher.connect();
|
|
504
508
|
pusher.connection.options.timeline.info({});
|
|
505
|
-
expect(Factory.createTimelineSender.calls.
|
|
509
|
+
expect(Factory.createTimelineSender.calls.count()).toEqual(1);
|
|
506
510
|
expect(Factory.createTimelineSender).toHaveBeenCalledWith(
|
|
507
511
|
pusher.timeline, { host: "stats.pusher.com", path: "/timeline/v2/" + timelineTransport }
|
|
508
512
|
);
|
|
@@ -511,23 +515,23 @@ describe("Pusher", function() {
|
|
|
511
515
|
it("should not be sent before calling connect", function() {
|
|
512
516
|
var pusher = new Pusher("foo", { enableStats: true });
|
|
513
517
|
pusher.connection.options.timeline.info({});
|
|
514
|
-
jasmine.
|
|
515
|
-
expect(timelineSender.send.calls.
|
|
518
|
+
jasmine.clock().tick(1000000);
|
|
519
|
+
expect(timelineSender.send.calls.count()).toEqual(0);
|
|
516
520
|
});
|
|
517
521
|
|
|
518
522
|
it("should be sent every 60 seconds after calling connect", function() {
|
|
519
523
|
var pusher = new Pusher("foo", { enableStats: true });
|
|
520
524
|
pusher.connect();
|
|
521
|
-
expect(Factory.createTimelineSender.calls.
|
|
525
|
+
expect(Factory.createTimelineSender.calls.count()).toEqual(1);
|
|
522
526
|
|
|
523
527
|
pusher.connection.options.timeline.info({});
|
|
524
528
|
|
|
525
|
-
jasmine.
|
|
526
|
-
expect(timelineSender.send.calls.
|
|
527
|
-
jasmine.
|
|
528
|
-
expect(timelineSender.send.calls.
|
|
529
|
-
jasmine.
|
|
530
|
-
expect(timelineSender.send.calls.
|
|
529
|
+
jasmine.clock().tick(59999);
|
|
530
|
+
expect(timelineSender.send.calls.count()).toEqual(0);
|
|
531
|
+
jasmine.clock().tick(1);
|
|
532
|
+
expect(timelineSender.send.calls.count()).toEqual(1);
|
|
533
|
+
jasmine.clock().tick(60000);
|
|
534
|
+
expect(timelineSender.send.calls.count()).toEqual(2);
|
|
531
535
|
});
|
|
532
536
|
|
|
533
537
|
it("should be sent after connecting", function() {
|
|
@@ -538,7 +542,7 @@ describe("Pusher", function() {
|
|
|
538
542
|
pusher.connection.state = "connected";
|
|
539
543
|
pusher.connection.emit("connected");
|
|
540
544
|
|
|
541
|
-
expect(timelineSender.send.calls.
|
|
545
|
+
expect(timelineSender.send.calls.count()).toEqual(1);
|
|
542
546
|
});
|
|
543
547
|
|
|
544
548
|
it("should not be sent after disconnecting", function() {
|
|
@@ -548,13 +552,13 @@ describe("Pusher", function() {
|
|
|
548
552
|
|
|
549
553
|
pusher.connection.options.timeline.info({});
|
|
550
554
|
|
|
551
|
-
jasmine.
|
|
552
|
-
expect(timelineSender.send.calls.
|
|
555
|
+
jasmine.clock().tick(1000000);
|
|
556
|
+
expect(timelineSender.send.calls.count()).toEqual(0);
|
|
553
557
|
});
|
|
554
558
|
|
|
555
559
|
it("should be sent without TLS if connection is not using TLS", function() {
|
|
556
560
|
var pusher = new Pusher("foo", { enableStats: true });
|
|
557
|
-
pusher.connection.isUsingTLS.
|
|
561
|
+
pusher.connection.isUsingTLS.and.returnValue(false);
|
|
558
562
|
|
|
559
563
|
pusher.connect();
|
|
560
564
|
pusher.connection.options.timeline.info({});
|
|
@@ -567,7 +571,7 @@ describe("Pusher", function() {
|
|
|
567
571
|
|
|
568
572
|
it("should be sent with TLS if connection is over TLS", function() {
|
|
569
573
|
var pusher = new Pusher("foo", { enableStats: true });
|
|
570
|
-
pusher.connection.isUsingTLS.
|
|
574
|
+
pusher.connection.isUsingTLS.and.returnValue(true);
|
|
571
575
|
|
|
572
576
|
pusher.connect();
|
|
573
577
|
pusher.connection.options.timeline.info({});
|
|
@@ -32,7 +32,7 @@ describe("BestConnectedEverStrategy", function() {
|
|
|
32
32
|
expect(this.callback).toHaveBeenCalledWith(null, {
|
|
33
33
|
transport: transport1
|
|
34
34
|
});
|
|
35
|
-
expect(this.callback.calls.
|
|
35
|
+
expect(this.callback.calls.count()).toEqual(1);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
it("should force min priorities on all substrategies", function() {
|
|
@@ -50,7 +50,7 @@ describe("BestConnectedEverStrategy", function() {
|
|
|
50
50
|
expect(this.callback).toHaveBeenCalledWith(null, {
|
|
51
51
|
transport: transport2
|
|
52
52
|
});
|
|
53
|
-
expect(this.callback.calls.
|
|
53
|
+
expect(this.callback.calls.count()).toEqual(2);
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
56
|
|
|
@@ -67,12 +67,12 @@ describe("BestConnectedEverStrategy", function() {
|
|
|
67
67
|
it("should not pass errors after one substrategy succeeded", function() {
|
|
68
68
|
var transport = Mocks.getTransport();
|
|
69
69
|
this.substrategies[0]._callback(null, { transport: transport });
|
|
70
|
-
expect(this.callback.calls.
|
|
70
|
+
expect(this.callback.calls.count()).toEqual(1);
|
|
71
71
|
|
|
72
72
|
this.substrategies[1]._callback(true);
|
|
73
|
-
expect(this.callback.calls.
|
|
73
|
+
expect(this.callback.calls.count()).toEqual(1);
|
|
74
74
|
this.substrategies[2]._callback(true);
|
|
75
|
-
expect(this.callback.calls.
|
|
75
|
+
expect(this.callback.calls.count()).toEqual(1);
|
|
76
76
|
});
|
|
77
77
|
});
|
|
78
78
|
});
|
|
@@ -5,7 +5,11 @@ var Util = require('core/util').default;
|
|
|
5
5
|
|
|
6
6
|
describe("CachedStrategy", function() {
|
|
7
7
|
beforeEach(function() {
|
|
8
|
-
jasmine.
|
|
8
|
+
jasmine.clock().install();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
afterEach(function() {
|
|
12
|
+
jasmine.clock().uninstall();
|
|
9
13
|
});
|
|
10
14
|
|
|
11
15
|
describe("after calling isSupported", function() {
|
|
@@ -24,7 +28,7 @@ describe("CachedStrategy", function() {
|
|
|
24
28
|
|
|
25
29
|
describe("on browsers not supporting localStorage", function() {
|
|
26
30
|
beforeEach(function() {
|
|
27
|
-
spyOn(Runtime, "getLocalStorage").
|
|
31
|
+
spyOn(Runtime, "getLocalStorage").and.returnValue(undefined);
|
|
28
32
|
});
|
|
29
33
|
|
|
30
34
|
it("should try the substrategy immediately", function() {
|
|
@@ -41,7 +45,7 @@ describe("CachedStrategy", function() {
|
|
|
41
45
|
|
|
42
46
|
beforeEach(function() {
|
|
43
47
|
localStorage = {};
|
|
44
|
-
spyOn(Runtime, "getLocalStorage").
|
|
48
|
+
spyOn(Runtime, "getLocalStorage").and.returnValue(localStorage);
|
|
45
49
|
});
|
|
46
50
|
|
|
47
51
|
function buildCachedTransportTests(useTLS) {
|
|
@@ -114,10 +118,10 @@ describe("CachedStrategy", function() {
|
|
|
114
118
|
|
|
115
119
|
beforeEach(function() {
|
|
116
120
|
startTimestamp = Util.now();
|
|
117
|
-
spyOn(Util, "now").
|
|
121
|
+
spyOn(Util, "now").and.returnValue(startTimestamp);
|
|
118
122
|
|
|
119
123
|
strategy.connect(0, callback);
|
|
120
|
-
Util.now.
|
|
124
|
+
Util.now.and.returnValue(startTimestamp + 1000);
|
|
121
125
|
|
|
122
126
|
transport = Mocks.getTransport(true);
|
|
123
127
|
transport.name = "test";
|
|
@@ -208,10 +212,10 @@ describe("CachedStrategy", function() {
|
|
|
208
212
|
|
|
209
213
|
beforeEach(function() {
|
|
210
214
|
startTimestamp = Util.now();
|
|
211
|
-
spyOn(Util, "now").
|
|
215
|
+
spyOn(Util, "now").and.returnValue(startTimestamp);
|
|
212
216
|
|
|
213
217
|
strategy.connect(0, callback);
|
|
214
|
-
Util.now.
|
|
218
|
+
Util.now.and.returnValue(startTimestamp + 2000);
|
|
215
219
|
|
|
216
220
|
transport = Mocks.getTransport(true);
|
|
217
221
|
transport.name = "test";
|
|
@@ -240,12 +244,12 @@ describe("CachedStrategy", function() {
|
|
|
240
244
|
describe("after double the cached latency + 1s", function() {
|
|
241
245
|
beforeEach(function() {
|
|
242
246
|
startTimestamp = Util.now();
|
|
243
|
-
spyOn(Util, "now").
|
|
247
|
+
spyOn(Util, "now").and.returnValue(startTimestamp);
|
|
244
248
|
|
|
245
249
|
strategy.connect(0, callback);
|
|
246
250
|
|
|
247
|
-
Util.now.
|
|
248
|
-
jasmine.
|
|
251
|
+
Util.now.and.returnValue(startTimestamp + 3000);
|
|
252
|
+
jasmine.clock().tick(3000);
|
|
249
253
|
});
|
|
250
254
|
|
|
251
255
|
it("should abort the cached strategy", function() {
|
|
@@ -267,13 +271,13 @@ describe("CachedStrategy", function() {
|
|
|
267
271
|
|
|
268
272
|
beforeEach(function() {
|
|
269
273
|
startTimestamp = Util.now();
|
|
270
|
-
spyOn(Util, "now").
|
|
274
|
+
spyOn(Util, "now").and.returnValue(startTimestamp);
|
|
271
275
|
|
|
272
276
|
runner = strategy.connect(0, callback);
|
|
273
277
|
runner.forceMinPriority(666);
|
|
274
|
-
Util.now.
|
|
278
|
+
Util.now.and.returnValue(startTimestamp + 2000);
|
|
275
279
|
transports.test._callback("error");
|
|
276
|
-
Util.now.
|
|
280
|
+
Util.now.and.returnValue(startTimestamp + 2500);
|
|
277
281
|
});
|
|
278
282
|
|
|
279
283
|
it("should fall back to the substrategy", function() {
|
|
@@ -7,7 +7,11 @@ describe("DelayedStrategy", function() {
|
|
|
7
7
|
this.strategy = new DelayedStrategy(this.substrategy, { delay: 0 });
|
|
8
8
|
this.callback = jasmine.createSpy();
|
|
9
9
|
|
|
10
|
-
jasmine.
|
|
10
|
+
jasmine.clock().install();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterEach(function() {
|
|
14
|
+
jasmine.clock().uninstall();
|
|
11
15
|
});
|
|
12
16
|
|
|
13
17
|
describe("after calling isSupported", function() {
|
|
@@ -33,9 +37,9 @@ describe("DelayedStrategy", function() {
|
|
|
33
37
|
strategy.connect(0, this.callback);
|
|
34
38
|
|
|
35
39
|
expect(this.substrategy.connect).not.toHaveBeenCalled();
|
|
36
|
-
jasmine.
|
|
40
|
+
jasmine.clock().tick(99);
|
|
37
41
|
expect(this.substrategy.connect).not.toHaveBeenCalled();
|
|
38
|
-
jasmine.
|
|
42
|
+
jasmine.clock().tick(1);
|
|
39
43
|
expect(this.substrategy.connect).toHaveBeenCalled();
|
|
40
44
|
|
|
41
45
|
var handshake = {};
|
|
@@ -46,7 +50,7 @@ describe("DelayedStrategy", function() {
|
|
|
46
50
|
|
|
47
51
|
it("should pass an error when substrategy fails", function() {
|
|
48
52
|
this.strategy.connect(0, this.callback);
|
|
49
|
-
jasmine.
|
|
53
|
+
jasmine.clock().tick(0);
|
|
50
54
|
this.substrategy._callback(true);
|
|
51
55
|
|
|
52
56
|
expect(this.callback).toHaveBeenCalledWith(true);
|
|
@@ -56,7 +60,7 @@ describe("DelayedStrategy", function() {
|
|
|
56
60
|
describe("on abort", function() {
|
|
57
61
|
it("should abort substrategy when connecting", function() {
|
|
58
62
|
var runner = this.strategy.connect(0);
|
|
59
|
-
jasmine.
|
|
63
|
+
jasmine.clock().tick(0);
|
|
60
64
|
runner.abort();
|
|
61
65
|
expect(this.substrategy._abort).toHaveBeenCalled();
|
|
62
66
|
});
|
|
@@ -65,7 +69,7 @@ describe("DelayedStrategy", function() {
|
|
|
65
69
|
var run = this.strategy.connect(0);
|
|
66
70
|
expect(this.substrategy.connect).not.toHaveBeenCalled();
|
|
67
71
|
run.abort();
|
|
68
|
-
jasmine.
|
|
72
|
+
jasmine.clock().tick(10000);
|
|
69
73
|
expect(this.substrategy._abort).not.toHaveBeenCalled();
|
|
70
74
|
expect(this.substrategy.connect).not.toHaveBeenCalled();
|
|
71
75
|
});
|
|
@@ -75,14 +79,14 @@ describe("DelayedStrategy", function() {
|
|
|
75
79
|
it("should force the priority while waiting", function() {
|
|
76
80
|
var runner = this.strategy.connect(0, this.callback);
|
|
77
81
|
runner.forceMinPriority(5);
|
|
78
|
-
jasmine.
|
|
82
|
+
jasmine.clock().tick(0);
|
|
79
83
|
expect(this.substrategy.connect)
|
|
80
84
|
.toHaveBeenCalledWith(5, jasmine.any(Function));
|
|
81
85
|
});
|
|
82
86
|
|
|
83
87
|
it("should force the priority while connecting", function() {
|
|
84
88
|
var runner = this.strategy.connect(0, this.callback);
|
|
85
|
-
jasmine.
|
|
89
|
+
jasmine.clock().tick(0);
|
|
86
90
|
runner.forceMinPriority(5);
|
|
87
91
|
expect(this.substrategy._forceMinPriority).toHaveBeenCalledWith(5);
|
|
88
92
|
});
|
|
@@ -7,7 +7,11 @@ describe("SequentialStrategy", function() {
|
|
|
7
7
|
this.substrategies = Mocks.getStrategies([true, true]);
|
|
8
8
|
this.strategy = new SequentialStrategy(this.substrategies, {});
|
|
9
9
|
|
|
10
|
-
jasmine.
|
|
10
|
+
jasmine.clock().install();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterEach(function() {
|
|
14
|
+
jasmine.clock().uninstall();
|
|
11
15
|
});
|
|
12
16
|
|
|
13
17
|
describe("after calling isSupported", function() {
|
|
@@ -51,7 +55,7 @@ describe("SequentialStrategy", function() {
|
|
|
51
55
|
this.substrategies[1]._callback(true);
|
|
52
56
|
expect(this.substrategies[1]._abort).not.toHaveBeenCalled();
|
|
53
57
|
expect(this.callback).toHaveBeenCalledWith(true);
|
|
54
|
-
expect(this.callback.calls.
|
|
58
|
+
expect(this.callback.calls.count()).toEqual(1);
|
|
55
59
|
});
|
|
56
60
|
|
|
57
61
|
it("should support looping", function() {
|
|
@@ -60,18 +64,18 @@ describe("SequentialStrategy", function() {
|
|
|
60
64
|
});
|
|
61
65
|
var runner = strategy.connect(0, this.callback);
|
|
62
66
|
|
|
63
|
-
expect(this.substrategies[0].connect.calls.
|
|
64
|
-
expect(this.substrategies[1].connect.calls.
|
|
67
|
+
expect(this.substrategies[0].connect.calls.count()).toEqual(1);
|
|
68
|
+
expect(this.substrategies[1].connect.calls.count()).toEqual(0);
|
|
65
69
|
|
|
66
70
|
this.substrategies[0]._callback(true);
|
|
67
71
|
|
|
68
|
-
expect(this.substrategies[0].connect.calls.
|
|
69
|
-
expect(this.substrategies[1].connect.calls.
|
|
72
|
+
expect(this.substrategies[0].connect.calls.count()).toEqual(1);
|
|
73
|
+
expect(this.substrategies[1].connect.calls.count()).toEqual(1);
|
|
70
74
|
|
|
71
75
|
this.substrategies[1]._callback(true);
|
|
72
76
|
|
|
73
|
-
expect(this.substrategies[0].connect.calls.
|
|
74
|
-
expect(this.substrategies[1].connect.calls.
|
|
77
|
+
expect(this.substrategies[0].connect.calls.count()).toEqual(2);
|
|
78
|
+
expect(this.substrategies[1].connect.calls.count()).toEqual(1);
|
|
75
79
|
|
|
76
80
|
runner.abort();
|
|
77
81
|
expect(this.substrategies[0]._abort).toHaveBeenCalled();
|
|
@@ -111,7 +115,7 @@ describe("SequentialStrategy", function() {
|
|
|
111
115
|
expect(this.substrategies[1].connect).not.toHaveBeenCalled();
|
|
112
116
|
|
|
113
117
|
runner.abort();
|
|
114
|
-
jasmine.
|
|
118
|
+
jasmine.clock().tick(100);
|
|
115
119
|
expect(this.substrategies[1].connect).not.toHaveBeenCalled();
|
|
116
120
|
});
|
|
117
121
|
});
|
|
@@ -126,9 +130,9 @@ describe("SequentialStrategy", function() {
|
|
|
126
130
|
strategy.connect(0, this.callback);
|
|
127
131
|
substrategy._callback(true);
|
|
128
132
|
|
|
129
|
-
jasmine.
|
|
133
|
+
jasmine.clock().tick(99);
|
|
130
134
|
expect(this.callback).not.toHaveBeenCalled();
|
|
131
|
-
jasmine.
|
|
135
|
+
jasmine.clock().tick(1);
|
|
132
136
|
expect(this.callback).toHaveBeenCalled();
|
|
133
137
|
});
|
|
134
138
|
|
|
@@ -160,31 +164,31 @@ describe("SequentialStrategy", function() {
|
|
|
160
164
|
expect(substrategies[0].connect).toHaveBeenCalled();
|
|
161
165
|
expect(substrategies[1].connect).not.toHaveBeenCalled();
|
|
162
166
|
|
|
163
|
-
jasmine.
|
|
167
|
+
jasmine.clock().tick(99);
|
|
164
168
|
expect(substrategies[1].connect).not.toHaveBeenCalled();
|
|
165
169
|
|
|
166
|
-
jasmine.
|
|
170
|
+
jasmine.clock().tick(1);
|
|
167
171
|
expect(substrategies[1].connect).toHaveBeenCalled();
|
|
168
172
|
expect(substrategies[2].connect).not.toHaveBeenCalled();
|
|
169
173
|
|
|
170
|
-
jasmine.
|
|
174
|
+
jasmine.clock().tick(199);
|
|
171
175
|
expect(substrategies[2].connect).not.toHaveBeenCalled();
|
|
172
176
|
|
|
173
|
-
jasmine.
|
|
177
|
+
jasmine.clock().tick(1);
|
|
174
178
|
expect(substrategies[2].connect).toHaveBeenCalled();
|
|
175
179
|
expect(substrategies[3].connect).not.toHaveBeenCalled();
|
|
176
180
|
|
|
177
|
-
jasmine.
|
|
181
|
+
jasmine.clock().tick(399);
|
|
178
182
|
expect(substrategies[3].connect).not.toHaveBeenCalled();
|
|
179
183
|
|
|
180
|
-
jasmine.
|
|
184
|
+
jasmine.clock().tick(1);
|
|
181
185
|
expect(substrategies[3].connect).toHaveBeenCalled();
|
|
182
186
|
expect(substrategies[4].connect).not.toHaveBeenCalled();
|
|
183
187
|
|
|
184
|
-
jasmine.
|
|
188
|
+
jasmine.clock().tick(399);
|
|
185
189
|
expect(substrategies[4].connect).not.toHaveBeenCalled();
|
|
186
190
|
|
|
187
|
-
jasmine.
|
|
191
|
+
jasmine.clock().tick(1);
|
|
188
192
|
expect(substrategies[4].connect).toHaveBeenCalled();
|
|
189
193
|
});
|
|
190
194
|
});
|