1- import { AppEvent , AppEventWatcher , EventType , ExtensionEvent } from './app-event-watcher.js'
1+ import { AppEventWatcher , EventType , ExtensionEvent } from './app-event-watcher.js'
22import { OutputContextOptions , WatcherEvent , FileWatcher } from './file-watcher.js'
3- import { ESBuildContextManager } from './app-watcher-esbuild.js'
43import {
54 testAppAccessConfigExtension ,
65 testAppConfigExtensions ,
@@ -22,7 +21,6 @@ import {joinPath} from '@shopify/cli-kit/node/path'
2221import { Writable } from 'stream'
2322
2423vi . mock ( '../../../models/app/loader.js' )
25- vi . mock ( './app-watcher-esbuild.js' )
2624
2725// Extensions 1 and 1B simulate extensions defined in the same directory (same toml)
2826const extension1 = await testUIExtension ( {
@@ -360,9 +358,8 @@ describe('app-event-watcher', () => {
360358 configuration : testAppConfiguration ,
361359 } )
362360
363- const mockManager = new MockESBuildContextManager ( )
364361 const mockFileWatcher = new MockFileWatcher ( app , outputOptions , [ fileWatchEvent ] )
365- const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockManager , mockFileWatcher )
362+ const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockFileWatcher )
366363 const emitSpy = vi . spyOn ( watcher , 'emit' )
367364 await watcher . start ( { stdout, stderr, signal : abortController . signal } )
368365
@@ -433,9 +430,8 @@ describe('app-event-watcher', () => {
433430 } )
434431 const generateTypesSpy = vi . spyOn ( app , 'generateExtensionTypes' )
435432
436- const mockManager = new MockESBuildContextManager ( )
437433 const mockFileWatcher = new MockFileWatcher ( app , outputOptions , [ fileWatchEvent ] )
438- const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockManager , mockFileWatcher )
434+ const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockFileWatcher )
439435 const emitSpy = vi . spyOn ( watcher , 'emit' )
440436
441437 // When
@@ -468,9 +464,8 @@ describe('app-event-watcher', () => {
468464 configuration : testAppConfiguration ,
469465 } )
470466
471- const mockManager = new MockESBuildContextManager ( )
472467 const mockFileWatcher = new MockFileWatcher ( app , outputOptions , [ fileWatchEvent ] )
473- const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockManager , mockFileWatcher )
468+ const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockFileWatcher )
474469 const emitSpy = vi . spyOn ( watcher , 'emit' )
475470
476471 // When
@@ -503,9 +498,8 @@ describe('app-event-watcher', () => {
503498 configuration : testAppConfiguration ,
504499 } )
505500
506- const mockManager = new MockESBuildContextManager ( )
507501 const mockFileWatcher = new MockFileWatcher ( app , outputOptions , [ fileWatchEvent ] )
508- const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockManager , mockFileWatcher )
502+ const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockFileWatcher )
509503 const emitSpy = vi . spyOn ( watcher , 'emit' )
510504
511505 // When
@@ -535,9 +529,8 @@ describe('app-event-watcher', () => {
535529 } )
536530 const generateTypesSpy = vi . spyOn ( app , 'generateExtensionTypes' )
537531
538- const mockManager = new MockESBuildContextManager ( )
539532 const mockFileWatcher = new MockFileWatcher ( app , outputOptions , [ fileWatchEvent ] )
540- const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockManager , mockFileWatcher )
533+ const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockFileWatcher )
541534 const emitSpy = vi . spyOn ( watcher , 'emit' )
542535
543536 // When
@@ -571,19 +564,17 @@ describe('app-event-watcher', () => {
571564 ] ,
572565 }
573566
574- const mockManager = new MockESBuildContextManager ( )
575- mockManager . rebuildContext = vi . fn ( ) . mockRejectedValueOnce ( esbuildError )
576-
577567 const buildOutputPath = joinPath ( tmpDir , '.shopify' , 'bundle' )
578568 const app = testAppLinked ( {
579569 allExtensions : [ extension1 ] ,
580570 configPath : 'shopify.app.custom.toml' ,
581571 configuration : testAppConfiguration ,
582572 } )
573+ extension1 . buildForBundle = vi . fn ( ) . mockRejectedValueOnce ( esbuildError )
583574 const mockFileWatcher = new MockFileWatcher ( app , outputOptions , [ fileWatchEvent ] )
584575
585576 // When
586- const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockManager , mockFileWatcher )
577+ const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockFileWatcher )
587578 const emitSpy = vi . spyOn ( watcher , 'emit' )
588579 const stderr = { write : vi . fn ( ) } as unknown as Writable
589580 const stdout = { write : vi . fn ( ) } as unknown as Writable
@@ -627,9 +618,9 @@ describe('app-event-watcher', () => {
627618 } )
628619
629620 // When
630- const mockManager = new MockESBuildContextManager ( )
621+
631622 const mockFileWatcher = new MockFileWatcher ( app , outputOptions , [ fileWatchEvent ] )
632- const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockManager , mockFileWatcher )
623+ const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockFileWatcher )
633624 const emitSpy = vi . spyOn ( watcher , 'emit' )
634625 const stderr = { write : vi . fn ( ) } as unknown as Writable
635626 const stdout = { write : vi . fn ( ) } as unknown as Writable
@@ -661,13 +652,14 @@ describe('app-event-watcher', () => {
661652 configPath : 'shopify.app.custom.toml' ,
662653 configuration : testAppConfiguration ,
663654 } )
655+
656+ // Make rescanImports throw to simulate an uncaught error in the watcher pipeline
657+ extension1 . rescanImports = vi . fn ( ) . mockRejectedValueOnce ( uncaughtError )
658+
664659 const mockFileWatcher = new MockFileWatcher ( app , outputOptions , [ fileWatchEvent ] )
665660
666661 // When
667- const mockManager = new MockESBuildContextManager ( )
668- mockManager . updateContexts = vi . fn ( ) . mockRejectedValueOnce ( uncaughtError )
669-
670- const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockManager , mockFileWatcher )
662+ const watcher = new AppEventWatcher ( app , 'url' , buildOutputPath , mockFileWatcher )
671663 const emitSpy = vi . spyOn ( watcher , 'emit' )
672664 const stderr = { write : vi . fn ( ) } as unknown as Writable
673665 const stdout = { write : vi . fn ( ) } as unknown as Writable
@@ -684,26 +676,6 @@ describe('app-event-watcher', () => {
684676 } )
685677 } )
686678} )
687- // Mock class for ESBuildContextManager
688- // It handles the ESBuild contexts for the extensions that are being watched
689- class MockESBuildContextManager extends ESBuildContextManager {
690- contexts = {
691- // The keys are the extension handles, the values are the ESBuild contexts mocked
692- uid1 : [ { rebuild : vi . fn ( ) , watch : vi . fn ( ) , serve : vi . fn ( ) , cancel : vi . fn ( ) , dispose : vi . fn ( ) } ] ,
693- uid1B : [ { rebuild : vi . fn ( ) , watch : vi . fn ( ) , serve : vi . fn ( ) , cancel : vi . fn ( ) , dispose : vi . fn ( ) } ] ,
694- uid2 : [ { rebuild : vi . fn ( ) , watch : vi . fn ( ) , serve : vi . fn ( ) , cancel : vi . fn ( ) , dispose : vi . fn ( ) } ] ,
695- 'test-ui-extension' : [ { rebuild : vi . fn ( ) , watch : vi . fn ( ) , serve : vi . fn ( ) , cancel : vi . fn ( ) , dispose : vi . fn ( ) } ] ,
696- }
697-
698- constructor ( ) {
699- super ( { dotEnvVariables : { } , url : 'url' , outputPath : 'outputPath' } )
700- }
701-
702- async createContexts ( extensions : ExtensionInstance [ ] ) { }
703- async updateContexts ( appEvent : AppEvent ) { }
704- async deleteContexts ( extensions : ExtensionInstance [ ] ) { }
705- }
706-
707679// Mock class for FileWatcher
708680// Used to trigger mocked file system events immediately after the watcher is started.
709681class MockFileWatcher extends FileWatcher {
0 commit comments