@@ -408,6 +408,7 @@ describe("createSentryBuildPluginManager", () => {
408408 // Should upload from temp folder
409409 expect ( mockCliUploadSourceMaps ) . toHaveBeenCalledWith ( "some-release-name" , {
410410 include : [ { paths : [ "/tmp/sentry-upload-xyz" ] , rewrite : false , dist : "1" } ] ,
411+ projects : [ "p" ] ,
411412 live : "rejectOnError" ,
412413 } ) ;
413414 } ) ;
@@ -463,4 +464,173 @@ describe("createSentryBuildPluginManager", () => {
463464 ) ;
464465 } ) ;
465466 } ) ;
467+
468+ describe ( "uploadSourcemaps with multiple projects" , ( ) => {
469+ beforeEach ( ( ) => {
470+ jest . clearAllMocks ( ) ;
471+ mockGlob . mockResolvedValue ( [ "/path/to/bundle.js" ] ) ;
472+ mockPrepareBundleForDebugIdUpload . mockResolvedValue ( undefined ) ;
473+ mockCliUploadSourceMaps . mockResolvedValue ( undefined ) ;
474+
475+ // Mock fs operations needed for temp folder upload path
476+ jest . spyOn ( fs . promises , "mkdtemp" ) . mockResolvedValue ( "/tmp/sentry-test" ) ;
477+ jest . spyOn ( fs . promises , "readdir" ) . mockResolvedValue ( [ ] ) ;
478+ jest . spyOn ( fs . promises , "stat" ) . mockResolvedValue ( { size : 1000 } as fs . Stats ) ;
479+ jest . spyOn ( fs . promises , "rm" ) . mockResolvedValue ( undefined ) ;
480+ } ) ;
481+
482+ afterEach ( ( ) => {
483+ jest . restoreAllMocks ( ) ;
484+ } ) ;
485+
486+ it ( "should pass projects array to uploadSourceMaps when multiple projects configured" , async ( ) => {
487+ const buildPluginManager = createSentryBuildPluginManager (
488+ {
489+ authToken : "test-token" ,
490+ org : "test-org" ,
491+ project : [ "proj-a" , "proj-b" , "proj-c" ] ,
492+ release : { name : "test-release" } ,
493+ } ,
494+ {
495+ buildTool : "webpack" ,
496+ loggerPrefix : "[sentry-webpack-plugin]" ,
497+ }
498+ ) ;
499+
500+ await buildPluginManager . uploadSourcemaps ( [ "/path/to/bundle.js" ] ) ;
501+
502+ expect ( mockCliUploadSourceMaps ) . toHaveBeenCalledWith (
503+ "test-release" ,
504+ expect . objectContaining ( {
505+ projects : [ "proj-a" , "proj-b" , "proj-c" ] ,
506+ } )
507+ ) ;
508+ } ) ;
509+
510+ it ( "should pass single project as array to uploadSourceMaps" , async ( ) => {
511+ const buildPluginManager = createSentryBuildPluginManager (
512+ {
513+ authToken : "test-token" ,
514+ org : "test-org" ,
515+ project : "single-project" ,
516+ release : { name : "test-release" } ,
517+ } ,
518+ {
519+ buildTool : "webpack" ,
520+ loggerPrefix : "[sentry-webpack-plugin]" ,
521+ }
522+ ) ;
523+
524+ await buildPluginManager . uploadSourcemaps ( [ "/path/to/bundle.js" ] ) ;
525+
526+ expect ( mockCliUploadSourceMaps ) . toHaveBeenCalledWith (
527+ "test-release" ,
528+ expect . objectContaining ( {
529+ projects : [ "single-project" ] ,
530+ } )
531+ ) ;
532+ } ) ;
533+
534+ it ( "should pass projects array in direct upload mode" , async ( ) => {
535+ const buildPluginManager = createSentryBuildPluginManager (
536+ {
537+ authToken : "test-token" ,
538+ org : "test-org" ,
539+ project : [ "proj-a" , "proj-b" ] ,
540+ release : { name : "test-release" } ,
541+ } ,
542+ {
543+ buildTool : "webpack" ,
544+ loggerPrefix : "[sentry-webpack-plugin]" ,
545+ }
546+ ) ;
547+
548+ await buildPluginManager . uploadSourcemaps ( [ "/path/to/bundle.js" ] , {
549+ prepareArtifacts : false ,
550+ } ) ;
551+
552+ expect ( mockCliUploadSourceMaps ) . toHaveBeenCalledWith (
553+ "test-release" ,
554+ expect . objectContaining ( {
555+ projects : [ "proj-a" , "proj-b" ] ,
556+ } )
557+ ) ;
558+ } ) ;
559+ } ) ;
560+
561+ describe ( "moduleMetadata callback with multiple projects" , ( ) => {
562+ it ( "should pass project as string and projects as array when multiple projects configured" , ( ) => {
563+ const moduleMetadataCallback = jest . fn ( ) . mockReturnValue ( { custom : "metadata" } ) ;
564+
565+ createSentryBuildPluginManager (
566+ {
567+ authToken : "test-token" ,
568+ org : "test-org" ,
569+ project : [ "proj-a" , "proj-b" , "proj-c" ] ,
570+ release : { name : "test-release" } ,
571+ moduleMetadata : moduleMetadataCallback ,
572+ } ,
573+ {
574+ buildTool : "webpack" ,
575+ loggerPrefix : "[sentry-webpack-plugin]" ,
576+ }
577+ ) ;
578+
579+ expect ( moduleMetadataCallback ) . toHaveBeenCalledWith ( {
580+ org : "test-org" ,
581+ project : "proj-a" ,
582+ projects : [ "proj-a" , "proj-b" , "proj-c" ] ,
583+ release : "test-release" ,
584+ } ) ;
585+ } ) ;
586+
587+ it ( "should pass project as string and projects as array with single project" , ( ) => {
588+ const moduleMetadataCallback = jest . fn ( ) . mockReturnValue ( { custom : "metadata" } ) ;
589+
590+ createSentryBuildPluginManager (
591+ {
592+ authToken : "test-token" ,
593+ org : "test-org" ,
594+ project : "single-project" ,
595+ release : { name : "test-release" } ,
596+ moduleMetadata : moduleMetadataCallback ,
597+ } ,
598+ {
599+ buildTool : "webpack" ,
600+ loggerPrefix : "[sentry-webpack-plugin]" ,
601+ }
602+ ) ;
603+
604+ expect ( moduleMetadataCallback ) . toHaveBeenCalledWith ( {
605+ org : "test-org" ,
606+ project : "single-project" ,
607+ projects : [ "single-project" ] ,
608+ release : "test-release" ,
609+ } ) ;
610+ } ) ;
611+
612+ it ( "should pass undefined for projects when no project configured" , ( ) => {
613+ const moduleMetadataCallback = jest . fn ( ) . mockReturnValue ( { custom : "metadata" } ) ;
614+
615+ createSentryBuildPluginManager (
616+ {
617+ authToken : "test-token" ,
618+ org : "test-org" ,
619+ release : { name : "test-release" } ,
620+ moduleMetadata : moduleMetadataCallback ,
621+ } ,
622+ {
623+ buildTool : "webpack" ,
624+ loggerPrefix : "[sentry-webpack-plugin]" ,
625+ }
626+ ) ;
627+
628+ expect ( moduleMetadataCallback ) . toHaveBeenCalledWith ( {
629+ org : "test-org" ,
630+ project : undefined ,
631+ projects : undefined ,
632+ release : "test-release" ,
633+ } ) ;
634+ } ) ;
635+ } ) ;
466636} ) ;
0 commit comments