11import assert from "assert" ;
22import fs from "fs/promises" ;
3-
43import path from "path" ;
4+ import { text } from "stream/consumers" ;
5+ import type { CompressionStream , DecompressionStream } from "stream/web" ;
56import { CorePlugin , Request , Response , Scheduler } from "@miniflare/core" ;
67import {
78 Compatibility ,
@@ -16,6 +17,7 @@ import {
1617 parsePluginWranglerConfig ,
1718 useServer ,
1819 useTmp ,
20+ utf8Encode ,
1921} from "@miniflare/shared-test" ;
2022import test , { ThrowsExpectation } from "ava" ;
2123import { File , FormData } from "undici" ;
@@ -303,82 +305,84 @@ test("CorePlugin: setup: includes web standards", async (t) => {
303305 const { globals } = await plugin . setup ( ) ;
304306 assert ( globals ) ;
305307
306- t . true ( typeof globals . console === "object" ) ;
307-
308- t . true ( typeof globals . setTimeout === "function" ) ;
309- t . true ( typeof globals . setInterval === "function" ) ;
310- t . true ( typeof globals . clearTimeout === "function" ) ;
311- t . true ( typeof globals . clearInterval === "function" ) ;
312- t . true ( typeof globals . queueMicrotask === "function" ) ;
313- t . true ( typeof globals . scheduler . wait === "function" ) ;
314-
315- t . true ( typeof globals . atob === "function" ) ;
316- t . true ( typeof globals . btoa === "function" ) ;
317-
318- t . true ( typeof globals . crypto === "object" ) ;
319- t . true ( typeof globals . CryptoKey === "function" ) ;
320- t . true ( typeof globals . TextDecoder === "function" ) ;
321- t . true ( typeof globals . TextEncoder === "function" ) ;
322-
323- t . true ( typeof globals . fetch === "function" ) ;
324- t . true ( typeof globals . Headers === "function" ) ;
325- t . true ( typeof globals . Request === "function" ) ;
326- t . true ( typeof globals . Response === "function" ) ;
327- t . true ( typeof globals . FormData === "function" ) ;
328- t . true ( typeof globals . Blob === "function" ) ;
329- t . true ( typeof globals . File === "function" ) ;
330- t . true ( typeof globals . URL === "function" ) ;
331- t . true ( typeof globals . URLSearchParams === "function" ) ;
332- t . true ( typeof globals . URLPattern === "function" ) ;
333-
334- t . true ( typeof globals . ByteLengthQueuingStrategy === "function" ) ;
335- t . true ( typeof globals . CountQueuingStrategy === "function" ) ;
336- t . true ( typeof globals . ReadableByteStreamController === "function" ) ;
337- t . true ( typeof globals . ReadableStream === "function" ) ;
338- t . true ( typeof globals . ReadableStreamBYOBReader === "function" ) ;
339- t . true ( typeof globals . ReadableStreamBYOBRequest === "function" ) ;
340- t . true ( typeof globals . ReadableStreamDefaultController === "function" ) ;
341- t . true ( typeof globals . ReadableStreamDefaultReader === "function" ) ;
342- t . true ( typeof globals . TransformStream === "function" ) ;
343- t . true ( typeof globals . TransformStreamDefaultController === "function" ) ;
344- t . true ( typeof globals . WritableStream === "function" ) ;
345- t . true ( typeof globals . WritableStreamDefaultController === "function" ) ;
346- t . true ( typeof globals . WritableStreamDefaultWriter === "function" ) ;
347- t . true ( typeof globals . FixedLengthStream === "function" ) ;
348-
349- t . true ( typeof globals . Event === "function" ) ;
350- t . true ( typeof globals . EventTarget === "function" ) ;
351- t . true ( typeof globals . AbortController === "function" ) ;
352- t . true ( typeof globals . AbortSignal === "function" ) ;
353- t . true ( typeof globals . FetchEvent === "function" ) ;
354- t . true ( typeof globals . ScheduledEvent === "function" ) ;
355-
356- t . true ( typeof globals . DOMException === "function" ) ;
357- t . true ( typeof globals . WorkerGlobalScope === "function" ) ;
358-
359- t . true ( typeof globals . structuredClone === "function" ) ;
360-
361- t . true ( typeof globals . ArrayBuffer === "function" ) ;
362- t . true ( typeof globals . Atomics === "object" ) ;
363- t . true ( typeof globals . BigInt64Array === "function" ) ;
364- t . true ( typeof globals . BigUint64Array === "function" ) ;
365- t . true ( typeof globals . DataView === "function" ) ;
366- t . true ( typeof globals . Date === "function" ) ;
367- t . true ( typeof globals . Float32Array === "function" ) ;
368- t . true ( typeof globals . Float64Array === "function" ) ;
369- t . true ( typeof globals . Int8Array === "function" ) ;
370- t . true ( typeof globals . Int16Array === "function" ) ;
371- t . true ( typeof globals . Int32Array === "function" ) ;
372- t . true ( typeof globals . Map === "function" ) ;
373- t . true ( typeof globals . Set === "function" ) ;
374- t . true ( typeof globals . SharedArrayBuffer === "function" ) ;
375- t . true ( typeof globals . Uint8Array === "function" ) ;
376- t . true ( typeof globals . Uint8ClampedArray === "function" ) ;
377- t . true ( typeof globals . Uint16Array === "function" ) ;
378- t . true ( typeof globals . Uint32Array === "function" ) ;
379- t . true ( typeof globals . WeakMap === "function" ) ;
380- t . true ( typeof globals . WeakSet === "function" ) ;
381- t . true ( typeof globals . WebAssembly === "object" ) ;
308+ t . is ( typeof globals . console , "object" ) ;
309+
310+ t . is ( typeof globals . setTimeout , "function" ) ;
311+ t . is ( typeof globals . setInterval , "function" ) ;
312+ t . is ( typeof globals . clearTimeout , "function" ) ;
313+ t . is ( typeof globals . clearInterval , "function" ) ;
314+ t . is ( typeof globals . queueMicrotask , "function" ) ;
315+ t . is ( typeof globals . scheduler . wait , "function" ) ;
316+
317+ t . is ( typeof globals . atob , "function" ) ;
318+ t . is ( typeof globals . btoa , "function" ) ;
319+
320+ t . is ( typeof globals . crypto , "object" ) ;
321+ t . is ( typeof globals . CryptoKey , "function" ) ;
322+ t . is ( typeof globals . TextDecoder , "function" ) ;
323+ t . is ( typeof globals . TextEncoder , "function" ) ;
324+
325+ t . is ( typeof globals . fetch , "function" ) ;
326+ t . is ( typeof globals . Headers , "function" ) ;
327+ t . is ( typeof globals . Request , "function" ) ;
328+ t . is ( typeof globals . Response , "function" ) ;
329+ t . is ( typeof globals . FormData , "function" ) ;
330+ t . is ( typeof globals . Blob , "function" ) ;
331+ t . is ( typeof globals . File , "function" ) ;
332+ t . is ( typeof globals . URL , "function" ) ;
333+ t . is ( typeof globals . URLSearchParams , "function" ) ;
334+ t . is ( typeof globals . URLPattern , "function" ) ;
335+
336+ t . is ( typeof globals . ByteLengthQueuingStrategy , "function" ) ;
337+ t . is ( typeof globals . CountQueuingStrategy , "function" ) ;
338+ t . is ( typeof globals . ReadableByteStreamController , "function" ) ;
339+ t . is ( typeof globals . ReadableStream , "function" ) ;
340+ t . is ( typeof globals . ReadableStreamBYOBReader , "function" ) ;
341+ t . is ( typeof globals . ReadableStreamBYOBRequest , "function" ) ;
342+ t . is ( typeof globals . ReadableStreamDefaultController , "function" ) ;
343+ t . is ( typeof globals . ReadableStreamDefaultReader , "function" ) ;
344+ t . is ( typeof globals . TransformStream , "function" ) ;
345+ t . is ( typeof globals . TransformStreamDefaultController , "function" ) ;
346+ t . is ( typeof globals . WritableStream , "function" ) ;
347+ t . is ( typeof globals . WritableStreamDefaultController , "function" ) ;
348+ t . is ( typeof globals . WritableStreamDefaultWriter , "function" ) ;
349+ t . is ( typeof globals . FixedLengthStream , "function" ) ;
350+ t . is ( typeof globals . CompressionStream , "function" ) ;
351+ t . is ( typeof globals . DecompressionStream , "function" ) ;
352+
353+ t . is ( typeof globals . Event , "function" ) ;
354+ t . is ( typeof globals . EventTarget , "function" ) ;
355+ t . is ( typeof globals . AbortController , "function" ) ;
356+ t . is ( typeof globals . AbortSignal , "function" ) ;
357+ t . is ( typeof globals . FetchEvent , "function" ) ;
358+ t . is ( typeof globals . ScheduledEvent , "function" ) ;
359+
360+ t . is ( typeof globals . DOMException , "function" ) ;
361+ t . is ( typeof globals . WorkerGlobalScope , "function" ) ;
362+
363+ t . is ( typeof globals . structuredClone , "function" ) ;
364+
365+ t . is ( typeof globals . ArrayBuffer , "function" ) ;
366+ t . is ( typeof globals . Atomics , "object" ) ;
367+ t . is ( typeof globals . BigInt64Array , "function" ) ;
368+ t . is ( typeof globals . BigUint64Array , "function" ) ;
369+ t . is ( typeof globals . DataView , "function" ) ;
370+ t . is ( typeof globals . Date , "function" ) ;
371+ t . is ( typeof globals . Float32Array , "function" ) ;
372+ t . is ( typeof globals . Float64Array , "function" ) ;
373+ t . is ( typeof globals . Int8Array , "function" ) ;
374+ t . is ( typeof globals . Int16Array , "function" ) ;
375+ t . is ( typeof globals . Int32Array , "function" ) ;
376+ t . is ( typeof globals . Map , "function" ) ;
377+ t . is ( typeof globals . Set , "function" ) ;
378+ t . is ( typeof globals . SharedArrayBuffer , "function" ) ;
379+ t . is ( typeof globals . Uint8Array , "function" ) ;
380+ t . is ( typeof globals . Uint8ClampedArray , "function" ) ;
381+ t . is ( typeof globals . Uint16Array , "function" ) ;
382+ t . is ( typeof globals . Uint32Array , "function" ) ;
383+ t . is ( typeof globals . WeakMap , "function" ) ;
384+ t . is ( typeof globals . WeakSet , "function" ) ;
385+ t . is ( typeof globals . WebAssembly , "object" ) ;
382386
383387 t . true ( globals . MINIFLARE ) ;
384388} ) ;
@@ -540,6 +544,7 @@ test("CorePlugin: setup: uses actual time if option enabled", async (t) => {
540544 } ) ;
541545} ) ;
542546
547+ // Test standards with basic-Miniflare and Node implementations
543548test ( "CorePlugin: setup: structuredClone: creates deep-copy of value" , async ( t ) => {
544549 const plugin = new CorePlugin ( ctx ) ;
545550 const { globals } = await plugin . setup ( ) ;
@@ -554,6 +559,30 @@ test("CorePlugin: setup: structuredClone: creates deep-copy of value", async (t)
554559 t . not ( thing , copy ) ;
555560 t . deepEqual ( thing , copy ) ;
556561} ) ;
562+ test ( "CorePlugin: setup: (De)CompressionStream: (de)compresses data" , async ( t ) => {
563+ const plugin = new CorePlugin ( ctx ) ;
564+ const { globals } = await plugin . setup ( ) ;
565+ assert ( globals ) ;
566+
567+ const CompressionStreamImpl : typeof CompressionStream =
568+ globals . CompressionStream ;
569+ const DecompressionStreamImpl : typeof DecompressionStream =
570+ globals . DecompressionStream ;
571+
572+ const compressor = new CompressionStreamImpl ( "gzip" ) ;
573+ const decompressor = new DecompressionStreamImpl ( "gzip" ) ;
574+ const data = "" . padStart ( 1024 , "x" ) ;
575+ const writer = compressor . writable . getWriter ( ) ;
576+ // noinspection ES6MissingAwait
577+ void writer . write ( utf8Encode ( data ) ) ;
578+ // noinspection ES6MissingAwait
579+ void writer . close ( ) ;
580+ const decompressed = await text (
581+ // @ts -expect-error ReadableStream types are incompatible
582+ compressor . readable . pipeThrough ( decompressor )
583+ ) ;
584+ t . is ( decompressed , data ) ;
585+ } ) ;
557586
558587test ( "CorePlugin: processedModuleRules: processes rules includes default module rules" , ( t ) => {
559588 const plugin = new CorePlugin ( ctx , {
0 commit comments