@@ -2,6 +2,7 @@ import * as fs from 'fs';
2
2
import * as os from 'os' ;
3
3
import * as path from 'path' ;
4
4
import * as rimraf from 'rimraf' ;
5
+ import { DefinePlugin } from 'webpack' ;
5
6
6
7
import { withSentryConfig } from '../src/config' ;
7
8
import {
@@ -326,6 +327,43 @@ describe('webpack config', () => {
326
327
) ;
327
328
} ) ;
328
329
} ) ;
330
+
331
+ describe . only ( '`distDir` value in default server-side `RewriteFrames` integration' , ( ) => {
332
+ describe ( '`DefinePlugin` existence and inclusion of `__rewriteFramesDistDir__` definition' , ( ) => {
333
+ it . each ( [
334
+ [ 'no custom `distDir`, pre-existing `DefinePlugin`' , undefined , true ] ,
335
+ [ 'no custom `distDir`, no pre-existing `DefinePlugin`' , undefined , false ] ,
336
+ [ 'custom `distDir`, pre-existing `DefinePlugin`' , 'some/output/directory' , true ] ,
337
+ [ 'custom `distDir`, no pre-existing `DefinePlugin`' , 'some/output/directory' , false ] ,
338
+ ] ) (
339
+ '%s' ,
340
+ async ( _testTitle : string , customDistDir : string | undefined , existingDefinePlugin : boolean ) : Promise < void > => {
341
+ const userNextConfigMaybeWithDistDir = {
342
+ ...userNextConfig ,
343
+ ...( customDistDir && { distDir : customDistDir } ) ,
344
+ } ;
345
+ const serverWebpackConfigMaybeWithDefinePlugin = {
346
+ ...serverWebpackConfig ,
347
+ ...( existingDefinePlugin && { plugins : [ new DefinePlugin ( { __dogName__ : 'Maisey' } ) ] } ) ,
348
+ } ;
349
+
350
+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
351
+ userNextConfig : userNextConfigMaybeWithDistDir ,
352
+ incomingWebpackConfig : serverWebpackConfigMaybeWithDefinePlugin ,
353
+ incomingWebpackBuildContext : getBuildContext ( 'server' , userNextConfigMaybeWithDistDir ) ,
354
+ } ) ;
355
+
356
+ expect ( finalWebpackConfig . plugins ) . toEqual ( expect . arrayContaining ( [ expect . any ( DefinePlugin ) ] ) ) ;
357
+
358
+ const definePluginInstance = findWebpackPlugin ( finalWebpackConfig , 'DefinePlugin' ) as DefinePlugin ;
359
+ expect ( definePluginInstance . definitions . __rewriteFramesDistDir__ ) . toEqual ( customDistDir ) ;
360
+ } ,
361
+ ) ;
362
+ } ) ;
363
+ describe ( '`RewriteFrames` ends up with correct `distDir` value' , ( ) => {
364
+ // TODO: this, along with any number of other parts of the build process, should be tested with an integration test
365
+ } ) ;
366
+ } ) ;
329
367
} ) ;
330
368
331
369
describe ( 'Sentry webpack plugin config' , ( ) => {
@@ -337,6 +375,7 @@ describe('Sentry webpack plugin config', () => {
337
375
incomingWebpackConfig : serverWebpackConfig ,
338
376
incomingWebpackBuildContext : serverBuildContext ,
339
377
} ) ;
378
+
340
379
const sentryWebpackPluginInstance = findWebpackPlugin (
341
380
finalWebpackConfig ,
342
381
'SentryCliPlugin' ,
@@ -366,7 +405,12 @@ describe('Sentry webpack plugin config', () => {
366
405
incomingWebpackBuildContext : serverBuildContext ,
367
406
} ) ;
368
407
369
- expect ( ( finalWebpackConfig . plugins ?. [ 0 ] . options as SentryWebpackPluginOptions ) . debug ) . toEqual ( true ) ;
408
+ const sentryWebpackPluginInstance = findWebpackPlugin (
409
+ finalWebpackConfig ,
410
+ 'SentryCliPlugin' ,
411
+ ) as SentryWebpackPluginType ;
412
+
413
+ expect ( sentryWebpackPluginInstance . options . debug ) . toEqual ( true ) ;
370
414
} ) ;
371
415
372
416
it ( 'warns when overriding certain default values' , ( ) => {
@@ -385,9 +429,12 @@ describe('Sentry webpack plugin config', () => {
385
429
incomingWebpackBuildContext : clientBuildContext ,
386
430
} ) ;
387
431
388
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
432
+ const sentryWebpackPluginInstance = findWebpackPlugin (
433
+ finalWebpackConfig ,
434
+ 'SentryCliPlugin' ,
435
+ ) as SentryWebpackPluginType ;
389
436
390
- expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
437
+ expect ( sentryWebpackPluginInstance . options ?. include ) . toEqual ( [
391
438
{ paths : [ '.next/static/chunks/pages' ] , urlPrefix : '~/_next/static/chunks/pages' } ,
392
439
] ) ;
393
440
} ) ;
@@ -402,9 +449,12 @@ describe('Sentry webpack plugin config', () => {
402
449
incomingWebpackBuildContext : getBuildContext ( 'server' , userNextConfigServerless ) ,
403
450
} ) ;
404
451
405
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
452
+ const sentryWebpackPluginInstance = findWebpackPlugin (
453
+ finalWebpackConfig ,
454
+ 'SentryCliPlugin' ,
455
+ ) as SentryWebpackPluginType ;
406
456
407
- expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
457
+ expect ( sentryWebpackPluginInstance . options ?. include ) . toEqual ( [
408
458
{ paths : [ '.next/serverless/' ] , urlPrefix : '~/_next/serverless' } ,
409
459
] ) ;
410
460
} ) ;
@@ -419,9 +469,12 @@ describe('Sentry webpack plugin config', () => {
419
469
incomingWebpackBuildContext : serverBuildContextWebpack4 ,
420
470
} ) ;
421
471
422
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
472
+ const sentryWebpackPluginInstance = findWebpackPlugin (
473
+ finalWebpackConfig ,
474
+ 'SentryCliPlugin' ,
475
+ ) as SentryWebpackPluginType ;
423
476
424
- expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
477
+ expect ( sentryWebpackPluginInstance . options ?. include ) . toEqual ( [
425
478
{ paths : [ '.next/server/pages/' ] , urlPrefix : '~/_next/server/pages' } ,
426
479
] ) ;
427
480
} ) ;
@@ -433,9 +486,12 @@ describe('Sentry webpack plugin config', () => {
433
486
incomingWebpackBuildContext : serverBuildContext ,
434
487
} ) ;
435
488
436
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
489
+ const sentryWebpackPluginInstance = findWebpackPlugin (
490
+ finalWebpackConfig ,
491
+ 'SentryCliPlugin' ,
492
+ ) as SentryWebpackPluginType ;
437
493
438
- expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
494
+ expect ( sentryWebpackPluginInstance . options ?. include ) . toEqual ( [
439
495
{ paths : [ '.next/server/pages/' ] , urlPrefix : '~/_next/server/pages' } ,
440
496
{ paths : [ '.next/server/chunks/' ] , urlPrefix : '~/_next/server/chunks' } ,
441
497
] ) ;
@@ -455,9 +511,12 @@ describe('Sentry webpack plugin config', () => {
455
511
incomingWebpackBuildContext : getBuildContext ( 'client' , userNextConfigWithBasePath ) ,
456
512
} ) ;
457
513
458
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
514
+ const sentryWebpackPluginInstance = findWebpackPlugin (
515
+ finalWebpackConfig ,
516
+ 'SentryCliPlugin' ,
517
+ ) as SentryWebpackPluginType ;
459
518
460
- expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
519
+ expect ( sentryWebpackPluginInstance . options ?. include ) . toEqual ( [
461
520
{ paths : [ '.next/static/chunks/pages' ] , urlPrefix : '~/city-park/_next/static/chunks/pages' } ,
462
521
] ) ;
463
522
} ) ;
@@ -472,9 +531,12 @@ describe('Sentry webpack plugin config', () => {
472
531
incomingWebpackBuildContext : getBuildContext ( 'server' , userNextConfigServerless ) ,
473
532
} ) ;
474
533
475
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
534
+ const sentryWebpackPluginInstance = findWebpackPlugin (
535
+ finalWebpackConfig ,
536
+ 'SentryCliPlugin' ,
537
+ ) as SentryWebpackPluginType ;
476
538
477
- expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
539
+ expect ( sentryWebpackPluginInstance . options ?. include ) . toEqual ( [
478
540
{ paths : [ '.next/serverless/' ] , urlPrefix : '~/city-park/_next/serverless' } ,
479
541
] ) ;
480
542
} ) ;
@@ -489,9 +551,12 @@ describe('Sentry webpack plugin config', () => {
489
551
incomingWebpackBuildContext : serverBuildContextWebpack4 ,
490
552
} ) ;
491
553
492
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
554
+ const sentryWebpackPluginInstance = findWebpackPlugin (
555
+ finalWebpackConfig ,
556
+ 'SentryCliPlugin' ,
557
+ ) as SentryWebpackPluginType ;
493
558
494
- expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
559
+ expect ( sentryWebpackPluginInstance . options ?. include ) . toEqual ( [
495
560
{ paths : [ '.next/server/pages/' ] , urlPrefix : '~/city-park/_next/server/pages' } ,
496
561
] ) ;
497
562
} ) ;
@@ -503,9 +568,12 @@ describe('Sentry webpack plugin config', () => {
503
568
incomingWebpackBuildContext : getBuildContext ( 'server' , userNextConfigWithBasePath ) ,
504
569
} ) ;
505
570
506
- const sentryWebpackPlugin = finalWebpackConfig . plugins ?. [ 0 ] as SentryWebpackPluginType ;
571
+ const sentryWebpackPluginInstance = findWebpackPlugin (
572
+ finalWebpackConfig ,
573
+ 'SentryCliPlugin' ,
574
+ ) as SentryWebpackPluginType ;
507
575
508
- expect ( sentryWebpackPlugin . options ?. include ) . toEqual ( [
576
+ expect ( sentryWebpackPluginInstance . options ?. include ) . toEqual ( [
509
577
{ paths : [ '.next/server/pages/' ] , urlPrefix : '~/city-park/_next/server/pages' } ,
510
578
{ paths : [ '.next/server/chunks/' ] , urlPrefix : '~/city-park/_next/server/chunks' } ,
511
579
] ) ;
0 commit comments