cmd-control-client-lib 3.0.12 → 3.0.17
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/dist/@types/index.d.ts +1 -0
- package/dist/@types/reconnection-error-event.d.ts +4 -0
- package/dist/cmd-connection.d.ts +2 -1
- package/dist/cmd-control-client-lib.js +1 -1
- package/dist/cmd-control-client-lib.js.map +1 -1
- package/package.json +1 -1
- package/test/open-web-socket.spec.ts +8 -23
- package/dist/v-control-error-event.d.ts +0 -4
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CmdConnection, ConnectionConfig } from "../src/cmd-connection";
|
|
2
2
|
import { logger } from "../src/logger";
|
|
3
|
-
import { VControlErrorEvent } from "../src/v-control-error-event";
|
|
4
3
|
|
|
5
4
|
describe("WebSocket connection", () => {
|
|
6
5
|
it("Should open webSocket successfully", () => {
|
|
@@ -22,7 +21,6 @@ describe("WebSocket connection", () => {
|
|
|
22
21
|
it("Should make 5 attempts if webSocket open failed", () => {
|
|
23
22
|
logger.log = jest.fn();
|
|
24
23
|
jest.useFakeTimers();
|
|
25
|
-
const error = "Connection failed Mock";
|
|
26
24
|
// @ts-ignore
|
|
27
25
|
global.WebSocket = jest.fn().mockImplementation(() => {
|
|
28
26
|
return { readyState: 3 };
|
|
@@ -49,9 +47,7 @@ describe("WebSocket connection", () => {
|
|
|
49
47
|
expect(setTimeout).toHaveBeenCalledTimes(1);
|
|
50
48
|
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 15000);
|
|
51
49
|
|
|
52
|
-
const firstError =
|
|
53
|
-
firstError.reConnectTimeout = 15000;
|
|
54
|
-
firstError.isFatal = false;
|
|
50
|
+
const firstError = { reConnectionTimeout: 15000 };
|
|
55
51
|
expect(connectionConfig.onError).toHaveBeenCalledWith(firstError);
|
|
56
52
|
jest.runOnlyPendingTimers();
|
|
57
53
|
expect(logger.log).toHaveBeenCalledWith("CMDP. retry connect in 15000 ms");
|
|
@@ -62,9 +58,7 @@ describe("WebSocket connection", () => {
|
|
|
62
58
|
CMDConnection._socket.onerror();
|
|
63
59
|
CMDConnection._socket.onclose();
|
|
64
60
|
|
|
65
|
-
const secondError =
|
|
66
|
-
secondError.reConnectTimeout = 30000;
|
|
67
|
-
secondError.isFatal = false;
|
|
61
|
+
const secondError = { reConnectionTimeout: 30000 };
|
|
68
62
|
expect(setTimeout).toHaveBeenCalledTimes(2);
|
|
69
63
|
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 30000);
|
|
70
64
|
expect(connectionConfig.onError).toHaveBeenCalledWith(secondError);
|
|
@@ -77,9 +71,7 @@ describe("WebSocket connection", () => {
|
|
|
77
71
|
CMDConnection._socket.onerror();
|
|
78
72
|
CMDConnection._socket.onclose();
|
|
79
73
|
|
|
80
|
-
const thirdError =
|
|
81
|
-
thirdError.reConnectTimeout = 45000;
|
|
82
|
-
thirdError.isFatal = false;
|
|
74
|
+
const thirdError = { reConnectionTimeout: 45000 };
|
|
83
75
|
expect(setTimeout).toHaveBeenCalledTimes(3);
|
|
84
76
|
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 45000);
|
|
85
77
|
expect(connectionConfig.onError).toHaveBeenCalledWith(thirdError);
|
|
@@ -92,9 +84,7 @@ describe("WebSocket connection", () => {
|
|
|
92
84
|
CMDConnection._socket.onerror();
|
|
93
85
|
CMDConnection._socket.onclose();
|
|
94
86
|
|
|
95
|
-
const fourthError =
|
|
96
|
-
fourthError.reConnectTimeout = 60000;
|
|
97
|
-
fourthError.isFatal = false;
|
|
87
|
+
const fourthError = { reConnectionTimeout: 60000 };
|
|
98
88
|
expect(setTimeout).toHaveBeenCalledTimes(4);
|
|
99
89
|
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 60000);
|
|
100
90
|
expect(connectionConfig.onError).toHaveBeenCalledWith(fourthError);
|
|
@@ -107,9 +97,7 @@ describe("WebSocket connection", () => {
|
|
|
107
97
|
CMDConnection._socket.onerror();
|
|
108
98
|
CMDConnection._socket.onclose();
|
|
109
99
|
|
|
110
|
-
const fifthError =
|
|
111
|
-
fifthError.reConnectTimeout = 75000;
|
|
112
|
-
fifthError.isFatal = false;
|
|
100
|
+
const fifthError = { reConnectionTimeout: 75000 };
|
|
113
101
|
expect(setTimeout).toHaveBeenCalledTimes(5);
|
|
114
102
|
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 75000);
|
|
115
103
|
expect(connectionConfig.onError).toHaveBeenCalledWith(fifthError);
|
|
@@ -119,14 +107,11 @@ describe("WebSocket connection", () => {
|
|
|
119
107
|
expect(global.WebSocket).toHaveBeenCalledTimes(6);
|
|
120
108
|
CMDConnection._socket.onerror();
|
|
121
109
|
CMDConnection._socket.onclose();
|
|
122
|
-
|
|
123
|
-
fatalError
|
|
124
|
-
fatalError
|
|
110
|
+
|
|
111
|
+
const fatalError = { isFatal: true };
|
|
112
|
+
expect(connectionConfig.onError).toHaveBeenCalledWith(fatalError);
|
|
125
113
|
//No more setTimeout was called
|
|
126
114
|
expect(setTimeout).toHaveBeenCalledTimes(5);
|
|
127
|
-
expect(global.WebSocket).toHaveBeenCalledTimes(6);
|
|
128
|
-
expect(connectionConfig.onError).toHaveBeenCalledWith(fatalError);
|
|
129
115
|
expect(logger.log).toHaveBeenCalledWith("CMDP. maximum reconnect attempts count reached");
|
|
130
|
-
expect(CMDConnection._reConnectAttemptsCount).toEqual(0);
|
|
131
116
|
});
|
|
132
117
|
});
|