@@ -14,13 +14,9 @@ global.ReadableStream = require('web-streams-polyfill/ponyfill/es6').ReadableStr
1414global . TextEncoder = require ( 'util' ) . TextEncoder ;
1515global . TextDecoder = require ( 'util' ) . TextDecoder ;
1616
17- let webpackModuleIdx = 0 ;
18- let webpackModules = { } ;
19- let webpackMap = { } ;
20- global . __webpack_require__ = function ( id ) {
21- return webpackModules [ id ] ;
22- } ;
23-
17+ let clientExports ;
18+ let webpackMap ;
19+ let webpackModules ;
2420let act ;
2521let React ;
2622let ReactDOMClient ;
@@ -32,9 +28,11 @@ let Suspense;
3228describe ( 'ReactFlightDOMBrowser' , ( ) => {
3329 beforeEach ( ( ) => {
3430 jest . resetModules ( ) ;
35- webpackModules = { } ;
36- webpackMap = { } ;
3731 act = require ( 'jest-react' ) . act ;
32+ const WebpackMock = require ( './utils/WebpackMock' ) ;
33+ clientExports = WebpackMock . clientExports ;
34+ webpackMap = WebpackMock . webpackMap ;
35+ webpackModules = WebpackMock . webpackModules ;
3836 React = require ( 'react' ) ;
3937 ReactDOMClient = require ( 'react-dom/client' ) ;
4038 ReactDOMServer = require ( 'react-dom/server.browser' ) ;
@@ -43,22 +41,6 @@ describe('ReactFlightDOMBrowser', () => {
4341 Suspense = React . Suspense ;
4442 } ) ;
4543
46- function moduleReference ( moduleExport ) {
47- const idx = webpackModuleIdx ++ ;
48- webpackModules [ idx ] = {
49- d : moduleExport ,
50- } ;
51- webpackMap [ 'path/' + idx ] = {
52- default : {
53- id : '' + idx ,
54- chunks : [ ] ,
55- name : 'd' ,
56- } ,
57- } ;
58- const MODULE_TAG = Symbol . for ( 'react.module.reference' ) ;
59- return { $$typeof : MODULE_TAG , filepath : 'path/' + idx , name : 'default' } ;
60- }
61-
6244 async function waitForSuspense ( fn ) {
6345 while ( true ) {
6446 try {
@@ -249,7 +231,7 @@ describe('ReactFlightDOMBrowser', () => {
249231 return < div > { games } </ div > ;
250232 }
251233
252- const MyErrorBoundaryClient = moduleReference ( MyErrorBoundary ) ;
234+ const MyErrorBoundaryClient = clientExports ( MyErrorBoundary ) ;
253235
254236 function ProfileContent ( ) {
255237 return (
@@ -478,19 +460,19 @@ describe('ReactFlightDOMBrowser', () => {
478460 }
479461 // The Client build may not have the same IDs as the Server bundles for the same
480462 // component.
481- const ClientComponentOnTheClient = moduleReference ( ClientComponent ) ;
482- const ClientComponentOnTheServer = moduleReference ( ClientComponent ) ;
463+ const ClientComponentOnTheClient = clientExports ( ClientComponent ) ;
464+ const ClientComponentOnTheServer = clientExports ( ClientComponent ) ;
483465
484466 // In the SSR bundle this module won't exist. We simulate this by deleting it.
485- const clientId = webpackMap [ ClientComponentOnTheClient . filepath ] . default . id ;
467+ const clientId = webpackMap [ ClientComponentOnTheClient . filepath ] [ '*' ] . id ;
486468 delete webpackModules [ clientId ] ;
487469
488470 // Instead, we have to provide a translation from the client meta data to the SSR
489471 // meta data.
490- const ssrMetaData = webpackMap [ ClientComponentOnTheServer . filepath ] . default ;
472+ const ssrMetaData = webpackMap [ ClientComponentOnTheServer . filepath ] [ '*' ] ;
491473 const translationMap = {
492474 [ clientId ] : {
493- d : ssrMetaData ,
475+ '*' : ssrMetaData ,
494476 } ,
495477 } ;
496478
0 commit comments