@@ -87,9 +87,10 @@ describe('create-package/utils', () => {
8787 nodeVersions : '>=18.0.0' ,
8888 } ;
8989
90- ( fs . promises . stat as jest . Mock ) . mockResolvedValueOnce ( {
91- isDirectory : ( ) => false ,
92- } ) ;
90+ const mockError = new Error ( 'Not found' ) as NodeJS . ErrnoException ;
91+ mockError . code = 'ENOENT' ;
92+
93+ jest . spyOn ( fs . promises , 'stat' ) . mockRejectedValue ( mockError ) ;
9394
9495 ( fsUtils . readAllFiles as jest . Mock ) . mockResolvedValueOnce ( {
9596 'src/index.ts' : 'export default 42;' ,
@@ -181,5 +182,34 @@ describe('create-package/utils', () => {
181182 expect ( fs . promises . mkdir ) . not . toHaveBeenCalled ( ) ;
182183 expect ( fs . promises . writeFile ) . not . toHaveBeenCalled ( ) ;
183184 } ) ;
185+
186+ it ( 'throws if fs.stat fails with an error other than ENOENT' , async ( ) => {
187+ const mockError = new Error ( 'Permission denied' ) as NodeJS . ErrnoException ;
188+ mockError . code = 'EACCES' ;
189+
190+ jest . spyOn ( fs . promises , 'stat' ) . mockRejectedValue ( mockError ) ;
191+
192+ const packageData : PackageData = {
193+ name : '@metamask/foo' ,
194+ description : 'A foo package.' ,
195+ directoryName : 'foo' ,
196+ nodeVersions : '20.0.0' ,
197+ currentYear : '2023' ,
198+ } ;
199+
200+ const monorepoFileData = {
201+ tsConfig : {
202+ references : [ { path : './packages/bar' } ] ,
203+ } ,
204+ tsConfigBuild : {
205+ references : [ { path : './packages/bar' } ] ,
206+ } ,
207+ nodeVersions : '20.0.0' ,
208+ } ;
209+
210+ await expect (
211+ finalizeAndWriteData ( packageData , monorepoFileData ) ,
212+ ) . rejects . toThrow ( 'Permission denied' ) ;
213+ } ) ;
184214 } ) ;
185215} ) ;
0 commit comments