99 EntryPropertyFunction ,
1010 ExportedNextConfig ,
1111 NextConfigObject ,
12+ SentryWebpackPlugin as SentryWebpackPluginType ,
1213 SentryWebpackPluginOptions ,
1314 WebpackConfigObject ,
1415} from '../src/config/types' ;
@@ -44,7 +45,9 @@ 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' ;
50+ process . env . SENTRY_RELEASE = 'doGsaREgReaT' ;
4851
4952/** Mocks of the arguments passed to the result of `withSentryConfig` (when it's a function). */
5053const runtimePhase = 'ball-fetching' ;
@@ -83,7 +86,7 @@ const clientWebpackConfig = {
8386
8487const baseBuildContext = {
8588 dev : false ,
86- buildId : 'doGsaREgReaT ' ,
89+ buildId : 'sItStAyLiEdOwN ' ,
8790 dir : '/Users/Maisey/projects/squirrelChasingSimulator' ,
8891 config : { target : 'server' as const } ,
8992} ;
@@ -102,7 +105,7 @@ const clientBuildContext = { isServer: false, ...baseBuildContext };
102105 */
103106function materializeFinalNextConfig (
104107 userNextConfig : ExportedNextConfig ,
105- userSentryWebpackPluginConfig ?: SentryWebpackPluginOptions ,
108+ userSentryWebpackPluginConfig ?: Partial < SentryWebpackPluginOptions > ,
106109) : NextConfigObject {
107110 const sentrifiedConfig = withSentryConfig ( userNextConfig , userSentryWebpackPluginConfig ) ;
108111 let finalConfigValues = sentrifiedConfig ;
@@ -133,7 +136,7 @@ function materializeFinalNextConfig(
133136 */
134137async function materializeFinalWebpackConfig ( options : {
135138 userNextConfig : ExportedNextConfig ;
136- userSentryWebpackPluginConfig ?: SentryWebpackPluginOptions ;
139+ userSentryWebpackPluginConfig ?: Partial < SentryWebpackPluginOptions > ;
137140 incomingWebpackConfig : WebpackConfigObject ;
138141 incomingWebpackBuildContext : BuildContext ;
139142} ) : Promise < WebpackConfigObject > {
@@ -313,12 +316,40 @@ describe('webpack config', () => {
313316} ) ;
314317
315318describe ( 'Sentry webpack plugin config' , ( ) => {
316- it ( 'includes expected properties' , ( ) => {
317- // TODO
319+ it ( 'includes expected properties' , async ( ) => {
320+ // also, can pull from either env or user config (see notes on specific properties below)
321+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
322+ userNextConfig,
323+ userSentryWebpackPluginConfig,
324+ incomingWebpackConfig : serverWebpackConfig ,
325+ incomingWebpackBuildContext : serverBuildContext ,
326+ } ) ;
327+
328+ expect ( finalWebpackConfig . plugins ?. [ 0 ] . options ) . toEqual (
329+ expect . objectContaining ( {
330+ include : expect . any ( Array ) , // default, tested separately elsewhere
331+ ignore : [ ] , // default
332+ org : 'squirrelChasers' , // from user webpack plugin config
333+ project : 'simulator' , // from user webpack plugin config
334+ authToken : 'dogsarebadatkeepingsecrets' , // picked up from env
335+ stripPrefix : [ 'webpack://_N_E/' ] , // default
336+ urlPrefix : `~/_next` , // default
337+ entries : expect . any ( Function ) , // default, tested separately elsewhere
338+ release : 'doGsaREgReaT' , // picked up from env
339+ dryRun : false , // based on buildContext.dev being false
340+ } ) ,
341+ ) ;
318342 } ) ;
319343
320- it ( 'preserves unrelated plugin config options' , ( ) => {
321- // TODO
344+ it ( 'preserves unrelated plugin config options' , async ( ) => {
345+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
346+ userNextConfig,
347+ userSentryWebpackPluginConfig : { ...userSentryWebpackPluginConfig , debug : true } ,
348+ incomingWebpackConfig : serverWebpackConfig ,
349+ incomingWebpackBuildContext : serverBuildContext ,
350+ } ) ;
351+
352+ expect ( ( finalWebpackConfig . plugins ?. [ 0 ] . options as SentryWebpackPluginOptions ) . debug ) . toEqual ( true ) ;
322353 } ) ;
323354
324355 it ( 'warns when overriding certain default values' , ( ) => {
@@ -329,6 +360,51 @@ describe('Sentry webpack plugin config', () => {
329360 // do we even want to do this?
330361 } ) ;
331362
363+ describe ( 'Sentry webpack plugin `include` option' , ( ) => {
364+ it ( 'has the correct value when building client bundles' , async ( ) => {
365+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
366+ userNextConfig,
367+ incomingWebpackConfig : clientWebpackConfig ,
368+ incomingWebpackBuildContext : clientBuildContext ,
369+ } ) ;
370+
371+ const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
372+
373+ expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
374+ { paths : [ '.next/static/chunks/pages' ] , urlPrefix : '~/_next/static/chunks/pages' } ,
375+ ] ) ;
376+ } ) ;
377+
378+ it ( 'has the correct value when building serverless server bundles' , async ( ) => {
379+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
380+ userNextConfig,
381+ incomingWebpackConfig : serverWebpackConfig ,
382+ incomingWebpackBuildContext : { ...serverBuildContext , config : { target : 'experimental-serverless-trace' } } ,
383+ } ) ;
384+
385+ const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
386+
387+ expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
388+ { paths : [ '.next/serverless/' ] , urlPrefix : '~/_next/serverless' } ,
389+ ] ) ;
390+ } ) ;
391+
392+ it ( 'has the correct value when building serverful server bundles' , async ( ) => {
393+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
394+ userNextConfig,
395+ incomingWebpackConfig : serverWebpackConfig ,
396+ incomingWebpackBuildContext : serverBuildContext ,
397+ } ) ;
398+
399+ const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
400+
401+ expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
402+ { paths : [ '.next/server/chunks/' ] , urlPrefix : '~/_next/server/chunks' } ,
403+ { paths : [ '.next/server/pages/' ] , urlPrefix : '~/_next/server/pages' } ,
404+ ] ) ;
405+ } ) ;
406+ } ) ;
407+
332408 it ( 'allows SentryWebpackPlugin to be turned off for client code (independent of server code)' , ( ) => {
333409 const clientFinalNextConfig = materializeFinalNextConfig ( {
334410 ...userNextConfig ,
0 commit comments