@@ -44,6 +44,153 @@ const mockPrepareBundleForDebugIdUpload = prepareBundleForDebugIdUpload as jest.
4444describe ( "createSentryBuildPluginManager" , ( ) => {
4545 beforeEach ( ( ) => {
4646 jest . clearAllMocks ( ) ;
47+ // Clean up environment variables
48+ delete process . env [ "SENTRY_LOG_LEVEL" ] ;
49+ } ) ;
50+
51+ describe ( "debug option" , ( ) => {
52+ it ( "should set SENTRY_LOG_LEVEL environment variable when debug is true" , ( ) => {
53+ createSentryBuildPluginManager (
54+ {
55+ authToken : "test-token" ,
56+ org : "test-org" ,
57+ project : "test-project" ,
58+ debug : true ,
59+ } ,
60+ {
61+ buildTool : "webpack" ,
62+ loggerPrefix : "[sentry-webpack-plugin]" ,
63+ }
64+ ) ;
65+
66+ expect ( process . env [ "SENTRY_LOG_LEVEL" ] ) . toBe ( "debug" ) ;
67+ } ) ;
68+
69+ it ( "should not set SENTRY_LOG_LEVEL environment variable when debug is false" , ( ) => {
70+ createSentryBuildPluginManager (
71+ {
72+ authToken : "test-token" ,
73+ org : "test-org" ,
74+ project : "test-project" ,
75+ debug : false ,
76+ } ,
77+ {
78+ buildTool : "webpack" ,
79+ loggerPrefix : "[sentry-webpack-plugin]" ,
80+ }
81+ ) ;
82+
83+ expect ( process . env [ "SENTRY_LOG_LEVEL" ] ) . toBeUndefined ( ) ;
84+ } ) ;
85+
86+ it ( "should not set SENTRY_LOG_LEVEL environment variable when debug is not specified" , ( ) => {
87+ createSentryBuildPluginManager (
88+ {
89+ authToken : "test-token" ,
90+ org : "test-org" ,
91+ project : "test-project" ,
92+ } ,
93+ {
94+ buildTool : "webpack" ,
95+ loggerPrefix : "[sentry-webpack-plugin]" ,
96+ }
97+ ) ;
98+
99+ expect ( process . env [ "SENTRY_LOG_LEVEL" ] ) . toBeUndefined ( ) ;
100+ } ) ;
101+
102+ it ( "should have SENTRY_LOG_LEVEL set when CLI operations are performed with debug enabled" , async ( ) => {
103+ mockCliExecute . mockImplementation ( ( ) => {
104+ // Verify the environment variable is set at the time the CLI is called
105+ expect ( process . env [ "SENTRY_LOG_LEVEL" ] ) . toBe ( "debug" ) ;
106+ return Promise . resolve ( undefined ) ;
107+ } ) ;
108+
109+ const buildPluginManager = createSentryBuildPluginManager (
110+ {
111+ authToken : "test-token" ,
112+ org : "test-org" ,
113+ project : "test-project" ,
114+ debug : true ,
115+ } ,
116+ {
117+ buildTool : "webpack" ,
118+ loggerPrefix : "[sentry-webpack-plugin]" ,
119+ }
120+ ) ;
121+
122+ // Verify it's set immediately after creation
123+ expect ( process . env [ "SENTRY_LOG_LEVEL" ] ) . toBe ( "debug" ) ;
124+
125+ // Perform a CLI operation and verify the env var is still set
126+ await buildPluginManager . injectDebugIds ( [ "/path/to/bundle" ] ) ;
127+
128+ expect ( mockCliExecute ) . toHaveBeenCalled ( ) ;
129+ } ) ;
130+
131+ it ( "should have SENTRY_LOG_LEVEL set during error scenarios with debug enabled" , async ( ) => {
132+ // Simulate CLI error
133+ mockCliExecute . mockImplementation ( ( ) => {
134+ // Verify the environment variable is set even when CLI encounters an error
135+ // This ensures the CLI won't emit the "Add --log-level=debug" warning
136+ expect ( process . env [ "SENTRY_LOG_LEVEL" ] ) . toBe ( "debug" ) ;
137+ return Promise . reject ( new Error ( "CLI error" ) ) ;
138+ } ) ;
139+
140+ const buildPluginManager = createSentryBuildPluginManager (
141+ {
142+ authToken : "test-token" ,
143+ org : "test-org" ,
144+ project : "test-project" ,
145+ debug : true ,
146+ } ,
147+ {
148+ buildTool : "webpack" ,
149+ loggerPrefix : "[sentry-webpack-plugin]" ,
150+ }
151+ ) ;
152+
153+ // Verify it's set before the error
154+ expect ( process . env [ "SENTRY_LOG_LEVEL" ] ) . toBe ( "debug" ) ;
155+
156+ // Perform a CLI operation that will fail
157+ await buildPluginManager . injectDebugIds ( [ "/path/to/bundle" ] ) ;
158+
159+ // The error should have been caught, but env var should still be set
160+ expect ( process . env [ "SENTRY_LOG_LEVEL" ] ) . toBe ( "debug" ) ;
161+ } ) ;
162+
163+ it ( "should NOT have SENTRY_LOG_LEVEL set during error scenarios when debug is disabled" , async ( ) => {
164+ // Simulate CLI error
165+ mockCliExecute . mockImplementation ( ( ) => {
166+ // Verify the environment variable is NOT set
167+ // In this case, the CLI WOULD emit the "Add --log-level=debug" warning
168+ expect ( process . env [ "SENTRY_LOG_LEVEL" ] ) . toBeUndefined ( ) ;
169+ return Promise . reject ( new Error ( "CLI error" ) ) ;
170+ } ) ;
171+
172+ const buildPluginManager = createSentryBuildPluginManager (
173+ {
174+ authToken : "test-token" ,
175+ org : "test-org" ,
176+ project : "test-project" ,
177+ debug : false ,
178+ } ,
179+ {
180+ buildTool : "webpack" ,
181+ loggerPrefix : "[sentry-webpack-plugin]" ,
182+ }
183+ ) ;
184+
185+ // Verify it's not set
186+ expect ( process . env [ "SENTRY_LOG_LEVEL" ] ) . toBeUndefined ( ) ;
187+
188+ // Perform a CLI operation that will fail
189+ await buildPluginManager . injectDebugIds ( [ "/path/to/bundle" ] ) ;
190+
191+ // The error should have been caught, and env var should still not be set
192+ expect ( process . env [ "SENTRY_LOG_LEVEL" ] ) . toBeUndefined ( ) ;
193+ } ) ;
47194 } ) ;
48195
49196 describe ( "when disabled" , ( ) => {
0 commit comments