@@ -22,14 +22,16 @@ describe('lz4 module loader', () => {
2222 } ) ;
2323 } ) ;
2424
25- const mockModuleLoad = ( lz4MockOrError : unknown ) : { restore : ( ) => void ; wasLz4LoadAttempted : ( ) => boolean } => {
25+ const mockModuleLoad = (
26+ lz4MockOrError : unknown ,
27+ ) : { restore : ( ) => void ; wasLz4LoadAttempted : ( ) => boolean } => {
2628 // eslint-disable-next-line global-require
2729 const Module = require ( 'module' ) ;
2830 const originalLoad = Module . _load ;
2931 let lz4LoadAttempted = false ;
3032
3133 Module . _load = ( request : string , parent : unknown , isMain : boolean ) => {
32- if ( request === 'lz4' ) {
34+ if ( request === 'lz4-napi ' ) {
3335 lz4LoadAttempted = true ;
3436 if ( lz4MockOrError instanceof Error ) {
3537 throw lz4MockOrError ;
@@ -53,19 +55,19 @@ describe('lz4 module loader', () => {
5355 return require ( '../../../lib/utils/lz4' ) ;
5456 } ;
5557
56- it ( 'should successfully load and use lz4 module when available' , ( ) => {
57- const fakeLz4 = {
58- encode : ( buf : Buffer ) => {
58+ it ( 'should successfully load and use lz4-napi module when available' , ( ) => {
59+ const fakeLz4Napi = {
60+ compressFrameSync : ( buf : Buffer ) => {
5961 const compressed = Buffer . from ( `compressed:${ buf . toString ( ) } ` ) ;
6062 return compressed ;
6163 } ,
62- decode : ( buf : Buffer ) => {
64+ decompressFrameSync : ( buf : Buffer ) => {
6365 const decompressed = buf . toString ( ) . replace ( 'compressed:' , '' ) ;
6466 return Buffer . from ( decompressed ) ;
6567 } ,
6668 } ;
6769
68- const { restore } = mockModuleLoad ( fakeLz4 ) ;
70+ const { restore } = mockModuleLoad ( fakeLz4Napi ) ;
6971 const moduleExports = loadLz4Module ( ) ;
7072 const lz4Module = moduleExports . default ( ) ;
7173 restore ( ) ;
@@ -82,8 +84,8 @@ describe('lz4 module loader', () => {
8284 expect ( consoleWarnStub . called ) . to . be . false ;
8385 } ) ;
8486
85- it ( 'should return undefined when lz4 module fails to load with MODULE_NOT_FOUND' , ( ) => {
86- const err : NodeJS . ErrnoException = new Error ( "Cannot find module 'lz4'" ) ;
87+ it ( 'should return undefined when lz4-napi module fails to load with MODULE_NOT_FOUND' , ( ) => {
88+ const err : NodeJS . ErrnoException = new Error ( "Cannot find module 'lz4-napi '" ) ;
8789 err . code = 'MODULE_NOT_FOUND' ;
8890
8991 const { restore } = mockModuleLoad ( err ) ;
@@ -95,7 +97,7 @@ describe('lz4 module loader', () => {
9597 expect ( consoleWarnStub . called ) . to . be . false ;
9698 } ) ;
9799
98- it ( 'should return undefined and log warning when lz4 fails with ERR_DLOPEN_FAILED' , ( ) => {
100+ it ( 'should return undefined and log warning when lz4-napi fails with ERR_DLOPEN_FAILED' , ( ) => {
99101 const err : NodeJS . ErrnoException = new Error ( 'Module did not self-register' ) ;
100102 err . code = 'ERR_DLOPEN_FAILED' ;
101103
@@ -109,7 +111,7 @@ describe('lz4 module loader', () => {
109111 expect ( consoleWarnStub . firstCall . args [ 0 ] ) . to . include ( 'Architecture or version mismatch' ) ;
110112 } ) ;
111113
112- it ( 'should return undefined and log warning when lz4 fails with unknown error code' , ( ) => {
114+ it ( 'should return undefined and log warning when lz4-napi fails with unknown error code' , ( ) => {
113115 const err : NodeJS . ErrnoException = new Error ( 'Some unknown error' ) ;
114116 err . code = 'UNKNOWN_ERROR' ;
115117
@@ -136,13 +138,13 @@ describe('lz4 module loader', () => {
136138 expect ( consoleWarnStub . firstCall . args [ 0 ] ) . to . include ( 'Invalid error object' ) ;
137139 } ) ;
138140
139- it ( 'should not attempt to load lz4 module when getResolvedModule is not called' , ( ) => {
140- const fakeLz4 = {
141- encode : ( ) => Buffer . from ( '' ) ,
142- decode : ( ) => Buffer . from ( '' ) ,
141+ it ( 'should not attempt to load lz4-napi module when getResolvedModule is not called' , ( ) => {
142+ const fakeLz4Napi = {
143+ compressFrameSync : ( ) => Buffer . from ( '' ) ,
144+ decompressFrameSync : ( ) => Buffer . from ( '' ) ,
143145 } ;
144146
145- const { restore, wasLz4LoadAttempted } = mockModuleLoad ( fakeLz4 ) ;
147+ const { restore, wasLz4LoadAttempted } = mockModuleLoad ( fakeLz4Napi ) ;
146148
147149 // Load the module but don't call getResolvedModule
148150 loadLz4Module ( ) ;
0 commit comments