@@ -27,10 +27,14 @@ function installCollection(dir: string, prefix: string, icon: string) {
2727 } ) )
2828}
2929
30- function createContext ( rootDir : string , workspaceDir : string , icons : string [ ] ) {
30+ function createContext ( rootDir : string , workspaceDir : string , icons : string [ ] , hookIcons : string [ ] = [ ] ) {
3131 const nuxt = {
3232 options : { rootDir, workspaceDir } ,
33- callHook : async ( ) => { } ,
33+ // Mimic a module contributing icons through the `icon:clientBundleIcons` hook
34+ callHook : async ( _name : string , set : Set < string > ) => {
35+ for ( const icon of hookIcons )
36+ set . add ( icon )
37+ } ,
3438 }
3539 return new NuxtIconModuleContext ( nuxt as never , {
3640 clientBundle : { icons } ,
@@ -75,3 +79,36 @@ it('falls back to workspaceDir when the collection is not under rootDir', async
7579 expect ( result . count ) . toBe ( 1 )
7680 expect ( result . collections . find ( c => c . prefix === 'nuxt-icon-test-ws' ) ?. icons . bar ) . toBeTruthy ( )
7781} )
82+
83+ it ( 'does not hard-fail when a hook-contributed icon cannot be resolved' , async ( ) => {
84+ // A module adds an icon from a collection that is not installed. It must be
85+ // best-effort: omitted from the bundle (so it falls back to runtime loading)
86+ // and never added to `failed` (which would throw in a production build).
87+ const context = createContext ( appDir ( ) , appDir ( ) , [ 'nuxt-icon-test:foo' ] , [ 'not-installed:missing' ] )
88+ const result = await context . loadClientBundleCollections ( )
89+
90+ expect ( result . failed ) . toEqual ( [ ] )
91+ expect ( result . dropped ) . toEqual ( [ 'not-installed:missing' ] )
92+ expect ( result . count ) . toBe ( 1 )
93+ expect ( result . collections . find ( c => c . prefix === 'not-installed' ) ) . toBeUndefined ( )
94+ expect ( result . collections . find ( c => c . prefix === 'nuxt-icon-test' ) ?. icons . foo ) . toBeTruthy ( )
95+ } )
96+
97+ it ( 'does not hard-fail when a hook-contributed icon name does not exist in an installed collection' , async ( ) => {
98+ // The collection is installed but the specific icon name does not exist
99+ // (e.g. version skew). Still best-effort, not a hard failure.
100+ const context = createContext ( appDir ( ) , appDir ( ) , [ ] , [ 'nuxt-icon-test:does-not-exist' ] )
101+ const result = await context . loadClientBundleCollections ( )
102+
103+ expect ( result . failed ) . toEqual ( [ ] )
104+ expect ( result . dropped ) . toEqual ( [ 'nuxt-icon-test:does-not-exist' ] )
105+ expect ( result . count ) . toBe ( 0 )
106+ } )
107+
108+ it ( 'still hard-fails when an icon explicitly listed in clientBundle.icons cannot be resolved' , async ( ) => {
109+ const context = createContext ( appDir ( ) , appDir ( ) , [ 'not-installed:missing' ] )
110+ const result = await context . loadClientBundleCollections ( )
111+
112+ expect ( result . failed ) . toEqual ( [ 'not-installed:missing' ] )
113+ expect ( result . dropped ) . toEqual ( [ ] )
114+ } )
0 commit comments