1+ import fs from 'fs' ;
2+
13import {
24 DEFAULT_DIR_DOWNLOADED_TYPES , DEFAULT_DIR_EMITTED_TYPES ,
35} from '../../constants' ;
@@ -17,6 +19,7 @@ jest.mock('../../downloadTypes', () => ({
1719 getRemoteManifestUrls : jest . fn ( ) ,
1820} ) ) ;
1921jest . mock ( '../helpers' , ( ) => ( {
22+ ...jest . requireActual ( '../helpers' ) ,
2023 assertRunningFromRoot : jest . fn ( ( ) => true ) ,
2124 getOptionsFromWebpackConfig : jest . fn ( ) ,
2225} ) ) ;
@@ -43,6 +46,7 @@ const validOptions: ReturnType<typeof getOptionsFromWebpackConfig> = {
4346
4447describe ( 'download-federated-types' , ( ) => {
4548 const originalArgv = process . argv ;
49+ const originalExistsSync = fs . existsSync ;
4650 const originalProcessExit = process . exit ;
4751 const mockConsoleLog = jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
4852 const mockConsoleError = jest . spyOn ( console , 'error' ) . mockImplementation ( ) ;
@@ -64,10 +68,12 @@ describe('download-federated-types', () => {
6468
6569 afterAll ( ( ) => {
6670 process . exit = originalProcessExit ;
71+ fs . existsSync = originalExistsSync ;
6772 } ) ;
6873
6974 test ( 'exits when remote URL is invalid' , ( ) => {
7075 const remoteEntryUrls = { url1 : 'invalid-url' } ;
76+ fs . existsSync = jest . fn ( ) . mockReturnValue ( true ) ;
7177 mockGetOptionsFromWebpackConfig . mockReturnValue ( {
7278 mfPluginOptions : { } ,
7379 mfTypesPluginOptions : {
@@ -79,7 +85,7 @@ describe('download-federated-types', () => {
7985 require ( '../download-federated-types' ) ;
8086 } ) ;
8187
82- expect ( mockGetOptionsFromWebpackConfig ) . toHaveBeenCalledWith ( 'webpack.config.js ' ) ;
88+ expect ( mockGetOptionsFromWebpackConfig ) . toHaveBeenCalledWith ( 'webpack.config.ts ' ) ;
8389 expect ( mockConsoleError ) . toHaveBeenCalledWith ( 'One or more remote URLs are invalid:' , remoteEntryUrls ) ;
8490 expect ( process . exit ) . toHaveBeenCalledWith ( 1 ) ;
8591 } ) ;
0 commit comments