9
9
EntryPropertyFunction ,
10
10
ExportedNextConfig ,
11
11
NextConfigObject ,
12
+ SentryWebpackPlugin as SentryWebpackPluginType ,
12
13
SentryWebpackPluginOptions ,
13
14
WebpackConfigObject ,
14
15
} from '../src/config/types' ;
@@ -44,7 +45,9 @@ const userNextConfig = {
44
45
} ) ,
45
46
} ) ,
46
47
} ;
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' ;
48
51
49
52
/** Mocks of the arguments passed to the result of `withSentryConfig` (when it's a function). */
50
53
const runtimePhase = 'ball-fetching' ;
@@ -83,7 +86,7 @@ const clientWebpackConfig = {
83
86
84
87
const baseBuildContext = {
85
88
dev : false ,
86
- buildId : 'doGsaREgReaT ' ,
89
+ buildId : 'sItStAyLiEdOwN ' ,
87
90
dir : '/Users/Maisey/projects/squirrelChasingSimulator' ,
88
91
config : { target : 'server' as const } ,
89
92
} ;
@@ -102,7 +105,7 @@ const clientBuildContext = { isServer: false, ...baseBuildContext };
102
105
*/
103
106
function materializeFinalNextConfig (
104
107
userNextConfig : ExportedNextConfig ,
105
- userSentryWebpackPluginConfig ?: SentryWebpackPluginOptions ,
108
+ userSentryWebpackPluginConfig ?: Partial < SentryWebpackPluginOptions > ,
106
109
) : NextConfigObject {
107
110
const sentrifiedConfig = withSentryConfig ( userNextConfig , userSentryWebpackPluginConfig ) ;
108
111
let finalConfigValues = sentrifiedConfig ;
@@ -133,7 +136,7 @@ function materializeFinalNextConfig(
133
136
*/
134
137
async function materializeFinalWebpackConfig ( options : {
135
138
userNextConfig : ExportedNextConfig ;
136
- userSentryWebpackPluginConfig ?: SentryWebpackPluginOptions ;
139
+ userSentryWebpackPluginConfig ?: Partial < SentryWebpackPluginOptions > ;
137
140
incomingWebpackConfig : WebpackConfigObject ;
138
141
incomingWebpackBuildContext : BuildContext ;
139
142
} ) : Promise < WebpackConfigObject > {
@@ -313,12 +316,40 @@ describe('webpack config', () => {
313
316
} ) ;
314
317
315
318
describe ( '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
+ ) ;
318
342
} ) ;
319
343
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 ) ;
322
353
} ) ;
323
354
324
355
it ( 'warns when overriding certain default values' , ( ) => {
@@ -329,6 +360,51 @@ describe('Sentry webpack plugin config', () => {
329
360
// do we even want to do this?
330
361
} ) ;
331
362
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
+
332
408
it ( 'allows SentryWebpackPlugin to be turned off for client code (independent of server code)' , ( ) => {
333
409
const clientFinalNextConfig = materializeFinalNextConfig ( {
334
410
...userNextConfig ,
0 commit comments