@@ -14,13 +14,9 @@ global.ReadableStream = require('web-streams-polyfill/ponyfill/es6').ReadableStr
14
14
global . TextEncoder = require ( 'util' ) . TextEncoder ;
15
15
global . TextDecoder = require ( 'util' ) . TextDecoder ;
16
16
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 ;
24
20
let act ;
25
21
let React ;
26
22
let ReactDOMClient ;
@@ -32,9 +28,11 @@ let Suspense;
32
28
describe ( 'ReactFlightDOMBrowser' , ( ) => {
33
29
beforeEach ( ( ) => {
34
30
jest . resetModules ( ) ;
35
- webpackModules = { } ;
36
- webpackMap = { } ;
37
31
act = require ( 'jest-react' ) . act ;
32
+ const WebpackMock = require ( './utils/WebpackMock' ) ;
33
+ clientExports = WebpackMock . clientExports ;
34
+ webpackMap = WebpackMock . webpackMap ;
35
+ webpackModules = WebpackMock . webpackModules ;
38
36
React = require ( 'react' ) ;
39
37
ReactDOMClient = require ( 'react-dom/client' ) ;
40
38
ReactDOMServer = require ( 'react-dom/server.browser' ) ;
@@ -43,22 +41,6 @@ describe('ReactFlightDOMBrowser', () => {
43
41
Suspense = React . Suspense ;
44
42
} ) ;
45
43
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
-
62
44
async function waitForSuspense ( fn ) {
63
45
while ( true ) {
64
46
try {
@@ -249,7 +231,7 @@ describe('ReactFlightDOMBrowser', () => {
249
231
return < div > { games } </ div > ;
250
232
}
251
233
252
- const MyErrorBoundaryClient = moduleReference ( MyErrorBoundary ) ;
234
+ const MyErrorBoundaryClient = clientExports ( MyErrorBoundary ) ;
253
235
254
236
function ProfileContent ( ) {
255
237
return (
@@ -478,19 +460,19 @@ describe('ReactFlightDOMBrowser', () => {
478
460
}
479
461
// The Client build may not have the same IDs as the Server bundles for the same
480
462
// component.
481
- const ClientComponentOnTheClient = moduleReference ( ClientComponent ) ;
482
- const ClientComponentOnTheServer = moduleReference ( ClientComponent ) ;
463
+ const ClientComponentOnTheClient = clientExports ( ClientComponent ) ;
464
+ const ClientComponentOnTheServer = clientExports ( ClientComponent ) ;
483
465
484
466
// 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 ;
486
468
delete webpackModules [ clientId ] ;
487
469
488
470
// Instead, we have to provide a translation from the client meta data to the SSR
489
471
// meta data.
490
- const ssrMetaData = webpackMap [ ClientComponentOnTheServer . filepath ] . default ;
472
+ const ssrMetaData = webpackMap [ ClientComponentOnTheServer . filepath ] [ '*' ] ;
491
473
const translationMap = {
492
474
[ clientId ] : {
493
- d : ssrMetaData ,
475
+ '*' : ssrMetaData ,
494
476
} ,
495
477
} ;
496
478
0 commit comments