@@ -2,7 +2,7 @@ import * as fs from 'fs';
2
2
import * as os from 'os' ;
3
3
import * as path from 'path' ;
4
4
5
- import { BuildContext } from '../../../src/config/types' ;
5
+ import { BuildContext , ExportedNextConfig } from '../../../src/config/types' ;
6
6
import { getUserConfigFile , getWebpackPluginOptions , SentryWebpackPlugin } from '../../../src/config/webpack' ;
7
7
import {
8
8
clientBuildContext ,
@@ -14,7 +14,7 @@ import {
14
14
userSentryWebpackPluginConfig ,
15
15
} from '../fixtures' ;
16
16
import { exitsSync , mkdtempSyncSpy , mockExistsSync , realExistsSync } from '../mocks' ;
17
- import { findWebpackPlugin , materializeFinalNextConfig , materializeFinalWebpackConfig } from '../testUtils' ;
17
+ import { findWebpackPlugin , materializeFinalWebpackConfig } from '../testUtils' ;
18
18
19
19
describe ( 'Sentry webpack plugin config' , ( ) => {
20
20
it ( 'includes expected properties' , async ( ) => {
@@ -283,44 +283,111 @@ describe('Sentry webpack plugin config', () => {
283
283
} ) ;
284
284
} ) ;
285
285
286
- describe ( 'disabling SentryWebpackPlugin' , ( ) => {
287
- it ( 'allows SentryWebpackPlugin to be turned off for client code (independent of server code)' , ( ) => {
288
- const clientFinalNextConfig = materializeFinalNextConfig ( {
289
- ...exportedNextConfig ,
290
- sentry : { disableClientWebpackPlugin : true } ,
291
- } ) ;
292
- const clientFinalWebpackConfig = clientFinalNextConfig . webpack ?.( clientWebpackConfig , clientBuildContext ) ;
286
+ describe ( 'SentryWebpackPlugin enablement' , ( ) => {
287
+ let processEnvBackup : typeof process . env ;
293
288
294
- const serverFinalNextConfig = materializeFinalNextConfig ( exportedNextConfig , userSentryWebpackPluginConfig ) ;
295
- const serverFinalWebpackConfig = serverFinalNextConfig . webpack ?.( serverWebpackConfig , serverBuildContext ) ;
296
-
297
- expect ( clientFinalWebpackConfig ?. plugins ) . not . toEqual ( expect . arrayContaining ( [ expect . any ( SentryWebpackPlugin ) ] ) ) ;
298
- expect ( serverFinalWebpackConfig ?. plugins ) . toEqual ( expect . arrayContaining ( [ expect . any ( SentryWebpackPlugin ) ] ) ) ;
289
+ beforeEach ( ( ) => {
290
+ processEnvBackup = { ...process . env } ;
299
291
} ) ;
300
- it ( 'allows SentryWebpackPlugin to be turned off for server code (independent of client code)' , ( ) => {
301
- const serverFinalNextConfig = materializeFinalNextConfig ( {
302
- ...exportedNextConfig ,
303
- sentry : { disableServerWebpackPlugin : true } ,
304
- } ) ;
305
- const serverFinalWebpackConfig = serverFinalNextConfig . webpack ?.( serverWebpackConfig , serverBuildContext ) ;
306
292
307
- const clientFinalNextConfig = materializeFinalNextConfig ( exportedNextConfig , userSentryWebpackPluginConfig ) ;
308
- const clientFinalWebpackConfig = clientFinalNextConfig . webpack ?.( clientWebpackConfig , clientBuildContext ) ;
309
-
310
- expect ( serverFinalWebpackConfig ?. plugins ) . not . toEqual ( expect . arrayContaining ( [ expect . any ( SentryWebpackPlugin ) ] ) ) ;
311
- expect ( clientFinalWebpackConfig ?. plugins ) . toEqual ( expect . arrayContaining ( [ expect . any ( SentryWebpackPlugin ) ] ) ) ;
293
+ afterEach ( ( ) => {
294
+ process . env = processEnvBackup ;
312
295
} ) ;
313
296
314
- it ( "doesn't set devtool if webpack plugin is disabled" , ( ) => {
315
- const finalNextConfig = materializeFinalNextConfig ( {
316
- ...exportedNextConfig ,
317
- webpack : ( ) => ( { devtool : 'something-besides-source-map' } as any ) ,
318
- sentry : { disableServerWebpackPlugin : true } ,
319
- } ) ;
320
- const finalWebpackConfig = finalNextConfig . webpack ?.( serverWebpackConfig , serverBuildContext ) ;
321
-
322
- expect ( finalWebpackConfig ?. devtool ) . not . toEqual ( 'source-map' ) ;
323
- } ) ;
297
+ it . each ( [
298
+ // [testName, exportedNextConfig, extraEnvValues, shouldFindServerPlugin, shouldFindClientPlugin]
299
+ [
300
+ 'obeys `disableClientWebpackPlugin = true`' ,
301
+ {
302
+ ...exportedNextConfig ,
303
+ sentry : { disableClientWebpackPlugin : true } ,
304
+ } ,
305
+ { } ,
306
+ true ,
307
+ false ,
308
+ ] ,
309
+
310
+ [
311
+ 'obeys `disableServerWebpackPlugin = true`' ,
312
+ {
313
+ ...exportedNextConfig ,
314
+ sentry : { disableServerWebpackPlugin : true } ,
315
+ } ,
316
+ { } ,
317
+ false ,
318
+ true ,
319
+ ] ,
320
+ [
321
+ 'disables the plugin in Vercel `preview` environment' ,
322
+ exportedNextConfig ,
323
+ { VERCEL_ENV : 'preview' } ,
324
+ false ,
325
+ false ,
326
+ ] ,
327
+ [
328
+ 'disables the plugin in Vercel `development` environment' ,
329
+ exportedNextConfig ,
330
+ { VERCEL_ENV : 'development' } ,
331
+ false ,
332
+ false ,
333
+ ] ,
334
+ [
335
+ 'allows `disableClientWebpackPlugin = false` to override env vars`' ,
336
+ {
337
+ ...exportedNextConfig ,
338
+ sentry : { disableClientWebpackPlugin : false } ,
339
+ } ,
340
+ { VERCEL_ENV : 'preview' } ,
341
+ false ,
342
+ true ,
343
+ ] ,
344
+ [
345
+ 'allows `disableServerWebpackPlugin = false` to override env vars`' ,
346
+ {
347
+ ...exportedNextConfig ,
348
+ sentry : { disableServerWebpackPlugin : false } ,
349
+ } ,
350
+ { VERCEL_ENV : 'preview' } ,
351
+ true ,
352
+ false ,
353
+ ] ,
354
+ ] ) (
355
+ '%s' ,
356
+ async (
357
+ _testName : string ,
358
+ exportedNextConfig : ExportedNextConfig ,
359
+ extraEnvValues : Record < string , string > ,
360
+ shouldFindServerPlugin : boolean ,
361
+ shouldFindClientPlugin : boolean ,
362
+ ) => {
363
+ process . env = { ...process . env , ...extraEnvValues } ;
364
+
365
+ // We create a copy of the next config for each `materializeFinalWebpackConfig` call because the `sentry`
366
+ // property gets deleted along the way, and its value matters for some of our test cases
367
+ const serverFinalWebpackConfig = await materializeFinalWebpackConfig ( {
368
+ exportedNextConfig : { ...exportedNextConfig } ,
369
+ userSentryWebpackPluginConfig,
370
+ incomingWebpackConfig : serverWebpackConfig ,
371
+ incomingWebpackBuildContext : serverBuildContext ,
372
+ } ) ;
373
+
374
+ const clientFinalWebpackConfig = await materializeFinalWebpackConfig ( {
375
+ exportedNextConfig : { ...exportedNextConfig } ,
376
+ userSentryWebpackPluginConfig,
377
+ incomingWebpackConfig : clientWebpackConfig ,
378
+ incomingWebpackBuildContext : clientBuildContext ,
379
+ } ) ;
380
+
381
+ const genericSentryWebpackPluginInstance = expect . any ( SentryWebpackPlugin ) ;
382
+
383
+ expect ( findWebpackPlugin ( serverFinalWebpackConfig , 'SentryCliPlugin' ) ) . toEqual (
384
+ shouldFindServerPlugin ? genericSentryWebpackPluginInstance : undefined ,
385
+ ) ;
386
+ expect ( findWebpackPlugin ( clientFinalWebpackConfig , 'SentryCliPlugin' ) ) . toEqual (
387
+ shouldFindClientPlugin ? genericSentryWebpackPluginInstance : undefined ,
388
+ ) ;
389
+ } ,
390
+ ) ;
324
391
} ) ;
325
392
326
393
describe ( 'getUserConfigFile' , ( ) => {
0 commit comments