99 EntryPropertyFunction ,
1010 ExportedNextConfig ,
1111 NextConfigObject ,
12+ SentryWebpackPlugin as SentryWebpackPluginType ,
1213 SentryWebpackPluginOptions ,
1314 WebpackConfigObject ,
1415} from '../src/config/types' ;
@@ -44,7 +45,8 @@ const userNextConfig = {
4445 } ) ,
4546 } ) ,
4647} ;
47- const userSentryWebpackPluginConfig = { org : 'squirrelChasers' , project : 'simulator' , include : './thirdPartyMaps' } ;
48+ const userSentryWebpackPluginConfig = { org : 'squirrelChasers' , project : 'simulator' } ;
49+ process . env . SENTRY_AUTH_TOKEN = 'dogsarebadatkeepingsecrets' ;
4850
4951/** Mocks of the arguments passed to the result of `withSentryConfig` (when it's a function). */
5052const runtimePhase = 'ball-fetching' ;
@@ -102,7 +104,7 @@ const clientBuildContext = { isServer: false, ...baseBuildContext };
102104 */
103105function materializeFinalNextConfig (
104106 userNextConfig : ExportedNextConfig ,
105- userSentryWebpackPluginConfig ?: SentryWebpackPluginOptions ,
107+ userSentryWebpackPluginConfig ?: Partial < SentryWebpackPluginOptions > ,
106108) : NextConfigObject {
107109 const sentrifiedConfig = withSentryConfig ( userNextConfig , userSentryWebpackPluginConfig ) ;
108110 let finalConfigValues = sentrifiedConfig ;
@@ -133,7 +135,7 @@ function materializeFinalNextConfig(
133135 */
134136async function materializeFinalWebpackConfig ( options : {
135137 userNextConfig : ExportedNextConfig ;
136- userSentryWebpackPluginConfig ?: SentryWebpackPluginOptions ;
138+ userSentryWebpackPluginConfig ?: Partial < SentryWebpackPluginOptions > ;
137139 incomingWebpackConfig : WebpackConfigObject ;
138140 incomingWebpackBuildContext : BuildContext ;
139141} ) : Promise < WebpackConfigObject > {
@@ -313,12 +315,40 @@ describe('webpack config', () => {
313315} ) ;
314316
315317describe ( 'Sentry webpack plugin config' , ( ) => {
316- it ( 'includes expected properties' , ( ) => {
317- // TODO
318+ it ( 'includes expected properties' , async ( ) => {
319+ // also, can pull from either env or user config (see notes on specific properties below)
320+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
321+ userNextConfig,
322+ userSentryWebpackPluginConfig,
323+ incomingWebpackConfig : serverWebpackConfig ,
324+ incomingWebpackBuildContext : serverBuildContext ,
325+ } ) ;
326+
327+ expect ( finalWebpackConfig . plugins ?. [ 0 ] . options ) . toEqual (
328+ expect . objectContaining ( {
329+ include : expect . any ( Array ) , // default, tested separately elsewhere
330+ ignore : [ ] , // default
331+ org : 'squirrelChasers' , // from user webpack plugin config
332+ project : 'simulator' , // from user webpack plugin config
333+ authToken : 'dogsarebadatkeepingsecrets' , // picked up from env
334+ stripPrefix : [ 'webpack://_N_E/' ] , // default
335+ urlPrefix : `~/_next` , // default
336+ entries : expect . any ( Function ) , // default, tested separately elsewhere
337+ release : 'doGsaREgReaT' , // from build context
338+ dryRun : false , // based on buildContext.dev being false
339+ } ) ,
340+ ) ;
318341 } ) ;
319342
320- it ( 'preserves unrelated plugin config options' , ( ) => {
321- // TODO
343+ it ( 'preserves unrelated plugin config options' , async ( ) => {
344+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
345+ userNextConfig,
346+ userSentryWebpackPluginConfig : { ...userSentryWebpackPluginConfig , debug : true } ,
347+ incomingWebpackConfig : serverWebpackConfig ,
348+ incomingWebpackBuildContext : serverBuildContext ,
349+ } ) ;
350+
351+ expect ( ( finalWebpackConfig . plugins ?. [ 0 ] . options as SentryWebpackPluginOptions ) . debug ) . toEqual ( true ) ;
322352 } ) ;
323353
324354 it ( 'warns when overriding certain default values' , ( ) => {
@@ -329,6 +359,51 @@ describe('Sentry webpack plugin config', () => {
329359 // do we even want to do this?
330360 } ) ;
331361
362+ describe ( 'Sentry webpack plugin `include` option' , ( ) => {
363+ it ( 'has the correct value when building client bundles' , async ( ) => {
364+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
365+ userNextConfig,
366+ incomingWebpackConfig : clientWebpackConfig ,
367+ incomingWebpackBuildContext : clientBuildContext ,
368+ } ) ;
369+
370+ const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
371+
372+ expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
373+ { paths : [ '.next/static/chunks/pages' ] , urlPrefix : '~/_next/static/chunks/pages' } ,
374+ ] ) ;
375+ } ) ;
376+
377+ it ( 'has the correct value when building serverless server bundles' , async ( ) => {
378+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
379+ userNextConfig,
380+ incomingWebpackConfig : serverWebpackConfig ,
381+ incomingWebpackBuildContext : { ...serverBuildContext , config : { target : 'experimental-serverless-trace' } } ,
382+ } ) ;
383+
384+ const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
385+
386+ expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
387+ { paths : [ '.next/serverless/' ] , urlPrefix : '~/_next/serverless' } ,
388+ ] ) ;
389+ } ) ;
390+
391+ it ( 'has the correct value when building serverful server bundles' , async ( ) => {
392+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
393+ userNextConfig,
394+ incomingWebpackConfig : serverWebpackConfig ,
395+ incomingWebpackBuildContext : serverBuildContext ,
396+ } ) ;
397+
398+ const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
399+
400+ expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
401+ { paths : [ '.next/server/chunks/' ] , urlPrefix : '~/_next/server/chunks' } ,
402+ { paths : [ '.next/server/pages/' ] , urlPrefix : '~/_next/server/pages' } ,
403+ ] ) ;
404+ } ) ;
405+ } ) ;
406+
332407 it ( 'allows SentryWebpackPlugin to be turned off for client code (independent of server code)' , ( ) => {
333408 const clientFinalNextConfig = materializeFinalNextConfig ( {
334409 ...userNextConfig ,
0 commit comments