split-frames 2.4.4 → 2.5.0

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.
@@ -1,394 +0,0 @@
1
- /*
2
- eslint no-new: 0
3
- */
4
-
5
- "use strict";
6
-
7
- // deps
8
-
9
- const assert = require("assert");
10
- const SplitFrames = require(require("path").join(__dirname, "..", "lib", "main.js"));
11
-
12
- // consts
13
-
14
- const STX = 0x02;
15
- const ETX = 0x03;
16
- const ACK = 0x06;
17
- const WAK = 0x13;
18
- const NAK = 0x15;
19
-
20
- // module
21
-
22
- describe("parameters", () => {
23
-
24
- it("should check with wrong options", () => {
25
-
26
- assert.throws(() => {
27
- new SplitFrames(false);
28
- }, TypeError);
29
-
30
- });
31
-
32
- describe("basic validations", () => {
33
-
34
- describe("start tag", () => {
35
-
36
- it("should check with wrong parameter", () => {
37
-
38
- assert.throws(() => {
39
- new SplitFrames({
40
- "startWith": "test"
41
- });
42
- }, TypeError);
43
-
44
- assert.throws(() => {
45
- new SplitFrames({
46
- "startWith": [ "test" ]
47
- });
48
- }, TypeError);
49
-
50
- });
51
-
52
- it("should check with right parameter", () => {
53
-
54
- assert.doesNotThrow(() => {
55
- new SplitFrames({
56
- "startWith": 0x02
57
- });
58
- });
59
-
60
- assert.doesNotThrow(() => {
61
- new SplitFrames({
62
- "startWith": [ 0x02, 0x03 ]
63
- });
64
- });
65
-
66
- assert.doesNotThrow(() => {
67
- new SplitFrames({
68
- "startWith": [ Buffer.from([ 0x02 ]) ]
69
- });
70
- });
71
-
72
- assert.doesNotThrow(() => {
73
- new SplitFrames({
74
- "startWith": [ Buffer.from([ 0x02 ]), Buffer.from([ 0x03 ]) ]
75
- });
76
- });
77
-
78
- });
79
-
80
- });
81
-
82
- describe("start timeout tag", () => {
83
-
84
- it("should check with wrong parameter", () => {
85
-
86
- assert.throws(() => {
87
- new SplitFrames({
88
- "startTimeout": "test"
89
- });
90
- }, TypeError);
91
-
92
- });
93
-
94
- it("should check with right parameter", () => {
95
-
96
- assert.doesNotThrow(() => {
97
- new SplitFrames({
98
- "startTimeout": 200
99
- });
100
- });
101
-
102
- });
103
-
104
- });
105
-
106
- describe("end tag", () => {
107
-
108
- it("should check with wrong parameter", () => {
109
-
110
- assert.throws(() => {
111
- new SplitFrames({
112
- "endWith": "test"
113
- });
114
- }, TypeError);
115
-
116
- assert.throws(() => {
117
- new SplitFrames({
118
- "endWith": [ "test" ]
119
- });
120
- }, TypeError);
121
-
122
- });
123
-
124
- it("should check with right parameter", () => {
125
-
126
- assert.doesNotThrow(() => {
127
- new SplitFrames({
128
- "endWith": 0x02
129
- });
130
- });
131
-
132
- assert.doesNotThrow(() => {
133
- new SplitFrames({
134
- "endWith": [ 0x02, 0x03 ]
135
- });
136
- });
137
-
138
- assert.doesNotThrow(() => {
139
- new SplitFrames({
140
- "endWith": [ Buffer.from([ 0x02 ]) ]
141
- });
142
- });
143
-
144
- assert.doesNotThrow(() => {
145
- new SplitFrames({
146
- "endWith": [ Buffer.from([ 0x02 ]), Buffer.from([ 0x03 ]) ]
147
- });
148
- });
149
-
150
- });
151
-
152
- });
153
-
154
- describe("escapeWith tag", () => {
155
-
156
- it("should check with wrong parameter", () => {
157
-
158
- assert.throws(() => {
159
- new SplitFrames({
160
- "escapeWith": "test"
161
- });
162
- }, TypeError);
163
-
164
- assert.throws(() => {
165
- new SplitFrames({
166
- "escapeWith": [ "test" ]
167
- });
168
- }, TypeError);
169
-
170
- });
171
-
172
- it("should check with right parameter", () => {
173
-
174
- assert.doesNotThrow(() => {
175
- new SplitFrames({
176
- "escapeWith": 0x02
177
- });
178
- });
179
-
180
- });
181
-
182
- });
183
-
184
- describe("escaped tag", () => {
185
-
186
- it("should check with wrong parameter", () => {
187
-
188
- assert.throws(() => {
189
- new SplitFrames({
190
- "escaped": "test"
191
- });
192
- }, TypeError);
193
-
194
- assert.throws(() => {
195
- new SplitFrames({
196
- "escaped": [ "test" ]
197
- });
198
- }, TypeError);
199
-
200
- });
201
-
202
- it("should check with right parameter", () => {
203
-
204
- assert.doesNotThrow(() => {
205
- new SplitFrames({
206
- "escaped": 0x02
207
- });
208
- });
209
-
210
- assert.doesNotThrow(() => {
211
- new SplitFrames({
212
- "escaped": [ 0x02 ]
213
- });
214
- });
215
-
216
- });
217
-
218
- });
219
-
220
- describe("specifics tag", () => {
221
-
222
- it("should check with wrong parameter", () => {
223
-
224
- assert.throws(() => {
225
- new SplitFrames({
226
- "specifics": "test"
227
- });
228
- }, TypeError);
229
-
230
- assert.throws(() => {
231
- new SplitFrames({
232
- "specifics": {
233
- "nak": "test"
234
- }
235
- });
236
- }, Error);
237
-
238
- assert.throws(() => {
239
- new SplitFrames({
240
- "specifics": {
241
- "nak": [ "test" ]
242
- }
243
- });
244
- }, Error);
245
-
246
- });
247
-
248
- it("should check with right parameter", () => {
249
-
250
- assert.doesNotThrow(() => {
251
- new SplitFrames({
252
- "specifics": {
253
- "nak": 0x02
254
- }
255
- });
256
- });
257
-
258
- assert.doesNotThrow(() => {
259
- new SplitFrames({
260
- "specifics": {
261
- "nak": [ 0x02, 0x03 ]
262
- }
263
- });
264
- });
265
-
266
- assert.doesNotThrow(() => {
267
- new SplitFrames({
268
- "specifics": {
269
- "nak": [ Buffer.from([ 0x02 ]) ]
270
- }
271
- });
272
- });
273
-
274
- assert.doesNotThrow(() => {
275
- new SplitFrames({
276
- "specifics": {
277
- "nak": [ Buffer.from([ 0x02 ]), Buffer.from([ 0x03 ]) ]
278
- }
279
- });
280
- });
281
-
282
- });
283
-
284
- });
285
-
286
- });
287
-
288
- describe("specific tag validations with start and/or end", () => {
289
-
290
- it("should check ack tag with start only", () => {
291
-
292
- assert.throws(() => {
293
- new SplitFrames({
294
- "specifics": {
295
- "ack": ACK
296
- },
297
- "startWith": STX
298
- });
299
- }, Error);
300
-
301
- });
302
-
303
- it("should check ack tag with end only", () => {
304
-
305
- assert.doesNotThrow(() => {
306
- new SplitFrames({
307
- "specifics": {
308
- "ack": ACK
309
- },
310
- "endWith": ETX
311
- });
312
- }, Error);
313
-
314
- });
315
-
316
- it("should check nak tag with start only", () => {
317
-
318
- assert.throws(() => {
319
- new SplitFrames({
320
- "specifics": {
321
- "nak": NAK
322
- },
323
- "startWith": STX
324
- });
325
- }, Error);
326
-
327
- });
328
-
329
- it("should check nak tag with end only", () => {
330
-
331
- assert.doesNotThrow(() => {
332
- new SplitFrames({
333
- "specifics": {
334
- "nak": NAK
335
- },
336
- "endWith": ETX
337
- });
338
- }, Error);
339
-
340
- });
341
-
342
- it("should check wak tag with start only", () => {
343
-
344
- assert.throws(() => {
345
- new SplitFrames({
346
- "specifics": {
347
- "wak": WAK
348
- },
349
- "startWith": STX
350
- });
351
- }, Error);
352
-
353
- });
354
-
355
- it("should check wak tag with end only", () => {
356
-
357
- assert.doesNotThrow(() => {
358
- new SplitFrames({
359
- "specifics": {
360
- "wak": WAK
361
- },
362
- "endWith": ETX
363
- });
364
- }, Error);
365
-
366
- });
367
-
368
- });
369
-
370
- describe("control bits", () => {
371
-
372
- it("should check controlBits type", () => {
373
-
374
- assert.throws(() => {
375
- new SplitFrames({
376
- "controlBits": false
377
- });
378
- }, TypeError);
379
-
380
- });
381
-
382
- it("should check controlBits value", () => {
383
-
384
- assert.throws(() => {
385
- new SplitFrames({
386
- "controlBits": "end+3"
387
- });
388
- }, Error);
389
-
390
- });
391
-
392
- });
393
-
394
- });
@@ -1,81 +0,0 @@
1
- /*
2
- eslint no-new: 0
3
- */
4
-
5
- "use strict";
6
-
7
- // deps
8
-
9
- const assert = require("assert");
10
- const SplitFrames = require(require("path").join(__dirname, "..", "lib", "main.js"));
11
-
12
- // consts
13
-
14
- const STX = 0x02;
15
- const DLE = 0x10;
16
-
17
- // module
18
-
19
- describe("without tags", () => {
20
-
21
- it("should split frame without options", () => {
22
-
23
- return new Promise((resolve, reject) => {
24
-
25
- new SplitFrames().once("error", reject).once("data", (chunk) => {
26
-
27
- assert.strictEqual(typeof chunk, "object", "The chunk is not an object");
28
- assert.strictEqual(chunk instanceof Buffer, true, "The chunk is not a Buffer");
29
- assert.deepStrictEqual(chunk, Buffer.from([ 0x01, 0x02, 0x03, 0x04, 0x05 ]), "The chunk is not as expected");
30
-
31
- resolve();
32
-
33
- }).write(Buffer.from([ 0x01, 0x02, 0x03, 0x04, 0x05 ]));
34
-
35
- });
36
-
37
- });
38
-
39
- it("should split empty frame", () => {
40
-
41
- return new Promise((resolve, reject) => {
42
-
43
- const splitter = new SplitFrames().once("error", reject).once("data", (chunk) => {
44
-
45
- assert.strictEqual(typeof chunk, "object", "The chunk is not an object");
46
- assert.strictEqual(chunk instanceof Buffer, true, "The chunk is not a Buffer");
47
- assert.deepStrictEqual(chunk, Buffer.from([ 0x01 ]), "The chunk is not as expected");
48
-
49
- resolve();
50
-
51
- });
52
-
53
- splitter.write(Buffer.from([ ]));
54
- splitter.write(Buffer.from([ 0x01 ]));
55
-
56
- });
57
-
58
- });
59
-
60
- it("should split frame with escaped data", () => {
61
-
62
- return new Promise((resolve, reject) => {
63
-
64
- new SplitFrames({
65
- "escapeWith": DLE,
66
- "escaped": [ DLE, STX ]
67
- }).once("error", reject).once("data", (chunk) => {
68
-
69
- assert.strictEqual(typeof chunk, "object", "The chunk is not an object");
70
- assert.strictEqual(chunk instanceof Buffer, true, "The chunk is not a Buffer");
71
- assert.deepStrictEqual(chunk, Buffer.from([ 0x01, DLE, 0x04, 0x05, DLE, DLE, 0x06, 0x07, DLE, STX ]), "The chunk is not as expected");
72
-
73
- resolve();
74
-
75
- }).write(Buffer.from([ 0x01, DLE, 0x04, 0x05, DLE, DLE, 0x06, 0x07, DLE, STX ]));
76
-
77
- });
78
-
79
- });
80
-
81
- });