1
- var parser = require ( '..' ) ;
2
- var expect = require ( 'expect.js' ) ;
3
- var helpers = require ( './helpers.js' ) ;
1
+ const { PacketType , Decoder , Encoder } = require ( '..' ) ;
2
+ const expect = require ( 'expect.js' ) ;
3
+ const helpers = require ( './helpers.js' ) ;
4
4
5
5
describe ( 'parser' , function ( ) {
6
6
7
7
it ( 'exposes types' , function ( ) {
8
- expect ( parser . CONNECT ) . to . be . a ( 'number' ) ;
9
- expect ( parser . DISCONNECT ) . to . be . a ( 'number' ) ;
10
- expect ( parser . EVENT ) . to . be . a ( 'number' ) ;
11
- expect ( parser . ACK ) . to . be . a ( 'number' ) ;
12
- expect ( parser . ERROR ) . to . be . a ( 'number' ) ;
13
- expect ( parser . BINARY_EVENT ) . to . be . a ( 'number' ) ;
14
- expect ( parser . BINARY_ACK ) . to . be . a ( 'number' ) ;
8
+ expect ( PacketType . CONNECT ) . to . be . a ( 'number' ) ;
9
+ expect ( PacketType . DISCONNECT ) . to . be . a ( 'number' ) ;
10
+ expect ( PacketType . EVENT ) . to . be . a ( 'number' ) ;
11
+ expect ( PacketType . ACK ) . to . be . a ( 'number' ) ;
12
+ expect ( PacketType . ERROR ) . to . be . a ( 'number' ) ;
13
+ expect ( PacketType . BINARY_EVENT ) . to . be . a ( 'number' ) ;
14
+ expect ( PacketType . BINARY_ACK ) . to . be . a ( 'number' ) ;
15
15
} ) ;
16
16
17
17
it ( 'encodes connection' , function ( ) {
18
18
helpers . test ( {
19
- type : parser . CONNECT ,
19
+ type : PacketType . CONNECT ,
20
20
nsp : '/woot'
21
21
} ) ;
22
22
} ) ;
23
23
24
24
it ( 'encodes disconnection' , function ( ) {
25
25
helpers . test ( {
26
- type : parser . DISCONNECT ,
26
+ type : PacketType . DISCONNECT ,
27
27
nsp : '/woot'
28
28
} ) ;
29
29
} ) ;
30
30
31
31
it ( 'encodes an event' , function ( ) {
32
32
helpers . test ( {
33
- type : parser . EVENT ,
33
+ type : PacketType . EVENT ,
34
34
data : [ 'a' , 1 , { } ] ,
35
35
nsp : '/'
36
36
} ) ;
37
37
helpers . test ( {
38
- type : parser . EVENT ,
38
+ type : PacketType . EVENT ,
39
39
data : [ 'a' , 1 , { } ] ,
40
40
id : 1 ,
41
41
nsp : '/test'
@@ -44,7 +44,7 @@ describe('parser', function(){
44
44
45
45
it ( 'encodes an ack' , function ( ) {
46
46
helpers . test ( {
47
- type : parser . ACK ,
47
+ type : PacketType . ACK ,
48
48
data : [ 'a' , 1 , { } ] ,
49
49
id : 123 ,
50
50
nsp : '/'
@@ -53,7 +53,7 @@ describe('parser', function(){
53
53
54
54
it ( 'encodes an error' , function ( ) {
55
55
helpers . test ( {
56
- type : parser . ERROR ,
56
+ type : PacketType . ERROR ,
57
57
data : 'Unauthorized' ,
58
58
nsp : '/'
59
59
} ) ;
@@ -64,13 +64,13 @@ describe('parser', function(){
64
64
a . b = a ;
65
65
66
66
var data = {
67
- type : parser . EVENT ,
67
+ type : PacketType . EVENT ,
68
68
data : a ,
69
69
id : 1 ,
70
70
nsp : '/'
71
71
}
72
72
73
- var encoder = new parser . Encoder ( ) ;
73
+ const encoder = new Encoder ( ) ;
74
74
75
75
encoder . encode ( data , function ( encodedPackets ) {
76
76
expect ( encodedPackets [ 0 ] ) . to . be ( '4"encode error"' ) ;
@@ -79,15 +79,15 @@ describe('parser', function(){
79
79
80
80
it ( 'decodes a bad binary packet' , function ( ) {
81
81
try {
82
- var decoder = new parser . Decoder ( ) ;
82
+ const decoder = new Decoder ( ) ;
83
83
decoder . add ( '5' ) ;
84
84
} catch ( e ) {
85
85
expect ( e . message ) . to . match ( / I l l e g a l / ) ;
86
86
}
87
87
} ) ;
88
88
89
89
it ( 'throw an error upon parsing error' , ( ) => {
90
- expect ( ( ) => new parser . Decoder ( ) . add ( '442["some","data"' ) ) . to . throwException ( / ^ i n v a l i d p a y l o a d $ / ) ;
91
- expect ( ( ) => new parser . Decoder ( ) . add ( '999' ) ) . to . throwException ( / ^ u n k n o w n p a c k e t t y p e 9 $ / ) ;
90
+ expect ( ( ) => new Decoder ( ) . add ( '442["some","data"' ) ) . to . throwException ( / ^ i n v a l i d p a y l o a d $ / ) ;
91
+ expect ( ( ) => new Decoder ( ) . add ( '999' ) ) . to . throwException ( / ^ u n k n o w n p a c k e t t y p e 9 $ / ) ;
92
92
} ) ;
93
93
} ) ;
0 commit comments