1- import { decodePacket , decodePayload , encodePacket , encodePayload } from ".." ;
1+ import {
2+ decodePacket ,
3+ decodePayload ,
4+ encodePacket ,
5+ encodePayload ,
6+ Packet
7+ } from ".." ;
28import * as expect from "expect.js" ;
39import { areArraysEqual } from "./util" ;
410
511describe ( "engine.io-parser (node.js only)" , ( ) => {
612 describe ( "single packet" , ( ) => {
713 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+ } ;
918 encodePacket ( packet , true , encodedPacket => {
1019 expect ( encodedPacket ) . to . eql ( packet . data ) ; // noop
11- expect ( decodePacket ( encodedPacket , { } ) ) . to . eql ( packet ) ;
20+ expect ( decodePacket ( encodedPacket ) ) . to . eql ( packet ) ;
1221 done ( ) ;
1322 } ) ;
1423 } ) ;
1524
1625 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+ } ;
1830 encodePacket ( packet , false , encodedPacket => {
1931 expect ( encodedPacket ) . to . eql ( "bAQIDBA==" ) ;
20- expect ( decodePacket ( encodedPacket , "buffer " ) ) . to . eql ( packet ) ;
32+ expect ( decodePacket ( encodedPacket , "nodebuffer " ) ) . to . eql ( packet ) ;
2133 done ( ) ;
2234 } ) ;
2335 } ) ;
2436
2537 it ( "should encode/decode an ArrayBuffer" , done => {
26- const packet = {
38+ const packet : Packet = {
2739 type : "message" ,
2840 data : Int8Array . from ( [ 1 , 2 , 3 , 4 ] ) . buffer
2941 } ;
@@ -38,7 +50,7 @@ describe("engine.io-parser (node.js only)", () => {
3850 } ) ;
3951
4052 it ( "should encode/decode an ArrayBuffer as base64" , done => {
41- const packet = {
53+ const packet : Packet = {
4254 type : "message" ,
4355 data : Int8Array . from ( [ 1 , 2 , 3 , 4 ] ) . buffer
4456 } ;
@@ -83,13 +95,13 @@ describe("engine.io-parser (node.js only)", () => {
8395
8496 describe ( "payload" , ( ) => {
8597 it ( "should encode/decode a string + Buffer payload" , done => {
86- const packets = [
98+ const packets : Packet [ ] = [
8799 { type : "message" , data : "test" } ,
88100 { type : "message" , data : Buffer . from ( [ 1 , 2 , 3 , 4 ] ) }
89101 ] ;
90102 encodePayload ( packets , payload => {
91103 expect ( payload ) . to . eql ( "4test\x1ebAQIDBA==" ) ;
92- expect ( decodePayload ( payload , "buffer " ) ) . to . eql ( packets ) ;
104+ expect ( decodePayload ( payload , "nodebuffer " ) ) . to . eql ( packets ) ;
93105 done ( ) ;
94106 } ) ;
95107 } ) ;
0 commit comments