@@ -113,4 +113,56 @@ describe('Loader hooks', { concurrency: true }, () => {
113113 assert . strictEqual ( signal , null ) ;
114114 } ) ;
115115 } ) ;
116+
117+ it ( 'should work without worker permission' , async ( ) => {
118+ const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
119+ '--no-warnings' ,
120+ '--experimental-permission' ,
121+ '--allow-fs-read' ,
122+ '*' ,
123+ '--experimental-loader' ,
124+ fixtures . fileURL ( 'empty.js' ) ,
125+ fixtures . path ( 'es-modules/esm-top-level-await.mjs' ) ,
126+ ] ) ;
127+
128+ assert . strictEqual ( stderr , '' ) ;
129+ assert . match ( stdout , / ^ 1 \r ? \n 2 \r ? \n $ / ) ;
130+ assert . strictEqual ( code , 0 ) ;
131+ assert . strictEqual ( signal , null ) ;
132+ } ) ;
133+
134+ it ( 'should allow loader hooks to spawn workers when allowed by the CLI flags' , async ( ) => {
135+ const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
136+ '--no-warnings' ,
137+ '--experimental-permission' ,
138+ '--allow-worker' ,
139+ '--allow-fs-read' ,
140+ '*' ,
141+ '--experimental-loader' ,
142+ `data:text/javascript,import{Worker}from"worker_threads";new Worker(${ encodeURIComponent ( JSON . stringify ( fixtures . path ( 'empty.js' ) ) ) } ).unref()` ,
143+ fixtures . path ( 'es-modules/esm-top-level-await.mjs' ) ,
144+ ] ) ;
145+
146+ assert . strictEqual ( stderr , '' ) ;
147+ assert . match ( stdout , / ^ 1 \r ? \n 2 \r ? \n $ / ) ;
148+ assert . strictEqual ( code , 0 ) ;
149+ assert . strictEqual ( signal , null ) ;
150+ } ) ;
151+
152+ it ( 'should not allow loader hooks to spawn workers if restricted by the CLI flags' , async ( ) => {
153+ const { code, signal, stdout, stderr } = await spawnPromisified ( execPath , [
154+ '--no-warnings' ,
155+ '--experimental-permission' ,
156+ '--allow-fs-read' ,
157+ '*' ,
158+ '--experimental-loader' ,
159+ `data:text/javascript,import{Worker}from"worker_threads";new Worker(${ encodeURIComponent ( JSON . stringify ( fixtures . path ( 'empty.js' ) ) ) } ).unref()` ,
160+ fixtures . path ( 'es-modules/esm-top-level-await.mjs' ) ,
161+ ] ) ;
162+
163+ assert . match ( stderr , / c o d e : ' E R R _ A C C E S S _ D E N I E D ' / ) ;
164+ assert . strictEqual ( stdout , '' ) ;
165+ assert . strictEqual ( code , 1 ) ;
166+ assert . strictEqual ( signal , null ) ;
167+ } ) ;
116168} ) ;
0 commit comments