@dr.pogodin/react-utils 1.54.3 → 1.55.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/__type_tests__/ts-compiler-behavior.ts +13 -0
  2. package/__type_tests__/type-exports.ts +17 -0
  3. package/babel.build.config.js +9 -0
  4. package/babel.config.js +2 -5
  5. package/babel.libweb.config.js +2 -3
  6. package/babel.scripts.config.js +5 -11
  7. package/bin/build.js +4 -21
  8. package/bin/release.sh +1 -1
  9. package/build/development/client/getInj.js +2 -9
  10. package/build/development/client/getInj.js.map +1 -1
  11. package/build/development/client/index.js.map +1 -1
  12. package/build/development/client/init.js +1 -3
  13. package/build/development/client/init.js.map +1 -1
  14. package/build/development/index.js +1 -18
  15. package/build/development/index.js.map +1 -1
  16. package/build/development/server/Cache.js.map +1 -1
  17. package/build/development/server/index.js.map +1 -1
  18. package/build/development/server/renderer.js +10 -24
  19. package/build/development/server/renderer.js.map +1 -1
  20. package/build/development/server/server.js +6 -8
  21. package/build/development/server/server.js.map +1 -1
  22. package/build/development/server/utils/errors.js +11 -11
  23. package/build/development/server/utils/errors.js.map +1 -1
  24. package/build/development/shared/components/Button/index.js.map +1 -1
  25. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  26. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  27. package/build/development/shared/components/Input/index.js.map +1 -1
  28. package/build/development/shared/components/Link.js.map +1 -1
  29. package/build/development/shared/components/Modal/index.js.map +1 -1
  30. package/build/development/shared/components/NavLink.js.map +1 -1
  31. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  32. package/build/development/shared/components/TextArea/index.js.map +1 -1
  33. package/build/development/shared/components/Throbber/index.js.map +1 -1
  34. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  35. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  36. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  37. package/build/development/shared/components/index.js.map +1 -1
  38. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +2 -5
  39. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  40. package/build/development/shared/components/selectors/CustomDropdown/index.js +1 -4
  41. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  42. package/build/development/shared/components/selectors/NativeDropdown/index.js +2 -5
  43. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  44. package/build/development/shared/components/selectors/Switch/index.js +2 -2
  45. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  46. package/build/development/shared/components/selectors/common.js.map +1 -1
  47. package/build/development/shared/components/selectors/index.js.map +1 -1
  48. package/build/development/shared/utils/config.js.map +1 -1
  49. package/build/development/shared/utils/globalState.js.map +1 -1
  50. package/build/development/shared/utils/index.js.map +1 -1
  51. package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
  52. package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
  53. package/build/development/shared/utils/isomorphy/index.js +4 -5
  54. package/build/development/shared/utils/isomorphy/index.js.map +1 -1
  55. package/build/development/shared/utils/jest/E2eSsrEnv/index.js +32 -71
  56. package/build/development/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  57. package/build/development/shared/utils/jest/E2eSsrEnv/ssr-preload.js +23 -0
  58. package/build/development/shared/utils/jest/E2eSsrEnv/ssr-preload.js.map +1 -0
  59. package/build/development/shared/utils/jest/E2eSsrEnv/ssr.js +1 -1
  60. package/build/development/shared/utils/jest/E2eSsrEnv/ssr.js.map +1 -1
  61. package/build/development/shared/utils/jest/global.js.map +1 -1
  62. package/build/development/shared/utils/jest/index.js +3 -3
  63. package/build/development/shared/utils/jest/index.js.map +1 -1
  64. package/build/development/shared/utils/splitComponent.js +17 -40
  65. package/build/development/shared/utils/splitComponent.js.map +1 -1
  66. package/build/development/shared/utils/time.js +28 -65
  67. package/build/development/shared/utils/time.js.map +1 -1
  68. package/build/development/shared/utils/webpack.js +3 -5
  69. package/build/development/shared/utils/webpack.js.map +1 -1
  70. package/build/production/client/getInj.js +1 -1
  71. package/build/production/client/getInj.js.map +1 -1
  72. package/build/production/client/index.js.map +1 -1
  73. package/build/production/client/init.js.map +1 -1
  74. package/build/production/index.js +1 -23
  75. package/build/production/index.js.map +1 -1
  76. package/build/production/server/Cache.js.map +1 -1
  77. package/build/production/server/index.js.map +1 -1
  78. package/build/production/server/renderer.js +5 -5
  79. package/build/production/server/renderer.js.map +1 -1
  80. package/build/production/server/server.js +4 -4
  81. package/build/production/server/server.js.map +1 -1
  82. package/build/production/server/utils/errors.js +2 -2
  83. package/build/production/server/utils/errors.js.map +1 -1
  84. package/build/production/shared/components/Button/index.js.map +1 -1
  85. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  86. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  87. package/build/production/shared/components/Input/index.js.map +1 -1
  88. package/build/production/shared/components/Link.js.map +1 -1
  89. package/build/production/shared/components/Modal/index.js.map +1 -1
  90. package/build/production/shared/components/NavLink.js.map +1 -1
  91. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  92. package/build/production/shared/components/TextArea/index.js.map +1 -1
  93. package/build/production/shared/components/Throbber/index.js.map +1 -1
  94. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  95. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  96. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  97. package/build/production/shared/components/index.js.map +1 -1
  98. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
  99. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  100. package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -1
  101. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  102. package/build/production/shared/components/selectors/NativeDropdown/index.js +2 -2
  103. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  104. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  105. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  106. package/build/production/shared/components/selectors/common.js.map +1 -1
  107. package/build/production/shared/components/selectors/index.js.map +1 -1
  108. package/build/production/shared/utils/config.js.map +1 -1
  109. package/build/production/shared/utils/globalState.js.map +1 -1
  110. package/build/production/shared/utils/index.js.map +1 -1
  111. package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
  112. package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
  113. package/build/production/shared/utils/isomorphy/index.js.map +1 -1
  114. package/build/production/shared/utils/jest/E2eSsrEnv/index.js +12 -37
  115. package/build/production/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  116. package/build/production/shared/utils/jest/E2eSsrEnv/ssr-preload.js +5 -0
  117. package/build/production/shared/utils/jest/E2eSsrEnv/ssr-preload.js.map +1 -0
  118. package/build/production/shared/utils/jest/E2eSsrEnv/ssr.js +1 -1
  119. package/build/production/shared/utils/jest/E2eSsrEnv/ssr.js.map +1 -1
  120. package/build/production/shared/utils/jest/global.js.map +1 -1
  121. package/build/production/shared/utils/jest/index.js +3 -3
  122. package/build/production/shared/utils/jest/index.js.map +1 -1
  123. package/build/production/shared/utils/splitComponent.js +7 -20
  124. package/build/production/shared/utils/splitComponent.js.map +1 -1
  125. package/build/production/shared/utils/time.js +2 -2
  126. package/build/production/shared/utils/time.js.map +1 -1
  127. package/build/production/shared/utils/webpack.js +3 -3
  128. package/build/production/shared/utils/webpack.js.map +1 -1
  129. package/build/types-code/index.d.ts +7 -0
  130. package/build/types-code/shared/utils/webpack.d.ts +2 -2
  131. package/build/web/client/getInj.js +2 -2
  132. package/build/web/client/getInj.js.map +1 -1
  133. package/build/web/client/index.js +1 -1
  134. package/build/web/client/index.js.map +1 -1
  135. package/build/web/client/init.js +1 -1
  136. package/build/web/client/init.js.map +1 -1
  137. package/build/web/index.js +1 -23
  138. package/build/web/index.js.map +1 -1
  139. package/build/web/server/Cache.js.map +1 -1
  140. package/build/web/server/index.js +1 -1
  141. package/build/web/server/index.js.map +1 -1
  142. package/build/web/server/renderer.js +6 -6
  143. package/build/web/server/renderer.js.map +1 -1
  144. package/build/web/server/server.js +5 -5
  145. package/build/web/server/server.js.map +1 -1
  146. package/build/web/server/utils/errors.js +2 -2
  147. package/build/web/server/utils/errors.js.map +1 -1
  148. package/build/web/server/utils/index.js +1 -1
  149. package/build/web/server/utils/index.js.map +1 -1
  150. package/build/web/shared/components/Button/index.js +1 -1
  151. package/build/web/shared/components/Button/index.js.map +1 -1
  152. package/build/web/shared/components/Checkbox/index.js.map +1 -1
  153. package/build/web/shared/components/GenericLink/index.js.map +1 -1
  154. package/build/web/shared/components/Input/index.js.map +1 -1
  155. package/build/web/shared/components/Link.js +1 -1
  156. package/build/web/shared/components/Link.js.map +1 -1
  157. package/build/web/shared/components/Modal/index.js.map +1 -1
  158. package/build/web/shared/components/NavLink.js +1 -1
  159. package/build/web/shared/components/NavLink.js.map +1 -1
  160. package/build/web/shared/components/PageLayout/index.js.map +1 -1
  161. package/build/web/shared/components/TextArea/index.js.map +1 -1
  162. package/build/web/shared/components/Throbber/index.js.map +1 -1
  163. package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
  164. package/build/web/shared/components/WithTooltip/index.js +1 -1
  165. package/build/web/shared/components/WithTooltip/index.js.map +1 -1
  166. package/build/web/shared/components/YouTubeVideo/index.js +1 -1
  167. package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
  168. package/build/web/shared/components/index.js +1 -1
  169. package/build/web/shared/components/index.js.map +1 -1
  170. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
  171. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  172. package/build/web/shared/components/selectors/CustomDropdown/index.js +1 -1
  173. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  174. package/build/web/shared/components/selectors/NativeDropdown/index.js +3 -3
  175. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  176. package/build/web/shared/components/selectors/Switch/index.js +1 -1
  177. package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
  178. package/build/web/shared/components/selectors/common.js.map +1 -1
  179. package/build/web/shared/components/selectors/index.js +1 -1
  180. package/build/web/shared/components/selectors/index.js.map +1 -1
  181. package/build/web/shared/utils/config.js +1 -1
  182. package/build/web/shared/utils/config.js.map +1 -1
  183. package/build/web/shared/utils/globalState.js.map +1 -1
  184. package/build/web/shared/utils/index.js +1 -1
  185. package/build/web/shared/utils/index.js.map +1 -1
  186. package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -1
  187. package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -1
  188. package/build/web/shared/utils/isomorphy/index.js +1 -1
  189. package/build/web/shared/utils/isomorphy/index.js.map +1 -1
  190. package/build/web/shared/utils/jest/E2eSsrEnv/index.js +12 -37
  191. package/build/web/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  192. package/build/web/shared/utils/jest/E2eSsrEnv/ssr-preload.js +5 -0
  193. package/build/web/shared/utils/jest/E2eSsrEnv/ssr-preload.js.map +1 -0
  194. package/build/web/shared/utils/jest/E2eSsrEnv/ssr.js +2 -2
  195. package/build/web/shared/utils/jest/E2eSsrEnv/ssr.js.map +1 -1
  196. package/build/web/shared/utils/jest/global.js.map +1 -1
  197. package/build/web/shared/utils/jest/index.js +4 -4
  198. package/build/web/shared/utils/jest/index.js.map +1 -1
  199. package/build/web/shared/utils/splitComponent.js +7 -20
  200. package/build/web/shared/utils/splitComponent.js.map +1 -1
  201. package/build/web/shared/utils/time.js +2 -2
  202. package/build/web/shared/utils/time.js.map +1 -1
  203. package/build/web/shared/utils/webpack.js +4 -4
  204. package/build/web/shared/utils/webpack.js.map +1 -1
  205. package/config/babel/node-ssr.d.ts +2 -3
  206. package/config/babel/node-ssr.js +15 -55
  207. package/config/babel/webpack.d.ts +7 -5
  208. package/config/babel/webpack.js +19 -24
  209. package/config/eslint/default.mjs +1 -1
  210. package/config/jest/default.js +6 -7
  211. package/config/jest/resolver.js +1 -3
  212. package/config/jest/setup.js +2 -2
  213. package/config/stylelint/default.js +1 -4
  214. package/config/webpack/app-base.js +40 -41
  215. package/config/webpack/app-development.d.ts +1 -1
  216. package/config/webpack/app-development.js +12 -18
  217. package/config/webpack/app-production.d.ts +1 -1
  218. package/config/webpack/app-production.js +10 -16
  219. package/package.json +37 -35
  220. package/patches/jest-resolve+30.4.1.patch +29 -0
  221. package/tsconfig.configs.json +6 -1
  222. package/tsconfig.json +2 -1
  223. package/tsconfig.types.json +1 -0
  224. package/tstyche.json +1 -1
  225. package/babel.module.config.js +0 -11
  226. package/build/development/shared/utils/jest/E2eSsrEnv/register.js +0 -6
  227. package/build/development/shared/utils/jest/E2eSsrEnv/register.js.map +0 -1
  228. package/build/production/shared/utils/jest/E2eSsrEnv/register.js +0 -3
  229. package/build/production/shared/utils/jest/E2eSsrEnv/register.js.map +0 -1
  230. package/build/web/shared/utils/jest/E2eSsrEnv/register.js +0 -3
  231. package/build/web/shared/utils/jest/E2eSsrEnv/register.js.map +0 -1
  232. /package/build/types-code/shared/utils/jest/E2eSsrEnv/{register.d.ts → ssr-preload.d.ts} +0 -0
