@@ -2,6 +2,7 @@ import * as fs from 'fs';
2
2
import * as os from 'os' ;
3
3
import * as path from 'path' ;
4
4
import * as rimraf from 'rimraf' ;
5
+ import { WebpackPluginInstance } from 'webpack' ;
5
6
6
7
import { withSentryConfig } from '../src/config' ;
7
8
import {
@@ -176,6 +177,14 @@ async function materializeFinalWebpackConfig(options: {
176
177
return finalWebpackConfigValue ;
177
178
}
178
179
180
+ // helper function to make sure we're checking the correct plugin's data
181
+ export function findWebpackPlugin (
182
+ webpackConfig : WebpackConfigObject ,
183
+ pluginName : string ,
184
+ ) : WebpackPluginInstance | SentryWebpackPlugin | undefined {
185
+ return webpackConfig . plugins ?. find ( plugin => plugin . constructor . name === pluginName ) ;
186
+ }
187
+
179
188
describe ( 'withSentryConfig' , ( ) => {
180
189
it ( 'includes expected properties' , ( ) => {
181
190
const finalConfig = materializeFinalNextConfig ( userNextConfig ) ;
@@ -334,8 +343,9 @@ describe('Sentry webpack plugin config', () => {
334
343
incomingWebpackConfig : serverWebpackConfig ,
335
344
incomingWebpackBuildContext : serverBuildContext ,
336
345
} ) ;
346
+ const sentryWebpackPluginInstance = findWebpackPlugin ( finalWebpackConfig , 'SentryCliPlugin' ) as SentryWebpackPlugin ;
337
347
338
- expect ( ( finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPlugin ) . options ) . toEqual (
348
+ expect ( sentryWebpackPluginInstance . options ) . toEqual (
339
349
expect . objectContaining ( {
340
350
include : expect . any ( Array ) , // default, tested separately elsewhere
341
351
ignore : [ ] , // default
@@ -358,8 +368,9 @@ describe('Sentry webpack plugin config', () => {
358
368
incomingWebpackConfig : serverWebpackConfig ,
359
369
incomingWebpackBuildContext : serverBuildContext ,
360
370
} ) ;
371
+ const sentryWebpackPluginInstance = findWebpackPlugin ( finalWebpackConfig , 'SentryCliPlugin' ) as SentryWebpackPlugin ;
361
372
362
- expect ( ( finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPlugin ) . options . debug ) . toEqual ( true ) ;
373
+ expect ( sentryWebpackPluginInstance . options . debug ) . toEqual ( true ) ;
363
374
} ) ;
364
375
365
376
it ( 'warns when overriding certain default values' , ( ) => {
@@ -378,9 +389,12 @@ describe('Sentry webpack plugin config', () => {
378
389
incomingWebpackBuildContext : clientBuildContext ,
379
390
} ) ;
380
391
381
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
392
+ const sentryWebpackPluginInstance = findWebpackPlugin (
393
+ finalWebpackConfig ,
394
+ 'SentryCliPlugin' ,
395
+ ) as SentryWebpackPlugin ;
382
396
383
- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
397
+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
384
398
{ paths : [ '.next/static/chunks/pages' ] , urlPrefix : '~/_next/static/chunks/pages' } ,
385
399
] ) ;
386
400
} ) ;
@@ -395,9 +409,12 @@ describe('Sentry webpack plugin config', () => {
395
409
incomingWebpackBuildContext : getBuildContext ( 'server' , userNextConfigServerless ) ,
396
410
} ) ;
397
411
398
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
412
+ const sentryWebpackPluginInstance = findWebpackPlugin (
413
+ finalWebpackConfig ,
414
+ 'SentryCliPlugin' ,
415
+ ) as SentryWebpackPlugin ;
399
416
400
- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
417
+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
401
418
{ paths : [ '.next/serverless/' ] , urlPrefix : '~/_next/serverless' } ,
402
419
] ) ;
403
420
} ) ;
@@ -412,9 +429,12 @@ describe('Sentry webpack plugin config', () => {
412
429
incomingWebpackBuildContext : serverBuildContextWebpack4 ,
413
430
} ) ;
414
431
415
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
432
+ const sentryWebpackPluginInstance = findWebpackPlugin (
433
+ finalWebpackConfig ,
434
+ 'SentryCliPlugin' ,
435
+ ) as SentryWebpackPlugin ;
416
436
417
- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
437
+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
418
438
{ paths : [ '.next/server/pages/' ] , urlPrefix : '~/_next/server/pages' } ,
419
439
] ) ;
420
440
} ) ;
@@ -426,9 +446,12 @@ describe('Sentry webpack plugin config', () => {
426
446
incomingWebpackBuildContext : serverBuildContext ,
427
447
} ) ;
428
448
429
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
449
+ const sentryWebpackPluginInstance = findWebpackPlugin (
450
+ finalWebpackConfig ,
451
+ 'SentryCliPlugin' ,
452
+ ) as SentryWebpackPlugin ;
430
453
431
- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
454
+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
432
455
{ paths : [ '.next/server/pages/' ] , urlPrefix : '~/_next/server/pages' } ,
433
456
{ paths : [ '.next/server/chunks/' ] , urlPrefix : '~/_next/server/chunks' } ,
434
457
] ) ;
@@ -448,9 +471,12 @@ describe('Sentry webpack plugin config', () => {
448
471
incomingWebpackBuildContext : getBuildContext ( 'client' , userNextConfigWithBasePath ) ,
449
472
} ) ;
450
473
451
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
474
+ const sentryWebpackPluginInstance = findWebpackPlugin (
475
+ finalWebpackConfig ,
476
+ 'SentryCliPlugin' ,
477
+ ) as SentryWebpackPlugin ;
452
478
453
- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
479
+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
454
480
{ paths : [ '.next/static/chunks/pages' ] , urlPrefix : '~/city-park/_next/static/chunks/pages' } ,
455
481
] ) ;
456
482
} ) ;
@@ -465,9 +491,12 @@ describe('Sentry webpack plugin config', () => {
465
491
incomingWebpackBuildContext : getBuildContext ( 'server' , userNextConfigServerless ) ,
466
492
} ) ;
467
493
468
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
494
+ const sentryWebpackPluginInstance = findWebpackPlugin (
495
+ finalWebpackConfig ,
496
+ 'SentryCliPlugin' ,
497
+ ) as SentryWebpackPlugin ;
469
498
470
- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
499
+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
471
500
{ paths : [ '.next/serverless/' ] , urlPrefix : '~/city-park/_next/serverless' } ,
472
501
] ) ;
473
502
} ) ;
@@ -482,9 +511,12 @@ describe('Sentry webpack plugin config', () => {
482
511
incomingWebpackBuildContext : serverBuildContextWebpack4 ,
483
512
} ) ;
484
513
485
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
514
+ const sentryWebpackPluginInstance = findWebpackPlugin (
515
+ finalWebpackConfig ,
516
+ 'SentryCliPlugin' ,
517
+ ) as SentryWebpackPlugin ;
486
518
487
- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
519
+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
488
520
{ paths : [ '.next/server/pages/' ] , urlPrefix : '~/city-park/_next/server/pages' } ,
489
521
] ) ;
490
522
} ) ;
@@ -496,9 +528,12 @@ describe('Sentry webpack plugin config', () => {
496
528
incomingWebpackBuildContext : getBuildContext ( 'server' , userNextConfigWithBasePath ) ,
497
529
} ) ;
498
530
499
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
531
+ const sentryWebpackPluginInstance = findWebpackPlugin (
532
+ finalWebpackConfig ,
533
+ 'SentryCliPlugin' ,
534
+ ) as SentryWebpackPlugin ;
500
535
501
- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
536
+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
502
537
{ paths : [ '.next/server/pages/' ] , urlPrefix : '~/city-park/_next/server/pages' } ,
503
538
{ paths : [ '.next/server/chunks/' ] , urlPrefix : '~/city-park/_next/server/chunks' } ,
504
539
] ) ;
0 commit comments