@@ -332,35 +332,26 @@ describe('webpack config', () => {
332332 incomingWebpackBuildContext : serverBuildContext ,
333333 } ) ;
334334
335- const tempDir = mkdtempSyncSpy . mock . results [ 0 ] . value ;
336- const rewriteFramesHelper = path . join ( tempDir , 'rewriteFramesHelper.js' ) ;
337-
338335 expect ( finalWebpackConfig . entry ) . toEqual (
339336 expect . objectContaining ( {
340337 // original entrypoint value is a string
341338 // (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' ] ,
343340
344341 // original entrypoint value is a string array
345342 // (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' ] ,
352344
353345 // original entrypoint value is an object containing a string `import` value
354346 // (was { import: 'private-next-pages/api/simulator/dogStats/[name].js' })
355347 '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' ] ,
357349 } ,
358350
359351 // original entrypoint value is an object containing a string array `import` value
360352 // (was { import: ['./node_modules/dogPoints/converter.js', 'private-next-pages/api/simulator/leaderboard.js'] })
361353 'pages/api/simulator/leaderboard' : {
362354 import : [
363- rewriteFramesHelper ,
364355 serverConfigFilePath ,
365356 './node_modules/dogPoints/converter.js' ,
366357 'private-next-pages/api/simulator/leaderboard.js' ,
@@ -370,7 +361,7 @@ describe('webpack config', () => {
370361 // original entrypoint value is an object containg properties besides `import`
371362 // (was { import: 'private-next-pages/api/tricks/[trickName].js', dependOn: 'treats', })
372363 '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' ] ,
374365 dependOn : 'treats' , // untouched
375366 } ,
376367 } ) ,
@@ -478,53 +469,45 @@ describe('webpack config', () => {
478469 } ) ,
479470 ) ;
480471 } ) ;
472+ } ) ;
481473
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 ( ) => {
483500 const finalWebpackConfig = await materializeFinalWebpackConfig ( {
484501 userNextConfig,
485502 incomingWebpackConfig : clientWebpackConfig ,
486503 incomingWebpackBuildContext : clientBuildContext ,
487504 } ) ;
488505
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 ( ) ;
495507 } ) ;
496508 } ) ;
497509
498510 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-
528511 describe ( '`RewriteFrames` ends up with correct `distDir` value' , ( ) => {
529512 // TODO: this, along with any number of other parts of the build process, should be tested with an integration
530513 // test which actually runs webpack and inspects the resulting bundles (and that integration test should test
0 commit comments