@@ -76,17 +76,17 @@ describe('setupSourceMaps hooks', () => {
7676 } ) ;
7777
7878 describe ( 'vite plugin registration' , ( ) => {
79- it ( 'registers a vite plugin after modules:done hook ' , async ( ) => {
79+ it ( 'calls `addVitePlugin` when setupSourceMaps is called ' , async ( ) => {
8080 const { setupSourceMaps } = await import ( '../../src/vite/sourceMaps' ) ;
8181 const mockNuxt = createMockNuxt ( { _prepare : false , dev : false } ) ;
8282 const { mockAddVitePlugin, getCapturedPlugin } = createMockAddVitePlugin ( ) ;
8383
8484 setupSourceMaps ( { debug : true } , mockNuxt as unknown as Nuxt , mockAddVitePlugin ) ;
85- await mockNuxt . triggerHook ( 'modules:done' ) ;
8685
8786 const plugin = getCapturedPlugin ( ) ;
8887 expect ( plugin ) . not . toBeNull ( ) ;
8988 expect ( plugin ?. name ) . toBe ( 'sentry-nuxt-vite-config' ) ;
89+ // modules:done is called afterward. Later, the plugin is actually added
9090 } ) ;
9191
9292 it . each ( [
@@ -179,6 +179,66 @@ describe('setupSourceMaps hooks', () => {
179179 } ) ;
180180 } ) ;
181181
182+ describe ( 'shouldDeleteFilesFallback passed to getPluginOptions in Vite plugin' , ( ) => {
183+ const defaultFilesToDeleteAfterUpload = [
184+ '.*/**/public/**/*.map' ,
185+ '.*/**/server/**/*.map' ,
186+ '.*/**/output/**/*.map' ,
187+ '.*/**/function/**/*.map' ,
188+ ] ;
189+
190+ it ( 'uses mutated shouldDeleteFilesFallback (unset → true): plugin.config() after modules:done gets fallback filesToDeleteAfterUpload' , async ( ) => {
191+ const { setupSourceMaps } = await import ( '../../src/vite/sourceMaps' ) ;
192+ const mockNuxt = createMockNuxt ( {
193+ _prepare : false ,
194+ dev : false ,
195+ sourcemap : { client : undefined , server : undefined } ,
196+ } ) ;
197+ const { mockAddVitePlugin, getCapturedPlugin } = createMockAddVitePlugin ( ) ;
198+
199+ setupSourceMaps ( { debug : false } , mockNuxt as unknown as Nuxt , mockAddVitePlugin ) ;
200+ await mockNuxt . triggerHook ( 'modules:done' ) ;
201+
202+ const plugin = getCapturedPlugin ( ) ;
203+ expect ( plugin ) . not . toBeNull ( ) ;
204+ if ( plugin && typeof plugin . config === 'function' ) {
205+ plugin . config ( { build : { ssr : false } , plugins : [ ] } , { mode : 'production' , command : 'build' } ) ;
206+ }
207+
208+ expect ( mockSentryVitePlugin ) . toHaveBeenCalledWith (
209+ expect . objectContaining ( {
210+ sourcemaps : expect . objectContaining ( {
211+ filesToDeleteAfterUpload : defaultFilesToDeleteAfterUpload ,
212+ } ) ,
213+ } ) ,
214+ ) ;
215+ } ) ;
216+
217+ it ( 'uses mutated shouldDeleteFilesFallback (explicitly enabled → false): plugin.config() after modules:done gets no filesToDeleteAfterUpload' , async ( ) => {
218+ const { setupSourceMaps } = await import ( '../../src/vite/sourceMaps' ) ;
219+ const mockNuxt = createMockNuxt ( {
220+ _prepare : false ,
221+ dev : false ,
222+ sourcemap : { client : true , server : true } ,
223+ } ) ;
224+ const { mockAddVitePlugin, getCapturedPlugin } = createMockAddVitePlugin ( ) ;
225+
226+ setupSourceMaps ( { debug : false } , mockNuxt as unknown as Nuxt , mockAddVitePlugin ) ;
227+ await mockNuxt . triggerHook ( 'modules:done' ) ;
228+
229+ const plugin = getCapturedPlugin ( ) ;
230+ expect ( plugin ) . not . toBeNull ( ) ;
231+ if ( plugin && typeof plugin . config === 'function' ) {
232+ plugin . config ( { build : { ssr : false } , plugins : [ ] } , { mode : 'production' , command : 'build' } ) ;
233+ }
234+
235+ const pluginOptions = ( mockSentryVitePlugin ?. mock ?. calls ?. [ 0 ] as unknown [ ] ) ?. [ 0 ] as {
236+ sourcemaps ?: { filesToDeleteAfterUpload ?: string [ ] } ;
237+ } ;
238+ expect ( pluginOptions ?. sourcemaps ?. filesToDeleteAfterUpload ) . toBeUndefined ( ) ;
239+ } ) ;
240+ } ) ;
241+
182242 describe ( 'nitro:config hook' , ( ) => {
183243 it ( 'adds sentryRollupPlugin to nitro rollup config in production mode' , async ( ) => {
184244 const { setupSourceMaps } = await import ( '../../src/vite/sourceMaps' ) ;
0 commit comments