@@ -650,3 +650,44 @@ test('wrong import syntax should throw error after module mocking', async () =>
650650 assert . match ( stderr , / E r r o r \[ E R R _ M O D U L E _ N O T _ F O U N D \] : C a n n o t f i n d m o d u l e / ) ;
651651 assert . strictEqual ( code , 1 ) ;
652652} ) ;
653+
654+ test ( 'should throw ERR_ACCESS_DENIED when permission model is enabled' , async ( t ) => {
655+ const cwd = fixtures . path ( 'test-runner' ) ;
656+ const fixture = fixtures . path ( 'test-runner' , 'mock-nm.js' ) ;
657+ const args = [
658+ '--experimental-permission' ,
659+ '--allow-fs-read=*' ,
660+ '--experimental-test-module-mocks' ,
661+ fixture ,
662+ ] ;
663+ const {
664+ code,
665+ stdout,
666+ } = await common . spawnPromisified ( process . execPath , args , { cwd } ) ;
667+
668+ assert . strictEqual ( code , 1 ) ;
669+ assert . match ( stdout , / E r r o r : A c c e s s t o t h i s A P I h a s b e e n r e s t r i c t e d / ) ;
670+ assert . match ( stdout , / p e r m i s s i o n : ' W o r k e r T h r e a d s ' / ) ;
671+ } ) ;
672+
673+ test ( 'should work when --allow-worker is passed and permission model is enabled' , async ( t ) => {
674+ const cwd = fixtures . path ( 'test-runner' ) ;
675+ const fixture = fixtures . path ( 'test-runner' , 'mock-nm.js' ) ;
676+ const args = [
677+ '--experimental-permission' ,
678+ '--allow-fs-read=*' ,
679+ '--allow-worker' ,
680+ '--experimental-test-module-mocks' ,
681+ fixture ,
682+ ] ;
683+ const {
684+ code,
685+ stdout,
686+ stderr,
687+ signal,
688+ } = await common . spawnPromisified ( process . execPath , args , { cwd } ) ;
689+
690+ assert . strictEqual ( code , 0 , stderr ) ;
691+ assert . strictEqual ( signal , null ) ;
692+ assert . match ( stdout , / p a s s 1 / , stderr ) ;
693+ } ) ;
0 commit comments