@@ -168,8 +168,21 @@ describe('sentryAstro integration', () => {
168
168
expect ( sentryVitePluginSpy ) . toHaveBeenCalledTimes ( 0 ) ;
169
169
} ) ;
170
170
171
- it ( 'injects client and server init scripts' , async ( ) => {
172
- const integration = sentryAstro ( { } ) ;
171
+ it ( "doesn't add the plugin or enable source maps if the SDK is disabled" , async ( ) => {
172
+ const integration = sentryAstro ( {
173
+ enabled : false ,
174
+ } ) ;
175
+
176
+ expect ( integration . hooks [ 'astro:config:setup' ] ) . toBeDefined ( ) ;
177
+ // @ts -expect-error - the hook exists and we only need to pass what we actually use
178
+ await integration . hooks [ 'astro:config:setup' ] ( { updateConfig, injectScript, config } ) ;
179
+
180
+ expect ( updateConfig ) . toHaveBeenCalledTimes ( 0 ) ;
181
+ expect ( sentryVitePluginSpy ) . toHaveBeenCalledTimes ( 0 ) ;
182
+ } ) ;
183
+
184
+ it . each ( [ { } , { enabled : true } ] ) ( 'injects client and server init scripts' , async options => {
185
+ const integration = sentryAstro ( options ) ;
173
186
174
187
expect ( integration . hooks [ 'astro:config:setup' ] ) . toBeDefined ( ) ;
175
188
// @ts -expect-error - the hook exists and we only need to pass what we actually use
@@ -180,6 +193,41 @@ describe('sentryAstro integration', () => {
180
193
expect ( injectScript ) . toHaveBeenCalledWith ( 'page-ssr' , expect . stringContaining ( 'Sentry.init' ) ) ;
181
194
} ) ;
182
195
196
+ it ( "doesn't inject client init script if `enabled.client` is `false`" , async ( ) => {
197
+ const integration = sentryAstro ( { enabled : { client : false } } ) ;
198
+
199
+ expect ( integration . hooks [ 'astro:config:setup' ] ) . toBeDefined ( ) ;
200
+ // @ts -expect-error - the hook exists and we only need to pass what we actually use
201
+ await integration . hooks [ 'astro:config:setup' ] ( { updateConfig, injectScript, config } ) ;
202
+
203
+ expect ( injectScript ) . toHaveBeenCalledTimes ( 1 ) ;
204
+ expect ( injectScript ) . toHaveBeenCalledWith ( 'page-ssr' , expect . stringContaining ( 'Sentry.init' ) ) ;
205
+ } ) ;
206
+
207
+ it ( "doesn't inject server init script if `enabled.server` is `false`" , async ( ) => {
208
+ const integration = sentryAstro ( { enabled : { server : false } } ) ;
209
+
210
+ expect ( integration . hooks [ 'astro:config:setup' ] ) . toBeDefined ( ) ;
211
+ // @ts -expect-error - the hook exists and we only need to pass what we actually use
212
+ await integration . hooks [ 'astro:config:setup' ] ( { updateConfig, injectScript, config } ) ;
213
+
214
+ expect ( injectScript ) . toHaveBeenCalledTimes ( 1 ) ;
215
+ expect ( injectScript ) . toHaveBeenCalledWith ( 'page' , expect . stringContaining ( 'Sentry.init' ) ) ;
216
+ } ) ;
217
+
218
+ it . each ( [ false , { client : false , server : false } ] ) (
219
+ "doesn't inject any init script if `enabled` is generally false (`%s`)" ,
220
+ async enabled => {
221
+ const integration = sentryAstro ( { enabled } ) ;
222
+
223
+ expect ( integration . hooks [ 'astro:config:setup' ] ) . toBeDefined ( ) ;
224
+ // @ts -expect-error - the hook exists and we only need to pass what we actually use
225
+ await integration . hooks [ 'astro:config:setup' ] ( { updateConfig, injectScript, config } ) ;
226
+
227
+ expect ( injectScript ) . toHaveBeenCalledTimes ( 0 ) ;
228
+ } ,
229
+ ) ;
230
+
183
231
it ( 'injects client and server init scripts from custom paths' , async ( ) => {
184
232
const integration = sentryAstro ( {
185
233
clientInitPath : 'my-client-init-path.js' ,
@@ -278,4 +326,23 @@ describe('sentryAstro integration', () => {
278
326
expect ( updateConfig ) . toHaveBeenCalledTimes ( 1 ) ;
279
327
expect ( injectScript ) . toHaveBeenCalledTimes ( 2 ) ;
280
328
} ) ;
329
+
330
+ it ( "doesn't add middleware if the SDK is disabled" , ( ) => {
331
+ const integration = sentryAstro ( { enabled : false } ) ;
332
+ const addMiddleware = vi . fn ( ) ;
333
+ const updateConfig = vi . fn ( ) ;
334
+ const injectScript = vi . fn ( ) ;
335
+
336
+ expect ( integration . hooks [ 'astro:config:setup' ] ) . toBeDefined ( ) ;
337
+ // @ts -expect-error - the hook exists and we only need to pass what we actually use
338
+ integration . hooks [ 'astro:config:setup' ] ( {
339
+ // @ts -expect-error - we only need to pass what we actually use
340
+ config : { output : 'server' } ,
341
+ addMiddleware,
342
+ updateConfig,
343
+ injectScript,
344
+ } ) ;
345
+
346
+ expect ( addMiddleware ) . toHaveBeenCalledTimes ( 0 ) ;
347
+ } ) ;
281
348
} ) ;
0 commit comments