@@ -7,48 +7,52 @@ import * as HttpResponseCompression from "./HttpResponseCompression.ts";
77
88const body = new TextEncoder ( ) . encode ( `{"value":"${ "compressible" . repeat ( 1_000 ) } "}` ) ;
99
10- it . effect ( "creates a raw Node gzip stream" , ( ) =>
11- Effect . gen ( function * ( ) {
12- const compression = yield * HttpResponseCompression . HttpResponseCompression ;
13- const response = compression . gzip ( body , {
14- contentType : "application/json" ,
15- } ) ;
16-
17- expect ( response . body . _tag ) . toBe ( "Raw" ) ;
18- if ( response . body . _tag !== "Raw" ) throw new Error ( "Expected a raw response body." ) ;
19- expect ( response . body . body ) . toBeInstanceOf ( NodeStream . Readable ) ;
20- if ( ! ( response . body . body instanceof NodeStream . Readable ) ) {
21- throw new Error ( "Expected a Node readable." ) ;
22- }
23-
24- const rawBody = response . body . body ;
25- const chunks = yield * Effect . promise ( async ( ) => {
26- const chunks : Array < Buffer > = [ ] ;
27- for await ( const chunk of rawBody ) {
28- chunks . push ( Buffer . from ( chunk ) ) ;
10+ it . layer ( HttpResponseCompression . layerNode ) ( "Node HTTP response compression" , ( it ) => {
11+ it . effect ( "creates a raw gzip stream" , ( ) =>
12+ Effect . gen ( function * ( ) {
13+ const compression = yield * HttpResponseCompression . HttpResponseCompression ;
14+ const response = compression . gzip ( body , {
15+ contentType : "application/json" ,
16+ } ) ;
17+
18+ expect ( response . body . _tag ) . toBe ( "Raw" ) ;
19+ if ( response . body . _tag !== "Raw" ) throw new Error ( "Expected a raw response body." ) ;
20+ expect ( response . body . body ) . toBeInstanceOf ( NodeStream . Readable ) ;
21+ if ( ! ( response . body . body instanceof NodeStream . Readable ) ) {
22+ throw new Error ( "Expected a Node readable." ) ;
2923 }
30- return chunks ;
31- } ) ;
32- expect ( NodeZlib . gunzipSync ( Buffer . concat ( chunks ) ) ) . toEqual ( Buffer . from ( body ) ) ;
33- } ) . pipe ( Effect . provide ( HttpResponseCompression . layerNode ) ) ,
34- ) ;
35-
36- it . effect ( "creates a raw Bun gzip stream" , ( ) =>
37- Effect . gen ( function * ( ) {
38- const compression = yield * HttpResponseCompression . HttpResponseCompression ;
39- const response = compression . gzip ( body , {
40- contentType : "application/json" ,
41- } ) ;
42-
43- expect ( response . body . _tag ) . toBe ( "Raw" ) ;
44- if ( response . body . _tag !== "Raw" ) throw new Error ( "Expected a raw response body." ) ;
45- expect ( response . body . body ) . toBeInstanceOf ( ReadableStream ) ;
46- if ( ! ( response . body . body instanceof ReadableStream ) ) {
47- throw new Error ( "Expected a Web readable stream." ) ;
48- }
49-
50- const rawBody = response . body . body ;
51- const compressed = yield * Effect . promise ( ( ) => new Response ( rawBody ) . arrayBuffer ( ) ) ;
52- expect ( NodeZlib . gunzipSync ( compressed ) ) . toEqual ( Buffer . from ( body ) ) ;
53- } ) . pipe ( Effect . provide ( HttpResponseCompression . layerBun ) ) ,
54- ) ;
24+
25+ const rawBody = response . body . body ;
26+ const chunks = yield * Effect . promise ( async ( ) => {
27+ const chunks : Array < Buffer > = [ ] ;
28+ for await ( const chunk of rawBody ) {
29+ chunks . push ( Buffer . from ( chunk ) ) ;
30+ }
31+ return chunks ;
32+ } ) ;
33+ expect ( NodeZlib . gunzipSync ( Buffer . concat ( chunks ) ) ) . toEqual ( Buffer . from ( body ) ) ;
34+ } ) ,
35+ ) ;
36+ } ) ;
37+
38+ it . layer ( HttpResponseCompression . layerBun ) ( "Bun HTTP response compression" , ( it ) => {
39+ it . effect ( "creates a raw gzip stream" , ( ) =>
40+ Effect . gen ( function * ( ) {
41+ const compression = yield * HttpResponseCompression . HttpResponseCompression ;
42+ const response = compression . gzip ( body , {
43+ contentType : "application/json" ,
44+ } ) ;
45+
46+ expect ( response . body . _tag ) . toBe ( "Raw" ) ;
47+ if ( response . body . _tag !== "Raw" ) throw new Error ( "Expected a raw response body." ) ;
48+ expect ( response . body . body ) . toBeInstanceOf ( ReadableStream ) ;
49+ if ( ! ( response . body . body instanceof ReadableStream ) ) {
50+ throw new Error ( "Expected a Web readable stream." ) ;
51+ }
52+
53+ const rawBody = response . body . body ;
54+ const compressed = yield * Effect . promise ( ( ) => new Response ( rawBody ) . arrayBuffer ( ) ) ;
55+ expect ( NodeZlib . gunzipSync ( compressed ) ) . toEqual ( Buffer . from ( body ) ) ;
56+ } ) ,
57+ ) ;
58+ } ) ;
0 commit comments