33import { hasQuic , skip , mustCall } from '../common/index.mjs' ;
44import { ok , strictEqual , deepStrictEqual } from 'node:assert' ;
55import { readKey } from '../common/fixtures.mjs' ;
6+ import { KNOWN_BYTES_LONG , uint8concat } from '../common/quic/test-helpers.mjs' ;
67import { TransformStream } from 'node:stream/web' ;
78
89if ( ! hasQuic ) {
@@ -19,53 +20,6 @@ const certs = readKey('agent1-cert.pem');
1920// The opened promise should resolve when the client finished reading
2021const clientFinished = Promise . withResolvers ( ) ;
2122
22- // start demo data
23- // FIX ME: move the following to a central place
24- // if used in several tests
25- // taken from @fails -components/webtransport tests
26- // by the original author
27- function createBytesChunk ( length ) {
28- const workArray = new Array ( length / 2 ) ;
29- for ( let i = 0 ; i < length / 4 ; i ++ ) {
30- workArray [ 2 * i + 1 ] = length % 0xffff ;
31- workArray [ 2 * i ] = i ;
32- }
33- const helper = new Uint16Array ( workArray ) ;
34- const toreturn = new Uint8Array (
35- helper . buffer ,
36- helper . byteOffset ,
37- helper . byteLength
38- ) ;
39- return toreturn ;
40- }
41-
42- // The number in the comments, help you identify the chunk, as it is the length first two bytes
43- // this is helpful, when debugging buffer passing
44- const KNOWN_BYTES_LONG = [
45- createBytesChunk ( 60000 ) , // 96, 234
46- createBytesChunk ( 12 ) , // 0, 12
47- createBytesChunk ( 50000 ) , // 195, 80
48- createBytesChunk ( 1600 ) . buffer , // 6, 64 we use buffer here to increae test coverage
49- createBytesChunk ( 20000 ) , // 78, 32
50- createBytesChunk ( 30000 ) , // 117, 48
51- ] ;
52-
53- // end demo data
54-
55- function uint8concat ( arrays ) {
56- const length = arrays . reduce ( ( acc , curr ) => acc + curr . length , 0 ) ;
57- const result = new Uint8Array ( length ) ;
58- let pos = 0 ;
59- let array = 0 ;
60- while ( pos < length ) {
61- const curArr = arrays [ array ] ;
62- const curLen = curArr . byteLength ;
63- const dest = new Uint8Array ( result . buffer , result . byteOffset + pos , curLen ) ;
64- dest . set ( curArr ) ;
65- array ++ ;
66- pos += curArr . byteLength ;
67- }
68- }
6923
7024const serverEndpoint = await listen ( async ( serverSession ) => {
7125 await serverSession . opened ;
0 commit comments