2
2
import { Buffer } from "deno" ;
3
3
import { BufReader } from "../io/bufio.ts" ;
4
4
import { test , assert , assertEqual } from "../testing/mod.ts" ;
5
- import {
6
- createSecAccept ,
7
- OpCodeBinaryFrame ,
8
- OpCodeContinue ,
9
- OpcodePing ,
10
- OpcodePong ,
11
- OpCodeTextFrame ,
12
- readFrame ,
13
- unmask
14
- } from "./mod.ts" ;
5
+ import { createSecAccept , OpCode , readFrame , unmask } from "./mod.ts" ;
15
6
import { serve } from "../http/http.ts" ;
16
7
17
8
test ( async function testReadUnmaskedTextFrame ( ) {
@@ -20,7 +11,7 @@ test(async function testReadUnmaskedTextFrame() {
20
11
new Buffer ( new Uint8Array ( [ 0x81 , 0x05 , 0x48 , 0x65 , 0x6c , 0x6c , 0x6f ] ) )
21
12
) ;
22
13
const frame = await readFrame ( buf ) ;
23
- assertEqual ( frame . opcode , OpCodeTextFrame ) ;
14
+ assertEqual ( frame . opcode , OpCode . TextFrame ) ;
24
15
assertEqual ( frame . mask , undefined ) ;
25
16
assertEqual ( new Buffer ( frame . payload ) . toString ( ) , "Hello" ) ;
26
17
assertEqual ( frame . isLastFrame , true ) ;
@@ -47,7 +38,7 @@ test(async function testReadMakedTextFrame() {
47
38
) ;
48
39
const frame = await readFrame ( buf ) ;
49
40
console . dir ( frame ) ;
50
- assertEqual ( frame . opcode , OpCodeTextFrame ) ;
41
+ assertEqual ( frame . opcode , OpCode . TextFrame ) ;
51
42
unmask ( frame . payload , frame . mask ) ;
52
43
assertEqual ( new Buffer ( frame . payload ) . toString ( ) , "Hello" ) ;
53
44
assertEqual ( frame . isLastFrame , true ) ;
@@ -63,12 +54,12 @@ test(async function testReadUnmaskedSplittedTextFrames() {
63
54
const [ f1 , f2 ] = await Promise . all ( [ readFrame ( buf1 ) , readFrame ( buf2 ) ] ) ;
64
55
assertEqual ( f1 . isLastFrame , false ) ;
65
56
assertEqual ( f1 . mask , undefined ) ;
66
- assertEqual ( f1 . opcode , OpCodeTextFrame ) ;
57
+ assertEqual ( f1 . opcode , OpCode . TextFrame ) ;
67
58
assertEqual ( new Buffer ( f1 . payload ) . toString ( ) , "Hel" ) ;
68
59
69
60
assertEqual ( f2 . isLastFrame , true ) ;
70
61
assertEqual ( f2 . mask , undefined ) ;
71
- assertEqual ( f2 . opcode , OpCodeContinue ) ;
62
+ assertEqual ( f2 . opcode , OpCode . Continue ) ;
72
63
assertEqual ( new Buffer ( f2 . payload ) . toString ( ) , "lo" ) ;
73
64
} ) ;
74
65
@@ -78,7 +69,7 @@ test(async function testReadUnmaksedPingPongFrame() {
78
69
new Buffer ( new Uint8Array ( [ 0x89 , 0x05 , 0x48 , 0x65 , 0x6c , 0x6c , 0x6f ] ) )
79
70
) ;
80
71
const ping = await readFrame ( buf ) ;
81
- assertEqual ( ping . opcode , OpcodePing ) ;
72
+ assertEqual ( ping . opcode , OpCode . Ping ) ;
82
73
assertEqual ( new Buffer ( ping . payload ) . toString ( ) , "Hello" ) ;
83
74
84
75
const buf2 = new BufReader (
@@ -99,7 +90,7 @@ test(async function testReadUnmaksedPingPongFrame() {
99
90
)
100
91
) ;
101
92
const pong = await readFrame ( buf2 ) ;
102
- assertEqual ( pong . opcode , OpcodePong ) ;
93
+ assertEqual ( pong . opcode , OpCode . Pong ) ;
103
94
assert ( pong . mask !== undefined ) ;
104
95
unmask ( pong . payload , pong . mask ) ;
105
96
assertEqual ( new Buffer ( pong . payload ) . toString ( ) , "Hello" ) ;
@@ -112,7 +103,7 @@ test(async function testReadUnmaksedBigBinaryFrame() {
112
103
}
113
104
const buf = new BufReader ( new Buffer ( new Uint8Array ( a ) ) ) ;
114
105
const bin = await readFrame ( buf ) ;
115
- assertEqual ( bin . opcode , OpCodeBinaryFrame ) ;
106
+ assertEqual ( bin . opcode , OpCode . BinaryFrame ) ;
116
107
assertEqual ( bin . isLastFrame , true ) ;
117
108
assertEqual ( bin . mask , undefined ) ;
118
109
assertEqual ( bin . payload . length , 256 ) ;
@@ -125,7 +116,7 @@ test(async function testReadUnmaskedBigBigBinaryFrame() {
125
116
}
126
117
const buf = new BufReader ( new Buffer ( new Uint8Array ( a ) ) ) ;
127
118
const bin = await readFrame ( buf ) ;
128
- assertEqual ( bin . opcode , OpCodeBinaryFrame ) ;
119
+ assertEqual ( bin . opcode , OpCode . BinaryFrame ) ;
129
120
assertEqual ( bin . isLastFrame , true ) ;
130
121
assertEqual ( bin . mask , undefined ) ;
131
122
assertEqual ( bin . payload . length , 0xffff + 1 ) ;
0 commit comments