11const { Template } = require ( 'webpack' ) ;
22const getRefreshModuleRuntime = require ( '../../../loader/utils/getRefreshModuleRuntime' ) ;
3+ const refreshGlobals = `(typeof __webpack_global__ !== 'undefined' ? __webpack_global__ : __webpack_require__)` ;
34
45describe ( 'getRefreshModuleRuntime' , ( ) => {
56 it ( 'should return working refresh module runtime without const using CommonJS' , ( ) => {
67 const refreshModuleRuntime = getRefreshModuleRuntime ( Template , {
78 const : false ,
89 moduleSystem : 'cjs' ,
10+ refreshGlobals,
911 } ) ;
1012
1113 expect ( refreshModuleRuntime . indexOf ( 'var' ) ) . not . toBe ( - 1 ) ;
@@ -14,7 +16,7 @@ describe('getRefreshModuleRuntime', () => {
1416 expect ( refreshModuleRuntime . indexOf ( 'module.hot' ) ) . not . toBe ( - 1 ) ;
1517 expect ( refreshModuleRuntime . indexOf ( 'import.meta.webpackHot' ) ) . toBe ( - 1 ) ;
1618 expect ( refreshModuleRuntime ) . toMatchInlineSnapshot ( `
17- "var $ReactRefreshModuleId$ = __webpack_require__.$Refresh$.moduleId;
19+ "var $ReactRefreshModuleId$ = (typeof __webpack_global__ !== 'undefined' ? __webpack_global__ : __webpack_require__) .$Refresh$.moduleId;
1820 var $ReactRefreshCurrentExports$ = __react_refresh_utils__.getModuleExports(
1921 $ReactRefreshModuleId$
2022 );
@@ -51,6 +53,7 @@ describe('getRefreshModuleRuntime', () => {
5153 const refreshModuleRuntime = getRefreshModuleRuntime ( Template , {
5254 const : true ,
5355 moduleSystem : 'cjs' ,
56+ refreshGlobals,
5457 } ) ;
5558
5659 expect ( refreshModuleRuntime . indexOf ( 'var' ) ) . toBe ( - 1 ) ;
@@ -59,7 +62,7 @@ describe('getRefreshModuleRuntime', () => {
5962 expect ( refreshModuleRuntime . indexOf ( 'module.hot' ) ) . not . toBe ( - 1 ) ;
6063 expect ( refreshModuleRuntime . indexOf ( 'import.meta.webpackHot' ) ) . toBe ( - 1 ) ;
6164 expect ( refreshModuleRuntime ) . toMatchInlineSnapshot ( `
62- "const $ReactRefreshModuleId$ = __webpack_require__.$Refresh$.moduleId;
65+ "const $ReactRefreshModuleId$ = (typeof __webpack_global__ !== 'undefined' ? __webpack_global__ : __webpack_require__) .$Refresh$.moduleId;
6366 const $ReactRefreshCurrentExports$ = __react_refresh_utils__.getModuleExports(
6467 $ReactRefreshModuleId$
6568 );
@@ -96,6 +99,7 @@ describe('getRefreshModuleRuntime', () => {
9699 const refreshModuleRuntime = getRefreshModuleRuntime ( Template , {
97100 const : false ,
98101 moduleSystem : 'esm' ,
102+ refreshGlobals,
99103 } ) ;
100104
101105 expect ( refreshModuleRuntime . indexOf ( 'var' ) ) . not . toBe ( - 1 ) ;
@@ -104,7 +108,7 @@ describe('getRefreshModuleRuntime', () => {
104108 expect ( refreshModuleRuntime . indexOf ( 'module.hot' ) ) . toBe ( - 1 ) ;
105109 expect ( refreshModuleRuntime . indexOf ( 'import.meta.webpackHot' ) ) . not . toBe ( - 1 ) ;
106110 expect ( refreshModuleRuntime ) . toMatchInlineSnapshot ( `
107- "var $ReactRefreshModuleId$ = __webpack_require__.$Refresh$.moduleId;
111+ "var $ReactRefreshModuleId$ = (typeof __webpack_global__ !== 'undefined' ? __webpack_global__ : __webpack_require__) .$Refresh$.moduleId;
108112 var $ReactRefreshCurrentExports$ = __react_refresh_utils__.getModuleExports(
109113 $ReactRefreshModuleId$
110114 );
@@ -141,6 +145,7 @@ describe('getRefreshModuleRuntime', () => {
141145 const refreshModuleRuntime = getRefreshModuleRuntime ( Template , {
142146 const : true ,
143147 moduleSystem : 'esm' ,
148+ refreshGlobals,
144149 } ) ;
145150
146151 expect ( refreshModuleRuntime . indexOf ( 'var' ) ) . toBe ( - 1 ) ;
@@ -149,7 +154,7 @@ describe('getRefreshModuleRuntime', () => {
149154 expect ( refreshModuleRuntime . indexOf ( 'module.hot' ) ) . toBe ( - 1 ) ;
150155 expect ( refreshModuleRuntime . indexOf ( 'import.meta.webpackHot' ) ) . not . toBe ( - 1 ) ;
151156 expect ( refreshModuleRuntime ) . toMatchInlineSnapshot ( `
152- "const $ReactRefreshModuleId$ = __webpack_require__.$Refresh$.moduleId;
157+ "const $ReactRefreshModuleId$ = (typeof __webpack_global__ !== 'undefined' ? __webpack_global__ : __webpack_require__) .$Refresh$.moduleId;
153158 const $ReactRefreshCurrentExports$ = __react_refresh_utils__.getModuleExports(
154159 $ReactRefreshModuleId$
155160 );
0 commit comments