@@ -2,6 +2,7 @@ import * as fs from 'fs';
22import * as os from 'os' ;
33import * as path from 'path' ;
44import * as rimraf from 'rimraf' ;
5+ import { WebpackPluginInstance } from 'webpack' ;
56
67import { withSentryConfig } from '../src/config' ;
78import {
@@ -176,6 +177,14 @@ async function materializeFinalWebpackConfig(options: {
176177 return finalWebpackConfigValue ;
177178}
178179
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+
179188describe ( 'withSentryConfig' , ( ) => {
180189 it ( 'includes expected properties' , ( ) => {
181190 const finalConfig = materializeFinalNextConfig ( userNextConfig ) ;
@@ -334,8 +343,9 @@ describe('Sentry webpack plugin config', () => {
334343 incomingWebpackConfig : serverWebpackConfig ,
335344 incomingWebpackBuildContext : serverBuildContext ,
336345 } ) ;
346+ const sentryWebpackPluginInstance = findWebpackPlugin ( finalWebpackConfig , 'SentryCliPlugin' ) as SentryWebpackPlugin ;
337347
338- expect ( ( finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPlugin ) . options ) . toEqual (
348+ expect ( sentryWebpackPluginInstance . options ) . toEqual (
339349 expect . objectContaining ( {
340350 include : expect . any ( Array ) , // default, tested separately elsewhere
341351 ignore : [ ] , // default
@@ -358,8 +368,9 @@ describe('Sentry webpack plugin config', () => {
358368 incomingWebpackConfig : serverWebpackConfig ,
359369 incomingWebpackBuildContext : serverBuildContext ,
360370 } ) ;
371+ const sentryWebpackPluginInstance = findWebpackPlugin ( finalWebpackConfig , 'SentryCliPlugin' ) as SentryWebpackPlugin ;
361372
362- expect ( ( finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPlugin ) . options . debug ) . toEqual ( true ) ;
373+ expect ( sentryWebpackPluginInstance . options . debug ) . toEqual ( true ) ;
363374 } ) ;
364375
365376 it ( 'warns when overriding certain default values' , ( ) => {
@@ -378,9 +389,12 @@ describe('Sentry webpack plugin config', () => {
378389 incomingWebpackBuildContext : clientBuildContext ,
379390 } ) ;
380391
381- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
392+ const sentryWebpackPluginInstance = findWebpackPlugin (
393+ finalWebpackConfig ,
394+ 'SentryCliPlugin' ,
395+ ) as SentryWebpackPlugin ;
382396
383- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
397+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
384398 { paths : [ '.next/static/chunks/pages' ] , urlPrefix : '~/_next/static/chunks/pages' } ,
385399 ] ) ;
386400 } ) ;
@@ -395,9 +409,12 @@ describe('Sentry webpack plugin config', () => {
395409 incomingWebpackBuildContext : getBuildContext ( 'server' , userNextConfigServerless ) ,
396410 } ) ;
397411
398- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
412+ const sentryWebpackPluginInstance = findWebpackPlugin (
413+ finalWebpackConfig ,
414+ 'SentryCliPlugin' ,
415+ ) as SentryWebpackPlugin ;
399416
400- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
417+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
401418 { paths : [ '.next/serverless/' ] , urlPrefix : '~/_next/serverless' } ,
402419 ] ) ;
403420 } ) ;
@@ -412,9 +429,12 @@ describe('Sentry webpack plugin config', () => {
412429 incomingWebpackBuildContext : serverBuildContextWebpack4 ,
413430 } ) ;
414431
415- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
432+ const sentryWebpackPluginInstance = findWebpackPlugin (
433+ finalWebpackConfig ,
434+ 'SentryCliPlugin' ,
435+ ) as SentryWebpackPlugin ;
416436
417- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
437+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
418438 { paths : [ '.next/server/pages/' ] , urlPrefix : '~/_next/server/pages' } ,
419439 ] ) ;
420440 } ) ;
@@ -426,9 +446,12 @@ describe('Sentry webpack plugin config', () => {
426446 incomingWebpackBuildContext : serverBuildContext ,
427447 } ) ;
428448
429- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
449+ const sentryWebpackPluginInstance = findWebpackPlugin (
450+ finalWebpackConfig ,
451+ 'SentryCliPlugin' ,
452+ ) as SentryWebpackPlugin ;
430453
431- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
454+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
432455 { paths : [ '.next/server/pages/' ] , urlPrefix : '~/_next/server/pages' } ,
433456 { paths : [ '.next/server/chunks/' ] , urlPrefix : '~/_next/server/chunks' } ,
434457 ] ) ;
@@ -448,9 +471,12 @@ describe('Sentry webpack plugin config', () => {
448471 incomingWebpackBuildContext : getBuildContext ( 'client' , userNextConfigWithBasePath ) ,
449472 } ) ;
450473
451- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
474+ const sentryWebpackPluginInstance = findWebpackPlugin (
475+ finalWebpackConfig ,
476+ 'SentryCliPlugin' ,
477+ ) as SentryWebpackPlugin ;
452478
453- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
479+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
454480 { paths : [ '.next/static/chunks/pages' ] , urlPrefix : '~/city-park/_next/static/chunks/pages' } ,
455481 ] ) ;
456482 } ) ;
@@ -465,9 +491,12 @@ describe('Sentry webpack plugin config', () => {
465491 incomingWebpackBuildContext : getBuildContext ( 'server' , userNextConfigServerless ) ,
466492 } ) ;
467493
468- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
494+ const sentryWebpackPluginInstance = findWebpackPlugin (
495+ finalWebpackConfig ,
496+ 'SentryCliPlugin' ,
497+ ) as SentryWebpackPlugin ;
469498
470- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
499+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
471500 { paths : [ '.next/serverless/' ] , urlPrefix : '~/city-park/_next/serverless' } ,
472501 ] ) ;
473502 } ) ;
@@ -482,9 +511,12 @@ describe('Sentry webpack plugin config', () => {
482511 incomingWebpackBuildContext : serverBuildContextWebpack4 ,
483512 } ) ;
484513
485- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
514+ const sentryWebpackPluginInstance = findWebpackPlugin (
515+ finalWebpackConfig ,
516+ 'SentryCliPlugin' ,
517+ ) as SentryWebpackPlugin ;
486518
487- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
519+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
488520 { paths : [ '.next/server/pages/' ] , urlPrefix : '~/city-park/_next/server/pages' } ,
489521 ] ) ;
490522 } ) ;
@@ -496,9 +528,12 @@ describe('Sentry webpack plugin config', () => {
496528 incomingWebpackBuildContext : getBuildContext ( 'server' , userNextConfigWithBasePath ) ,
497529 } ) ;
498530
499- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
531+ const sentryWebpackPluginInstance = findWebpackPlugin (
532+ finalWebpackConfig ,
533+ 'SentryCliPlugin' ,
534+ ) as SentryWebpackPlugin ;
500535
501- expect ( sentryWebpackPlugin . options ? .include ) . toEqual ( [
536+ expect ( sentryWebpackPluginInstance . options . include ) . toEqual ( [
502537 { paths : [ '.next/server/pages/' ] , urlPrefix : '~/city-park/_next/server/pages' } ,
503538 { paths : [ '.next/server/chunks/' ] , urlPrefix : '~/city-park/_next/server/chunks' } ,
504539 ] ) ;
0 commit comments