@@ -332,35 +332,26 @@ describe('webpack config', () => {
332
332
incomingWebpackBuildContext : serverBuildContext ,
333
333
} ) ;
334
334
335
- const tempDir = mkdtempSyncSpy . mock . results [ 0 ] . value ;
336
- const rewriteFramesHelper = path . join ( tempDir , 'rewriteFramesHelper.js' ) ;
337
-
338
335
expect ( finalWebpackConfig . entry ) . toEqual (
339
336
expect . objectContaining ( {
340
337
// original entrypoint value is a string
341
338
// (was 'private-next-pages/_error.js')
342
- 'pages/_error' : [ rewriteFramesHelper , serverConfigFilePath , 'private-next-pages/_error.js' ] ,
339
+ 'pages/_error' : [ serverConfigFilePath , 'private-next-pages/_error.js' ] ,
343
340
344
341
// original entrypoint value is a string array
345
342
// (was ['./node_modules/smellOVision/index.js', 'private-next-pages/_app.js'])
346
- 'pages/_app' : [
347
- rewriteFramesHelper ,
348
- serverConfigFilePath ,
349
- './node_modules/smellOVision/index.js' ,
350
- 'private-next-pages/_app.js' ,
351
- ] ,
343
+ 'pages/_app' : [ serverConfigFilePath , './node_modules/smellOVision/index.js' , 'private-next-pages/_app.js' ] ,
352
344
353
345
// original entrypoint value is an object containing a string `import` value
354
346
// (was { import: 'private-next-pages/api/simulator/dogStats/[name].js' })
355
347
'pages/api/simulator/dogStats/[name]' : {
356
- import : [ rewriteFramesHelper , serverConfigFilePath , 'private-next-pages/api/simulator/dogStats/[name].js' ] ,
348
+ import : [ serverConfigFilePath , 'private-next-pages/api/simulator/dogStats/[name].js' ] ,
357
349
} ,
358
350
359
351
// original entrypoint value is an object containing a string array `import` value
360
352
// (was { import: ['./node_modules/dogPoints/converter.js', 'private-next-pages/api/simulator/leaderboard.js'] })
361
353
'pages/api/simulator/leaderboard' : {
362
354
import : [
363
- rewriteFramesHelper ,
364
355
serverConfigFilePath ,
365
356
'./node_modules/dogPoints/converter.js' ,
366
357
'private-next-pages/api/simulator/leaderboard.js' ,
@@ -370,7 +361,7 @@ describe('webpack config', () => {
370
361
// original entrypoint value is an object containg properties besides `import`
371
362
// (was { import: 'private-next-pages/api/tricks/[trickName].js', dependOn: 'treats', })
372
363
'pages/api/tricks/[trickName]' : {
373
- import : [ rewriteFramesHelper , serverConfigFilePath , 'private-next-pages/api/tricks/[trickName].js' ] ,
364
+ import : [ serverConfigFilePath , 'private-next-pages/api/tricks/[trickName].js' ] ,
374
365
dependOn : 'treats' , // untouched
375
366
} ,
376
367
} ) ,
@@ -478,53 +469,45 @@ describe('webpack config', () => {
478
469
} ) ,
479
470
) ;
480
471
} ) ;
472
+ } ) ;
481
473
482
- it ( 'does not inject `RewriteFrames` helper into client routes' , async ( ) => {
474
+ describe ( 'webpack loaders' , ( ) => {
475
+ it ( 'adds loader to server config' , async ( ) => {
476
+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
477
+ userNextConfig,
478
+ incomingWebpackConfig : serverWebpackConfig ,
479
+ incomingWebpackBuildContext : serverBuildContext ,
480
+ } ) ;
481
+
482
+ expect ( finalWebpackConfig . module ! . rules ) . toEqual (
483
+ expect . arrayContaining ( [
484
+ {
485
+ test : expect . any ( RegExp ) ,
486
+ use : [
487
+ {
488
+ loader : expect . any ( String ) ,
489
+ // Having no criteria for what the object contains is better than using `expect.any(Object)`, because that
490
+ // could be anything
491
+ options : expect . objectContaining ( { } ) ,
492
+ } ,
493
+ ] ,
494
+ } ,
495
+ ] ) ,
496
+ ) ;
497
+ } ) ;
498
+
499
+ it ( "doesn't add loader to client config" , async ( ) => {
483
500
const finalWebpackConfig = await materializeFinalWebpackConfig ( {
484
501
userNextConfig,
485
502
incomingWebpackConfig : clientWebpackConfig ,
486
503
incomingWebpackBuildContext : clientBuildContext ,
487
504
} ) ;
488
505
489
- expect ( finalWebpackConfig . entry ) . toEqual (
490
- expect . objectContaining ( {
491
- // was 'next-client-pages-loader?page=%2F_app', and now has client config but not`RewriteFrames` helper injected
492
- 'pages/_app' : [ clientConfigFilePath , 'next-client-pages-loader?page=%2F_app' ] ,
493
- } ) ,
494
- ) ;
506
+ expect ( finalWebpackConfig . module ) . toBeUndefined ( ) ;
495
507
} ) ;
496
508
} ) ;
497
509
498
510
describe ( '`distDir` value in default server-side `RewriteFrames` integration' , ( ) => {
499
- it . each ( [
500
- [ 'no custom `distDir`' , undefined , '.next' ] ,
501
- [ 'custom `distDir`' , 'dist' , 'dist' ] ,
502
- ] ) (
503
- 'creates file injecting `distDir` value into `global` - %s' ,
504
- async ( _name , customDistDir , expectedInjectedValue ) => {
505
- // Note: the fact that the file tested here gets injected correctly is covered in the 'webpack `entry` property
506
- // config' tests above
507
-
508
- const userNextConfigDistDir = {
509
- ...userNextConfig ,
510
- ...( customDistDir && { distDir : customDistDir } ) ,
511
- } ;
512
- await materializeFinalWebpackConfig ( {
513
- userNextConfig : userNextConfigDistDir ,
514
- incomingWebpackConfig : serverWebpackConfig ,
515
- incomingWebpackBuildContext : getBuildContext ( 'server' , userNextConfigDistDir ) ,
516
- } ) ;
517
-
518
- const tempDir = mkdtempSyncSpy . mock . results [ 0 ] . value ;
519
- const rewriteFramesHelper = path . join ( tempDir , 'rewriteFramesHelper.js' ) ;
520
-
521
- expect ( fs . existsSync ( rewriteFramesHelper ) ) . toBe ( true ) ;
522
-
523
- const injectedCode = fs . readFileSync ( rewriteFramesHelper ) . toString ( ) ;
524
- expect ( injectedCode ) . toEqual ( `global.__rewriteFramesDistDir__ = '${ expectedInjectedValue } ';\n` ) ;
525
- } ,
526
- ) ;
527
-
528
511
describe ( '`RewriteFrames` ends up with correct `distDir` value' , ( ) => {
529
512
// TODO: this, along with any number of other parts of the build process, should be tested with an integration
530
513
// test which actually runs webpack and inspects the resulting bundles (and that integration test should test
0 commit comments