@@ -1,2 +1,2 @@
1
- import"core-js/modules/es.array.push.js";import{c as _c}from"react/compiler-runtime";import{useTheme}from"@dr.pogodin/react-themes";import{optionValueName}from"../common";import defaultTheme from"./theme.scss";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const Switch=t0=>{const $=_c(16);const{label,onChange,options,theme,value}=t0;const composed=useTheme("Switch",defaultTheme,theme);if(!options||!composed.option){throw Error("Internal error");}let optionNodes;if($[0]!==composed.option||$[1]!==composed.selected||$[2]!==onChange||$[3]!==options||$[4]!==value){optionNodes=[];for(const option of options){const[iValue,iName]=optionValueName(option);let className=composed.option;let onPress;if(iValue===value){className=className+` ${composed.selected}`;}else{if(onChange){onPress=()=>{onChange(iValue)};}}optionNodes.push(onPress?/*#__PURE__*/_jsx("div",{className:className,onClick:onPress,onKeyDown:e=>{if(e.key==="Enter"){onPress()}},role:"button",tabIndex:0,children:iName},iValue):/*#__PURE__*/_jsx("div",{className:className,children:iName},iValue))}$[0]=composed.option;$[1]=composed.selected;$[2]=onChange;$[3]=options;$[4]=value;$[5]=optionNodes}else{optionNodes=$[5]}let t1;if($[6]!==composed.label||$[7]!==label){t1=label?/*#__PURE__*/_jsx("div",{className:composed.label,children:label}):null;$[6]=composed.label;$[7]=label;$[8]=t1}else{t1=$[8]}let t2;if($[9]!==composed.options||$[10]!==optionNodes){t2=/*#__PURE__*/_jsx("div",{className:composed.options,children:optionNodes});$[9]=composed.options;$[10]=optionNodes;$[11]=t2}else{t2=$[11]}let t3;if($[12]!==composed.container||$[13]!==t1||$[14]!==t2){t3=/*#__PURE__*/_jsxs("div",{className:composed.container,children:[t1,t2]});$[12]=composed.container;$[13]=t1;$[14]=t2;$[15]=t3}else{t3=$[15]}return t3};
1
+ import _pushInstanceProperty from"core-js-pure/stable/instance/push.js";import{c as _c}from"react/compiler-runtime";import{useTheme}from"@dr.pogodin/react-themes";import{optionValueName}from"../common.js";import defaultTheme from"./theme.scss";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const Switch=t0=>{const $=_c(16);const{label,onChange,options,theme,value}=t0;const composed=useTheme("Switch",defaultTheme,theme);if(!options||!composed.option){throw Error("Internal error");}let optionNodes;if($[0]!==composed.option||$[1]!==composed.selected||$[2]!==onChange||$[3]!==options||$[4]!==value){optionNodes=[];for(const option of options){const[iValue,iName]=optionValueName(option);let className=composed.option;let onPress;if(iValue===value){className=className+` ${composed.selected}`;}else{if(onChange){onPress=()=>{onChange(iValue)};}}_pushInstanceProperty(optionNodes).call(optionNodes,onPress?/*#__PURE__*/_jsx("div",{className:className,onClick:onPress,onKeyDown:e=>{if(e.key==="Enter"){onPress()}},role:"button",tabIndex:0,children:iName},iValue):/*#__PURE__*/_jsx("div",{className:className,children:iName},iValue))}$[0]=composed.option;$[1]=composed.selected;$[2]=onChange;$[3]=options;$[4]=value;$[5]=optionNodes}else{optionNodes=$[5]}let t1;if($[6]!==composed.label||$[7]!==label){t1=label?/*#__PURE__*/_jsx("div",{className:composed.label,children:label}):null;$[6]=composed.label;$[7]=label;$[8]=t1}else{t1=$[8]}let t2;if($[9]!==composed.options||$[10]!==optionNodes){t2=/*#__PURE__*/_jsx("div",{className:composed.options,children:optionNodes});$[9]=composed.options;$[10]=optionNodes;$[11]=t2}else{t2=$[11]}let t3;if($[12]!==composed.container||$[13]!==t1||$[14]!==t2){t3=/*#__PURE__*/_jsxs("div",{className:composed.container,children:[t1,t2]});$[12]=composed.container;$[13]=t1;$[14]=t2;$[15]=t3}else{t3=$[15]}return t3};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["useTheme","optionValueName","defaultTheme","jsx","_jsx","jsxs","_jsxs","Switch","t0","$","_c","label","onChange","options","theme","value","composed","option","Error","optionNodes","selected","iValue","iName","className","onPress","push","onKeyDown","e","key","role","tabIndex","children","t1","t2","t3","container"],"sources":["../../../../../../src/shared/components/selectors/Switch/index.tsx"],"sourcesContent":["import type { FunctionComponent, ReactNode } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport {\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../common';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeT = Theme<'container' | 'label' | 'option' | 'options' | 'selected'>;\n\ntype PropsT = {\n label?: ReactNode;\n onChange?: (value: ValueT) => void;\n options?: Readonly<OptionsT<ReactNode>>;\n theme?: ThemeT;\n value?: ValueT;\n};\n\nexport const Switch: FunctionComponent<PropsT> = ({\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const composed = useTheme('Switch', defaultTheme, theme);\n\n if (!options || !composed.option) throw Error('Internal error');\n\n const optionNodes: React.ReactNode[] = [];\n for (const option of options) {\n const [iValue, iName] = optionValueName(option);\n\n let className: string = composed.option;\n let onPress: (() => void) | undefined;\n if (iValue === value) className += ` ${composed.selected}`;\n else if (onChange) {\n onPress = () => {\n onChange(iValue);\n };\n }\n\n optionNodes.push(\n onPress\n ? (\n <div\n className={className}\n key={iValue}\n onClick={onPress}\n onKeyDown={(e) => {\n if (e.key === 'Enter') onPress();\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>\n )\n : <div className={className} key={iValue}>{iName}</div>,\n );\n }\n\n return (\n <div className={composed.container}>\n {label ? <div className={composed.label}>{label}</div> : null}\n\n <div className={composed.options}>\n {optionNodes}\n </div>\n </div>\n );\n};\n"],"mappings":"qFAEA,OAAqBA,QAAQ,KAAQ,0BAA0B,CAE/D,OAGEC,eAAe,iBAGjB,MAAO,CAAAC,YAAY,oBAAqB,OAAAC,GAAA,IAAAC,IAAA,CAAAC,IAAA,IAAAC,KAAA,yBAYxC,MAAO,MAAM,CAAAC,MAAiC,CAAGC,EAAA,SAAAC,CAAA,CAAAC,EAAA,KAAC,MAAAC,KAAA,CAAAC,QAAA,CAAAC,OAAA,CAAAC,KAAA,CAAAC,KAAA,EAAAP,EAMjD,CACC,MAAAQ,QAAA,CAAiBhB,QAAQ,CAAC,QAAQ,CAAEE,YAAY,CAAEY,KAAK,CAAC,CAExD,GAAI,CAACD,OAA2B,EAA5B,CAAaG,QAAQ,CAAAC,MAAO,EAAE,KAAM,CAAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,KAAAC,WAAA,IAAAV,CAAA,MAAAO,QAAA,CAAAC,MAAA,EAAAR,CAAA,MAAAO,QAAA,CAAAI,QAAA,EAAAX,CAAA,MAAAG,QAAA,EAAAH,CAAA,MAAAI,OAAA,EAAAJ,CAAA,MAAAM,KAAA,EAEhEI,WAAA,CAAuC,EAAE,CACzC,IAAK,MAAAF,MAAY,GAAI,CAAAJ,OAAO,EAC1B,MAAAQ,MAAA,CAAAC,KAAA,EAAwBrB,eAAe,CAACgB,MAAM,CAAC,CAE/C,IAAAM,SAAA,CAAwBP,QAAQ,CAAAC,MAAO,CACnCO,GAAA,CAAA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gBmB,SAAgB,CAAhBP,QAAQ,CAAAH,OAAQ,CAAAkB,QAAA,CAC7BZ,WAAW,CACT,CAAC,CAAAV,CAAA,IAAAO,QAAA,CAAAH,OAAAJ,CAAA,MAAAU,WAAAV,CAAA,MAAAwB,EAAA,MAAAA,EAAA,CAAAxB,CAAA,SAAAyB,EAAA,IAAAzB,CAAA,OAAAO,QAAA,CAAAmB,SAAA,EAAA1B,CAAA,OAAAuB,EAAA,EAAAvB,CAAA,OAAAwB,EAAA,EALRC,EAAA,cAAA5B,KAAA,QAAgBiB,SAAkB,CAAlBP,QAAQ,CAAAmB,SAAU,CAAAJ,QAAA,EAC/BC,EAA4D,CAE7DC,EAEM,EACH,CAAC,CAAAxB,CAAA,KAAAO,QAAA,CAAAmB,SAAA1B,CAAA,MAAAuB,EAAAvB,CAAA,MAAAwB,EAAAxB,CAAA,MAAAyB,EAAA,MAAAA,EAAA,CAAAzB,CAAA,WANN,CAAAyB,EAMM,CAET","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["onPress"],"sources":["../../../../../../src/shared/components/selectors/Switch/index.tsx"],"sourcesContent":["import type { FunctionComponent, ReactNode } from 'react';\n\nimport { type Theme, useTheme } from '@dr.pogodin/react-themes';\n\nimport {\n type OptionsT,\n type ValueT,\n optionValueName,\n} from '../common';\n\nimport defaultTheme from './theme.scss';\n\ntype ThemeT = Theme<'container' | 'label' | 'option' | 'options' | 'selected'>;\n\ntype PropsT = {\n label?: ReactNode;\n onChange?: (value: ValueT) => void;\n options?: Readonly<OptionsT<ReactNode>>;\n theme?: ThemeT;\n value?: ValueT;\n};\n\nexport const Switch: FunctionComponent<PropsT> = ({\n label,\n onChange,\n options,\n theme,\n value,\n}) => {\n const composed = useTheme('Switch', defaultTheme, theme);\n\n if (!options || !composed.option) throw Error('Internal error');\n\n const optionNodes: React.ReactNode[] = [];\n for (const option of options) {\n const [iValue, iName] = optionValueName(option);\n\n let className: string = composed.option;\n let onPress: (() => void) | undefined;\n if (iValue === value) className += ` ${composed.selected}`;\n else if (onChange) {\n onPress = () => {\n onChange(iValue);\n };\n }\n\n optionNodes.push(\n onPress\n ? (\n <div\n className={className}\n key={iValue}\n onClick={onPress}\n onKeyDown={(e) => {\n if (e.key === 'Enter') onPress();\n }}\n role=\"button\"\n tabIndex={0}\n >\n {iName}\n </div>\n )\n : <div className={className} key={iValue}>{iName}</div>,\n );\n }\n\n return (\n <div className={composed.container}>\n {label ? <div className={composed.label}>{label}</div> : null}\n\n <div className={composed.options}>\n {optionNodes}\n </div>\n </div>\n );\n};\n"],"mappings":"oHAEA,OAAqB,QAAQ,KAAQ,0BAA0B,CAAC,OAK9D,eAAe,oBAGjB,MAAO,aAAY,oBAAqB,yDAYxC,MAAO,MAAM,OAAiC,CAAG,oBAAC,4CAMjD,CACC,eAAiB,QAAQ,CAAC,QAAQ,CAAE,YAAY,CAAE,KAAK,CAAC,CAExD,GAAI,CAAC,OAA2B,EAA5B,CAAa,QAAQ,OAAO,EAAE,KAAM,MAAK,CAAC,gBAAgB,CAAC,CAAC,qHAEhE,YAAuC,EAAE,CACzC,IAAK,YAAY,GAAI,QAAO,EAC1B,oBAAwB,eAAe,CAAC,MAAM,CAAC,CAE/C,cAAwB,QAAQ,OAAO,CACnCA,GAAA,SACJ,GAAI,MAAM,GAAK,KAAK,EAAE,mBAAS,CAAI,IAAI,QAAQ,SAAS,EAAE,OACrD,GAAI,QAAQ,EACf,OAAAA,CAAUA,KACR,QAAQ,CAAC,MAAM,CAAC,CACjB,CAFM,CAGR,CAED,iCAAW,OAAX,WAAW,CACT,OAAO,cAAP,YAGiB,SAAS,CAAT,SAAS,CAEXA,OAAO,CAAP,OAAO,CACL,SAEV,CAFU,IACT,GAAI,CAAC,IAAI,GAAK,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAClC,CACI,IAAQ,CAAR,QAAQ,CACH,QAAC,CAAD,CAAC,UAEV,KAAK,EARD,MAW6C,CAAC,cAfzD,YAeoB,SAAS,CAAT,SAAS,UAAgB,KAAK,EAAd,MAAoB,CAC1D,CAAC,CACF,wKAII,QAAK,cAAL,YAAwB,SAAc,CAAd,QAAQ,MAAM,UAAG,KAAK,CAAa,CAAC,CAA5D,IAA4D,6GAE7D,4BAAgB,SAAgB,CAAhB,QAAQ,QAAQ,UAC7B,WAAW,CACT,CAAC,8HALR,6BAAgB,SAAkB,CAAlB,QAAQ,UAAU,WAC/B,EAA4D,CAE7D,EAEM,EACH,CAAC,yEANN,GAMM,CAET","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","names":["isValue","x","type","optionValueName","option","value","name"],"sources":["../../../../../src/shared/components/selectors/common.ts"],"sourcesContent":["// The stuff common between different dropdown implementations.\n\nimport type { ChangeEventHandler, MouseEventHandler, ReactNode } from 'react';\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\nexport type ThemeT = Theme<\n | 'active'\n | 'arrow'\n | 'container'\n | 'dropdown'\n | 'hiddenOption'\n | 'label'\n | 'option'\n | 'select'\n\n // TODO: This is currently only valid for (native) <Dropdown>,\n // other kinds of selectors should be evaluated, and aligned with this\n // feature, if appropriate.\n | 'invalid'\n\n // TODO: This is only valid for <CustomDropdown>, thus we need to re-factor it\n // into a separate theme spec for that component.\n | 'upward'\n>;\n\nexport type ValueT = number | string;\n\nexport type OptionT<NameT> = {\n name?: NameT | null;\n value: ValueT;\n};\n\nexport type OptionsT<NameT> = Readonly<Array<OptionT<NameT> | ValueT>>;\n\nexport type PropsT<\n NameT,\n OnChangeT = ChangeEventHandler<HTMLSelectElement>,\n> = {\n filter?: (item: OptionT<NameT> | ValueT) => boolean;\n label?: ReactNode;\n onChange?: OnChangeT;\n onClick?: MouseEventHandler;\n options: Readonly<OptionsT<NameT>>;\n testId?: string;\n theme?: ThemeT;\n value?: ValueT;\n};\n\nfunction isValue<T>(x: OptionT<T> | ValueT): x is ValueT {\n const type = typeof x;\n return type === 'number' || type === 'string';\n}\n\n/** Returns option value and name as a tuple. */\nexport function optionValueName<NameT>(\n option: OptionT<NameT> | ValueT,\n): [ValueT, NameT | ValueT] {\n return isValue(option)\n ? [option, option]\n : [option.value, option.name ?? option.value];\n}\n"],"mappings":"AAAA;AAiDA,QAAS,CAAAA,OAAOA,CAAIC,CAAsB,CAAe,CACvD,KAAM,CAAAC,IAAI,CAAG,MAAO,CAAAD,CAAC,CACrB,MAAO,CAAAC,IAAI,GAAK,QAAQ,EAAIA,IAAI,GAAK,QAAQ,CAC/C,CAEA,gDACA,MAAO,SAAS,CAAAC,eAAeA,CAC7BC,MAA+B,CACL,CAC1B,MAAO,CAAAJ,OAAO,CAACI,MAAM,CAAC,CAClB,CAACA,MAAM,CAAEA,MAAM,CAAC,CAChB,CAACA,MAAM,CAACC,KAAK,CAAED,MAAM,CAACE,IAAI,EAAIF,MAAM,CAACC,KAAK,CAAC,CACjD","ignoreList":[]}
1
+ {"version":3,"file":"common.js","names":[],"sources":["../../../../../src/shared/components/selectors/common.ts"],"sourcesContent":["// The stuff common between different dropdown implementations.\n\nimport type { ChangeEventHandler, MouseEventHandler, ReactNode } from 'react';\n\nimport type { Theme } from '@dr.pogodin/react-themes';\n\nexport type ThemeT = Theme<\n | 'active'\n | 'arrow'\n | 'container'\n | 'dropdown'\n | 'hiddenOption'\n | 'label'\n | 'option'\n | 'select'\n\n // TODO: This is currently only valid for (native) <Dropdown>,\n // other kinds of selectors should be evaluated, and aligned with this\n // feature, if appropriate.\n | 'invalid'\n\n // TODO: This is only valid for <CustomDropdown>, thus we need to re-factor it\n // into a separate theme spec for that component.\n | 'upward'\n>;\n\nexport type ValueT = number | string;\n\nexport type OptionT<NameT> = {\n name?: NameT | null;\n value: ValueT;\n};\n\nexport type OptionsT<NameT> = Readonly<Array<OptionT<NameT> | ValueT>>;\n\nexport type PropsT<\n NameT,\n OnChangeT = ChangeEventHandler<HTMLSelectElement>,\n> = {\n filter?: (item: OptionT<NameT> | ValueT) => boolean;\n label?: ReactNode;\n onChange?: OnChangeT;\n onClick?: MouseEventHandler;\n options: Readonly<OptionsT<NameT>>;\n testId?: string;\n theme?: ThemeT;\n value?: ValueT;\n};\n\nfunction isValue<T>(x: OptionT<T> | ValueT): x is ValueT {\n const type = typeof x;\n return type === 'number' || type === 'string';\n}\n\n/** Returns option value and name as a tuple. */\nexport function optionValueName<NameT>(\n option: OptionT<NameT> | ValueT,\n): [ValueT, NameT | ValueT] {\n return isValue(option)\n ? [option, option]\n : [option.value, option.name ?? option.value];\n}\n"],"mappings":"AAAA;AAiDA,QAAS,QAAO,CAAI,CAAsB,CAAe,CACvD,KAAM,KAAI,CAAG,MAAO,EAAC,CACrB,MAAO,KAAI,GAAK,QAAQ,EAAI,IAAI,GAAK,QAAQ,CAC/C,CAEA,gDACA,MAAO,SAAS,gBAAe,CAC7B,MAA+B,CACL,CAC1B,MAAO,QAAO,CAAC,MAAM,CAAC,CAClB,CAAC,MAAM,CAAE,MAAM,CAAC,CAChB,CAAC,MAAM,CAAC,KAAK,CAAE,MAAM,CAAC,IAAI,EAAI,MAAM,CAAC,KAAK,CAAC,CACjD","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- export{default as CustomDropdown}from"./CustomDropdown";export{default as Dropdown}from"./NativeDropdown";export{Switch}from"./Switch";
1
+ export{default as CustomDropdown}from"./CustomDropdown/index.js";export{default as Dropdown}from"./NativeDropdown/index.js";export{Switch}from"./Switch/index.js";
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["default","CustomDropdown","Dropdown","Switch"],"sources":["../../../../../src/shared/components/selectors/index.ts"],"sourcesContent":["export { default as CustomDropdown } from './CustomDropdown';\nexport { default as Dropdown } from './NativeDropdown';\nexport { Switch } from './Switch';\n\nexport type { OptionT, OptionsT } from './common';\n"],"mappings":"AAAA,OAASA,OAAO,GAAI,CAAAC,cAAc,wBAClC,OAASD,OAAO,GAAI,CAAAE,QAAQ,wBAC5B,OAASC,MAAM","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/components/selectors/index.ts"],"sourcesContent":["export { default as CustomDropdown } from './CustomDropdown';\nexport { default as Dropdown } from './NativeDropdown';\nexport { Switch } from './Switch';\n\nexport type { OptionT, OptionsT } from './common';\n"],"mappings":"OAAS,OAAO,GAAI,eAAc,wCACzB,OAAO,GAAI,SAAQ,wCACnB,MAAM","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- /* global document */import{parseCookie}from"cookie";import clientGetInj from"../../client/getInj";import{IS_CLIENT_SIDE}from"./isomorphy/environment-check";import{requireWeak}from"./webpack";let config;/**
1
+ /* global document */import{parseCookie}from"cookie";import clientGetInj from"../../client/getInj.js";import{IS_CLIENT_SIDE}from"./isomorphy/environment-check.js";import{requireWeak}from"./webpack.js";let config;/**
2
2
  * Injects CSRF token into config (on client-side only).
3
3
  *
4
4
  * BEWARE: It mutates the argument, and also returns it as the result,
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","names":["parseCookie","clientGetInj","IS_CLIENT_SIDE","requireWeak","config","injectCsrfToken","cfg","document","CSRF","cookie","csrfToken","getConfig","sync","inj","Promise","then","injection","res","CONFIG","weak","Error"],"sources":["../../../../src/shared/utils/config.ts"],"sourcesContent":["/* global document */\n\nimport { parseCookie } from 'cookie';\n\nimport clientGetInj from '../../client/getInj';\n\nimport { IS_CLIENT_SIDE } from './isomorphy/environment-check';\nimport { requireWeak } from './webpack';\n\ntype ConfigT = Record<string, unknown>;\n\nlet config: ConfigT | Promise<ConfigT> | undefined;\n\n/**\n * Injects CSRF token into config (on client-side only).\n *\n * BEWARE: It mutates the argument, and also returns it as the result,\n * for chaining.\n */\nfunction injectCsrfToken(cfg: ConfigT): ConfigT {\n // The safeguard for \"document\" is necessary because in non-Node environments,\n // like React Native, IS_CLIENT_SIDE is \"true\", however \"document\" and a bunch\n // of other browser-world features are not available.\n if (IS_CLIENT_SIDE && typeof document !== 'undefined') {\n // eslint-disable-next-line no-param-reassign\n cfg.CSRF = parseCookie(document.cookie).csrfToken;\n }\n\n return cfg;\n}\n\nexport function getConfig<T extends ConfigT>(sync: true): T;\n\nexport function getConfig<T extends ConfigT>(sync?: boolean): Promise<T> | T;\n\nexport function getConfig<T extends ConfigT>(sync?: boolean): Promise<T> | T {\n if (!config) {\n if (IS_CLIENT_SIDE) {\n const inj = clientGetInj();\n config = inj instanceof Promise\n ? inj.then((injection) => {\n const res = injectCsrfToken(injection.CONFIG ?? {});\n config = res;\n return res;\n })\n : injectCsrfToken(inj.CONFIG ?? {});\n } else {\n const weak = requireWeak<ConfigT>('config');\n if (!weak) throw Error('Internal error');\n config = weak;\n }\n }\n\n if (sync && (config instanceof Promise)) {\n throw Error('The config is not available yet');\n }\n\n return config as T;\n}\n"],"mappings":"AAAA,qBAEA,OAASA,WAAW,KAAQ,QAAQ,CAEpC,MAAO,CAAAC,YAAY,2BAEnB,OAASC,cAAc,qCACvB,OAASC,WAAW,iBAIpB,GAAI,CAAAC,MAA8C,CAElD;AACA;AACA;AACA;AACA;AACA,GACA,QAAS,CAAAC,eAAeA,CAACC,GAAY,CAAW,CAC9C;AACA;AACA;AACA,GAAIJ,cAAc,EAAI,MAAO,CAAAK,QAAQ,GAAK,WAAW,CAAE,CACrD;AACAD,GAAG,CAACE,IAAI,CAAGR,WAAW,CAACO,QAAQ,CAACE,MAAM,CAAC,CAACC,SAAS,CACnD,CAEA,MAAO,CAAAJ,GAAG,CACZ,CAMA,MAAO,SAAS,CAAAK,SAASA,CAAoBC,IAAc,CAAkB,CAC3E,GAAI,CAACR,MAAM,CAAE,CACX,GAAIF,cAAc,CAAE,CAClB,KAAM,CAAAW,GAAG,CAAGZ,YAAY,CAAC,CAAC,CAC1BG,MAAM,CAAGS,GAAG,WAAY,CAAAC,OAAO,CAC3BD,GAAG,CAACE,IAAI,CAAEC,SAAS,EAAK,CACxB,KAAM,CAAAC,GAAG,CAAGZ,eAAe,CAACW,SAAS,CAACE,MAAM,EAAI,CAAC,CAAC,CAAC,CACnDd,MAAM,CAAGa,GAAG,CACZ,MAAO,CAAAA,GAAG,CACZ,CAAC,CAAC,CACAZ,eAAe,CAACQ,GAAG,CAACK,MAAM,EAAI,CAAC,CAAC,CAAC,CACvC,CAAC,IAAM,CACL,KAAM,CAAAC,IAAI,CAAGhB,WAAW,CAAU,QAAQ,CAAC,CAC3C,GAAI,CAACgB,IAAI,CAAE,KAAM,CAAAC,KAAK,CAAC,gBAAgB,CAAC,CACxChB,MAAM,CAAGe,IAAI,CACf,CACF,CAEA,GAAIP,IAAI,EAAKR,MAAM,WAAY,CAAAU,OAAQ,CAAE,CACvC,KAAM,CAAAM,KAAK,CAAC,iCAAiC,CAAC,CAChD,CAEA,MAAO,CAAAhB,MAAM,CACf","ignoreList":[]}
1
+ {"version":3,"file":"config.js","names":[],"sources":["../../../../src/shared/utils/config.ts"],"sourcesContent":["/* global document */\n\nimport { parseCookie } from 'cookie';\n\nimport clientGetInj from '../../client/getInj';\n\nimport { IS_CLIENT_SIDE } from './isomorphy/environment-check';\nimport { requireWeak } from './webpack';\n\ntype ConfigT = Record<string, unknown>;\n\nlet config: ConfigT | Promise<ConfigT> | undefined;\n\n/**\n * Injects CSRF token into config (on client-side only).\n *\n * BEWARE: It mutates the argument, and also returns it as the result,\n * for chaining.\n */\nfunction injectCsrfToken(cfg: ConfigT): ConfigT {\n // The safeguard for \"document\" is necessary because in non-Node environments,\n // like React Native, IS_CLIENT_SIDE is \"true\", however \"document\" and a bunch\n // of other browser-world features are not available.\n if (IS_CLIENT_SIDE && typeof document !== 'undefined') {\n // eslint-disable-next-line no-param-reassign\n cfg.CSRF = parseCookie(document.cookie).csrfToken;\n }\n\n return cfg;\n}\n\nexport function getConfig<T extends ConfigT>(sync: true): T;\n\nexport function getConfig<T extends ConfigT>(sync?: boolean): Promise<T> | T;\n\nexport function getConfig<T extends ConfigT>(sync?: boolean): Promise<T> | T {\n if (!config) {\n if (IS_CLIENT_SIDE) {\n const inj = clientGetInj();\n config = inj instanceof Promise\n ? inj.then((injection) => {\n const res = injectCsrfToken(injection.CONFIG ?? {});\n config = res;\n return res;\n })\n : injectCsrfToken(inj.CONFIG ?? {});\n } else {\n const weak = requireWeak<ConfigT>('config');\n if (!weak) throw Error('Internal error');\n config = weak;\n }\n }\n\n if (sync && (config instanceof Promise)) {\n throw Error('The config is not available yet');\n }\n\n return config as T;\n}\n"],"mappings":"AAAA,qBAEA,OAAS,WAAW,KAAQ,QAAQ,CAAC,MAE9B,aAAY,qCAEV,cAAc,+CACd,WAAW,oBAIpB,GAAI,OAA8C,CAElD;AACA;AACA;AACA;AACA;AACA,GACA,QAAS,gBAAe,CAAC,GAAY,CAAW,CAC9C;AACA;AACA;AACA,GAAI,cAAc,EAAI,MAAO,SAAQ,GAAK,WAAW,CAAE,CACrD;AACA,GAAG,CAAC,IAAI,CAAG,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,SAAS,CACnD,CAEA,MAAO,IAAG,CACZ,CAMA,MAAO,SAAS,UAAS,CAAoB,IAAc,CAAkB,CAC3E,GAAI,CAAC,MAAM,CAAE,CACX,GAAI,cAAc,CAAE,CAClB,KAAM,IAAG,CAAG,YAAY,CAAC,CAAC,CAC1B,MAAM,CAAG,GAAG,WAAY,QAAO,CAC3B,GAAG,CAAC,IAAI,CAAE,SAAS,EAAK,CACxB,KAAM,IAAG,CAAG,eAAe,CAAC,SAAS,CAAC,MAAM,EAAI,CAAC,CAAC,CAAC,CACnD,MAAM,CAAG,GAAG,CACZ,MAAO,IAAG,CACZ,CAAC,CAAC,CACA,eAAe,CAAC,GAAG,CAAC,MAAM,EAAI,CAAC,CAAC,CAAC,CACvC,CAAC,IAAM,CACL,KAAM,KAAI,CAAG,WAAW,CAAU,QAAQ,CAAC,CAC3C,GAAI,CAAC,IAAI,CAAE,KAAM,MAAK,CAAC,gBAAgB,CAAC,CACxC,MAAM,CAAG,IAAI,CACf,CACF,CAEA,GAAI,IAAI,EAAK,MAAM,WAAY,QAAQ,CAAE,CACvC,KAAM,MAAK,CAAC,iCAAiC,CAAC,CAChD,CAEA,MAAO,OAAM,CACf","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"globalState.js","names":["withGlobalStateType","useSsrContext"],"sources":["../../../../src/shared/utils/globalState.ts"],"sourcesContent":["import type { Request } from 'express';\n\nimport { type SsrContext, withGlobalStateType } from '@dr.pogodin/react-global-state';\n\n/** Mapping \"chunkName\" > array of asset paths. */\nexport type ChunkGroupsT = Record<string, string[]>;\n\n// The type of data object injected by server into generated markup.\nexport type InjT = {\n CHUNK_GROUPS?: ChunkGroupsT;\n CONFIG?: Record<string, unknown>;\n ISTATE?: unknown;\n};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n REACT_UTILS_INJECTION?: InjT;\n }\n}\n\n// TODO: Not 100% sure now, whether it indeed can be replaced by type,\n// or do we really need it to be an interface. Keeping the interface for now.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface SsrContextT<StateT> extends SsrContext<StateT> {\n chunkGroups: ChunkGroupsT;\n chunks: string[];\n\n /** If set at the end of SSR, the rendered will trigger\n * server-side redirect to this URL (and use the status\n * code). */\n redirectTo?: string;\n\n req: Request;\n status: number;\n}\n\nconst {\n useSsrContext,\n} = withGlobalStateType<unknown, SsrContextT<unknown>>();\n\nexport {\n useSsrContext,\n};\n"],"mappings":"AAEA,OAA0BA,mBAAmB,KAAQ,gCAAgC,CAErF,kDAGA;AAcA;AACA;AACA;AAcA,KAAM,CACJC,aACF,CAAC,CAAGD,mBAAmB,CAAgC,CAAC,CAExD,OACEC,aAAa","ignoreList":[]}
1
+ {"version":3,"file":"globalState.js","names":[],"sources":["../../../../src/shared/utils/globalState.ts"],"sourcesContent":["import type { Request } from 'express';\n\nimport { type SsrContext, withGlobalStateType } from '@dr.pogodin/react-global-state';\n\n/** Mapping \"chunkName\" > array of asset paths. */\nexport type ChunkGroupsT = Record<string, string[]>;\n\n// The type of data object injected by server into generated markup.\nexport type InjT = {\n CHUNK_GROUPS?: ChunkGroupsT;\n CONFIG?: Record<string, unknown>;\n ISTATE?: unknown;\n};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n REACT_UTILS_INJECTION?: InjT;\n }\n}\n\n// TODO: Not 100% sure now, whether it indeed can be replaced by type,\n// or do we really need it to be an interface. Keeping the interface for now.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface SsrContextT<StateT> extends SsrContext<StateT> {\n chunkGroups: ChunkGroupsT;\n chunks: string[];\n\n /** If set at the end of SSR, the rendered will trigger\n * server-side redirect to this URL (and use the status\n * code). */\n redirectTo?: string;\n\n req: Request;\n status: number;\n}\n\nconst {\n useSsrContext,\n} = withGlobalStateType<unknown, SsrContextT<unknown>>();\n\nexport {\n useSsrContext,\n};\n"],"mappings":"AAEA,OAA0B,mBAAmB,KAAQ,gCAAgC,CAErF,kDAGA;AAcA;AACA;AACA;AAcA,KAAM,CACJ,aACF,CAAC,CAAG,mBAAmB,CAAgC,CAAC,CAExD,OACE,aAAa","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- import{getConfig}from"./config";import time from"./time";import*as webpack from"./webpack";export*from"./isomorphy";export{Barrier,Cached,Emitter,Semaphore,assertEmptyObject,withRetries}from"@dr.pogodin/js-utils";export{COMPOSE as THEME_COMPOSE,PRIORITY as THEME_PRIORITY,ThemeProvider,useTheme}from"@dr.pogodin/react-themes";export{useSsrContext}from"./globalState";export{setClientChunkGroups,default as splitComponent}from"./splitComponent";export{getConfig,time,webpack};
1
+ import{getConfig}from"./config.js";import time from"./time.js";import*as webpack from"./webpack.js";export*from"./isomorphy/index.js";export{Barrier,Cached,Emitter,Semaphore,assertEmptyObject,withRetries}from"@dr.pogodin/js-utils";export{COMPOSE as THEME_COMPOSE,PRIORITY as THEME_PRIORITY,ThemeProvider,useTheme}from"@dr.pogodin/react-themes";export{useSsrContext}from"./globalState.js";export{setClientChunkGroups,default as splitComponent}from"./splitComponent.js";export{getConfig,time,webpack};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["getConfig","time","webpack","Barrier","Cached","Emitter","Semaphore","assertEmptyObject","withRetries","COMPOSE","THEME_COMPOSE","PRIORITY","THEME_PRIORITY","ThemeProvider","useTheme","useSsrContext","setClientChunkGroups","default","splitComponent"],"sources":["../../../../src/shared/utils/index.ts"],"sourcesContent":["import { getConfig } from './config';\nimport time from './time';\nimport * as webpack from './webpack';\n\nexport * from './isomorphy';\n\nexport {\n Barrier,\n Cached,\n Emitter,\n type Listener,\n type ObjectKey,\n Semaphore,\n assertEmptyObject,\n withRetries,\n} from '@dr.pogodin/js-utils';\n\nexport {\n COMPOSE as THEME_COMPOSE,\n PRIORITY as THEME_PRIORITY,\n type Theme,\n ThemeProvider,\n useTheme,\n} from '@dr.pogodin/react-themes';\n\nexport { useSsrContext } from './globalState';\n\nexport {\n setClientChunkGroups,\n default as splitComponent,\n} from './splitComponent';\n\nexport { getConfig, time, webpack };\n"],"mappings":"AAAA,OAASA,SAAS,gBAClB,MAAO,CAAAC,IAAI,cACX,MAAO,GAAK,CAAAC,OAAO,iBAEnB,yBAEA,OACEC,OAAO,CACPC,MAAM,CACNC,OAAO,CAGPC,SAAS,CACTC,iBAAiB,CACjBC,WAAW,KACN,sBAAsB,CAE7B,OACEC,OAAO,GAAI,CAAAC,aAAa,CACxBC,QAAQ,GAAI,CAAAC,cAAc,CAE1BC,aAAa,CACbC,QAAQ,KACH,0BAA0B,CAEjC,OAASC,aAAa,qBAEtB,OACEC,oBAAoB,CACpBC,OAAO,GAAI,CAAAC,cAAc,wBAG3B,OAASlB,SAAS,CAAEC,IAAI,CAAEC,OAAO","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/shared/utils/index.ts"],"sourcesContent":["import { getConfig } from './config';\nimport time from './time';\nimport * as webpack from './webpack';\n\nexport * from './isomorphy';\n\nexport {\n Barrier,\n Cached,\n Emitter,\n type Listener,\n type ObjectKey,\n Semaphore,\n assertEmptyObject,\n withRetries,\n} from '@dr.pogodin/js-utils';\n\nexport {\n COMPOSE as THEME_COMPOSE,\n PRIORITY as THEME_PRIORITY,\n type Theme,\n ThemeProvider,\n useTheme,\n} from '@dr.pogodin/react-themes';\n\nexport { useSsrContext } from './globalState';\n\nexport {\n setClientChunkGroups,\n default as splitComponent,\n} from './splitComponent';\n\nexport { getConfig, time, webpack };\n"],"mappings":"OAAS,SAAS,yBACX,KAAI,uBACJ,GAAK,QAAO,sDAInB,OACE,OAAO,CACP,MAAM,CACN,OAAO,CAGP,SAAS,CACT,iBAAiB,CACjB,WAAW,KACN,sBAAsB,CAE7B,OACE,OAAO,GAAI,cAAa,CACxB,QAAQ,GAAI,eAAc,CAE1B,aAAa,CACb,QAAQ,KACH,0BAA0B,CAAC,OAEzB,aAAa,+BAGpB,oBAAoB,CACpB,OAAO,GAAI,eAAc,2BAG3B,OAAS,SAAS,CAAE,IAAI,CAAE,OAAO","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"buildInfo.js","names":["buildInfo","BUILD_INFO","setBuildInfo","info","force","undefined","Error","getBuildInfo"],"sources":["../../../../../src/shared/utils/isomorphy/buildInfo.ts"],"sourcesContent":["// Encapsulates access to \"Build Info\" data.\n\n// BEWARE: This should match the type of build info object generated by\n// Webpack build (see \"/config/webpack/app-base.js\"), and currently this\n// match is not checked automatically.\nexport type BuildInfoT = {\n key: string;\n publicPath: string;\n timestamp: string;\n useServiceWorker: boolean;\n};\n\n// Depending on the build mode & environment, BUILD_INFO is either a global\n// variable defined at the app launch, or it is replaced by the actual value\n// by the Webpack build.\ndeclare const BUILD_INFO: BuildInfoT | undefined;\n\nlet buildInfo: BuildInfoT | undefined;\n\n// On the client side \"BUILD_INFO\" should be injected by Webpack. Note, however,\n// that in test environment we may need situations were environment is mocked as\n// client-side, although no proper Webpack compilation is executed, thus no info\n// injected; because of this we don't do a hard environment check here.\nif (typeof BUILD_INFO !== 'undefined') buildInfo = BUILD_INFO;\n\n/**\n * In scenarious where \"BUILD_INFO\" is not injected by Webpack (server-side,\n * tests, etc.) we expect the host codebase to explicitly set it before it is\n * ever requested. As a precaution, this function throws if build info has been\n * set already, unless `force` flag is explicitly set.\n * @param info\n * @param force\n */\nexport function setBuildInfo(info?: BuildInfoT, force = false): void {\n if (buildInfo !== undefined && !force) {\n throw Error('\"Build Info\" is already initialized');\n }\n buildInfo = info;\n}\n\n/**\n * Returns \"Build Info\" object; throws if it has not been initialized yet.\n * @returns\n */\nexport function getBuildInfo(): BuildInfoT {\n if (buildInfo === undefined) {\n throw Error('\"Build Info\" has not been initialized yet');\n }\n return buildInfo;\n}\n"],"mappings":"AAAA;AAEA;AACA;AACA;AAQA;AACA;AACA;AAGA,GAAI,CAAAA,SAAiC,CAErC;AACA;AACA;AACA;AACA,GAAI,MAAO,CAAAC,UAAU,GAAK,WAAW,CAAED,SAAS,CAAGC,UAAU,CAE7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,SAAS,CAAAC,YAAYA,CAACC,IAAiB,CAAEC,KAAK,CAAG,KAAK,CAAQ,CACnE,GAAIJ,SAAS,GAAKK,SAAS,EAAI,CAACD,KAAK,CAAE,CACrC,KAAM,CAAAE,KAAK,CAAC,uCAAqC,CAAC,CACpD,CACAN,SAAS,CAAGG,IAAI,CAClB,CAEA;AACA;AACA;AACA,GACA,MAAO,SAAS,CAAAI,YAAYA,CAAA,CAAe,CACzC,GAAIP,SAAS,GAAKK,SAAS,CAAE,CAC3B,KAAM,CAAAC,KAAK,CAAC,6CAA2C,CAAC,CAC1D,CACA,MAAO,CAAAN,SAAS,CAClB","ignoreList":[]}
1
+ {"version":3,"file":"buildInfo.js","names":[],"sources":["../../../../../src/shared/utils/isomorphy/buildInfo.ts"],"sourcesContent":["// Encapsulates access to \"Build Info\" data.\n\n// BEWARE: This should match the type of build info object generated by\n// Webpack build (see \"/config/webpack/app-base.js\"), and currently this\n// match is not checked automatically.\nexport type BuildInfoT = {\n key: string;\n publicPath: string;\n timestamp: string;\n useServiceWorker: boolean;\n};\n\n// Depending on the build mode & environment, BUILD_INFO is either a global\n// variable defined at the app launch, or it is replaced by the actual value\n// by the Webpack build.\ndeclare const BUILD_INFO: BuildInfoT | undefined;\n\nlet buildInfo: BuildInfoT | undefined;\n\n// On the client side \"BUILD_INFO\" should be injected by Webpack. Note, however,\n// that in test environment we may need situations were environment is mocked as\n// client-side, although no proper Webpack compilation is executed, thus no info\n// injected; because of this we don't do a hard environment check here.\nif (typeof BUILD_INFO !== 'undefined') buildInfo = BUILD_INFO;\n\n/**\n * In scenarious where \"BUILD_INFO\" is not injected by Webpack (server-side,\n * tests, etc.) we expect the host codebase to explicitly set it before it is\n * ever requested. As a precaution, this function throws if build info has been\n * set already, unless `force` flag is explicitly set.\n * @param info\n * @param force\n */\nexport function setBuildInfo(info?: BuildInfoT, force = false): void {\n if (buildInfo !== undefined && !force) {\n throw Error('\"Build Info\" is already initialized');\n }\n buildInfo = info;\n}\n\n/**\n * Returns \"Build Info\" object; throws if it has not been initialized yet.\n * @returns\n */\nexport function getBuildInfo(): BuildInfoT {\n if (buildInfo === undefined) {\n throw Error('\"Build Info\" has not been initialized yet');\n }\n return buildInfo;\n}\n"],"mappings":"AAAA;AAEA;AACA;AACA;AAQA;AACA;AACA;AAGA,GAAI,UAAiC,CAErC;AACA;AACA;AACA;AACA,GAAI,MAAO,WAAU,GAAK,WAAW,CAAE,SAAS,CAAG,UAAU,CAE7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,SAAS,aAAY,CAAC,IAAiB,CAAE,KAAK,CAAG,KAAK,CAAQ,CACnE,GAAI,SAAS,GAAK,SAAS,EAAI,CAAC,KAAK,CAAE,CACrC,KAAM,MAAK,CAAC,uCAAqC,CAAC,CACpD,CACA,SAAS,CAAG,IAAI,CAClB,CAEA;AACA;AACA;AACA,GACA,MAAO,SAAS,aAAY,EAAe,CACzC,GAAI,SAAS,GAAK,SAAS,CAAE,CAC3B,KAAM,MAAK,CAAC,6CAA2C,CAAC,CAC1D,CACA,MAAO,UAAS,CAClB","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"environment-check.js","names":["IS_CLIENT_SIDE","process","versions","node","global","REACT_UTILS_FORCE_CLIENT_SIDE","REACT_UTILS_WEBPACK_BUNDLE","IS_SERVER_SIDE","assertClientSide","Error","assertServerSide"],"sources":["../../../../../src/shared/utils/isomorphy/environment-check.ts"],"sourcesContent":["// Checks for client- vs. server-side environment detection.\n\n/**\n * `true` within client-side environment (browser), `false` at server-side.\n */\nexport const IS_CLIENT_SIDE: boolean = typeof process !== 'object'\n // NOTE: Because in this case we assume the host environment might be partially\n // polyfilled to emulate some Node interfaces, thus it might have global `process`\n // object, but without `versions` sub-object inside it.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n || !process.versions?.node\n || !!global.REACT_UTILS_FORCE_CLIENT_SIDE\n || typeof REACT_UTILS_WEBPACK_BUNDLE !== 'undefined';\n\n/**\n * `true` within the server-side environment (node), `false` at client-side.\n */\nexport const IS_SERVER_SIDE: boolean = !IS_CLIENT_SIDE;\n\n/** Throws an error if executed not on the client side. */\nexport function assertClientSide(): void {\n if (!IS_CLIENT_SIDE) throw Error('Client-side only.');\n}\n\n/** Throws an error if executed not on the server side. */\nexport function assertServerSide(): void {\n if (!IS_SERVER_SIDE) throw Error('Server-side only');\n}\n"],"mappings":"AAAA;AAEA;AACA;AACA,GACA,MAAO,MAAM,CAAAA,cAAuB,CAAG,MAAO,CAAAC,OAAO,GAAK,QACxD;AACA;AACA;AACA;AAAA,EACG,CAACA,OAAO,CAACC,QAAQ,EAAEC,IAAI,EACvB,CAAC,CAACC,MAAM,CAACC,6BAA6B,EACtC,MAAO,CAAAC,0BAA0B,GAAK,WAAW,CAEtD;AACA;AACA,GACA,MAAO,MAAM,CAAAC,cAAuB,CAAG,CAACP,cAAc,CAEtD,0DACA,MAAO,SAAS,CAAAQ,gBAAgBA,CAAA,CAAS,CACvC,GAAI,CAACR,cAAc,CAAE,KAAM,CAAAS,KAAK,CAAC,mBAAmB,CAAC,CACvD,CAEA,0DACA,MAAO,SAAS,CAAAC,gBAAgBA,CAAA,CAAS,CACvC,GAAI,CAACH,cAAc,CAAE,KAAM,CAAAE,KAAK,CAAC,kBAAkB,CAAC,CACtD","ignoreList":[]}
1
+ {"version":3,"file":"environment-check.js","names":[],"sources":["../../../../../src/shared/utils/isomorphy/environment-check.ts"],"sourcesContent":["// Checks for client- vs. server-side environment detection.\n\n/**\n * `true` within client-side environment (browser), `false` at server-side.\n */\nexport const IS_CLIENT_SIDE: boolean = typeof process !== 'object'\n // NOTE: Because in this case we assume the host environment might be partially\n // polyfilled to emulate some Node interfaces, thus it might have global `process`\n // object, but without `versions` sub-object inside it.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n || !process.versions?.node\n || !!global.REACT_UTILS_FORCE_CLIENT_SIDE\n || typeof REACT_UTILS_WEBPACK_BUNDLE !== 'undefined';\n\n/**\n * `true` within the server-side environment (node), `false` at client-side.\n */\nexport const IS_SERVER_SIDE: boolean = !IS_CLIENT_SIDE;\n\n/** Throws an error if executed not on the client side. */\nexport function assertClientSide(): void {\n if (!IS_CLIENT_SIDE) throw Error('Client-side only.');\n}\n\n/** Throws an error if executed not on the server side. */\nexport function assertServerSide(): void {\n if (!IS_SERVER_SIDE) throw Error('Server-side only');\n}\n"],"mappings":"AAAA;AAEA;AACA;AACA,GACA,MAAO,MAAM,eAAuB,CAAG,MAAO,QAAO,GAAK,QACxD;AACA;AACA;AACA;AAAA,EACG,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,EACvB,CAAC,CAAC,MAAM,CAAC,6BAA6B,EACtC,MAAO,2BAA0B,GAAK,WAAW,CAEtD;AACA;AACA,GACA,MAAO,MAAM,eAAuB,CAAG,CAAC,cAAc,CAEtD,0DACA,MAAO,SAAS,iBAAgB,EAAS,CACvC,GAAI,CAAC,cAAc,CAAE,KAAM,MAAK,CAAC,mBAAmB,CAAC,CACvD,CAEA,0DACA,MAAO,SAAS,iBAAgB,EAAS,CACvC,GAAI,CAAC,cAAc,CAAE,KAAM,MAAK,CAAC,kBAAkB,CAAC,CACtD","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import{getBuildInfo}from"./buildInfo";export*from"./environment-check";/**
1
+ import{getBuildInfo}from"./buildInfo.js";export*from"./environment-check.js";/**
2
2
  * @ignore
3
3
  * @return {string} Code mode: "development" or "production".
4
4
  */function getMode(){return process.env.NODE_ENV;}/**
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["getBuildInfo","getMode","process","env","NODE_ENV","isDevBuild","isProdBuild","buildTimestamp","timestamp"],"sources":["../../../../../src/shared/utils/isomorphy/index.ts"],"sourcesContent":["import { getBuildInfo } from './buildInfo';\n\nexport * from './environment-check';\n\n/**\n * @ignore\n * @return {string} Code mode: \"development\" or \"production\".\n */\nfunction getMode() {\n return process.env.NODE_ENV;\n}\n\n/**\n * Returns `true` if development version of the code is running;\n * `false` otherwise.\n */\nexport function isDevBuild(): boolean {\n return getMode() === 'development';\n}\n\n/**\n * Returns `true` if production build of the code is running;\n * `false` otherwise.\n */\nexport function isProdBuild(): boolean {\n return getMode() === 'production';\n}\n\n/**\n * Returns build timestamp of the front-end JS bundle.\n * @return ISO date/time string.\n */\nexport function buildTimestamp(): string {\n return getBuildInfo().timestamp;\n}\n\nexport { getBuildInfo };\n"],"mappings":"AAAA,OAASA,YAAY,mBAErB,iCAEA;AACA;AACA;AACA,GACA,QAAS,CAAAC,OAAOA,CAAA,CAAG,CACjB,MAAO,CAAAC,OAAO,CAACC,GAAG,CAACC,QAAQ,CAC7B,CAEA;AACA;AACA;AACA,GACA,MAAO,SAAS,CAAAC,UAAUA,CAAA,CAAY,CACpC,MAAO,CAAAJ,OAAO,CAAC,CAAC,GAAK,aAAa,CACpC,CAEA;AACA;AACA;AACA,GACA,MAAO,SAAS,CAAAK,WAAWA,CAAA,CAAY,CACrC,MAAO,CAAAL,OAAO,CAAC,CAAC,GAAK,YAAY,CACnC,CAEA;AACA;AACA;AACA,GACA,MAAO,SAAS,CAAAM,cAAcA,CAAA,CAAW,CACvC,MAAO,CAAAP,YAAY,CAAC,CAAC,CAACQ,SAAS,CACjC,CAEA,OAASR,YAAY","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/utils/isomorphy/index.ts"],"sourcesContent":["import { getBuildInfo } from './buildInfo';\n\nexport * from './environment-check';\n\n/**\n * @ignore\n * @return {string} Code mode: \"development\" or \"production\".\n */\nfunction getMode() {\n return process.env.NODE_ENV;\n}\n\n/**\n * Returns `true` if development version of the code is running;\n * `false` otherwise.\n */\nexport function isDevBuild(): boolean {\n return getMode() === 'development';\n}\n\n/**\n * Returns `true` if production build of the code is running;\n * `false` otherwise.\n */\nexport function isProdBuild(): boolean {\n return getMode() === 'production';\n}\n\n/**\n * Returns build timestamp of the front-end JS bundle.\n * @return ISO date/time string.\n */\nexport function buildTimestamp(): string {\n return getBuildInfo().timestamp;\n}\n\nexport { getBuildInfo };\n"],"mappings":"OAAS,YAAY,0DAIrB;AACA;AACA;AACA,GACA,QAAS,QAAO,EAAG,CACjB,MAAO,QAAO,CAAC,GAAG,CAAC,QAAQ,CAC7B,CAEA;AACA;AACA;AACA,GACA,MAAO,SAAS,WAAU,EAAY,CACpC,MAAO,QAAO,CAAC,CAAC,GAAK,aAAa,CACpC,CAEA;AACA;AACA;AACA,GACA,MAAO,SAAS,YAAW,EAAY,CACrC,MAAO,QAAO,CAAC,CAAC,GAAK,YAAY,CACnC,CAEA;AACA;AACA;AACA,GACA,MAAO,SAAS,eAAc,EAAW,CACvC,MAAO,aAAY,CAAC,CAAC,CAAC,SAAS,CACjC,CAEA,OAAS,YAAY","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import"core-js/modules/es.iterator.constructor.js";import"core-js/modules/es.iterator.for-each.js";import"core-js/modules/es.json.parse.js";/**
1
+ import _JSON$parse from"core-js-pure/stable/json/parse.js";/**
2
2
  * Jest environment for end-to-end SSR and client-side testing. It relies on
3
3
  * the standard react-utils mechanics to execute SSR of given scene, and also
4
4
  * Webpack build of the code for client-side execution, it further exposes
@@ -14,12 +14,12 @@ import"core-js/modules/es.iterator.constructor.js";import"core-js/modules/es.ite
14
14
  // TODO: We need to add correct typing for environment options.
15
15
  // As this environment is a part of the Jest testing utils,
16
16
  // we assume development dependencies are available when it is used.
17
- /* eslint-disable import/no-extraneous-dependencies */import{fork}from"node:child_process";import{access}from"node:fs/promises";import path from"node:path";import JsdomEnv from"jest-environment-jsdom";import{defaults,set}from"lodash-es";import{Volume,createFsFromVolume}from"memfs";import webpack from"webpack";import register from"@babel/register/experimental-worker";import{deduceChunkGroups}from"../../../../server/renderer";async function findModule(module){try{const res=`${module}.ts`;await access(res);return res;}catch{// NOOP
17
+ /* eslint-disable import/no-extraneous-dependencies */import{fork}from"node:child_process";import{access}from"node:fs/promises";import path from"node:path";import JsdomEnv from"jest-environment-jsdom";import{defaults,set}from"lodash-es";import{Volume,createFsFromVolume}from"memfs";import webpack from"webpack";import register,{revert}from"@babel/register";import{deduceChunkGroups}from"../../../../server/renderer.js";async function findModule(module){try{const res=`${module}.ts`;await access(res);return res;}catch{// NOOP
18
18
  }try{const res=`${module}.js`;await access(res);return res;}catch{// NOOP
19
- }throw Error(`Module "${module}" was not found, neither as TS, nor as JS`);}export default class E2eSsrEnv extends JsdomEnv{/**
19
+ }throw Error(`Module "${module}" was not found, neither as TS, nor as JS`);}export default class E2eSsrEnv extends JsdomEnv{pragmas;ssrRequest;rootDir;testFolder;withSsr;webpackStats;/**
20
20
  * Loads Webpack config, and exposes it to the environment via global
21
21
  * webpackConfig object.
22
- */async loadWebpackConfig(){const optionsString=this.pragmas["webpack-config-options"];const options=optionsString?JSON.parse(optionsString):{};defaults(options,{context:this.testFolder,fs:this.global.webpackOutputFs});const factoryPath=this.pragmas["webpack-config-factory"];let factory=await import(/* webpackChunkName: "not-a-valid-chunk" */path.resolve(this.rootDir,factoryPath));factory="default"in factory?factory.default:factory;this.global.webpackConfig=factory(options);const fs=this.global.webpackOutputFs;let buildInfo=`${options.context}/.build-info`;if(fs.existsSync(buildInfo)){buildInfo=fs.readFileSync(buildInfo,"utf8");this.global.buildInfo=JSON.parse(buildInfo);}}/**
22
+ */async loadWebpackConfig(){const optionsString=this.pragmas["webpack-config-options"];const options=optionsString?_JSON$parse(optionsString):{};defaults(options,{context:this.testFolder,fs:this.global.webpackOutputFs});const factoryPath=this.pragmas["webpack-config-factory"];let factory=await import(/* webpackChunkName: "not-a-valid-chunk" */path.resolve(this.rootDir,factoryPath));factory="default"in factory?factory.default:factory;this.global.webpackConfig=factory(options);const fs=this.global.webpackOutputFs;let buildInfo=`${options.context}/.build-info`;if(fs.existsSync(buildInfo)){buildInfo=fs.readFileSync(buildInfo,"utf8");this.global.buildInfo=_JSON$parse(buildInfo);}}/**
23
23
  * Executes Webpack build.
24
24
  * @return {Promise}
25
25
  */async runWebpack(){await this.loadWebpackConfig();if(!this.global.webpackConfig)throw Error("Failed to load Webpack config");const compiler=webpack(this.global.webpackConfig);// TODO: The "as typeof compiler.outputFileSystem" piece below is
@@ -29,21 +29,14 @@ compiler.outputFileSystem=this.global.webpackOutputFs;return new Promise((done,f
29
29
  console.error(stats.toJson().errors);fail(Error("Webpack compilation failed"));}this.global.webpackStats=stats?.toJson();// Keeps reference to the raw Webpack stats object, which should be
30
30
  // explicitly passed to the server-side renderer alongside the request,
31
31
  // so that it can to pick up asset paths for different named chunks.
32
- this.webpackStats=stats;done();});});}async runSsr(){// NOTE: These are TS modules in the source code, and they turn into JS
33
- // modules in the distributed code, after Babel compilation. As we rely
34
- // on them for the forked NodeJS process, we need to resolve the correct
35
- // extentions ourselves (as NodeJS will hit the given paths, without any
32
+ this.webpackStats=stats;done();});});}async runSsr(){// NOTE: This is a TS module in the source code, and it turn into JS
33
+ // module in the distributed code, after Babel compilation. As we rely
34
+ // on it for the forked NodeJS process, we need to resolve the correct
35
+ // extention ourselves (as NodeJS will hit the given path, without any
36
36
  // additional resolutions / transformations).
37
- const regModulePath=await findModule(`${import.meta.dirname}/register`);const ssrModulePath=await findModule(`${import.meta.dirname}/ssr`);const cp=fork(ssrModulePath,[],{// NOTE: We have to preload this "register" module, to setup Babel
38
- // transformation for the loaded "ssr.ts" module itself (I believe,
39
- // it is relevant only when the source code is executed within
40
- // the library codebase itself, as the distributed code already
41
- // has "ssr.ts" transpiled).
42
- execArgv:["-r",regModulePath]});const optionsString=this.pragmas["ssr-options"];const options=optionsString?JSON.parse(optionsString):{};options.buildInfo??=this.global.buildInfo;if(!this.webpackStats)throw Error("Missing Webpack stats");options.chunkGroups=deduceChunkGroups(this.webpackStats);return new Promise((resolve,reject)=>{cp.on("exit",code=>{if(code)reject(Error("SSR process crashed"));});cp.on("message",message=>{this.global.ssrMarkup=message.markup;this.global.ssrOptions=options;this.global.ssrStatus=message.status;cp.kill();resolve();});if(!this.global.webpackConfig)throw Error("Missing Webpack config");cp.send({options,root:options.root==="TEST"?this.testFolder:process.cwd(),ssrRequest:this.ssrRequest,testFolder:this.testFolder,webpackConfig:this.global.webpackConfig});});}constructor(config,context){const pragmas=context.docblockPragmas;const requestString=pragmas["ssr-request"];const request=requestString?JSON.parse(requestString):{};request.url??="/";// This ensures the initial JsDom URL matches the value we use for SSR.
37
+ const ssrModulePath=await findModule(`${import.meta.dirname}/ssr-preload`);const cp=fork(ssrModulePath);const optionsString=this.pragmas["ssr-options"];const options=optionsString?_JSON$parse(optionsString):{};options.buildInfo??=this.global.buildInfo;if(!this.webpackStats)throw Error("Missing Webpack stats");options.chunkGroups=deduceChunkGroups(this.webpackStats);return new Promise((resolve,reject)=>{cp.on("exit",code=>{if(code)reject(Error("SSR process crashed"));});cp.on("message",message=>{this.global.ssrMarkup=message.markup;this.global.ssrOptions=options;this.global.ssrStatus=message.status;cp.kill();resolve();});if(!this.global.webpackConfig)throw Error("Missing Webpack config");cp.send({options,root:options.root==="TEST"?this.testFolder:process.cwd(),ssrRequest:this.ssrRequest,testFolder:this.testFolder,webpackConfig:this.global.webpackConfig});});}constructor(config,context){const pragmas=context.docblockPragmas;const requestString=pragmas["ssr-request"];const request=requestString?_JSON$parse(requestString):{};request.url??="/";// This ensures the initial JsDom URL matches the value we use for SSR.
43
38
  set(config.projectConfig,"testEnvironmentOptions.url",`http://localhost${request.url}`);super(config,context);this.global.dom=this.dom;this.global.webpackOutputFs=createFsFromVolume(new Volume);// Extracts necessary settings from config and context.
44
- const{projectConfig}=config;this.rootDir=projectConfig.rootDir;this.testFolder=path.dirname(context.testPath);this.withSsr=!pragmas["no-ssr"];this.ssrRequest=request;this.pragmas=pragmas;// The usual "babel-jest" transformation setup does not apply to
45
- // the environment code and imports from it, this workaround enables it.
46
- const optionsString=this.pragmas["ssr-options"];const options=optionsString?JSON.parse(optionsString):{};let root;switch(options.root){case"TEST":root=this.testFolder;break;default:root=process.cwd();}// BEWARE: Anything imported prior to this register() call seems to be
39
+ const{projectConfig}=config;this.rootDir=projectConfig.rootDir;this.testFolder=path.dirname(context.testPath);this.withSsr=!pragmas["no-ssr"];this.ssrRequest=request;this.pragmas=pragmas;// BEWARE: Anything imported prior to this register() call seems to be
47
40
  // transpiled again by Babel if loaded after this call. This causes very
48
41
  // confusing errors when testing the code dependent on some sort of contexts
49
42
  // (because loading a module again effectively creates a new context object,
@@ -52,24 +45,6 @@ const optionsString=this.pragmas["ssr-options"];const options=optionsString?JSON
52
45
  // BEWARE: Although we also do the registration inside SSR testing code,
53
46
  // we still need it here to correctly process imported Webpack configurations
54
47
  // (which are imported directly from this module).
55
- register({envName:options.babelEnv,extensions:[".js",".jsx",".ts",".tsx",".svg"],root});}async setup(){await super.setup();await this.runWebpack();// NOTE: It is possible that the Webpack run above, and the SSR run below
56
- // load different versions of the same module (CommonJS, and ES), and it may
57
- // cause very confusing problems (e.g. see:
58
- // https://github.com/birdofpreyru/react-utils/issues/413).
59
- // It seems we can't reset the cache of ES modules, and Jest's module reset
60
- // does not reset modules loaded in this enviroment module, and also only
61
- // replacing entire cache object by and empty {} seems to help (in contrast
62
- // to deleting all entries by their keys, as it is done within .teardown()
63
- // method below). Thus, for now we do this as a hotfix, and we also reset
64
- // build info to undefined, because ES module version not beeing reset
65
- // triggers an error on the subsequent test using the environment.
66
- // TODO: Look for a cleaner solution.
67
- require.cache={};// eslint-disable-next-line import/dynamic-import-chunkname
68
- const{setBuildInfo}=await import("../../isomorphy/buildInfo");setBuildInfo(undefined,true);if(this.withSsr)await this.runSsr();this.global.REACT_UTILS_FORCE_CLIENT_SIDE=true;}async teardown(){delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;// Resets module cache and @babel/register. Effectively this ensures that
69
- // the next time an instance of this environment is set up, all modules are
70
- // transformed by Babel from scratch, thus taking into account the latest
71
- // Babel config (which may change between different environment instances,
72
- // which does not seem to be taken into account by Babel / Node caches
73
- // automatically).
74
- Object.keys(require.cache).forEach(key=>{delete require.cache[key];});register.revert();await super.teardown();}}
48
+ register({extensions:[".js",".jsx",".ts",".tsx",".svg"]});}async setup(){await super.setup();await this.runWebpack();// eslint-disable-next-line import/dynamic-import-chunkname
49
+ const{setBuildInfo}=await import("../../isomorphy/buildInfo.js");setBuildInfo(undefined,true);if(this.withSsr)await this.runSsr();this.global.REACT_UTILS_FORCE_CLIENT_SIDE=true;}async teardown(){delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;revert();await super.teardown();}}
75
50
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["fork","access","path","JsdomEnv","defaults","set","Volume","createFsFromVolume","webpack","register","deduceChunkGroups","findModule","module","res","Error","E2eSsrEnv","loadWebpackConfig","optionsString","pragmas","options","JSON","parse","context","testFolder","fs","global","webpackOutputFs","factoryPath","factory","resolve","rootDir","default","webpackConfig","buildInfo","existsSync","readFileSync","runWebpack","compiler","outputFileSystem","Promise","done","fail","run","err","stats","hasErrors","console","error","toJson","errors","webpackStats","runSsr","regModulePath","import","meta","dirname","ssrModulePath","cp","execArgv","chunkGroups","reject","on","code","message","ssrMarkup","markup","ssrOptions","ssrStatus","status","kill","send","root","process","cwd","ssrRequest","constructor","config","docblockPragmas","requestString","request","url","projectConfig","dom","testPath","withSsr","envName","babelEnv","extensions","setup","require","cache","setBuildInfo","undefined","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","forEach","key","revert"],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/index.ts"],"sourcesContent":["/**\n * Jest environment for end-to-end SSR and client-side testing. It relies on\n * the standard react-utils mechanics to execute SSR of given scene, and also\n * Webpack build of the code for client-side execution, it further exposes\n * Jsdom environment for the client-side testing of the outcomes.\n */\n\n// BEWARE: The module is not imported into the JU module / the main assembly of\n// the library, because doing so easily breaks stuff:\n// 1) This module depends on Node-specific modules, which would make JU\n// incompatible with JsDom if included into JU.\n// 2) If this module is weakly imported from somewhere else in the lib,\n// it seems to randomly break tests using it for a different reason,\n// probably some sort of a require-loop, or some issues with weak\n// require in that scenario.\n\n// TODO: We need to add correct typing for environment options.\n\n// As this environment is a part of the Jest testing utils,\n// we assume development dependencies are available when it is used.\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport { fork } from 'node:child_process';\nimport { access } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { defaults, set } from 'lodash-es';\nimport { Volume, createFsFromVolume } from 'memfs';\nimport webpack, { type Configuration, type Stats } from 'webpack';\n\nimport register from '@babel/register/experimental-worker';\n\nimport type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\n\nimport { deduceChunkGroups } from 'server/renderer';\n\nimport type { LaunchT, ResultT } from './ssr';\n\nasync function findModule(module: string): Promise<string> {\n try {\n const res = `${module}.ts`;\n await access(res);\n return res;\n } catch {\n // NOOP\n }\n\n try {\n const res = `${module}.js`;\n await access(res);\n return res;\n } catch {\n // NOOP\n }\n\n throw Error(`Module \"${module}\" was not found, neither as TS, nor as JS`);\n}\n\nexport default class E2eSsrEnv extends JsdomEnv {\n pragmas: Record<string, string | string[]>;\n\n ssrRequest: object;\n\n rootDir: string;\n\n testFolder: string;\n\n withSsr: boolean;\n\n webpackStats?: Stats;\n\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n private async loadWebpackConfig() {\n const optionsString = this.pragmas['webpack-config-options'] as string;\n\n const options = (optionsString ? JSON.parse(optionsString) : {}) as\n webpack.Configuration;\n\n defaults(options, {\n context: this.testFolder,\n fs: this.global.webpackOutputFs,\n });\n\n const factoryPath = this.pragmas['webpack-config-factory'] as string;\n\n let factory = await import(/* webpackChunkName: \"not-a-valid-chunk\" */\n path.resolve(this.rootDir, factoryPath)\n ) as (((ops: Configuration) => Configuration) | {\n default: (ops: Configuration) => Configuration;\n });\n\n factory = 'default' in factory ? factory.default : factory;\n\n this.global.webpackConfig = factory(options);\n\n const fs = this.global.webpackOutputFs;\n let buildInfo = `${options.context}/.build-info`;\n if (fs.existsSync(buildInfo)) {\n buildInfo = fs.readFileSync(buildInfo, 'utf8') as string;\n this.global.buildInfo = JSON.parse(buildInfo);\n }\n }\n\n /**\n * Executes Webpack build.\n * @return {Promise}\n */\n async runWebpack(): Promise<void> {\n await this.loadWebpackConfig();\n\n if (!this.global.webpackConfig) throw Error('Failed to load Webpack config');\n const compiler = webpack(this.global.webpackConfig);\n\n // TODO: The \"as typeof compiler.outputFileSystem\" piece below is\n // a workaround for the Webpack regression:\n // https://github.com/webpack/webpack/issues/18242\n compiler.outputFileSystem = this.global.webpackOutputFs as\n typeof compiler.outputFileSystem;\n\n return new Promise<void>((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n if (stats?.hasErrors()) {\n // eslint-disable-next-line no-console\n console.error(stats.toJson().errors);\n fail(Error('Webpack compilation failed'));\n }\n\n this.global.webpackStats = stats?.toJson();\n\n // Keeps reference to the raw Webpack stats object, which should be\n // explicitly passed to the server-side renderer alongside the request,\n // so that it can to pick up asset paths for different named chunks.\n this.webpackStats = stats;\n\n done();\n });\n });\n }\n\n async runSsr(): Promise<void> {\n // NOTE: These are TS modules in the source code, and they turn into JS\n // modules in the distributed code, after Babel compilation. As we rely\n // on them for the forked NodeJS process, we need to resolve the correct\n // extentions ourselves (as NodeJS will hit the given paths, without any\n // additional resolutions / transformations).\n const regModulePath = await findModule(`${import.meta.dirname}/register`);\n const ssrModulePath = await findModule(`${import.meta.dirname}/ssr`);\n\n const cp = fork(ssrModulePath, [], {\n // NOTE: We have to preload this \"register\" module, to setup Babel\n // transformation for the loaded \"ssr.ts\" module itself (I believe,\n // it is relevant only when the source code is executed within\n // the library codebase itself, as the distributed code already\n // has \"ssr.ts\" transpiled).\n execArgv: ['-r', regModulePath],\n });\n\n const optionsString = this.pragmas['ssr-options'] as string;\n const options = optionsString\n ? JSON.parse(optionsString) as Record<string, unknown>\n : {};\n\n options.buildInfo ??= this.global.buildInfo;\n\n if (!this.webpackStats) throw Error('Missing Webpack stats');\n\n options.chunkGroups = deduceChunkGroups(this.webpackStats);\n\n return new Promise((resolve, reject) => {\n cp.on('exit', (code) => {\n if (code) reject(Error('SSR process crashed'));\n });\n\n cp.on('message', (message: ResultT) => {\n this.global.ssrMarkup = message.markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = message.status;\n cp.kill();\n resolve();\n });\n\n if (!this.global.webpackConfig) throw Error('Missing Webpack config');\n\n cp.send({\n options,\n root: options.root === 'TEST' ? this.testFolder : process.cwd(),\n ssrRequest: this.ssrRequest,\n testFolder: this.testFolder,\n webpackConfig: this.global.webpackConfig,\n } satisfies LaunchT);\n });\n }\n\n constructor(\n config: JestEnvironmentConfig,\n context: EnvironmentContext,\n ) {\n const pragmas = context.docblockPragmas;\n\n const requestString = pragmas['ssr-request'] as string;\n const request = requestString\n ? JSON.parse(requestString) as Record<string, unknown>\n : {};\n\n request.url ??= '/';\n\n // This ensures the initial JsDom URL matches the value we use for SSR.\n set(\n config.projectConfig,\n 'testEnvironmentOptions.url',\n `http://localhost${request.url as string}`,\n );\n\n super(config, context);\n\n this.global.dom = this.dom;\n this.global.webpackOutputFs = createFsFromVolume(new Volume());\n\n // Extracts necessary settings from config and context.\n const { projectConfig } = config;\n this.rootDir = projectConfig.rootDir;\n this.testFolder = path.dirname(context.testPath);\n this.withSsr = !pragmas['no-ssr'];\n this.ssrRequest = request;\n this.pragmas = pragmas;\n\n // The usual \"babel-jest\" transformation setup does not apply to\n // the environment code and imports from it, this workaround enables it.\n const optionsString = this.pragmas['ssr-options'] as string;\n const options = optionsString\n ? JSON.parse(optionsString) as Record<string, unknown>\n : {};\n let root;\n switch (options.root) {\n case 'TEST':\n root = this.testFolder;\n break;\n default: root = process.cwd();\n }\n\n // BEWARE: Anything imported prior to this register() call seems to be\n // transpiled again by Babel if loaded after this call. This causes very\n // confusing errors when testing the code dependent on some sort of contexts\n // (because loading a module again effectively creates a new context object,\n // which is not recognized by the code expecting another context instance).\n // That's why below we prefer dynamic imports for some React Utils methods.\n // BEWARE: Although we also do the registration inside SSR testing code,\n // we still need it here to correctly process imported Webpack configurations\n // (which are imported directly from this module).\n register({\n envName: options.babelEnv as string,\n extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],\n root,\n });\n }\n\n async setup(): Promise<void> {\n await super.setup();\n await this.runWebpack();\n\n // NOTE: It is possible that the Webpack run above, and the SSR run below\n // load different versions of the same module (CommonJS, and ES), and it may\n // cause very confusing problems (e.g. see:\n // https://github.com/birdofpreyru/react-utils/issues/413).\n // It seems we can't reset the cache of ES modules, and Jest's module reset\n // does not reset modules loaded in this enviroment module, and also only\n // replacing entire cache object by and empty {} seems to help (in contrast\n // to deleting all entries by their keys, as it is done within .teardown()\n // method below). Thus, for now we do this as a hotfix, and we also reset\n // build info to undefined, because ES module version not beeing reset\n // triggers an error on the subsequent test using the environment.\n // TODO: Look for a cleaner solution.\n require.cache = {};\n\n // eslint-disable-next-line import/dynamic-import-chunkname\n const { setBuildInfo } = await import('../../isomorphy/buildInfo');\n setBuildInfo(undefined, true);\n\n if (this.withSsr) await this.runSsr();\n this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;\n }\n\n async teardown(): Promise<void> {\n delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n // Resets module cache and @babel/register. Effectively this ensures that\n // the next time an instance of this environment is set up, all modules are\n // transformed by Babel from scratch, thus taking into account the latest\n // Babel config (which may change between different environment instances,\n // which does not seem to be taken into account by Babel / Node caches\n // automatically).\n Object.keys(require.cache).forEach((key) => {\n delete require.cache[key];\n });\n register.revert();\n\n await super.teardown();\n }\n}\n"],"mappings":"4IAAA;AACA;AACA;AACA;AACA;AACA,GAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA,sDAEA,OAASA,IAAI,KAAQ,oBAAoB,CACzC,OAASC,MAAM,KAAQ,kBAAkB,CACzC,MAAO,CAAAC,IAAI,KAAM,WAAW,CAE5B,MAAO,CAAAC,QAAQ,KAAM,wBAAwB,CAC7C,OAASC,QAAQ,CAAEC,GAAG,KAAQ,WAAW,CACzC,OAASC,MAAM,CAAEC,kBAAkB,KAAQ,OAAO,CAClD,MAAO,CAAAC,OAAO,KAA0C,SAAS,CAEjE,MAAO,CAAAC,QAAQ,KAAM,qCAAqC,CAO1D,OAASC,iBAAiB,mCAI1B,cAAe,CAAAC,UAAUA,CAACC,MAAc,CAAmB,CACzD,GAAI,CACF,KAAM,CAAAC,GAAG,CAAG,GAAGD,MAAM,KAAK,CAC1B,KAAM,CAAAX,MAAM,CAACY,GAAG,CAAC,CACjB,MAAO,CAAAA,GAAG,CACZ,CAAE,KAAM,CACN;AAAA,CAGF,GAAI,CACF,KAAM,CAAAA,GAAG,CAAG,GAAGD,MAAM,KAAK,CAC1B,KAAM,CAAAX,MAAM,CAACY,GAAG,CAAC,CACjB,MAAO,CAAAA,GAAG,CACZ,CAAE,KAAM,CACN;AAAA,CAGF,KAAM,CAAAC,KAAK,CAAC,WAAWF,MAAM,2CAA2C,CAAC,CAC3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0F,MAAM,CAAC,CAAC,CAEjB,KAAM,MAAK,CAACL,QAAQ,CAAC,CAAC,CACxB,CACF","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/index.ts"],"sourcesContent":["/**\n * Jest environment for end-to-end SSR and client-side testing. It relies on\n * the standard react-utils mechanics to execute SSR of given scene, and also\n * Webpack build of the code for client-side execution, it further exposes\n * Jsdom environment for the client-side testing of the outcomes.\n */\n\n// BEWARE: The module is not imported into the JU module / the main assembly of\n// the library, because doing so easily breaks stuff:\n// 1) This module depends on Node-specific modules, which would make JU\n// incompatible with JsDom if included into JU.\n// 2) If this module is weakly imported from somewhere else in the lib,\n// it seems to randomly break tests using it for a different reason,\n// probably some sort of a require-loop, or some issues with weak\n// require in that scenario.\n\n// TODO: We need to add correct typing for environment options.\n\n// As this environment is a part of the Jest testing utils,\n// we assume development dependencies are available when it is used.\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport { fork } from 'node:child_process';\nimport { access } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { defaults, set } from 'lodash-es';\nimport { Volume, createFsFromVolume } from 'memfs';\nimport webpack, { type Configuration, type Stats } from 'webpack';\n\nimport register, { revert } from '@babel/register';\n\nimport type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\n\nimport { deduceChunkGroups } from 'server/renderer';\n\nimport type { LaunchT, ResultT } from './ssr';\n\nasync function findModule(module: string): Promise<string> {\n try {\n const res = `${module}.ts`;\n await access(res);\n return res;\n } catch {\n // NOOP\n }\n\n try {\n const res = `${module}.js`;\n await access(res);\n return res;\n } catch {\n // NOOP\n }\n\n throw Error(`Module \"${module}\" was not found, neither as TS, nor as JS`);\n}\n\nexport default class E2eSsrEnv extends JsdomEnv {\n pragmas: Record<string, string | string[]>;\n\n ssrRequest: object;\n\n rootDir: string;\n\n testFolder: string;\n\n withSsr: boolean;\n\n webpackStats?: Stats;\n\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n private async loadWebpackConfig() {\n const optionsString = this.pragmas['webpack-config-options'] as string;\n\n const options = (optionsString ? JSON.parse(optionsString) : {}) as\n webpack.Configuration;\n\n defaults(options, {\n context: this.testFolder,\n fs: this.global.webpackOutputFs,\n });\n\n const factoryPath = this.pragmas['webpack-config-factory'] as string;\n\n let factory = await import(/* webpackChunkName: \"not-a-valid-chunk\" */\n path.resolve(this.rootDir, factoryPath)\n ) as (((ops: Configuration) => Configuration) | {\n default: (ops: Configuration) => Configuration;\n });\n\n factory = 'default' in factory ? factory.default : factory;\n\n this.global.webpackConfig = factory(options);\n\n const fs = this.global.webpackOutputFs;\n let buildInfo = `${options.context}/.build-info`;\n if (fs.existsSync(buildInfo)) {\n buildInfo = fs.readFileSync(buildInfo, 'utf8') as string;\n this.global.buildInfo = JSON.parse(buildInfo);\n }\n }\n\n /**\n * Executes Webpack build.\n * @return {Promise}\n */\n async runWebpack(): Promise<void> {\n await this.loadWebpackConfig();\n\n if (!this.global.webpackConfig) throw Error('Failed to load Webpack config');\n const compiler = webpack(this.global.webpackConfig);\n\n // TODO: The \"as typeof compiler.outputFileSystem\" piece below is\n // a workaround for the Webpack regression:\n // https://github.com/webpack/webpack/issues/18242\n compiler.outputFileSystem = this.global.webpackOutputFs as\n typeof compiler.outputFileSystem;\n\n return new Promise<void>((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n if (stats?.hasErrors()) {\n // eslint-disable-next-line no-console\n console.error(stats.toJson().errors);\n fail(Error('Webpack compilation failed'));\n }\n\n this.global.webpackStats = stats?.toJson();\n\n // Keeps reference to the raw Webpack stats object, which should be\n // explicitly passed to the server-side renderer alongside the request,\n // so that it can to pick up asset paths for different named chunks.\n this.webpackStats = stats;\n\n done();\n });\n });\n }\n\n async runSsr(): Promise<void> {\n // NOTE: This is a TS module in the source code, and it turn into JS\n // module in the distributed code, after Babel compilation. As we rely\n // on it for the forked NodeJS process, we need to resolve the correct\n // extention ourselves (as NodeJS will hit the given path, without any\n // additional resolutions / transformations).\n const ssrModulePath = await findModule(`${import.meta.dirname}/ssr-preload`);\n\n const cp = fork(ssrModulePath);\n\n const optionsString = this.pragmas['ssr-options'] as string;\n const options = optionsString\n ? JSON.parse(optionsString) as Record<string, unknown>\n : {};\n\n options.buildInfo ??= this.global.buildInfo;\n\n if (!this.webpackStats) throw Error('Missing Webpack stats');\n\n options.chunkGroups = deduceChunkGroups(this.webpackStats);\n\n return new Promise((resolve, reject) => {\n cp.on('exit', (code) => {\n if (code) reject(Error('SSR process crashed'));\n });\n\n cp.on('message', (message: ResultT) => {\n this.global.ssrMarkup = message.markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = message.status;\n cp.kill();\n resolve();\n });\n\n if (!this.global.webpackConfig) throw Error('Missing Webpack config');\n\n cp.send({\n options,\n root: options.root === 'TEST' ? this.testFolder : process.cwd(),\n ssrRequest: this.ssrRequest,\n testFolder: this.testFolder,\n webpackConfig: this.global.webpackConfig,\n } satisfies LaunchT);\n });\n }\n\n constructor(\n config: JestEnvironmentConfig,\n context: EnvironmentContext,\n ) {\n const pragmas = context.docblockPragmas;\n\n const requestString = pragmas['ssr-request'] as string;\n const request = requestString\n ? JSON.parse(requestString) as Record<string, unknown>\n : {};\n\n request.url ??= '/';\n\n // This ensures the initial JsDom URL matches the value we use for SSR.\n set(\n config.projectConfig,\n 'testEnvironmentOptions.url',\n `http://localhost${request.url as string}`,\n );\n\n super(config, context);\n\n this.global.dom = this.dom;\n this.global.webpackOutputFs = createFsFromVolume(new Volume());\n\n // Extracts necessary settings from config and context.\n const { projectConfig } = config;\n this.rootDir = projectConfig.rootDir;\n this.testFolder = path.dirname(context.testPath);\n this.withSsr = !pragmas['no-ssr'];\n this.ssrRequest = request;\n this.pragmas = pragmas;\n\n // BEWARE: Anything imported prior to this register() call seems to be\n // transpiled again by Babel if loaded after this call. This causes very\n // confusing errors when testing the code dependent on some sort of contexts\n // (because loading a module again effectively creates a new context object,\n // which is not recognized by the code expecting another context instance).\n // That's why below we prefer dynamic imports for some React Utils methods.\n // BEWARE: Although we also do the registration inside SSR testing code,\n // we still need it here to correctly process imported Webpack configurations\n // (which are imported directly from this module).\n register({\n extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],\n });\n }\n\n async setup(): Promise<void> {\n await super.setup();\n await this.runWebpack();\n\n // eslint-disable-next-line import/dynamic-import-chunkname\n const { setBuildInfo } = await import('../../isomorphy/buildInfo');\n setBuildInfo(undefined, true);\n\n if (this.withSsr) await this.runSsr();\n this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;\n }\n\n async teardown(): Promise<void> {\n delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n revert();\n\n await super.teardown();\n }\n}\n"],"mappings":"2DAAA;AACA;AACA;AACA;AACA;AACA,GAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA,sDAEA,OAAS,IAAI,KAAQ,oBAAoB,CACzC,OAAS,MAAM,KAAQ,kBAAkB,CACzC,MAAO,KAAI,KAAM,WAAW,CAE5B,MAAO,SAAQ,KAAM,wBAAwB,CAC7C,OAAS,QAAQ,CAAE,GAAG,KAAQ,WAAW,CACzC,OAAS,MAAM,CAAE,kBAAkB,KAAQ,OAAO,CAClD,MAAO,QAAO,KAA0C,SAAS,CAEjE,MAAO,SAAQ,EAAI,MAAM,KAAQ,iBAAiB,CAAC,OAO1C,iBAAiB,sCAI1B,cAAe,WAAU,CAAC,MAAc,CAAmB,CACzD,GAAI,CACF,KAAM,IAAG,CAAG,GAAG,MAAM,KAAK,CAC1B,KAAM,OAAM,CAAC,GAAG,CAAC,CACjB,MAAO,IAAG,CACZ,CAAE,KAAM,CACN;AAAA,CAGF,GAAI,CACF,KAAM,IAAG,CAAG,GAAG,MAAM,KAAK,CAC1B,KAAM,OAAM,CAAC,GAAG,CAAC,CACjB,MAAO,IAAG,CACZ,CAAE,KAAM,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@ -0,0 +1,5 @@
1
+ import{existsSync,statSync}from"node:fs";import{registerHooks}from"node:module";const TRIAL=["",".cjs",".js",".jsx",".mjs",".ts",".tsx"];registerHooks({resolve:(specifier,context,next)=>{let path=specifier;// This works around the regular ESM limitation of having to have explicit
2
+ // file extensions on import specifiers.
3
+ if((specifier.startsWith(".")||specifier.startsWith("/"))&&context.conditions.includes("import")){const url=new URL(specifier,context.parentURL);path=url.pathname;if(existsSync(path)&&statSync(path).isDirectory())path+="/index";for(const ext of TRIAL){if(existsSync(path+ext)){path+=ext;break;}}}return next(path,context);}});// eslint-disable-next-line import/dynamic-import-chunkname
4
+ void import("./ssr.js");
5
+ //# sourceMappingURL=ssr-preload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssr-preload.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr-preload.ts"],"sourcesContent":["import { existsSync, statSync } from 'node:fs';\nimport { registerHooks } from 'node:module';\n\nconst TRIAL = [\n '',\n '.cjs',\n '.js',\n '.jsx',\n '.mjs',\n '.ts',\n '.tsx',\n];\n\nregisterHooks({\n resolve: (specifier, context, next) => {\n let path = specifier;\n\n // This works around the regular ESM limitation of having to have explicit\n // file extensions on import specifiers.\n if ((\n specifier.startsWith('.') || specifier.startsWith('/')\n ) && context.conditions.includes('import')) {\n const url = new URL(specifier, context.parentURL);\n path = url.pathname;\n\n if (existsSync(path) && statSync(path).isDirectory()) path += '/index';\n\n for (const ext of TRIAL) {\n if (existsSync(path + ext)) {\n path += ext;\n break;\n }\n }\n }\n\n return next(path, context);\n },\n});\n\n// eslint-disable-next-line import/dynamic-import-chunkname\nvoid import('./ssr');\n"],"mappings":"AAAA,OAAS,UAAU,CAAE,QAAQ,KAAQ,SAAS,CAC9C,OAAS,aAAa,KAAQ,aAAa,CAE3C,KAAM,MAAK,CAAG,CACZ,EAAE,CACF,MAAM,CACN,KAAK,CACL,MAAM,CACN,MAAM,CACN,KAAK,CACL,MAAM,CACP,CAED,aAAa,CAAC,CACZ,OAAO,CAAE,CAAC,SAAS,CAAE,OAAO,CAAE,IAAI,GAAK,CACrC,GAAI,KAAI,CAAG,SAAS,CAEpB;AACA;AACA,GAAI,CACF,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAI,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,GACnD,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAE,CAC1C,KAAM,IAAG,CAAG,GAAI,IAAG,CAAC,SAAS,CAAE,OAAO,CAAC,SAAS,CAAC,CACjD,IAAI,CAAG,GAAG,CAAC,QAAQ,CAEnB,GAAI,UAAU,CAAC,IAAI,CAAC,EAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,CAAC,CAAE,IAAI,EAAI,QAAQ,CAEtE,IAAK,KAAM,IAAG,GAAI,MAAK,CAAE,CACvB,GAAI,UAAU,CAAC,IAAI,CAAG,GAAG,CAAC,CAAE,CAC1B,IAAI,EAAI,GAAG,CACX,MACF,CACF,CACF,CAEA,MAAO,KAAI,CAAC,IAAI,CAAE,OAAO,CAAC,CAC5B,CACF,CAAC,CAAC,CAEF;AACA,IAAK,OAAM,YAAS","ignoreList":[]}
@@ -1,11 +1,11 @@
1
- /* eslint-disable import/dynamic-import-chunkname, import/no-extraneous-dependencies */import{readFileSync}from"node:fs";import{registerHooks}from"node:module";import{basename,dirname,resolve}from"node:path";import{fileURLToPath}from"node:url";import{transformSync}from"@babel/core";import ssrFactory from"../../../../server/renderer";function noop(){// NOOP
1
+ /* eslint-disable import/dynamic-import-chunkname, import/no-extraneous-dependencies */import{readFileSync}from"node:fs";import{registerHooks}from"node:module";import{basename,dirname,resolve}from"node:path";import{fileURLToPath}from"node:url";import{transformSync}from"@babel/core";import ssrFactory from"../../../../server/renderer.js";function noop(){// NOOP
2
2
  }async function run({options,root,ssrRequest,testFolder,webpackConfig}){// NOTE: It looks like @babel/register does not work for us here, because
3
3
  // it only supports transpiling of modules loaded with require(), so here
4
4
  // is, presumably, a temporary workaround relying on the new NodeJS module
5
5
  // API, and Babel's core, to transpile all modules loaded further into
6
6
  // CommonJS. I guess, later we'll be able to get rid of this, as Babel
7
7
  // register supports runtime transformation of modules loaded with import().
8
- registerHooks({load(url,context,nextLoad){if(url.startsWith("file://")&&!url.includes("/node_modules/")&&!url.includes("/config/babel/")&&url.match(/\.(js|jsx|ts|tsx|svg)$/)){const path=fileURLToPath(url);let code=readFileSync(path,"utf8");code=transformSync(code,{cwd:dirname(path),envName:options.babelEnv,filename:basename(path),root})?.code??"";return{format:"commonjs",shortCircuit:true,source:code};}return nextLoad(url,context);}});if(options.entry){const p=resolve(testFolder,options.entry);const babelModule=await import(p);// TODO: This is basically a hotfix hack, which works both for the library
8
+ registerHooks({load(url,context,nextLoad){if(url.startsWith("file://")&&!url.includes("/node_modules/")&&!url.includes("/config/babel/")&&url.match(/\.(js|jsx|ts|tsx|svg)$/)){const path=fileURLToPath(url);let code=readFileSync(path,"utf8");code=transformSync(code,{cwd:dirname(path),envName:options.babelEnv,filename:basename(path),root})?.code??"";return{format:"module",shortCircuit:true,source:code};}return nextLoad(url,context);}});if(options.entry){const p=resolve(testFolder,options.entry);const babelModule=await import(p);// TODO: This is basically a hotfix hack, which works both for the library
9
9
  // itself, and for dependent projects... (those tested so far). It sure has
10
10
  // to be reworked later.
11
11
  /* eslint-disable no-underscore-dangle */const module="__esModule"in babelModule&&typeof babelModule.__esModule==="boolean"&&babelModule.__esModule&&"default"in babelModule?babelModule.default:babelModule;/* eslint-enable no-underscore-dangle */const exportName=options.entryExportName||"default";if(exportName in module){// eslint-disable-next-line no-param-reassign
@@ -1 +1 @@
1
- {"version":3,"file":"ssr.js","names":["readFileSync","registerHooks","basename","dirname","resolve","fileURLToPath","transformSync","ssrFactory","noop","run","options","root","ssrRequest","testFolder","webpackConfig","load","url","context","nextLoad","startsWith","includes","match","path","code","cwd","envName","babelEnv","filename","format","shortCircuit","source","entry","p","babelModule","module","__esModule","default","exportName","entryExportName","Application","renderer","status","csrfToken","markup","Promise","done","fail","cookie","send","set","value","error","process","on","message"],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr.ts"],"sourcesContent":["/* eslint-disable import/dynamic-import-chunkname, import/no-extraneous-dependencies */\n\nimport { readFileSync } from 'node:fs';\nimport { registerHooks } from 'node:module';\nimport { basename, dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { Request, Response } from 'express';\nimport type { Configuration } from 'webpack';\n\nimport { transformSync } from '@babel/core';\n\nimport ssrFactory from 'server/renderer';\n\nexport type LaunchT = {\n // TODO: Should it be typed as the renderer's options type?\n options: Record<string, unknown>;\n\n root: string;\n ssrRequest: object;\n testFolder: string;\n webpackConfig: Configuration;\n};\n\nexport type ResultT = {\n markup: string;\n status: number;\n};\n\nfunction noop() {\n // NOOP\n}\n\nasync function run({\n options,\n root,\n ssrRequest,\n testFolder,\n webpackConfig,\n}: LaunchT) {\n // NOTE: It looks like @babel/register does not work for us here, because\n // it only supports transpiling of modules loaded with require(), so here\n // is, presumably, a temporary workaround relying on the new NodeJS module\n // API, and Babel's core, to transpile all modules loaded further into\n // CommonJS. I guess, later we'll be able to get rid of this, as Babel\n // register supports runtime transformation of modules loaded with import().\n registerHooks({\n load(url, context, nextLoad) {\n if (\n url.startsWith('file://')\n && !url.includes('/node_modules/')\n && !url.includes('/config/babel/')\n && url.match(/\\.(js|jsx|ts|tsx|svg)$/)\n ) {\n const path = fileURLToPath(url);\n let code = readFileSync(path, 'utf8');\n code = transformSync(code, {\n cwd: dirname(path),\n envName: options.babelEnv as string,\n filename: basename(path),\n root,\n })?.code ?? '';\n return {\n format: 'commonjs',\n shortCircuit: true,\n source: code,\n };\n }\n\n return nextLoad(url, context);\n },\n });\n\n if (options.entry) {\n const p = resolve(testFolder, options.entry as string);\n const babelModule = await import(p) as NodeJS.Module;\n\n // TODO: This is basically a hotfix hack, which works both for the library\n // itself, and for dependent projects... (those tested so far). It sure has\n // to be reworked later.\n /* eslint-disable no-underscore-dangle */\n const module = (\n '__esModule' in babelModule\n && typeof babelModule.__esModule === 'boolean'\n && babelModule.__esModule\n && 'default' in babelModule\n ? babelModule.default : babelModule\n ) as NodeJS.Module;\n /* eslint-enable no-underscore-dangle */\n\n const exportName = (options.entryExportName as string) || 'default';\n if (exportName in module) {\n // eslint-disable-next-line no-param-reassign\n options.Application = (\n module as unknown as Record<string, unknown>\n )[exportName];\n // eslint-disable-next-line no-param-reassign\n } else options.Application = module;\n }\n\n const renderer = ssrFactory(webpackConfig, options);\n let status = 200; // OK\n\n // eslint-disable-next-line no-param-reassign\n (ssrRequest as Request).csrfToken = () => '';\n\n const markup = await new Promise<string>((done, fail) => {\n void renderer(\n ssrRequest as Request,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n ({\n cookie: noop,\n send: done,\n set: noop,\n status: (value: number) => {\n status = value;\n },\n } as unknown) as Response,\n\n (error) => {\n // TODO: Strictly speaking, that error as Error casting is not all\n // correct, but it works, so no need to spend time on it right now.\n if (error) fail(error as Error);\n else done('');\n },\n );\n });\n\n process.send?.({ markup, status } satisfies ResultT);\n}\n\nprocess.on('message', (message: LaunchT) => {\n void run(message);\n});\n"],"mappings":"AAAA,uFAEA,OAASA,YAAY,KAAQ,SAAS,CACtC,OAASC,aAAa,KAAQ,aAAa,CAC3C,OAASC,QAAQ,CAAEC,OAAO,CAAEC,OAAO,KAAQ,WAAW,CACtD,OAASC,aAAa,KAAQ,UAAU,CAKxC,OAASC,aAAa,KAAQ,aAAa,CAE3C,MAAO,CAAAC,UAAU,mCAiBjB,QAAS,CAAAC,IAAIA,CAAA,CAAG,CACd;AAAA,CAGF,cAAe,CAAAC,GAAGA,CAAC,CACjBC,OAAO,CACPC,IAAI,CACJC,UAAU,CACVC,UAAU,CACVC,aACO,CAAC,CAAE,CACV;AACA;AACA;AACA;AACA;AACA;AACAb,aAAa,CAAC,CACZc,IAAIA,CAACC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I3B,OAAO,CAAC4B,eAAe,EAAe,SAAS,CACnE,GAAID,UAAU,GAAI,CAAAH,MAAM,CAAE,CACxB;AACAxB,OAAO,CAAC6B,WAAW,CACjBL,MAAM,CACNG,UAAU,CAAC,CACb;AACF,CAAC,IAAM,CAAA3B,OAAO,CAAC6B,WAAW,CAAGL,MAAM,CACrC,CAEA,KAAM,CAAAM,QAAQ,CAAGjC,UAAU,CAACO,aAAa,CAAEJ,OAAO,CAAC,CACnD,GAAI,CAAA+B,MAAM,CAAG,GAAG,CAAE;AAElB;AACC7B,UAAU,CAAa8B,SAAS,CAAG,IAAM,EAAE,CAE5C,KAAM,CAAAC,MAAM,CAAG,KAAM,IAAI,CAAAC,OAAO,CAAS,CAACC,IAAI,CAAEC,IAAI,GAAK,CACvD,IAAK,CAAAN,QAAQ,CACX5B,UAAU,CAEV;AACA;AACA;AACC,CACCmC,MAAM,CAAEvC,IAAI,CACZwC,IAAI,CAAEH,IAAI,CACVI,GAAG,CAAEzC,IAAI,CACTiC,MAAM,CAAGS,KAAa,EAAK,CACzBT,MAAM,CAAGS,KAAK,CAChB,CACF,CAAC,CAEAC,KAAK,EAAK,CACT;AACA;AACA,GAAIA,KAAK,CAAEL,IAAI,CAACK,KAAc,CAAC,CAAC,IAC3B,CAAAN,IAAI,CAAC,EAAE,CAAC,CACf,CACF,CAAC,CACH,CAAC,CAAC,CAEFO,OAAO,CAACJ,IAAI,GAAG,CAAEL,MAAM,CAAEF,MAAO,CAAmB,CAAC,CACtD,CAEAW,OAAO,CAACC,EAAE,CAAC,SAAS,CAAGC,OAAgB,EAAK,CAC1C,IAAK,CAAA7C,GAAG,CAAC6C,OAAO,CAAC,CACnB,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"ssr.js","names":[],"sources":["../../../../../../src/shared/utils/jest/E2eSsrEnv/ssr.ts"],"sourcesContent":["/* eslint-disable import/dynamic-import-chunkname, import/no-extraneous-dependencies */\n\nimport { readFileSync } from 'node:fs';\nimport { registerHooks } from 'node:module';\nimport { basename, dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { Request, Response } from 'express';\nimport type { Configuration } from 'webpack';\n\nimport { transformSync } from '@babel/core';\n\nimport ssrFactory from 'server/renderer';\n\nexport type LaunchT = {\n // TODO: Should it be typed as the renderer's options type?\n options: Record<string, unknown>;\n\n root: string;\n ssrRequest: object;\n testFolder: string;\n webpackConfig: Configuration;\n};\n\nexport type ResultT = {\n markup: string;\n status: number;\n};\n\nfunction noop() {\n // NOOP\n}\n\nasync function run({\n options,\n root,\n ssrRequest,\n testFolder,\n webpackConfig,\n}: LaunchT) {\n // NOTE: It looks like @babel/register does not work for us here, because\n // it only supports transpiling of modules loaded with require(), so here\n // is, presumably, a temporary workaround relying on the new NodeJS module\n // API, and Babel's core, to transpile all modules loaded further into\n // CommonJS. I guess, later we'll be able to get rid of this, as Babel\n // register supports runtime transformation of modules loaded with import().\n registerHooks({\n load(url, context, nextLoad) {\n if (\n url.startsWith('file://')\n && !url.includes('/node_modules/')\n && !url.includes('/config/babel/')\n && url.match(/\\.(js|jsx|ts|tsx|svg)$/)\n ) {\n const path = fileURLToPath(url);\n let code = readFileSync(path, 'utf8');\n code = transformSync(code, {\n cwd: dirname(path),\n envName: options.babelEnv as string,\n filename: basename(path),\n root,\n })?.code ?? '';\n return {\n format: 'module',\n shortCircuit: true,\n source: code,\n };\n }\n\n return nextLoad(url, context);\n },\n });\n\n if (options.entry) {\n const p = resolve(testFolder, options.entry as string);\n const babelModule = await import(p) as NodeJS.Module;\n\n // TODO: This is basically a hotfix hack, which works both for the library\n // itself, and for dependent projects... (those tested so far). It sure has\n // to be reworked later.\n /* eslint-disable no-underscore-dangle */\n const module = (\n '__esModule' in babelModule\n && typeof babelModule.__esModule === 'boolean'\n && babelModule.__esModule\n && 'default' in babelModule\n ? babelModule.default : babelModule\n ) as NodeJS.Module;\n /* eslint-enable no-underscore-dangle */\n\n const exportName = (options.entryExportName as string) || 'default';\n if (exportName in module) {\n // eslint-disable-next-line no-param-reassign\n options.Application = (\n module as unknown as Record<string, unknown>\n )[exportName];\n // eslint-disable-next-line no-param-reassign\n } else options.Application = module;\n }\n\n const renderer = ssrFactory(webpackConfig, options);\n let status = 200; // OK\n\n // eslint-disable-next-line no-param-reassign\n (ssrRequest as Request).csrfToken = () => '';\n\n const markup = await new Promise<string>((done, fail) => {\n void renderer(\n ssrRequest as Request,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n ({\n cookie: noop,\n send: done,\n set: noop,\n status: (value: number) => {\n status = value;\n },\n } as unknown) as Response,\n\n (error) => {\n // TODO: Strictly speaking, that error as Error casting is not all\n // correct, but it works, so no need to spend time on it right now.\n if (error) fail(error as Error);\n else done('');\n },\n );\n });\n\n process.send?.({ markup, status } satisfies ResultT);\n}\n\nprocess.on('message', (message: LaunchT) => {\n void run(message);\n});\n"],"mappings":"AAAA,uFAEA,OAAS,YAAY,KAAQ,SAAS,CACtC,OAAS,aAAa,KAAQ,aAAa,CAC3C,OAAS,QAAQ,CAAE,OAAO,CAAE,OAAO,KAAQ,WAAW,CACtD,OAAS,aAAa,KAAQ,UAAU,CAKxC,OAAS,aAAa,KAAQ,aAAa,CAAC,MAErC,WAAU,sCAiBjB,QAAS,KAAI,EAAG,CACd;AAAA,CAGF,cAAe,IAAG,CAAC,CACjB,OAAO,CACP,IAAI,CACJ,UAAU,CACV,UAAU,CACV,aACO,CAAC,CAAE,CACV;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,CAAC,CACZ,IAAI,CAAC,GAAG,CAAE,OAAO,CAAE,QAAQ,CAAE,CAC3B,GACE,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EACtB,CAAC,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAC/B,CAAC,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAC/B,GAAG,CAAC,KAAK,CAAC,wBAAwB,CAAC,CACtC,CACA,K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O,CAAS,CAAC,IAAI,CAAE,IAAI,GAAK,CACvD,IAAK,SAAQ,CACX,UAAU,CAEV;AACA;AACA;AACC,CACC,MAAM,CAAE,IAAI,CACZ,IAAI,CAAE,IAAI,CACV,GAAG,CAAE,IAAI,CACT,MAAM,CAAG,KAAa,EAAK,CACzB,MAAM,CAAG,KAAK,CAChB,CACF,CAAC,CAEA,KAAK,EAAK,CACT;AACA;AACA,GAAI,KAAK,CAAE,IAAI,CAAC,KAAc,CAAC,CAAC,IAC3B,KAAI,CAAC,EAAE,CAAC,CACf,CACF,CAAC,CACH,CAAC,CAAC,CAEF,OAAO,CAAC,IAAI,GAAG,CAAE,MAAM,CAAE,MAAO,CAAmB,CAAC,CACtD,CAEA,OAAO,CAAC,EAAE,CAAC,SAAS,CAAG,OAAgB,EAAK,CAC1C,IAAK,IAAG,CAAC,OAAO,CAAC,CACnB,CAAC,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"global.js","names":["getGlobal","global"],"sources":["../../../../../src/shared/utils/jest/global.ts"],"sourcesContent":["import type { IFs } from 'memfs';\nimport type { Configuration, StatsCompilation } from 'webpack';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n ssrMarkup: string | undefined;\n ssrStatus: number | undefined;\n webpackConfig: Configuration | undefined;\n webpackOutputFs: IFs;\n webpackStats?: StatsCompilation;\n }\n}\n\nexport default function getGlobal(): Window {\n return global as unknown as Window;\n}\n"],"mappings":"AAcA,cAAe,SAAS,CAAAA,SAASA,CAAA,CAAW,CAC1C,MAAO,CAAAC,MAAM,CACf","ignoreList":[]}
1
+ {"version":3,"file":"global.js","names":[],"sources":["../../../../../src/shared/utils/jest/global.ts"],"sourcesContent":["import type { IFs } from 'memfs';\nimport type { Configuration, StatsCompilation } from 'webpack';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n ssrMarkup: string | undefined;\n ssrStatus: number | undefined;\n webpackConfig: Configuration | undefined;\n webpackOutputFs: IFs;\n webpackStats?: StatsCompilation;\n }\n}\n\nexport default function getGlobal(): Window {\n return global as unknown as Window;\n}\n"],"mappings":"AAcA,cAAe,SAAS,UAAS,EAAW,CAC1C,MAAO,OAAM,CACf","ignoreList":[]}
@@ -1,7 +1,7 @@
1
- import"core-js/modules/es.json.stringify.js";/* global document *//* eslint-disable import/no-extraneous-dependencies */import mockdate from"mockdate";import{act}from"react";import{createRoot}from"react-dom/client";import{expect,jest}from"@jest/globals";import{render}from"@testing-library/react";/**
1
+ import _JSON$stringify from"core-js-pure/stable/json/stringify.js";/* global document *//* eslint-disable import/no-extraneous-dependencies */import mockdate from"mockdate";import{act}from"react";import{createRoot}from"react-dom/client";import{expect,jest}from"@jest/globals";import{render}from"@testing-library/react";/**
2
2
  * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)
3
3
  * from `react`.
4
- */export{act};export{default as getGlobal}from"./global";global.IS_REACT_ACT_ENVIRONMENT=true;const originalProcessVersions=process.versions;/**
4
+ */export{act};export{default as getGlobal}from"./global.js";global.IS_REACT_ACT_ENVIRONMENT=true;const originalProcessVersions=process.versions;/**
5
5
  * Tricks **react-utils** into thinking the test is running within client-side
6
6
  * (browser) environment.
7
7
  */export function mockClientSide(){Object.defineProperty(process,"versions",{value:undefined});}/**
@@ -13,8 +13,8 @@ import"core-js/modules/es.json.stringify.js";/* global document *//* eslint-disa
13
13
  * @return {string}
14
14
  */export function getMockUuid(seed=0){const x=seed.toString(16).padStart(32,"0");return`${x.slice(0,8)}-${x.slice(8,12)}-${x.slice(12,16)}-${x.slice(16,20)}-${x.slice(20)}`;}export function mockAxios(handlers){const axios=jest.requireActual("axios");axios.defaults.adapter=async config=>{for(const handler of handlers){const res=handler(config);if(res){return{config:config,data:null,headers:{},status:200,statusText:"OK",...res};}}// Fallback to the regular network request.
15
15
  let res;try{res=await axios({...config,adapter:["xhr","http","fetch"]});// eslint-disable-next-line no-console
16
- console.warn("Network request has not been mocked for a test.\n\nConfig:\n",config,"\n\nResult:\n",JSON.stringify(res,null,2));}catch(e){// eslint-disable-next-line no-console
17
- console.warn("Network request has not been mocked for a test, and failed.\n\nConfig:\n",config,"\n\nError\n",JSON.stringify(e,null,2));throw e;}return res;};return axios;}/**
16
+ console.warn("Network request has not been mocked for a test.\n\nConfig:\n",config,"\n\nResult:\n",_JSON$stringify(res,null,2));}catch(e){// eslint-disable-next-line no-console
17
+ console.warn("Network request has not been mocked for a test, and failed.\n\nConfig:\n",config,"\n\nError\n",_JSON$stringify(e,null,2));throw e;}return res;};return axios;}/**
18
18
  * Advances mock timers, and mock date by the specified time.
19
19
  * @param {number} time Time step [ms].
20
20
  * @returns {Promise} Wait for this to "jump after" any async code which should
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["mockdate","act","createRoot","expect","jest","render","default","getGlobal","global","IS_REACT_ACT_ENVIRONMENT","originalProcessVersions","process","versions","mockClientSide","Object","defineProperty","value","undefined","unmockClientSide","writable","getMockUuid","seed","x","toString","padStart","slice","mockAxios","handlers","axios","requireActual","defaults","adapter","config","handler","res","data","headers","status","statusText","console","warn","JSON","stringify","e","mockTimer","time","set","Date","now","advanceTimersByTimeAsync","mount","scene","root","element","document","createElement","body","appendChild","destroy","unmount","remove","snapshot","toMatchSnapshot","options","promise","await","Error","Promise","resolve","reject","rejected","then","nodes","asFragment","childNodes","length","error"],"sources":["../../../../../src/shared/utils/jest/index.ts"],"sourcesContent":["/* global document */\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport type {\n AxiosRequestConfig,\n AxiosResponse,\n AxiosStatic,\n InternalAxiosRequestConfig,\n} from 'axios';\n\nimport mockdate from 'mockdate';\nimport { type ReactElement, type ReactNode, act } from 'react';\nimport { type Root, createRoot } from 'react-dom/client';\n\nimport { expect, jest } from '@jest/globals';\nimport { type RenderResult, render } from '@testing-library/react';\n\n/**\n * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)\n * from `react`.\n */\nexport { act };\n\nexport { default as getGlobal } from './global';\n\nglobal.IS_REACT_ACT_ENVIRONMENT = true;\n\nconst originalProcessVersions = process.versions;\n\n/**\n * Tricks **react-utils** into thinking the test is running within client-side\n * (browser) environment.\n */\nexport function mockClientSide(): void {\n Object.defineProperty(process, 'versions', { value: undefined });\n}\n\n/**\n * Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.\n */\nexport function unmockClientSide(): void {\n Object.defineProperty(process, 'versions', {\n value: originalProcessVersions,\n writable: false,\n });\n}\n\n/**\n * Generates a mock UUID, or better said it determenistically transforms given\n * `seed` number into a UUID-formatted string.\n * @param {number} seed\n * @return {string}\n */\nexport function getMockUuid(seed = 0): `${string}-${string}-${string}-${string}-${string}` {\n const x = seed.toString(16).padStart(32, '0');\n return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;\n}\n\nexport type AxiosRequestHandlerT = (\n config: AxiosRequestConfig,\n) => Partial<AxiosResponse> | null | undefined;\n\nexport function mockAxios(handlers: AxiosRequestHandlerT[]): AxiosStatic {\n const axios: AxiosStatic = jest.requireActual('axios');\n\n axios.defaults.adapter = async (\n config: AxiosRequestConfig,\n ): Promise<AxiosResponse> => {\n for (const handler of handlers) {\n const res = handler(config);\n if (res) {\n return {\n config: config as InternalAxiosRequestConfig,\n data: null,\n headers: {},\n status: 200,\n statusText: 'OK',\n ...res,\n };\n }\n }\n\n // Fallback to the regular network request.\n let res: AxiosResponse;\n try {\n res = await axios({ ...config, adapter: ['xhr', 'http', 'fetch'] });\n // eslint-disable-next-line no-console\n console.warn(\n 'Network request has not been mocked for a test.\\n\\nConfig:\\n',\n config,\n '\\n\\nResult:\\n',\n JSON.stringify(res, null, 2),\n );\n } catch (e) {\n // eslint-disable-next-line no-console\n console.warn(\n 'Network request has not been mocked for a test, and failed.\\n\\nConfig:\\n',\n config,\n '\\n\\nError\\n',\n JSON.stringify(e, null, 2),\n );\n throw e;\n }\n\n return res;\n };\n\n return axios;\n}\n\n/**\n * Advances mock timers, and mock date by the specified time.\n * @param {number} time Time step [ms].\n * @returns {Promise} Wait for this to \"jump after\" any async code which should\n * be executed because of the mock time movement.\n */\nexport async function mockTimer(time: number): Promise<void> {\n mockdate.set(time + Date.now());\n await jest.advanceTimersByTimeAsync(time);\n}\n\nexport type MountedSceneT = HTMLElement & {\n destroy: () => void;\n snapshot: () => void;\n};\n\n/**\n * Mounts `scene` to the DOM, and returns the root scene element.\n * @param scene\n * @return Created container DOM element with destroy() function\n * attached.\n */\nexport function mount(scene: ReactNode): MountedSceneT {\n let root: Root;\n const element = document.createElement('div');\n document.body.appendChild(element);\n\n const res: MountedSceneT = (element as unknown) as MountedSceneT;\n res.destroy = () => {\n // NOTE: As it seems @testing-library may reset this flag to false\n // when it is simulating user events.\n global.IS_REACT_ACT_ENVIRONMENT = true;\n\n act(() => {\n root.unmount();\n });\n res.remove();\n };\n\n res.snapshot = () => {\n expect(res).toMatchSnapshot();\n };\n\n // NOTE: As it seems @testing-library may reset this flag to false\n // when it is simulating user events.\n global.IS_REACT_ACT_ENVIRONMENT = true;\n\n act(() => {\n root = createRoot(res);\n root.render(scene);\n });\n return res;\n}\n\n// NOTE: If in future we have additional options here, they should be distributed\n// across two objects, depending whether they are applicable to the sync, or async\n// versions of snapshot(), or both.\ntype AsyncSnapshotOptionsT = {\n await?: Promise<void>;\n};\n\nexport function snapshot(element: ReactElement): RenderResult;\n\nexport async function snapshot(\n element: ReactElement,\n options: AsyncSnapshotOptionsT,\n): Promise<RenderResult>;\n\nexport function snapshot(\n element: ReactElement,\n options?: AsyncSnapshotOptionsT,\n): Promise<RenderResult> | RenderResult {\n let res: RenderResult | undefined;\n\n // TODO: Just adding async to the actor function breaks stuff, as it makes\n // act() asynchronous no matter the `options.await` value, thus breaking all\n // calls that do not await for snapshot() result... thus... perhaps we need\n // to have a more complex typing to ensure it all works as intended in all\n // cases, and while being correctly enforced by TypeScript.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const promise = act(() => {\n res = render(element);\n return options?.await;\n });\n\n if (res === undefined) throw Error('Render failed');\n if (options?.await) {\n // BEWARE: Although `promise` is thenable (i.e. it has .then() method),\n // it is not an instance of proper Promise class, and returning it directly\n // breaks some async logic in Jest test or React test functions... thus, we\n // wrap it into Promise instance here.\n return new Promise((resolve, reject) => {\n let rejected = false;\n\n // BEWARE: The \"promise\" returned by act() does not behave as a regular\n // Promise instance:\n // 1. In case of errors its .then() method both calls its \"reject\"\n // callback (first), and then its \"resolve\" callback second.\n // 2. It errors out if a rendering error happens, and there is no\n // \"reject\" argument provided.\n void promise.then(() => {\n if (!rejected) {\n // TODO: These lines are the same as the lines below for sync variant of\n // the function. We should split and reuse them in both places.\n const nodes = res!.asFragment().childNodes;\n expect(nodes.length > 1 ? [...nodes] : nodes[0]).toMatchSnapshot();\n resolve(res!);\n }\n }, (error: unknown) => {\n rejected = true;\n\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n reject(error);\n });\n });\n }\n\n const nodes = res.asFragment().childNodes;\n expect(nodes.length > 1 ? [...nodes] : nodes[0]).toMatchSnapshot();\n return res;\n}\n"],"mappings":"6CAAA,qBACA,sDASA,MAAO,CAAAA,QAAQ,KAAM,UAAU,CAC/B,OAA4CC,GAAG,KAAQ,OAAO,CAC9D,OAAoBC,UAAU,KAAQ,kBAAkB,CAExD,OAASC,MAAM,CAAEC,IAAI,KAAQ,eAAe,CAC5C,OAA4BC,MAAM,KAAQ,wBAAwB,CAElE;AACA;AACA;AACA,GACA,OAASJ,GAAG,EAEZ,OAASK,OAAO,GAAI,CAAAC,SAAS,gBAE7BC,MAAM,CAACC,wBAAwB,CAAG,IAAI,CAEtC,KAAM,CAAAC,uBAAuB,CAAGC,OAAO,CAACC,QAAQ,CAEhD;AACA;AACA;AACA,GACA,MAAO,SAAS,CAAAC,cAAcA,CAAA,CAAS,CACrCC,MAAM,CAACC,cAAc,CAACJ,OAAO,CAAE,UAAU,CAAE,CAAEK,KAAK,CAAE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,GAAGH,KAAK,CAAC,CAAGA,KAAK,CAAC,CAAC,CAAC,CAAC,CAACV,eAAe,CAAC,CAAC,CAClEM,OAAO,CAAClC,GAAI,CAAC,CACf,CACF,CAAC,CAAG0C,KAAc,EAAK,CACrBN,QAAQ,CAAG,IAAI,CAEf;AACAD,MAAM,CAACO,KAAK,CAAC,CACf,CAAC,CAAC,CACJ,CAAC,CAAC,CACJ,CAEA,KAAM,CAAAJ,KAAK,CAAGtC,GAAG,CAACuC,UAAU,CAAC,CAAC,CAACC,UAAU,CACzCvE,MAAM,CAACqE,KAAK,CAACG,MAAM,CAAG,CAAC,CAAG,CAAC,GAAGH,KAAK,CAAC,CAAGA,KAAK,CAAC,CAAC,CAAC,CAAC,CAACV,eAAe,CAAC,CAAC,CAClE,MAAO,CAAA5B,GAAG,CACZ","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/shared/utils/jest/index.ts"],"sourcesContent":["/* global document */\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport type {\n AxiosRequestConfig,\n AxiosResponse,\n AxiosStatic,\n InternalAxiosRequestConfig,\n} from 'axios';\n\nimport mockdate from 'mockdate';\nimport { type ReactElement, type ReactNode, act } from 'react';\nimport { type Root, createRoot } from 'react-dom/client';\n\nimport { expect, jest } from '@jest/globals';\nimport { type RenderResult, render } from '@testing-library/react';\n\n/**\n * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)\n * from `react`.\n */\nexport { act };\n\nexport { default as getGlobal } from './global';\n\nglobal.IS_REACT_ACT_ENVIRONMENT = true;\n\nconst originalProcessVersions = process.versions;\n\n/**\n * Tricks **react-utils** into thinking the test is running within client-side\n * (browser) environment.\n */\nexport function mockClientSide(): void {\n Object.defineProperty(process, 'versions', { value: undefined });\n}\n\n/**\n * Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.\n */\nexport function unmockClientSide(): void {\n Object.defineProperty(process, 'versions', {\n value: originalProcessVersions,\n writable: false,\n });\n}\n\n/**\n * Generates a mock UUID, or better said it determenistically transforms given\n * `seed` number into a UUID-formatted string.\n * @param {number} seed\n * @return {string}\n */\nexport function getMockUuid(seed = 0): `${string}-${string}-${string}-${string}-${string}` {\n const x = seed.toString(16).padStart(32, '0');\n return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;\n}\n\nexport type AxiosRequestHandlerT = (\n config: AxiosRequestConfig,\n) => Partial<AxiosResponse> | null | undefined;\n\nexport function mockAxios(handlers: AxiosRequestHandlerT[]): AxiosStatic {\n const axios: AxiosStatic = jest.requireActual('axios');\n\n axios.defaults.adapter = async (\n config: AxiosRequestConfig,\n ): Promise<AxiosResponse> => {\n for (const handler of handlers) {\n const res = handler(config);\n if (res) {\n return {\n config: config as InternalAxiosRequestConfig,\n data: null,\n headers: {},\n status: 200,\n statusText: 'OK',\n ...res,\n };\n }\n }\n\n // Fallback to the regular network request.\n let res: AxiosResponse;\n try {\n res = await axios({ ...config, adapter: ['xhr', 'http', 'fetch'] });\n // eslint-disable-next-line no-console\n console.warn(\n 'Network request has not been mocked for a test.\\n\\nConfig:\\n',\n config,\n '\\n\\nResult:\\n',\n JSON.stringify(res, null, 2),\n );\n } catch (e) {\n // eslint-disable-next-line no-console\n console.warn(\n 'Network request has not been mocked for a test, and failed.\\n\\nConfig:\\n',\n config,\n '\\n\\nError\\n',\n JSON.stringify(e, null, 2),\n );\n throw e;\n }\n\n return res;\n };\n\n return axios;\n}\n\n/**\n * Advances mock timers, and mock date by the specified time.\n * @param {number} time Time step [ms].\n * @returns {Promise} Wait for this to \"jump after\" any async code which should\n * be executed because of the mock time movement.\n */\nexport async function mockTimer(time: number): Promise<void> {\n mockdate.set(time + Date.now());\n await jest.advanceTimersByTimeAsync(time);\n}\n\nexport type MountedSceneT = HTMLElement & {\n destroy: () => void;\n snapshot: () => void;\n};\n\n/**\n * Mounts `scene` to the DOM, and returns the root scene element.\n * @param scene\n * @return Created container DOM element with destroy() function\n * attached.\n */\nexport function mount(scene: ReactNode): MountedSceneT {\n let root: Root;\n const element = document.createElement('div');\n document.body.appendChild(element);\n\n const res: MountedSceneT = (element as unknown) as MountedSceneT;\n res.destroy = () => {\n // NOTE: As it seems @testing-library may reset this flag to false\n // when it is simulating user events.\n global.IS_REACT_ACT_ENVIRONMENT = true;\n\n act(() => {\n root.unmount();\n });\n res.remove();\n };\n\n res.snapshot = () => {\n expect(res).toMatchSnapshot();\n };\n\n // NOTE: As it seems @testing-library may reset this flag to false\n // when it is simulating user events.\n global.IS_REACT_ACT_ENVIRONMENT = true;\n\n act(() => {\n root = createRoot(res);\n root.render(scene);\n });\n return res;\n}\n\n// NOTE: If in future we have additional options here, they should be distributed\n// across two objects, depending whether they are applicable to the sync, or async\n// versions of snapshot(), or both.\ntype AsyncSnapshotOptionsT = {\n await?: Promise<void>;\n};\n\nexport function snapshot(element: ReactElement): RenderResult;\n\nexport async function snapshot(\n element: ReactElement,\n options: AsyncSnapshotOptionsT,\n): Promise<RenderResult>;\n\nexport function snapshot(\n element: ReactElement,\n options?: AsyncSnapshotOptionsT,\n): Promise<RenderResult> | RenderResult {\n let res: RenderResult | undefined;\n\n // TODO: Just adding async to the actor function breaks stuff, as it makes\n // act() asynchronous no matter the `options.await` value, thus breaking all\n // calls that do not await for snapshot() result... thus... perhaps we need\n // to have a more complex typing to ensure it all works as intended in all\n // cases, and while being correctly enforced by TypeScript.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const promise = act(() => {\n res = render(element);\n return options?.await;\n });\n\n if (res === undefined) throw Error('Render failed');\n if (options?.await) {\n // BEWARE: Although `promise` is thenable (i.e. it has .then() method),\n // it is not an instance of proper Promise class, and returning it directly\n // breaks some async logic in Jest test or React test functions... thus, we\n // wrap it into Promise instance here.\n return new Promise((resolve, reject) => {\n let rejected = false;\n\n // BEWARE: The \"promise\" returned by act() does not behave as a regular\n // Promise instance:\n // 1. In case of errors its .then() method both calls its \"reject\"\n // callback (first), and then its \"resolve\" callback second.\n // 2. It errors out if a rendering error happens, and there is no\n // \"reject\" argument provided.\n void promise.then(() => {\n if (!rejected) {\n // TODO: These lines are the same as the lines below for sync variant of\n // the function. We should split and reuse them in both places.\n const nodes = res!.asFragment().childNodes;\n expect(nodes.length > 1 ? [...nodes] : nodes[0]).toMatchSnapshot();\n resolve(res!);\n }\n }, (error: unknown) => {\n rejected = true;\n\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n reject(error);\n });\n });\n }\n\n const nodes = res.asFragment().childNodes;\n expect(nodes.length > 1 ? [...nodes] : nodes[0]).toMatchSnapshot();\n return res;\n}\n"],"mappings":"mEAAA,qBACA,sDASA,MAAO,SAAQ,KAAM,UAAU,CAC/B,OAA4C,GAAG,KAAQ,OAAO,CAC9D,OAAoB,UAAU,KAAQ,kBAAkB,CAExD,OAAS,MAAM,CAAE,IAAI,KAAQ,eAAe,CAC5C,OAA4B,MAAM,KAAQ,wBAAwB,CAElE;AACA;AACA;AACA,GACA,OAAS,GAAG,EAAG,OAEN,OAAO,GAAI,UAAS,mBAE7B,MAAM,CAAC,wBAAwB,CAAG,IAAI,CAEtC,KAAM,wBAAuB,CAAG,OAAO,CAAC,QAAQ,CAEhD;AACA;AACA;AACA,GACA,MAAO,SAAS,eAAc,EAAS,CACrC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAE,UAAU,CAAE,CAAE,KAAK,CAAE,SAAU,CAAC,CAAC,CAClE,CAEA;AACA;AACA,GACA,MAAO,SAAS,iBAAgB,EAAS,CACvC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAE,UAAU,CAAE,CACzC,KAAK,CAAE,uBAAuB,CAC9B,QAAQ,CAAE,KACZ,CAAC,CAAC,CACJ,CAEA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,SAAS,YAAW,CAAC,IAAI,CAAG,CAAC,CAAuD,CACzF,KAAM,EAAC,CAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAA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