11const { Template } = require ( 'webpack' ) ;
2- const getRefreshModuleRuntime = require ( '../../../loader/utils/getRefreshModuleRuntime' ) ;
2+ const {
3+ getRefreshModuleRuntime,
4+ RefreshGlobals : refreshGlobals ,
5+ } = require ( '../../../loader/utils' ) ;
36
47describe ( 'getRefreshModuleRuntime' , ( ) => {
58 it ( 'should return working refresh module runtime without const using CommonJS' , ( ) => {
69 const refreshModuleRuntime = getRefreshModuleRuntime ( Template , {
710 const : false ,
811 moduleSystem : 'cjs' ,
12+ refreshGlobals,
913 } ) ;
1014
1115 expect ( refreshModuleRuntime . indexOf ( 'var' ) ) . not . toBe ( - 1 ) ;
@@ -14,7 +18,7 @@ describe('getRefreshModuleRuntime', () => {
1418 expect ( refreshModuleRuntime . indexOf ( 'module.hot' ) ) . not . toBe ( - 1 ) ;
1519 expect ( refreshModuleRuntime . indexOf ( 'import.meta.webpackHot' ) ) . toBe ( - 1 ) ;
1620 expect ( refreshModuleRuntime ) . toMatchInlineSnapshot ( `
17- "var $ReactRefreshModuleId$ = __webpack_require__.$Refresh$.moduleId;
21+ "var $ReactRefreshModuleId$ = (typeof __webpack_global__ !== 'undefined' ? __webpack_global__ : __webpack_require__) .$Refresh$.moduleId;
1822 var $ReactRefreshCurrentExports$ = __react_refresh_utils__.getModuleExports(
1923 $ReactRefreshModuleId$
2024 );
@@ -51,6 +55,7 @@ describe('getRefreshModuleRuntime', () => {
5155 const refreshModuleRuntime = getRefreshModuleRuntime ( Template , {
5256 const : true ,
5357 moduleSystem : 'cjs' ,
58+ refreshGlobals,
5459 } ) ;
5560
5661 expect ( refreshModuleRuntime . indexOf ( 'var' ) ) . toBe ( - 1 ) ;
@@ -59,7 +64,7 @@ describe('getRefreshModuleRuntime', () => {
5964 expect ( refreshModuleRuntime . indexOf ( 'module.hot' ) ) . not . toBe ( - 1 ) ;
6065 expect ( refreshModuleRuntime . indexOf ( 'import.meta.webpackHot' ) ) . toBe ( - 1 ) ;
6166 expect ( refreshModuleRuntime ) . toMatchInlineSnapshot ( `
62- "const $ReactRefreshModuleId$ = __webpack_require__.$Refresh$.moduleId;
67+ "const $ReactRefreshModuleId$ = (typeof __webpack_global__ !== 'undefined' ? __webpack_global__ : __webpack_require__) .$Refresh$.moduleId;
6368 const $ReactRefreshCurrentExports$ = __react_refresh_utils__.getModuleExports(
6469 $ReactRefreshModuleId$
6570 );
@@ -96,6 +101,7 @@ describe('getRefreshModuleRuntime', () => {
96101 const refreshModuleRuntime = getRefreshModuleRuntime ( Template , {
97102 const : false ,
98103 moduleSystem : 'esm' ,
104+ refreshGlobals,
99105 } ) ;
100106
101107 expect ( refreshModuleRuntime . indexOf ( 'var' ) ) . not . toBe ( - 1 ) ;
@@ -104,7 +110,7 @@ describe('getRefreshModuleRuntime', () => {
104110 expect ( refreshModuleRuntime . indexOf ( 'module.hot' ) ) . toBe ( - 1 ) ;
105111 expect ( refreshModuleRuntime . indexOf ( 'import.meta.webpackHot' ) ) . not . toBe ( - 1 ) ;
106112 expect ( refreshModuleRuntime ) . toMatchInlineSnapshot ( `
107- "var $ReactRefreshModuleId$ = __webpack_require__.$Refresh$.moduleId;
113+ "var $ReactRefreshModuleId$ = (typeof __webpack_global__ !== 'undefined' ? __webpack_global__ : __webpack_require__) .$Refresh$.moduleId;
108114 var $ReactRefreshCurrentExports$ = __react_refresh_utils__.getModuleExports(
109115 $ReactRefreshModuleId$
110116 );
@@ -141,6 +147,7 @@ describe('getRefreshModuleRuntime', () => {
141147 const refreshModuleRuntime = getRefreshModuleRuntime ( Template , {
142148 const : true ,
143149 moduleSystem : 'esm' ,
150+ refreshGlobals,
144151 } ) ;
145152
146153 expect ( refreshModuleRuntime . indexOf ( 'var' ) ) . toBe ( - 1 ) ;
@@ -149,7 +156,7 @@ describe('getRefreshModuleRuntime', () => {
149156 expect ( refreshModuleRuntime . indexOf ( 'module.hot' ) ) . toBe ( - 1 ) ;
150157 expect ( refreshModuleRuntime . indexOf ( 'import.meta.webpackHot' ) ) . not . toBe ( - 1 ) ;
151158 expect ( refreshModuleRuntime ) . toMatchInlineSnapshot ( `
152- "const $ReactRefreshModuleId$ = __webpack_require__.$Refresh$.moduleId;
159+ "const $ReactRefreshModuleId$ = (typeof __webpack_global__ !== 'undefined' ? __webpack_global__ : __webpack_require__) .$Refresh$.moduleId;
153160 const $ReactRefreshCurrentExports$ = __react_refresh_utils__.getModuleExports(
154161 $ReactRefreshModuleId$
155162 );
0 commit comments