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.
Files changed (103) hide show
  1. package/.github/stale.yml +2 -2
  2. package/.github/workflows/release.yml +112 -0
  3. package/.github/workflows/release_pr.yml +42 -0
  4. package/.github/workflows/run-tests.yml +38 -0
  5. package/CHANGELOG.md +26 -0
  6. package/Makefile +17 -12
  7. package/README.md +28 -0
  8. package/dist/node/pusher.js +85 -44
  9. package/dist/node/pusher.js.map +1 -0
  10. package/dist/react-native/pusher.js +3 -2
  11. package/dist/react-native/pusher.js.map +1 -0
  12. package/dist/web/pusher-with-encryption.js +7 -5
  13. package/dist/web/pusher-with-encryption.js.map +1 -0
  14. package/dist/web/pusher-with-encryption.min.js +3 -2
  15. package/dist/web/pusher-with-encryption.min.js.map +1 -0
  16. package/dist/web/pusher.js +7 -5
  17. package/dist/web/pusher.js.map +1 -0
  18. package/dist/web/pusher.min.js +3 -2
  19. package/dist/web/pusher.min.js.map +1 -0
  20. package/dist/worker/pusher-with-encryption.worker.js +19 -7
  21. package/dist/worker/pusher-with-encryption.worker.js.map +1 -0
  22. package/dist/worker/pusher-with-encryption.worker.min.js +3 -2
  23. package/dist/worker/pusher-with-encryption.worker.min.js.map +1 -0
  24. package/dist/worker/pusher.worker.js +19 -7
  25. package/dist/worker/pusher.worker.js.map +1 -0
  26. package/dist/worker/pusher.worker.min.js +3 -2
  27. package/dist/worker/pusher.worker.min.js.map +1 -0
  28. package/package.json +17 -15
  29. package/spec/config/jasmine/helpers/reporter.js +14 -0
  30. package/spec/config/jasmine/integration.json +13 -0
  31. package/spec/config/jasmine/unit.json +13 -0
  32. package/spec/config/{jasmine-node → jasmine}/webpack.integration.js +4 -4
  33. package/spec/config/{jasmine-node → jasmine}/webpack.unit.js +4 -6
  34. package/spec/config/karma/config.common.js +10 -4
  35. package/spec/config/karma/config.integration.js +4 -4
  36. package/spec/config/karma/config.unit.js +5 -7
  37. package/spec/config/karma/integration.js +3 -3
  38. package/spec/config/karma/unit.js +2 -2
  39. package/spec/javascripts/helpers/mocks.js +18 -18
  40. package/spec/javascripts/helpers/waitsFor.js +37 -0
  41. package/spec/javascripts/integration/core/cluster_config_spec.js +45 -34
  42. package/spec/javascripts/integration/core/falling_back_spec.js +124 -127
  43. package/spec/javascripts/integration/core/pusher_spec/test_builder.js +264 -284
  44. package/spec/javascripts/integration/core/timeout_configuration_spec.js +24 -22
  45. package/spec/javascripts/integration/core/transport_lists_spec.js +8 -8
  46. package/spec/javascripts/integration/web/dom/jsonp_spec.js +67 -69
  47. package/spec/javascripts/integration/web/dom/script_request_spec.js +44 -52
  48. package/spec/javascripts/unit/core/channels/channel_spec.js +11 -21
  49. package/spec/javascripts/unit/core/channels/encrypted_channel_spec.js +9 -17
  50. package/spec/javascripts/unit/core/channels/presence_channel_spec.js +8 -19
  51. package/spec/javascripts/unit/core/channels/private_channel_spec.js +9 -19
  52. package/spec/javascripts/unit/core/config_spec.js +2 -2
  53. package/spec/javascripts/unit/core/connection/connection_manager_spec.js +69 -63
  54. package/spec/javascripts/unit/core/connection/connection_spec.js +14 -13
  55. package/spec/javascripts/unit/core/connection/handshake_spec.js +14 -12
  56. package/spec/javascripts/unit/core/connection/protocol_spec.js +9 -4
  57. package/spec/javascripts/unit/core/defaults_spec.js +1 -1
  58. package/spec/javascripts/unit/core/events_dispatcher_spec.js +20 -20
  59. package/spec/javascripts/unit/core/http/http_polling_socket_spec.js +4 -4
  60. package/spec/javascripts/unit/core/http/http_request_spec.js +20 -17
  61. package/spec/javascripts/unit/core/http/http_socket_spec.js +35 -32
  62. package/spec/javascripts/unit/core/http/http_streaming_socket_spec.js +4 -4
  63. package/spec/javascripts/unit/core/http/http_xhr_request_spec.js +13 -13
  64. package/spec/javascripts/unit/core/pusher_authorizer_spec.js +11 -11
  65. package/spec/javascripts/unit/core/pusher_spec.js +31 -27
  66. package/spec/javascripts/unit/core/strategies/best_connected_ever_strategy_spec.js +5 -5
  67. package/spec/javascripts/unit/core/strategies/cached_strategy_spec.js +17 -13
  68. package/spec/javascripts/unit/core/strategies/delayed_strategy_spec.js +12 -8
  69. package/spec/javascripts/unit/core/strategies/sequential_strategy_spec.js +23 -19
  70. package/spec/javascripts/unit/core/strategies/transport_strategy_spec.js +22 -24
  71. package/spec/javascripts/unit/core/timeline/timeline_spec.js +16 -9
  72. package/spec/javascripts/unit/core/transports/assistant_to_the_transport_manager_spec.js +36 -22
  73. package/spec/javascripts/unit/core/transports/hosts_and_ports_spec.js +10 -10
  74. package/spec/javascripts/unit/core/transports/transport_connection_spec.js +81 -86
  75. package/spec/javascripts/unit/core/transports/transport_manager_spec.js +1 -1
  76. package/spec/javascripts/unit/core/utils/periodic_timer_spec.js +17 -16
  77. package/spec/javascripts/unit/core/utils/timers_spec.js +32 -26
  78. package/spec/javascripts/unit/isomorphic/transports/hosts_and_ports_spec.js +12 -8
  79. package/spec/javascripts/unit/isomorphic/transports/transports_spec.js +7 -7
  80. package/spec/javascripts/unit/node/timeline_sender_spec.js +5 -5
  81. package/spec/javascripts/unit/web/dom/dependency_loader_spec.js +30 -30
  82. package/spec/javascripts/unit/web/dom/jsonp_request_spec.js +7 -7
  83. package/spec/javascripts/unit/web/http/http_xdomain_request_spec.js +22 -22
  84. package/spec/javascripts/unit/web/pusher_authorizer_spec.js +3 -3
  85. package/spec/javascripts/unit/web/timeline/timeline_sender_spec.js +12 -12
  86. package/spec/javascripts/unit/web/transports/hosts_and_ports_spec.js +15 -12
  87. package/spec/javascripts/unit/web/transports/transports_spec.js +24 -26
  88. package/spec/javascripts/unit/worker/pusher_authorizer_spec.js +2 -2
  89. package/spec/javascripts/unit/worker/timeline_sender_spec.js +2 -2
  90. package/src/core/auth/options.ts +1 -0
  91. package/types/src/core/auth/options.d.ts +1 -0
  92. package/webpack/config.node.js +2 -2
  93. package/webpack/config.react-native.js +2 -2
  94. package/webpack/config.shared.js +9 -1
  95. package/webpack/config.web.js +2 -2
  96. package/webpack/config.worker.js +5 -3
  97. package/worker/index.d.ts +15 -0
  98. package/worker/index.js +1 -0
  99. package/worker/with-encryption/index.d.ts +15 -0
  100. package/worker/with-encryption/index.js +1 -0
  101. package/.travis.build +0 -22
  102. package/.travis.yml +0 -7
  103. package/spec/config/jasmine-node/config.js +0 -10
