@@ -22,6 +22,7 @@ describe('DenoWorker', () => {
2222 const failScript = readFileSync ( failFile , { encoding : 'utf-8' } ) ;
2323 const envFile = path . resolve ( __dirname , './test/env.js' ) ;
2424 const envScript = readFileSync ( envFile , { encoding : 'utf-8' } ) ;
25+ const memoryCrashFile = path . resolve ( __dirname , './test/memory.js' ) ;
2526
2627 afterEach ( ( ) => {
2728 if ( worker ) {
@@ -1118,6 +1119,33 @@ describe('DenoWorker', () => {
11181119 expect ( exitSignal ) . toBe ( 'SIGKILL' ) ;
11191120 }
11201121 } ) ;
1122+
1123+ it ( 'should gracefully handle Deno out-of-memory' , async ( ) => {
1124+ let denoProcesses = await getDenoProcesses ( ) ;
1125+ expect ( denoProcesses ) . toEqual ( [ ] ) ;
1126+ worker = new DenoWorker ( memoryCrashFile , {
1127+ denoV8Flags : [ '--max-heap-size=10' ] ,
1128+ logStdout : true ,
1129+ } ) ;
1130+ worker . postMessage ( { } ) ;
1131+
1132+ const exitValues = await new Promise <
1133+ [ number | null , string | null ]
1134+ > ( ( resolve ) => {
1135+ worker . onexit = ( ...args ) => resolve ( args ) ;
1136+ } ) ;
1137+
1138+ const isWindows = / ^ w i n / . test ( process . platform ) ;
1139+
1140+ if ( isWindows ) {
1141+ expect ( typeof exitValues [ 0 ] ) . toEqual ( 'number' ) ;
1142+ expect ( exitValues [ 1 ] ) . toEqual ( null ) ;
1143+ } else {
1144+ expect ( exitValues ) . toEqual ( [ null , 'SIGTRAP' ] ) ;
1145+ }
1146+
1147+ worker . terminate ( ) ;
1148+ } ) ;
11211149 } ) ;
11221150} ) ;
11231151
0 commit comments