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,8 @@ 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' ;
48
50
49
51
/** Mocks of the arguments passed to the result of `withSentryConfig` (when it's a function). */
50
52
const runtimePhase = 'ball-fetching' ;
@@ -102,7 +104,7 @@ const clientBuildContext = { isServer: false, ...baseBuildContext };
102
104
*/
103
105
function materializeFinalNextConfig (
104
106
userNextConfig : ExportedNextConfig ,
105
- userSentryWebpackPluginConfig ?: SentryWebpackPluginOptions ,
107
+ userSentryWebpackPluginConfig ?: Partial < SentryWebpackPluginOptions > ,
106
108
) : NextConfigObject {
107
109
const sentrifiedConfig = withSentryConfig ( userNextConfig , userSentryWebpackPluginConfig ) ;
108
110
let finalConfigValues = sentrifiedConfig ;
@@ -133,7 +135,7 @@ function materializeFinalNextConfig(
133
135
*/
134
136
async function materializeFinalWebpackConfig ( options : {
135
137
userNextConfig : ExportedNextConfig ;
136
- userSentryWebpackPluginConfig ?: SentryWebpackPluginOptions ;
138
+ userSentryWebpackPluginConfig ?: Partial < SentryWebpackPluginOptions > ;
137
139
incomingWebpackConfig : WebpackConfigObject ;
138
140
incomingWebpackBuildContext : BuildContext ;
139
141
} ) : Promise < WebpackConfigObject > {
@@ -313,12 +315,40 @@ describe('webpack config', () => {
313
315
} ) ;
314
316
315
317
describe ( '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
+ ) ;
318
341
} ) ;
319
342
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 ) ;
322
352
} ) ;
323
353
324
354
it ( 'warns when overriding certain default values' , ( ) => {
@@ -329,6 +359,51 @@ describe('Sentry webpack plugin config', () => {
329
359
// do we even want to do this?
330
360
} ) ;
331
361
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
+
332
407
it ( 'allows SentryWebpackPlugin to be turned off for client code (independent of server code)' , ( ) => {
333
408
const clientFinalNextConfig = materializeFinalNextConfig ( {
334
409
...userNextConfig ,
0 commit comments