1
- import { decodePacket , decodePayload , encodePacket , encodePayload } from ".." ;
1
+ import {
2
+ decodePacket ,
3
+ decodePayload ,
4
+ encodePacket ,
5
+ encodePayload ,
6
+ Packet
7
+ } from ".." ;
2
8
import * as expect from "expect.js" ;
3
9
import { areArraysEqual } from "./util" ;
4
10
5
11
describe ( "engine.io-parser (node.js only)" , ( ) => {
6
12
describe ( "single packet" , ( ) => {
7
13
it ( "should encode/decode a Buffer" , done => {
8
- const packet = { type : "message" , data : Buffer . from ( [ 1 , 2 , 3 , 4 ] ) } ;
14
+ const packet : Packet = {
15
+ type : "message" ,
16
+ data : Buffer . from ( [ 1 , 2 , 3 , 4 ] )
17
+ } ;
9
18
encodePacket ( packet , true , encodedPacket => {
10
19
expect ( encodedPacket ) . to . eql ( packet . data ) ; // noop
11
- expect ( decodePacket ( encodedPacket , { } ) ) . to . eql ( packet ) ;
20
+ expect ( decodePacket ( encodedPacket ) ) . to . eql ( packet ) ;
12
21
done ( ) ;
13
22
} ) ;
14
23
} ) ;
15
24
16
25
it ( "should encode/decode a Buffer as base64" , done => {
17
- const packet = { type : "message" , data : Buffer . from ( [ 1 , 2 , 3 , 4 ] ) } ;
26
+ const packet : Packet = {
27
+ type : "message" ,
28
+ data : Buffer . from ( [ 1 , 2 , 3 , 4 ] )
29
+ } ;
18
30
encodePacket ( packet , false , encodedPacket => {
19
31
expect ( encodedPacket ) . to . eql ( "bAQIDBA==" ) ;
20
- expect ( decodePacket ( encodedPacket , "buffer " ) ) . to . eql ( packet ) ;
32
+ expect ( decodePacket ( encodedPacket , "nodebuffer " ) ) . to . eql ( packet ) ;
21
33
done ( ) ;
22
34
} ) ;
23
35
} ) ;
24
36
25
37
it ( "should encode/decode an ArrayBuffer" , done => {
26
- const packet = {
38
+ const packet : Packet = {
27
39
type : "message" ,
28
40
data : Int8Array . from ( [ 1 , 2 , 3 , 4 ] ) . buffer
29
41
} ;
@@ -38,7 +50,7 @@ describe("engine.io-parser (node.js only)", () => {
38
50
} ) ;
39
51
40
52
it ( "should encode/decode an ArrayBuffer as base64" , done => {
41
- const packet = {
53
+ const packet : Packet = {
42
54
type : "message" ,
43
55
data : Int8Array . from ( [ 1 , 2 , 3 , 4 ] ) . buffer
44
56
} ;
@@ -83,13 +95,13 @@ describe("engine.io-parser (node.js only)", () => {
83
95
84
96
describe ( "payload" , ( ) => {
85
97
it ( "should encode/decode a string + Buffer payload" , done => {
86
- const packets = [
98
+ const packets : Packet [ ] = [
87
99
{ type : "message" , data : "test" } ,
88
100
{ type : "message" , data : Buffer . from ( [ 1 , 2 , 3 , 4 ] ) }
89
101
] ;
90
102
encodePayload ( packets , payload => {
91
103
expect ( payload ) . to . eql ( "4test\x1ebAQIDBA==" ) ;
92
- expect ( decodePayload ( payload , "buffer " ) ) . to . eql ( packets ) ;
104
+ expect ( decodePayload ( payload , "nodebuffer " ) ) . to . eql ( packets ) ;
93
105
done ( ) ;
94
106
} ) ;
95
107
} ) ;
0 commit comments