cmd-control-client-lib 3.0.12 → 3.0.14

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cmd-control-client-lib",
3
3
  "description": "Cmd-Client-Library",
4
- "version": "3.0.12",
4
+ "version": "3.0.14",
5
5
  "directories": {
6
6
  "lib": "./dist"
7
7
  },
@@ -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 = new VControlErrorEvent("error");
53
- firstError.reConnectTimeout = 15000;
54
- firstError.isFatal = false;
50
+ const firstError = new CustomEvent("connection-error", { detail: { 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 = new VControlErrorEvent("error");
66
- secondError.reConnectTimeout = 30000;
67
- secondError.isFatal = false;
61
+ const secondError = new CustomEvent("connection-error", { detail: { 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 = new VControlErrorEvent("error");
81
- thirdError.reConnectTimeout = 45000;
82
- thirdError.isFatal = false;
74
+ const thirdError = new CustomEvent("connection-error", { detail: { 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 = new VControlErrorEvent("error");
96
- fourthError.reConnectTimeout = 60000;
97
- fourthError.isFatal = false;
87
+ const fourthError = new CustomEvent("connection-error", { detail: { 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 = new VControlErrorEvent("error");
111
- fifthError.reConnectTimeout = 75000;
112
- fifthError.isFatal = false;
100
+ const fifthError = new CustomEvent("connection-error", { detail: { 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
- const fatalError = new VControlErrorEvent("error");
123
- fatalError.reConnectTimeout = 90000;
124
- fatalError.isFatal = true;
110
+
111
+ const fatalError = new CustomEvent("connection-error", { detail: { 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
  });
@@ -1,4 +0,0 @@
1
- export declare class VControlErrorEvent extends Event {
2
- reConnectTimeout?: number;
3
- isFatal?: boolean;
4
- }