@@ -12,7 +12,7 @@ describe("TransportManager", function() {
12
12
  maxPingDelay: 2222
13
13
  });
14
14
 
15
- spyOn(Factory, 'createAssistantToTheTransportManager').andReturn(assistant);
15
+ spyOn(Factory, 'createAssistantToTheTransportManager').and.returnValue(assistant);
16
16
 
17
17
  expect(manager.getAssistant(transportClass)).toBe(assistant);
18
18
  expect(Factory.createAssistantToTheTransportManager).toHaveBeenCalledWith(
@@ -6,7 +6,7 @@ describe("PeriodicTimer", function() {
6
6
  var timer;
7
7
 
8
8
  beforeEach(function() {
9
- jasmine.Clock.useMock();
9
+ jasmine.clock().install();
10
10
 
11
11
  callback = jasmine.createSpy("callback");
12
12
  timer = new PeriodicTimer(123, callback);
@@ -14,30 +14,31 @@ describe("PeriodicTimer", function() {
14
14
 
15
15
  afterEach(function() {
16
16
  timer.ensureAborted();
17
+ jasmine.clock().uninstall();
17
18
  });
18
19
 
19
20
  it("should keep executing the callback with the specified interval", function() {
20
- expect(callback.calls.length).toEqual(0);
21
- jasmine.Clock.tick(122);
22
- expect(callback.calls.length).toEqual(0);
23
- jasmine.Clock.tick(1);
24
- expect(callback.calls.length).toEqual(1);
21
+ expect(callback.calls.count()).toEqual(0);
22
+ jasmine.clock().tick(122);
23
+ expect(callback.calls.count()).toEqual(0);
24
+ jasmine.clock().tick(1);
25
+ expect(callback.calls.count()).toEqual(1);
25
26
 
26
- expect(callback.calls.length).toEqual(1);
27
- jasmine.Clock.tick(122);
28
- expect(callback.calls.length).toEqual(1);
29
- jasmine.Clock.tick(1);
30
- expect(callback.calls.length).toEqual(2);
27
+ expect(callback.calls.count()).toEqual(1);
28
+ jasmine.clock().tick(122);
29
+ expect(callback.calls.count()).toEqual(1);
30
+ jasmine.clock().tick(1);
31
+ expect(callback.calls.count()).toEqual(2);
31
32
  });
32
33
 
33
34
  describe("#isRunning", function() {
34
35
  it("should return true before first execution", function() {
35
- jasmine.Clock.tick(122);
36
+ jasmine.clock().tick(122);
36
37
  expect(timer.isRunning()).toBe(true);
37
38
  });
38
39
 
39
40
  it("should return true after execution", function() {
40
- jasmine.Clock.tick(123);
41
+ jasmine.clock().tick(123);
41
42
  expect(timer.isRunning()).toBe(true);
42
43
  });
43
44
 
@@ -50,12 +51,12 @@ describe("PeriodicTimer", function() {
50
51
  describe("#ensureAborted", function() {
51
52
  it("should abort the timer before execution", function() {
52
53
  timer.ensureAborted();
53
- jasmine.Clock.tick(1000000);
54
+ jasmine.clock().tick(1000000);
54
55
  expect(callback).not.toHaveBeenCalled();
55
56
  });
56
57
 
57
58
  it("should play nice after first execution", function() {
58
- jasmine.Clock.tick(1000);
59
+ jasmine.clock().tick(1000);
59
60
  timer.ensureAborted();
60
61
  });
61
62
 
@@ -63,7 +64,7 @@ describe("PeriodicTimer", function() {
63
64
  // IE has some edge-case with clearInterval not working, let's simulate it
64
65
  spyOn(global, "clearInterval");
65
66
  timer.ensureAborted();
66
- jasmine.Clock.tick(1000);
67
+ jasmine.clock().tick(1000);
67
68
  expect(callback).not.toHaveBeenCalled();
68
69
  });
69
70
  });
@@ -1,12 +1,17 @@
1
1
  var timers = require('core/utils/timers');
2
2
 
3
3
  describe("timers", function() {
4
+ afterEach(() => {
5
+ jasmine.clock().uninstall();
6
+ });
7
+
4
8
  describe("Timer", function() {
5
9
  var callback;
6
10
  var timer;
7
11
 
8
12
  beforeEach(function() {
9
- jasmine.Clock.useMock();
13
+ jasmine.clock().uninstall();
14
+ jasmine.clock().install();
10
15
 
11
16
  callback = jasmine.createSpy("callback");
12
17
  timer = new timers.OneOffTimer(123, callback);
@@ -18,25 +23,25 @@ describe("timers", function() {
18
23
 
19
24
  it("should execute the callback with the specified delay", function() {
20
25
  expect(callback).not.toHaveBeenCalled();
21
- jasmine.Clock.tick(122);
26
+ jasmine.clock().tick(122);
22
27
  expect(callback).not.toHaveBeenCalled();
23
- jasmine.Clock.tick(1);
28
+ jasmine.clock().tick(1);
24
29
  expect(callback).toHaveBeenCalled();
25
30
  });
26
31
 
27
32
  it("should execute the callback exactly once", function() {
28
- jasmine.Clock.tick(1000);
29
- expect(callback.calls.length).toEqual(1);
33
+ jasmine.clock().tick(1000);
34
+ expect(callback.calls.count()).toEqual(1);
30
35
  });
31
36
 
32
37
  describe("#isRunning", function() {
33
38
  it("should return true before execution", function() {
34
- jasmine.Clock.tick(122);
39
+ jasmine.clock().tick(122);
35
40
  expect(timer.isRunning()).toBe(true);
36
41
  });
37
42
 
38
43
  it("should return false after execution", function() {
39
- jasmine.Clock.tick(123);
44
+ jasmine.clock().tick(123);
40
45
  expect(timer.isRunning()).toBe(false);
41
46
  });
42
47
 
@@ -49,12 +54,12 @@ describe("timers", function() {
49
54
  describe("#ensureAborted", function() {
50
55
  it("should abort the timer before execution", function() {
51
56
  timer.ensureAborted();
52
- jasmine.Clock.tick(1000);
57
+ jasmine.clock().tick(1000);
53
58
  expect(callback).not.toHaveBeenCalled();
54
59
  });
55
60
 
56
61
  it("should play nice after execution", function() {
57
- jasmine.Clock.tick(1000);
62
+ jasmine.clock().tick(1000);
58
63
  timer.ensureAborted();
59
64
  });
60
65
 
@@ -62,7 +67,7 @@ describe("timers", function() {
62
67
  // IE has some edge-case with clearTimeout not working, let's simulate it
63
68
  spyOn(global, "clearTimeout");
64
69
  timer.ensureAborted();
65
- jasmine.Clock.tick(1000);
70
+ jasmine.clock().tick(1000);
66
71
  expect(callback).not.toHaveBeenCalled();
67
72
  });
68
73
  });
@@ -73,7 +78,8 @@ describe("timers", function() {
73
78
  var timer;
74
79
 
75
80
  beforeEach(function() {
76
- jasmine.Clock.useMock();
81
+ jasmine.clock().uninstall();
82
+ jasmine.clock().install();
77
83
 
78
84
  callback = jasmine.createSpy("callback");
79
85
  timer = new timers.PeriodicTimer(123, callback);
@@ -85,27 +91,27 @@ describe("timers", function() {
85
91
 
86
92
  it("should execute the callback with the specified delay", function() {
87
93
  expect(callback).not.toHaveBeenCalled();
88
- jasmine.Clock.tick(122);
94
+ jasmine.clock().tick(122);
89
95
  expect(callback).not.toHaveBeenCalled();
90
- jasmine.Clock.tick(1);
96
+ jasmine.clock().tick(1);
91
97
  expect(callback).toHaveBeenCalled();
92
98
  });
93
99
 
94
100
  it("should execute the callback periodically", function() {
95
- jasmine.Clock.tick(123);
96
- expect(callback.calls.length).toEqual(1);
97
- jasmine.Clock.tick(123);
98
- expect(callback.calls.length).toEqual(2);
101
+ jasmine.clock().tick(123);
102
+ expect(callback.calls.count()).toEqual(1);
103
+ jasmine.clock().tick(123);
104
+ expect(callback.calls.count()).toEqual(2);
99
105
  });
100
106
 
101
107
  describe("#isRunning", function() {
102
108
  it("should return true before execution", function() {
103
- jasmine.Clock.tick(122);
109
+ jasmine.clock().tick(122);
104
110
  expect(timer.isRunning()).toBe(true);
105
111
  });
106
112
 
107
113
  it("should return true after execution", function() {
108
- jasmine.Clock.tick(123);
114
+ jasmine.clock().tick(123);
109
115
  expect(timer.isRunning()).toBe(true);
110
116
  });
111
117
 
@@ -118,22 +124,22 @@ describe("timers", function() {
118
124
  describe("#ensureAborted", function() {
119
125
  it("should abort the timer before execution", function() {
120
126
  timer.ensureAborted();
121
- jasmine.Clock.tick(1000);
127
+ jasmine.clock().tick(1000);
122
128
  expect(callback).not.toHaveBeenCalled();
123
129
  });
124
130
 
125
131
  it("should abort the timer after first execution", function() {
126
- jasmine.Clock.tick(123);
127
- expect(callback.calls.length).toEqual(1);
132
+ jasmine.clock().tick(123);
133
+ expect(callback.calls.count()).toEqual(1);
128
134
  timer.ensureAborted();
129
- jasmine.Clock.tick(1000);
130
- expect(callback.calls.length).toEqual(1);
135
+ jasmine.clock().tick(1000);
136
+ expect(callback.calls.count()).toEqual(1);
131
137
  });
132
138
 
133
139
  it("should be idempotent", function() {
134
140
  timer.ensureAborted();
135
141
  timer.ensureAborted();
136
- jasmine.Clock.tick(1000);
142
+ jasmine.clock().tick(1000);
137
143
  expect(callback).not.toHaveBeenCalled();
138
144
  });
139
145
 
@@ -141,7 +147,7 @@ describe("timers", function() {
141
147
  // IE has some edge-case with clearTimeout not working, let's simulate it
142
148
  spyOn(global, "clearTimeout");
143
149
  timer.ensureAborted();
144
- jasmine.Clock.tick(1000);
150
+ jasmine.clock().tick(1000);
145
151
  expect(callback).not.toHaveBeenCalled();
146
152
  });
147
153
  });
@@ -13,30 +13,34 @@ describe("Host/Port Configuration", function() {
13
13
  var Transports;
14
14
 
15
15
  beforeEach(function() {
16
- spyOn(Runtime, 'getNetwork').andCallFake(function(){
16
+ spyOn(Runtime, 'getNetwork').and.callFake(function(){
17
17
  var network = new NetInfo();
18
18
  network.isOnline = jasmine.createSpy("isOnline")
19
- .andReturn(true);
19
+ .and.returnValue(true);
20
20
  return network;
21
21
  });
22
- spyOn(Runtime, "getLocalStorage").andReturn({});
22
+ spyOn(Runtime, "getLocalStorage").and.returnValue({});
23
23
  });
24
24
 
25
25
  afterEach(function() {
26
- pusher.disconnect();
26
+ try {
27
+ pusher.disconnect();
28
+ } catch (e) {
29
+ console.log(`Received an error when tried to disconnect. Error message: ${e}`);
30
+ }
27
31
  });
28
32
 
29
33
  describe("WebSockets", function() {
30
34
  var _WebSocket;
31
35
 
32
36
  beforeEach(function() {
33
- spyOn(Runtime, 'createWebSocket').andReturn(Mocks.getTransport());
37
+ spyOn(Runtime, 'createWebSocket').and.returnValue(Mocks.getTransport());
34
38
 
35
39
  var Transports = Runtime.Transports;
36
40
 
37
- spyOn(Transports.ws, "isSupported").andReturn(true);
38
- spyOn(Transports.xhr_streaming, "isSupported").andReturn(false);
39
- spyOn(Transports.xhr_polling, "isSupported").andReturn(false);
41
+ spyOn(Transports.ws, "isSupported").and.returnValue(true);
42
+ spyOn(Transports.xhr_streaming, "isSupported").and.returnValue(false);
43
+ spyOn(Transports.xhr_polling, "isSupported").and.returnValue(false);
40
44
  });
41
45
 
42
46
  it("should connect to wss://ws-mt1.pusher.com:443 by default", function() {
@@ -38,7 +38,7 @@ describe("Transports", function() {
38
38
  "ws://example.com:123/path/app/foobar?protocol=7&client=js&version=" + VERSION + "&flash=false"
39
39
  );
40
40
  });
41
-
41
+
42
42
  it("should generate correct TLS URLs with custom path prefix", function() {
43
43
  var url = Transports.ws.hooks.urls.getInitial("foobar", {
44
44
  useTLS: true,
@@ -81,9 +81,9 @@ describe("Transports", function() {
81
81
  var FakeWebSocket = function(url) {
82
82
  this.url = url;
83
83
  }
84
- spyOn(Runtime, 'getWebSocketAPI').andReturn(FakeWebSocket);
84
+ spyOn(Runtime, 'getWebSocketAPI').and.returnValue(FakeWebSocket);
85
85
  var socket = Transports.ws.hooks.getSocket("testurl");
86
- expect(Runtime.getWebSocketAPI.calls.length).toEqual(1);
86
+ expect(Runtime.getWebSocketAPI.calls.count()).toEqual(1);
87
87
  expect(socket).toEqual(jasmine.any(FakeWebSocket));
88
88
  expect(socket.url).toEqual("testurl");
89
89
  });
@@ -170,12 +170,12 @@ describe("Transports", function() {
170
170
  describe(transport, function() {
171
171
  describe("getSocket hook", function() {
172
172
  it("should return a new streaming HTTPSocket object", function() {
173
- spyOn(HTTP, "createStreamingSocket").andCallFake(function(url) {
173
+ spyOn(HTTP, "createStreamingSocket").and.callFake(function(url) {
174
174
  return "streaming socket mock";
175
175
  });
176
176
 
177
177
  var socket = Transports[transport].hooks.getSocket("streamurl");
178
- expect(HTTP.createStreamingSocket.calls.length).toEqual(1);
178
+ expect(HTTP.createStreamingSocket.calls.count()).toEqual(1);
179
179
  expect(HTTP.createStreamingSocket).toHaveBeenCalledWith("streamurl");
180
180
  expect(socket).toEqual("streaming socket mock");
181
181
  });
@@ -187,12 +187,12 @@ describe("Transports", function() {
187
187
  describe(transport, function() {
188
188
  describe("getSocket hook", function() {
189
189
  it("should return a new polling HTTPSocket object", function() {
190
- spyOn(HTTP, "createPollingSocket").andCallFake(function(url) {
190
+ spyOn(HTTP, "createPollingSocket").and.callFake(function(url) {
191
191
  return "polling socket mock";
192
192
  });
193
193
 
194
194
  var socket = Transports[transport].hooks.getSocket("streamurl");
195
- expect(HTTP.createPollingSocket.calls.length).toEqual(1);
195
+ expect(HTTP.createPollingSocket.calls.count()).toEqual(1);
196
196
  expect(HTTP.createPollingSocket).toHaveBeenCalledWith("streamurl");
197
197
  expect(socket).toEqual("polling socket mock");
198
198
  });
@@ -7,8 +7,8 @@ describe("TimelineSender", function() {
7
7
 
8
8
  beforeEach(function(){
9
9
  timeline = Mocks.getTimeline();
10
- timeline.isEmpty.andReturn(false);
11
- timeline.send.andCallFake(function(sendXHR, callback) {
10
+ timeline.isEmpty.and.returnValue(false);
11
+ timeline.send.and.callFake(function(sendXHR, callback) {
12
12
  sendXHR({ events: [1, 2, 3]}, callback);
13
13
  });
14
14
 
@@ -23,7 +23,7 @@ describe("TimelineSender", function() {
23
23
  var xhrRequest;
24
24
 
25
25
  beforeEach(function() {
26
- spyOn(Runtime, "createXHR").andCallFake(function() {
26
+ spyOn(Runtime, "createXHR").and.callFake(function() {
27
27
  xhrRequest = Mocks.getXHR();
28
28
  return xhrRequest;
29
29
  });
@@ -47,7 +47,7 @@ describe("TimelineSender", function() {
47
47
  it("should send a non-empty timeline", function() {
48
48
  sender.send(false, onSend);
49
49
 
50
- expect(Runtime.createXHR.calls.length).toEqual(1);
50
+ expect(Runtime.createXHR.calls.count()).toEqual(1);
51
51
  var encodedParams = 'WzEsMiwzXQ%3D%3D';
52
52
 
53
53
  expect(xhrRequest.open).toHaveBeenCalledWith(
@@ -59,7 +59,7 @@ describe("TimelineSender", function() {
59
59
  });
60
60
 
61
61
  it("should not send an empty timeline", function() {
62
- timeline.isEmpty.andReturn(true);
62
+ timeline.isEmpty.and.returnValue(true);
63
63
  sender.send(false, onSend);
64
64
  expect(Runtime.createXHR).not.toHaveBeenCalled();
65
65
  });
@@ -15,8 +15,8 @@ describe("DependencyLoader", function() {
15
15
  doc = Mocks.getDocument();
16
16
  doc.location.protocol = "http:";
17
17
 
18
- spyOn(Runtime, "getDocument").andReturn(doc);
19
- spyOn(Runtime, "createScriptRequest").andCallFake(function() {
18
+ spyOn(Runtime, "getDocument").and.returnValue(doc);
19
+ spyOn(Runtime, "createScriptRequest").and.callFake(function() {
20
20
  scriptRequest = Mocks.getScriptRequest();
21
21
  return scriptRequest;
22
22
  });
@@ -108,7 +108,7 @@ describe("DependencyLoader", function() {
108
108
  it("should send an non TLS script request when served via http", function() {
109
109
  doc.location.protocol = "http:";
110
110
  loader.load("resource", {}, onLoaded);
111
- expect(Runtime.createScriptRequest.calls.length).toEqual(1);
111
+ expect(Runtime.createScriptRequest.calls.count()).toEqual(1);
112
112
  expect(Runtime.createScriptRequest).toHaveBeenCalledWith(
113
113
  "http://example.com/6.6.6/resource-test.js"
114
114
  );
@@ -117,7 +117,7 @@ describe("DependencyLoader", function() {
117
117
  it("should send a TLS script request when served via https", function() {
118
118
  doc.location.protocol = "https:";
119
119
  loader.load("resource", {}, onLoaded);
120
- expect(Runtime.createScriptRequest.calls.length).toEqual(1);
120
+ expect(Runtime.createScriptRequest.calls.count()).toEqual(1);
121
121
  expect(Runtime.createScriptRequest).toHaveBeenCalledWith(
122
122
  "https://example.com/6.6.6/resource-test.js"
123
123
  );
@@ -126,25 +126,25 @@ describe("DependencyLoader", function() {
126
126
  it("should send a TLS script request when served via http, but passed TLS via options", function() {
127
127
  doc.location.protocol = "http:";
128
128
  loader.load("resource", { useTLS: true }, onLoaded);
129
- expect(Runtime.createScriptRequest.calls.length).toEqual(1);
129
+ expect(Runtime.createScriptRequest.calls.count()).toEqual(1);
130
130
  expect(Runtime.createScriptRequest).toHaveBeenCalledWith(
131
131
  "https://example.com/6.6.6/resource-test.js"
132
132
  );
133
133
  });
134
134
 
135
135
  it("should only send one script request per resource at a time", function() {
136
- expect(Runtime.createScriptRequest.calls.length).toEqual(0);
136
+ expect(Runtime.createScriptRequest.calls.count()).toEqual(0);
137
137
 
138
138
  loader.load("resource", {}, function() {});
139
139
  loader.load("resource", {}, function() {});
140
140
  loader.load("resource", {}, function() {});
141
- expect(Runtime.createScriptRequest.calls.length).toEqual(1);
141
+ expect(Runtime.createScriptRequest.calls.count()).toEqual(1);
142
142
  expect(Runtime.createScriptRequest).toHaveBeenCalledWith(
143
143
  "http://example.com/6.6.6/resource-test.js"
144
144
  );
145
145
 
146
146
  loader.load("resource2", {}, function() {});
147
- expect(Runtime.createScriptRequest.calls.length).toEqual(2);
147
+ expect(Runtime.createScriptRequest.calls.count()).toEqual(2);
148
148
  expect(Runtime.createScriptRequest).toHaveBeenCalledWith(
149
149
  "http://example.com/6.6.6/resource2-test.js"
150
150
  );
@@ -152,7 +152,7 @@ describe("DependencyLoader", function() {
152
152
 
153
153
  it("should register a receiver", function() {
154
154
  loader.load("resource", {}, onLoaded);
155
- var receiver = scriptRequest.send.calls[0].args[0];
155
+ var receiver = scriptRequest.send.calls.first().args[0];
156
156
  expect(Pusher.ScriptReceivers[receiver.number]).toBe(
157
157
  receiver.callback
158
158
  );
@@ -160,7 +160,7 @@ describe("DependencyLoader", function() {
160
160
 
161
161
  it("should call back without an error if the resource loaded successfully", function() {
162
162
  loader.load("resource", {}, onLoaded);
163
- var receiver = scriptRequest.send.calls[0].args[0];
163
+ var receiver = scriptRequest.send.calls.first().args[0];
164
164
 
165
165
  expect(onLoaded).not.toHaveBeenCalled();
166
166
  receiver.callback(null);
@@ -169,7 +169,7 @@ describe("DependencyLoader", function() {
169
169
 
170
170
  it("should call back with an error if the resource failed to load", function() {
171
171
  loader.load("resource", {}, onLoaded);
172
- var receiver = scriptRequest.send.calls[0].args[0];
172
+ var receiver = scriptRequest.send.calls.first().args[0];
173
173
 
174
174
  expect(onLoaded).not.toHaveBeenCalled();
175
175
  receiver.callback("too bad");
@@ -185,23 +185,23 @@ describe("DependencyLoader", function() {
185
185
 
186
186
  loader.load("resource2", {}, onLoaded3);
187
187
 
188
- expect(onLoaded.calls.length).toEqual(0);
189
- expect(onLoaded2.calls.length).toEqual(0);
190
- expect(onLoaded3.calls.length).toEqual(0);
188
+ expect(onLoaded.calls.count()).toEqual(0);
189
+ expect(onLoaded2.calls.count()).toEqual(0);
190
+ expect(onLoaded3.calls.count()).toEqual(0);
191
191
 
192
- var firstReceiver = firstScriptRequest.send.calls[0].args[0];
192
+ var firstReceiver = firstScriptRequest.send.calls.first().args[0];
193
193
  firstReceiver.callback(null);
194
194
 
195
- expect(onLoaded.calls.length).toEqual(1);
196
- expect(onLoaded2.calls.length).toEqual(1);
197
- expect(onLoaded3.calls.length).toEqual(0);
195
+ expect(onLoaded.calls.count()).toEqual(1);
196
+ expect(onLoaded2.calls.count()).toEqual(1);
197
+ expect(onLoaded3.calls.count()).toEqual(0);
198
198
 
199
- var secondReceiver = scriptRequest.send.calls[0].args[0];
199
+ var secondReceiver = scriptRequest.send.calls.first().args[0];
200
200
  secondReceiver.callback(null);
201
201
 
202
- expect(onLoaded.calls.length).toEqual(1);
203
- expect(onLoaded2.calls.length).toEqual(1);
204
- expect(onLoaded3.calls.length).toEqual(1);
202
+ expect(onLoaded.calls.count()).toEqual(1);
203
+ expect(onLoaded2.calls.count()).toEqual(1);
204
+ expect(onLoaded3.calls.count()).toEqual(1);
205
205
  });
206
206
 
207
207
  describe("after loading the resource", function() {
@@ -209,7 +209,7 @@ describe("DependencyLoader", function() {
209
209
 
210
210
  beforeEach(function() {
211
211
  loader.load("resource", {}, onLoaded);
212
- receiver = scriptRequest.send.calls[0].args[0];
212
+ receiver = scriptRequest.send.calls.first().args[0];
213
213
  receiver.callback(null);
214
214
  });
215
215
 
@@ -220,29 +220,29 @@ describe("DependencyLoader", function() {
220
220
  });
221
221
 
222
222
  it("should not clean up the request when called back with true", function() {
223
- var loadCallback = onLoaded.calls[0].args[1];
223
+ var loadCallback = onLoaded.calls.first().args[1];
224
224
  expect(scriptRequest.cleanup).not.toHaveBeenCalled();
225
225
  loadCallback(true);
226
226
  expect(scriptRequest.cleanup).not.toHaveBeenCalled();
227
227
  });
228
228
 
229
229
  it("should clean up the request when called back with false", function() {
230
- var loadCallback = onLoaded.calls[0].args[1];
230
+ var loadCallback = onLoaded.calls.first().args[1];
231
231
  expect(scriptRequest.cleanup).not.toHaveBeenCalled();
232
232
  loadCallback(false);
233
- expect(scriptRequest.cleanup.calls.length).toEqual(1);
233
+ expect(scriptRequest.cleanup.calls.count()).toEqual(1);
234
234
  });
235
235
 
236
236
  it("should not call old callbacks after loading the script", function() {
237
- expect(onLoaded.calls.length).toEqual(1);
237
+ expect(onLoaded.calls.count()).toEqual(1);
238
238
 
239
239
  var onLoaded2 = jasmine.createSpy();
240
240
  loader.load("resource", {}, onLoaded2);
241
- var receiver = scriptRequest.send.calls[0].args[0];
241
+ var receiver = scriptRequest.send.calls.first().args[0];
242
242
  receiver.callback(null);
243
243
 
244
- expect(onLoaded.calls.length).toEqual(1);
245
- expect(onLoaded2.calls.length).toEqual(1);
244
+ expect(onLoaded.calls.count()).toEqual(1);
245
+ expect(onLoaded2.calls.count()).toEqual(1);
246
246
  });
247
247
  });
248
248
  });
@@ -9,7 +9,7 @@ describe("JSONPRequest", function() {
9
9
  var scriptRequest;
10
10
 
11
11
  beforeEach(function() {
12
- spyOn(Runtime, "createScriptRequest").andCallFake(function() {
12
+ spyOn(Runtime, "createScriptRequest").and.callFake(function() {
13
13
  scriptRequest = Mocks.getScriptRequest();
14
14
  return scriptRequest;
15
15
  });
@@ -21,7 +21,7 @@ describe("JSONPRequest", function() {
21
21
  it("should send the script request to a correct URL", function() {
22
22
  var request = new JSONPRequest("http://example.com", {});
23
23
  request.send(receiver);
24
- expect(Runtime.createScriptRequest.calls.length).toEqual(1);
24
+ expect(Runtime.createScriptRequest.calls.count()).toEqual(1);
25
25
  expect(Runtime.createScriptRequest).toHaveBeenCalledWith(
26
26
  "http://example.com/" + receiver.number + "?"
27
27
  );
@@ -32,7 +32,7 @@ describe("JSONPRequest", function() {
32
32
  var request = new JSONPRequest("http://example.org", {});
33
33
  request.send(receiver);
34
34
  expect(callback).not.toHaveBeenCalled();
35
- scriptRequest.send.calls[0].args[0].callback("first", "second");
35
+ scriptRequest.send.calls.first().args[0].callback("first", "second");
36
36
  expect(callback).toHaveBeenCalledWith("first", "second");
37
37
  });
38
38
 
@@ -44,7 +44,7 @@ describe("JSONPRequest", function() {
44
44
  });
45
45
 
46
46
  request.send(receiver);
47
- var url = Runtime.createScriptRequest.calls[0].args[0];
47
+ var url = Runtime.createScriptRequest.calls.first().args[0];
48
48
  var queryString = url.match(/http:\/\/example.org\/[0-9]+\?(.*)$/)[1];
49
49
  var queryStringPairs = queryString.split("&");
50
50
  expect(queryStringPairs.length).toEqual(3);
@@ -111,9 +111,9 @@ describe("JSONPRequest", function() {
111
111
  it("should be idempotent", function() {
112
112
  var request = new JSONPRequest("http://example.org", {});
113
113
  request.send(receiver);
114
- expect(Runtime.createScriptRequest.calls.length).toEqual(1);
114
+ expect(Runtime.createScriptRequest.calls.count()).toEqual(1);
115
115
  request.send(receiver);
116
- expect(Runtime.createScriptRequest.calls.length).toEqual(1);
116
+ expect(Runtime.createScriptRequest.calls.count()).toEqual(1);
117
117
  });
118
118
  });
119
119
 
@@ -121,7 +121,7 @@ describe("JSONPRequest", function() {
121
121
  it("should call cleanup on the script request", function() {
122
122
  var request = new JSONPRequest("http://example.com", {});
123
123
  request.send(receiver);
124
- expect(Runtime.createScriptRequest.calls.length).toEqual(1);
124
+ expect(Runtime.createScriptRequest.calls.count()).toEqual(1);
125
125
  expect(scriptRequest.cleanup).not.toHaveBeenCalled();
126
126
  request.cleanup();
127
127
  expect(scriptRequest.cleanup).toHaveBeenCalled();