@@ -654,18 +654,93 @@ test("CorePlugin: setup: uses actual time if option enabled", async (t) => {
654654 } ) ;
655655} ) ;
656656
657- test ( "CorePlugin: nodejs_compat compatibiltiy flag includes Node.js modules" , async ( t ) => {
658- const compat = new Compatibility ( undefined , [ "nodejs_compat" ] ) ;
659-
660- const plugin = new CorePlugin (
661- { ...ctx , compat } ,
662- { compatibilityFlags : [ "nodejs_compat" ] }
663- ) ;
664- const additionalModules = ( await plugin . setup ( ) ) . additionalModules ;
665- t . deepEqual (
666- Object . keys ( additionalModules ?. [ "node:async_hooks" ] . default ?? { } ) ,
667- [ "AsyncLocalStorage" , "AsyncResource" ]
657+ test ( "CorePlugin: nodejs_compat compatibility flag includes Node.js modules" , async ( t ) => {
658+ let compat = new Compatibility ( undefined , [ "nodejs_compat" ] ) ;
659+ let plugin = new CorePlugin ( { ...ctx , compat } ) ;
660+ let modules = ( await plugin . setup ( ) ) . additionalModules ! ;
661+ const names = Object . keys ( modules ) . sort ( ) ;
662+ t . deepEqual ( names , [ "node:async_hooks" , "node:events" ] ) ;
663+
664+ compat = new Compatibility ( undefined , [ "nodejs_compat" , "experimental" ] ) ;
665+ plugin = new CorePlugin ( { ...ctx , compat } ) ;
666+ modules = ( await plugin . setup ( ) ) . additionalModules ! ;
667+ const experimentalNames = Object . keys ( modules ) . filter (
668+ ( name ) => ! names . includes ( name )
668669 ) ;
670+ t . deepEqual ( experimentalNames , [ "node:assert" , "node:buffer" , "node:util" ] ) ;
671+
672+ // We're using Node's implementations of these modules' exports, so don't
673+ // bother testing their functionality. Instead, just check we've got the
674+ // same export types as `workerd`.
675+
676+ function exportTypes ( name : string ) : Record < string , string > {
677+ return Object . fromEntries (
678+ Object . entries ( modules [ name ] ) . map ( ( [ key , value ] ) => [ key , typeof value ] )
679+ ) ;
680+ }
681+
682+ t . deepEqual ( exportTypes ( "node:assert" ) , {
683+ AssertionError : "function" ,
684+ deepEqual : "function" ,
685+ deepStrictEqual : "function" ,
686+ default : "function" ,
687+ doesNotMatch : "function" ,
688+ doesNotReject : "function" ,
689+ doesNotThrow : "function" ,
690+ equal : "function" ,
691+ fail : "function" ,
692+ ifError : "function" ,
693+ match : "function" ,
694+ notDeepEqual : "function" ,
695+ notDeepStrictEqual : "function" ,
696+ notEqual : "function" ,
697+ notStrictEqual : "function" ,
698+ ok : "function" ,
699+ rejects : "function" ,
700+ strict : "function" ,
701+ strictEqual : "function" ,
702+ throws : "function" ,
703+ } ) ;
704+ t . deepEqual ( exportTypes ( "node:async_hooks" ) , {
705+ AsyncLocalStorage : "function" ,
706+ AsyncResource : "function" ,
707+ default : "object" ,
708+ } ) ;
709+ t . deepEqual ( exportTypes ( "node:buffer" ) , {
710+ Buffer : "function" ,
711+ SlowBuffer : "function" ,
712+ constants : "object" ,
713+ default : "object" ,
714+ kMaxLength : "number" ,
715+ kStringMaxLength : "number" ,
716+ } ) ;
717+ t . deepEqual ( exportTypes ( "node:events" ) , {
718+ EventEmitter : "function" ,
719+ // Miniflare's minimum support Node version is `16.13.0`, but
720+ // `EventEmitterAsyncResource` was only added in `16.14.0`:
721+ // https://nodejs.org/api/events.html#class-eventseventemitterasyncresource-extends-eventemitter
722+ EventEmitterAsyncResource : process . versions . node . startsWith ( "16.13." )
723+ ? "undefined"
724+ : "function" ,
725+ captureRejectionSymbol : "symbol" ,
726+ default : "function" ,
727+ defaultMaxListeners : "number" ,
728+ errorMonitor : "symbol" ,
729+ getEventListeners : "function" ,
730+ listenerCount : "function" ,
731+ on : "function" ,
732+ once : "function" ,
733+ setMaxListeners : "function" ,
734+ } ) ;
735+ t . deepEqual ( exportTypes ( "node:util" ) , {
736+ _extend : "function" ,
737+ callbackify : "function" ,
738+ default : "object" ,
739+ format : "function" ,
740+ inherits : "function" ,
741+ promisify : "function" ,
742+ types : "object" ,
743+ } ) ;
669744} ) ;
670745
671746// Test stream constructors
0 commit comments