@@ -99,6 +99,16 @@ function createMockHmrContext(
9999 } as HmrContext
100100}
101101
102+ async function callHandleHotUpdate (
103+ plugin : Plugin ,
104+ ctx : HmrContext ,
105+ ) : Promise < ModuleNode [ ] | void | undefined > {
106+ if ( typeof plugin . handleHotUpdate === 'function' ) {
107+ return ( plugin . handleHotUpdate as Function ) . call ( plugin , ctx )
108+ }
109+ return undefined
110+ }
111+
102112async function callPluginHook < TArgs extends unknown [ ] , TResult > (
103113 hook :
104114 | {
@@ -182,13 +192,10 @@ describe('handleHotUpdate - Issue #185', () => {
182192
183193 // A global CSS file (not referenced by any component's styleUrls)
184194 const globalCssFile = normalizePath ( join ( tempDir , 'src' , 'styles.css' ) )
185- const mockModules = [ { id : globalCssFile , type : 'css' } ]
195+ const mockModules = [ { id : globalCssFile } ]
186196 const ctx = createMockHmrContext ( globalCssFile , mockModules )
187197
188- let result : ModuleNode [ ] | void | undefined
189- if ( typeof plugin . handleHotUpdate === 'function' ) {
190- result = await plugin . handleHotUpdate ( ctx )
191- }
198+ const result = await callHandleHotUpdate ( plugin , ctx )
192199
193200 // Non-component CSS should NOT be swallowed — either undefined (pass through)
194201 // or the original modules array, but NOT an empty array
@@ -207,10 +214,7 @@ describe('handleHotUpdate - Issue #185', () => {
207214 const mockModules = [ { id : componentCssFile } ]
208215 const ctx = createMockHmrContext ( componentCssFile , mockModules , mockServer )
209216
210- let result : ModuleNode [ ] | void | undefined
211- if ( typeof plugin . handleHotUpdate === 'function' ) {
212- result = await plugin . handleHotUpdate ( ctx )
213- }
217+ const result = await callHandleHotUpdate ( plugin , ctx )
214218
215219 // Component resources MUST be swallowed (return [])
216220 expect ( result ) . toEqual ( [ ] )
@@ -225,10 +229,7 @@ describe('handleHotUpdate - Issue #185', () => {
225229 const componentHtmlFile = normalizePath ( templatePath )
226230 const ctx = createMockHmrContext ( componentHtmlFile , [ { id : componentHtmlFile } ] , mockServer )
227231
228- let result : ModuleNode [ ] | void | undefined
229- if ( typeof plugin . handleHotUpdate === 'function' ) {
230- result = await plugin . handleHotUpdate ( ctx )
231- }
232+ const result = await callHandleHotUpdate ( plugin , ctx )
232233
233234 // Component templates MUST be swallowed (return [])
234235 expect ( result ) . toEqual ( [ ] )
@@ -243,10 +244,7 @@ describe('handleHotUpdate - Issue #185', () => {
243244 const mockModules = [ { id : indexHtml } ]
244245 const ctx = createMockHmrContext ( indexHtml , mockModules )
245246
246- let result : ModuleNode [ ] | void | undefined
247- if ( typeof plugin . handleHotUpdate === 'function' ) {
248- result = await plugin . handleHotUpdate ( ctx )
249- }
247+ const result = await callHandleHotUpdate ( plugin , ctx )
250248
251249 // Non-component HTML should pass through, not be swallowed
252250 if ( result !== undefined ) {
@@ -262,10 +260,7 @@ describe('handleHotUpdate - Issue #185', () => {
262260 const mockModules = [ { id : utilFile } ]
263261 const ctx = createMockHmrContext ( utilFile , mockModules )
264262
265- let result : ModuleNode [ ] | void | undefined
266- if ( typeof plugin . handleHotUpdate === 'function' ) {
267- result = await plugin . handleHotUpdate ( ctx )
268- }
263+ const result = await callHandleHotUpdate ( plugin , ctx )
269264
270265 // Non-Angular .ts files should pass through with their modules
271266 if ( result !== undefined ) {
0 commit comments