@dr.pogodin/react-utils 1.46.2 → 1.47.0-alpha.11

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 (332) hide show
  1. package/babel.config.js +1 -0
  2. package/babel.libweb.config.js +16 -0
  3. package/babel.module.config.js +11 -0
  4. package/bin/build.js +21 -11
  5. package/bin/setup.js +11 -9
  6. package/build/development/client/getInj.js +57 -44
  7. package/build/development/client/getInj.js.map +1 -1
  8. package/build/development/client/index.js +15 -21
  9. package/build/development/client/index.js.map +1 -1
  10. package/build/development/client/init.js +2 -6
  11. package/build/development/client/init.js.map +1 -1
  12. package/build/development/index.js +3 -177
  13. package/build/development/index.js.map +1 -1
  14. package/build/development/server/Cache.js +1 -8
  15. package/build/development/server/Cache.js.map +1 -1
  16. package/build/development/server/index.js +22 -45
  17. package/build/development/server/index.js.map +1 -1
  18. package/build/development/server/renderer.js +84 -86
  19. package/build/development/server/renderer.js.map +1 -1
  20. package/build/development/server/server.js +58 -60
  21. package/build/development/server/server.js.map +1 -1
  22. package/build/development/server/utils/errors.js +8 -31
  23. package/build/development/server/utils/errors.js.map +1 -1
  24. package/build/development/server/utils/index.js +2 -9
  25. package/build/development/server/utils/index.js.map +1 -1
  26. package/build/development/shared/components/Button/index.js +15 -22
  27. package/build/development/shared/components/Button/index.js.map +1 -1
  28. package/build/development/shared/components/Checkbox/index.js +14 -21
  29. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  30. package/build/development/shared/components/GenericLink/index.js +9 -11
  31. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  32. package/build/development/shared/components/Input/index.js +21 -27
  33. package/build/development/shared/components/Input/index.js.map +1 -1
  34. package/build/development/shared/components/Link.js +6 -13
  35. package/build/development/shared/components/Link.js.map +1 -1
  36. package/build/development/shared/components/Modal/index.js +24 -28
  37. package/build/development/shared/components/Modal/index.js.map +1 -1
  38. package/build/development/shared/components/NavLink.js +6 -13
  39. package/build/development/shared/components/NavLink.js.map +1 -1
  40. package/build/development/shared/components/PageLayout/index.js +13 -20
  41. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  42. package/build/development/shared/components/TextArea/index.js +28 -31
  43. package/build/development/shared/components/TextArea/index.js.map +1 -1
  44. package/build/development/shared/components/Throbber/index.js +13 -20
  45. package/build/development/shared/components/Throbber/index.js.map +1 -1
  46. package/build/development/shared/components/WithTooltip/Tooltip.js +13 -18
  47. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  48. package/build/development/shared/components/WithTooltip/index.js +23 -30
  49. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  50. package/build/development/shared/components/YouTubeVideo/index.js +19 -26
  51. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  52. package/build/development/shared/components/index.js +16 -130
  53. package/build/development/shared/components/index.js.map +1 -1
  54. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +19 -20
  55. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  56. package/build/development/shared/components/selectors/CustomDropdown/index.js +35 -39
  57. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  58. package/build/development/shared/components/selectors/NativeDropdown/index.js +31 -31
  59. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  60. package/build/development/shared/components/selectors/Switch/index.js +19 -24
  61. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  62. package/build/development/shared/components/selectors/common.js +1 -7
  63. package/build/development/shared/components/selectors/common.js.map +1 -1
  64. package/build/development/shared/components/selectors/index.js +3 -27
  65. package/build/development/shared/components/selectors/index.js.map +1 -1
  66. package/build/development/shared/utils/config.js +40 -21
  67. package/build/development/shared/utils/config.js.map +1 -1
  68. package/build/development/shared/utils/globalState.js +3 -8
  69. package/build/development/shared/utils/globalState.js.map +1 -1
  70. package/build/development/shared/utils/index.js +12 -89
  71. package/build/development/shared/utils/index.js.map +1 -1
  72. package/build/development/shared/utils/isomorphy/buildInfo.js +2 -9
  73. package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
  74. package/build/development/shared/utils/isomorphy/environment-check.js +2 -8
  75. package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
  76. package/build/development/shared/utils/isomorphy/index.js +7 -32
  77. package/build/development/shared/utils/isomorphy/index.js.map +1 -1
  78. package/build/development/shared/utils/jest/E2eSsrEnv.js +34 -37
  79. package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  80. package/build/development/shared/utils/jest/global.js +1 -7
  81. package/build/development/shared/utils/jest/global.js.map +1 -1
  82. package/build/development/shared/utils/jest/index.js +20 -44
  83. package/build/development/shared/utils/jest/index.js.map +1 -1
  84. package/build/development/shared/utils/splitComponent.js +54 -45
  85. package/build/development/shared/utils/splitComponent.js.map +1 -1
  86. package/build/development/shared/utils/time.js +22 -31
  87. package/build/development/shared/utils/time.js.map +1 -1
  88. package/build/development/shared/utils/webpack.js +17 -16
  89. package/build/development/shared/utils/webpack.js.map +1 -1
  90. package/build/production/client/getInj.js +13 -11
  91. package/build/production/client/getInj.js.map +1 -1
  92. package/build/production/client/index.js +3 -3
  93. package/build/production/client/index.js.map +1 -1
  94. package/build/production/client/init.js +2 -2
  95. package/build/production/client/init.js.map +1 -1
  96. package/build/production/index.js +2 -3
  97. package/build/production/index.js.map +1 -1
  98. package/build/production/server/Cache.js +3 -3
  99. package/build/production/server/Cache.js.map +1 -1
  100. package/build/production/server/index.js +8 -8
  101. package/build/production/server/index.js.map +1 -1
  102. package/build/production/server/renderer.js +24 -25
  103. package/build/production/server/renderer.js.map +1 -1
  104. package/build/production/server/server.js +9 -11
  105. package/build/production/server/server.js.map +1 -1
  106. package/build/production/server/utils/errors.js +9 -9
  107. package/build/production/server/utils/errors.js.map +1 -1
  108. package/build/production/server/utils/index.js +2 -1
  109. package/build/production/server/utils/index.js.map +1 -1
  110. package/build/production/shared/components/Button/index.js +4 -4
  111. package/build/production/shared/components/Button/index.js.map +1 -1
  112. package/build/production/shared/components/Checkbox/index.js +1 -1
  113. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  114. package/build/production/shared/components/GenericLink/index.js +4 -4
  115. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  116. package/build/production/shared/components/Input/index.js +5 -5
  117. package/build/production/shared/components/Input/index.js.map +1 -1
  118. package/build/production/shared/components/Link.js +3 -3
  119. package/build/production/shared/components/Link.js.map +1 -1
  120. package/build/production/shared/components/Modal/index.js +7 -7
  121. package/build/production/shared/components/Modal/index.js.map +1 -1
  122. package/build/production/shared/components/NavLink.js +2 -2
  123. package/build/production/shared/components/NavLink.js.map +1 -1
  124. package/build/production/shared/components/PageLayout/index.js +2 -2
  125. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  126. package/build/production/shared/components/TextArea/index.js +5 -5
  127. package/build/production/shared/components/TextArea/index.js.map +1 -1
  128. package/build/production/shared/components/Throbber/index.js +2 -2
  129. package/build/production/shared/components/Throbber/index.js.map +1 -1
  130. package/build/production/shared/components/WithTooltip/Tooltip.js +4 -4
  131. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  132. package/build/production/shared/components/WithTooltip/index.js +4 -4
  133. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  134. package/build/production/shared/components/YouTubeVideo/index.js +4 -4
  135. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  136. package/build/production/shared/components/index.js +3 -1
  137. package/build/production/shared/components/index.js.map +1 -1
  138. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +2 -2
  139. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  140. package/build/production/shared/components/selectors/CustomDropdown/index.js +2 -2
  141. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  142. package/build/production/shared/components/selectors/NativeDropdown/index.js +4 -4
  143. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  144. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  145. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  146. package/build/production/shared/components/selectors/common.js +2 -2
  147. package/build/production/shared/components/selectors/common.js.map +1 -1
  148. package/build/production/shared/components/selectors/index.js +1 -1
  149. package/build/production/shared/components/selectors/index.js.map +1 -1
  150. package/build/production/shared/utils/config.js +8 -6
  151. package/build/production/shared/utils/config.js.map +1 -1
  152. package/build/production/shared/utils/globalState.js +2 -2
  153. package/build/production/shared/utils/globalState.js.map +1 -1
  154. package/build/production/shared/utils/index.js +1 -1
  155. package/build/production/shared/utils/index.js.map +1 -1
  156. package/build/production/shared/utils/isomorphy/buildInfo.js +3 -3
  157. package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
  158. package/build/production/shared/utils/isomorphy/environment-check.js +3 -3
  159. package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
  160. package/build/production/shared/utils/isomorphy/index.js +4 -4
  161. package/build/production/shared/utils/isomorphy/index.js.map +1 -1
  162. package/build/production/shared/utils/jest/E2eSsrEnv.js +16 -15
  163. package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  164. package/build/production/shared/utils/jest/global.js +1 -1
  165. package/build/production/shared/utils/jest/global.js.map +1 -1
  166. package/build/production/shared/utils/jest/index.js +11 -11
  167. package/build/production/shared/utils/jest/index.js.map +1 -1
  168. package/build/production/shared/utils/splitComponent.js +11 -22
  169. package/build/production/shared/utils/splitComponent.js.map +1 -1
  170. package/build/production/shared/utils/time.js +3 -3
  171. package/build/production/shared/utils/time.js.map +1 -1
  172. package/build/production/shared/utils/webpack.js +6 -6
  173. package/build/production/shared/utils/webpack.js.map +1 -1
  174. package/build/types-code/client/getInj.d.ts +1 -2
  175. package/build/types-code/client/index.d.ts +1 -1
  176. package/build/types-code/index.d.ts +1 -7
  177. package/build/types-code/server/index.d.ts +6 -11
  178. package/build/types-code/server/utils/index.d.ts +1 -1
  179. package/build/types-code/shared/utils/config.d.ts +4 -2
  180. package/build/types-code/shared/utils/index.d.ts +2 -2
  181. package/build/types-code/shared/utils/splitComponent.d.ts +6 -4
  182. package/build/web/client/getInj.js +65 -0
  183. package/build/web/client/getInj.js.map +1 -0
  184. package/{src/client/index.tsx → build/web/client/index.js} +13 -24
  185. package/build/web/client/index.js.map +1 -0
  186. package/{src/client/init.ts → build/web/client/init.js} +9 -14
  187. package/build/web/client/init.js.map +1 -0
  188. package/build/web/index.js +11 -0
  189. package/build/web/index.js.map +1 -0
  190. package/{src/server/Cache.ts → build/web/server/Cache.js} +15 -22
  191. package/build/web/server/Cache.js.map +1 -0
  192. package/{src/server/index.ts → build/web/server/index.js} +32 -81
  193. package/build/web/server/index.js.map +1 -0
  194. package/{src/server/renderer.tsx → build/web/server/renderer.js} +188 -333
  195. package/build/web/server/renderer.js.map +1 -0
  196. package/{src/server/server.ts → build/web/server/server.js} +82 -182
  197. package/build/web/server/server.js.map +1 -0
  198. package/{src/server/utils/errors.ts → build/web/server/utils/errors.js} +6 -25
  199. package/build/web/server/utils/errors.js.map +1 -0
  200. package/build/web/server/utils/index.js +4 -0
  201. package/build/web/server/utils/index.js.map +1 -0
  202. package/build/web/shared/components/Button/index.js +90 -0
  203. package/build/web/shared/components/Button/index.js.map +1 -0
  204. package/build/web/shared/components/Checkbox/index.js +35 -0
  205. package/build/web/shared/components/Checkbox/index.js.map +1 -0
  206. package/{src/shared/components/GenericLink/index.tsx → build/web/shared/components/GenericLink/index.js} +44 -78
  207. package/build/web/shared/components/GenericLink/index.js.map +1 -0
  208. package/build/web/shared/components/Input/index.js +71 -0
  209. package/build/web/shared/components/Input/index.js.map +1 -0
  210. package/build/web/shared/components/Link.js +20 -0
  211. package/build/web/shared/components/Link.js.map +1 -0
  212. package/{src → build/web}/shared/components/Modal/base-theme.scss +1 -1
  213. package/build/web/shared/components/Modal/index.js +128 -0
  214. package/build/web/shared/components/Modal/index.js.map +1 -0
  215. package/build/web/shared/components/NavLink.js +13 -0
  216. package/build/web/shared/components/NavLink.js.map +1 -0
  217. package/{src → build/web}/shared/components/PageLayout/base-theme.scss +1 -1
  218. package/{src/shared/components/PageLayout/index.tsx → build/web/shared/components/PageLayout/index.js} +20 -33
  219. package/build/web/shared/components/PageLayout/index.js.map +1 -0
  220. package/build/web/shared/components/TextArea/index.js +106 -0
  221. package/build/web/shared/components/TextArea/index.js.map +1 -0
  222. package/build/web/shared/components/Throbber/index.js +26 -0
  223. package/build/web/shared/components/Throbber/index.js.map +1 -0
  224. package/{src/shared/components/WithTooltip/Tooltip.tsx → build/web/shared/components/WithTooltip/Tooltip.js} +61 -109
  225. package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -0
  226. package/build/web/shared/components/WithTooltip/index.js +117 -0
  227. package/build/web/shared/components/WithTooltip/index.js.map +1 -0
  228. package/{src/shared/components/YouTubeVideo/index.tsx → build/web/shared/components/YouTubeVideo/index.js} +23 -40
  229. package/build/web/shared/components/YouTubeVideo/index.js.map +1 -0
  230. package/build/web/shared/components/index.js +18 -0
  231. package/build/web/shared/components/index.js.map +1 -0
  232. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +82 -0
  233. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -0
  234. package/{src/shared/components/selectors/CustomDropdown/index.tsx → build/web/shared/components/selectors/CustomDropdown/index.js} +56 -80
  235. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -0
  236. package/{src/shared/components/selectors/NativeDropdown/index.tsx → build/web/shared/components/selectors/NativeDropdown/index.js} +39 -44
  237. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -0
  238. package/build/web/shared/components/selectors/Switch/index.js +50 -0
  239. package/build/web/shared/components/selectors/Switch/index.js.map +1 -0
  240. package/build/web/shared/components/selectors/common.js +12 -0
  241. package/build/web/shared/components/selectors/common.js.map +1 -0
  242. package/build/web/shared/components/selectors/index.js +4 -0
  243. package/build/web/shared/components/selectors/index.js.map +1 -0
  244. package/build/web/shared/utils/config.js +45 -0
  245. package/build/web/shared/utils/config.js.map +1 -0
  246. package/build/web/shared/utils/globalState.js +15 -0
  247. package/build/web/shared/utils/globalState.js.map +1 -0
  248. package/build/web/shared/utils/index.js +13 -0
  249. package/build/web/shared/utils/index.js.map +1 -0
  250. package/{src/shared/utils/isomorphy/buildInfo.ts → build/web/shared/utils/isomorphy/buildInfo.js} +4 -10
  251. package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -0
  252. package/build/web/shared/utils/isomorphy/environment-check.js +17 -0
  253. package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -0
  254. package/{src/shared/utils/isomorphy/index.ts → build/web/shared/utils/isomorphy/index.js} +6 -6
  255. package/build/web/shared/utils/isomorphy/index.js.map +1 -0
  256. package/{src/shared/utils/jest/E2eSsrEnv.ts → build/web/shared/utils/jest/E2eSsrEnv.js} +73 -140
  257. package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -0
  258. package/build/web/shared/utils/jest/global.js +4 -0
  259. package/build/web/shared/utils/jest/global.js.map +1 -0
  260. package/{src/shared/utils/jest/index.ts → build/web/shared/utils/jest/index.js} +33 -83
  261. package/build/web/shared/utils/jest/index.js.map +1 -0
  262. package/{src/shared/utils/splitComponent.tsx → build/web/shared/utils/splitComponent.js} +77 -124
  263. package/build/web/shared/utils/splitComponent.js.map +1 -0
  264. package/{src/shared/utils/time.ts → build/web/shared/utils/time.js} +21 -37
  265. package/build/web/shared/utils/time.js.map +1 -0
  266. package/build/web/shared/utils/webpack.js +67 -0
  267. package/build/web/shared/utils/webpack.js.map +1 -0
  268. package/config/babel/node-ssr.js +12 -3
  269. package/config/babel/webpack.js +6 -1
  270. package/config/jest/default.js +8 -2
  271. package/config/jest/setup.js +8 -1
  272. package/config/webpack/app-base.js +25 -14
  273. package/config/webpack/app-development.js +2 -2
  274. package/config/webpack/lib-base.js +1 -2
  275. package/package.json +41 -42
  276. package/types.d.ts +1 -6
  277. package/build/development/__chunk_groups__.json +0 -6
  278. package/build/development/style.css +0 -909
  279. package/build/development/web.bundle.js +0 -752
  280. package/build/production/__chunk_groups__.json +0 -6
  281. package/build/production/style.css +0 -2
  282. package/build/production/style.css.map +0 -1
  283. package/build/production/web.bundle.js +0 -3
  284. package/build/production/web.bundle.js.LICENSE.txt +0 -9
  285. package/build/production/web.bundle.js.map +0 -1
  286. package/dev-styles.js +0 -1
  287. package/node-entry.js +0 -15
  288. package/null.js +0 -1
  289. package/prod-styles.js +0 -1
  290. package/src/client/getInj.ts +0 -51
  291. package/src/index.ts +0 -73
  292. package/src/server/utils/index.ts +0 -3
  293. package/src/shared/components/Button/index.tsx +0 -130
  294. package/src/shared/components/Checkbox/index.tsx +0 -53
  295. package/src/shared/components/Input/index.tsx +0 -96
  296. package/src/shared/components/Link.tsx +0 -25
  297. package/src/shared/components/Modal/index.tsx +0 -177
  298. package/src/shared/components/NavLink.tsx +0 -18
  299. package/src/shared/components/TextArea/index.tsx +0 -139
  300. package/src/shared/components/Throbber/index.tsx +0 -28
  301. package/src/shared/components/WithTooltip/index.tsx +0 -186
  302. package/src/shared/components/index.ts +0 -20
  303. package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +0 -124
  304. package/src/shared/components/selectors/Switch/index.tsx +0 -74
  305. package/src/shared/components/selectors/common.ts +0 -57
  306. package/src/shared/components/selectors/index.ts +0 -8
  307. package/src/shared/utils/config.ts +0 -28
  308. package/src/shared/utils/globalState.ts +0 -44
  309. package/src/shared/utils/index.ts +0 -45
  310. package/src/shared/utils/isomorphy/environment-check.ts +0 -18
  311. package/src/shared/utils/jest/global.ts +0 -17
  312. package/src/shared/utils/webpack.ts +0 -74
  313. /package/{src → build/web}/shared/components/Button/style.scss +0 -0
  314. /package/{src → build/web}/shared/components/Checkbox/theme.scss +0 -0
  315. /package/{src → build/web}/shared/components/GenericLink/style.scss +0 -0
  316. /package/{src → build/web}/shared/components/Input/theme.scss +0 -0
  317. /package/{src → build/web}/shared/components/Modal/styles.scss +0 -0
  318. /package/{src → build/web}/shared/components/TextArea/style.scss +0 -0
  319. /package/{src → build/web}/shared/components/Throbber/theme.scss +0 -0
  320. /package/{src → build/web}/shared/components/WithTooltip/default-theme.scss +0 -0
  321. /package/{src → build/web}/shared/components/YouTubeVideo/base.scss +0 -0
  322. /package/{src → build/web}/shared/components/YouTubeVideo/throbber.scss +0 -0
  323. /package/{src → build/web}/shared/components/selectors/CustomDropdown/Options/style.scss +0 -0
  324. /package/{src → build/web}/shared/components/selectors/CustomDropdown/theme.scss +0 -0
  325. /package/{src → build/web}/shared/components/selectors/NativeDropdown/theme.scss +0 -0
  326. /package/{src → build/web}/shared/components/selectors/Switch/theme.scss +0 -0
  327. /package/{src → build/web}/styles/_global/reset.css +0 -0
  328. /package/{src → build/web}/styles/_mixins/fonts.scss +0 -0
  329. /package/{src → build/web}/styles/_mixins/media.scss +0 -0
  330. /package/{src → build/web}/styles/_mixins/typography.scss +0 -0
  331. /package/{src → build/web}/styles/global.scss +0 -0
  332. /package/{src → build/web}/styles/mixins.scss +0 -0
@@ -1,3 +1,5 @@
1
+ import "core-js/modules/es.iterator.constructor.js";
2
+ import "core-js/modules/es.iterator.for-each.js";
1
3
  /**
2
4
  * Jest environment for end-to-end SSR and client-side testing. It relies on
3
5
  * the standard react-utils mechanics to execute SSR of given scene, and also
@@ -17,72 +19,42 @@
17
19
  // TODO: We need to add correct typing for environment options.
18
20
 
19
21
  import path from 'node:path';
20
-
21
- import type { Request, Response } from 'express';
22
- import { defaults, noop, set } from 'lodash';
23
- import type { ReactNode } from 'react';
24
-
22
+ import { defaults, set } from 'lodash-es';
25
23
  // As this environment is a part of the Jest testing utils,
26
24
  // we assume development dependencies are available when it is used.
27
25
  /* eslint-disable import/no-extraneous-dependencies */
28
26
  import register from '@babel/register/experimental-worker';
29
-
30
27
  import JsdomEnv from 'jest-environment-jsdom';
31
28
  import { Volume, createFsFromVolume } from 'memfs';
32
- import webpack, { type Configuration } from 'webpack';
29
+ import webpack from 'webpack';
33
30
  /* eslint-enable import/no-extraneous-dependencies */
34
31
 
35
- import type {
36
- EnvironmentContext,
37
- JestEnvironmentConfig,
38
- } from '@jest/environment';
39
-
40
- import ssrFactory from 'server/renderer';
41
-
42
- import { setBuildInfo } from '../isomorphy/buildInfo';
43
-
32
+ import ssrFactory from "../../../server/renderer";
33
+ import { setBuildInfo } from "../isomorphy/buildInfo";
34
+ function noop() {
35
+ // NOOP
36
+ }
44
37
  export default class E2eSsrEnv extends JsdomEnv {
45
- pragmas: Record<string, string | string[]>;
46
-
47
- ssrRequest: object;
48
-
49
- rootDir: string;
50
-
51
- testFolder: string;
52
-
53
- withSsr: boolean;
54
-
55
- webpackStats?: webpack.StatsCompilation;
56
-
57
38
  /**
58
39
  * Loads Webpack config, and exposes it to the environment via global
59
40
  * webpackConfig object.
60
41
  */
61
- private loadWebpackConfig() {
62
- const optionsString = this.pragmas['webpack-config-options'] as string;
63
-
64
- const options = (optionsString ? JSON.parse(optionsString) : {}) as
65
- webpack.Configuration;
66
-
42
+ loadWebpackConfig() {
43
+ const optionsString = this.pragmas['webpack-config-options'];
44
+ const options = optionsString ? JSON.parse(optionsString) : {};
67
45
  defaults(options, {
68
46
  context: this.testFolder,
69
- fs: this.global.webpackOutputFs,
47
+ fs: this.global.webpackOutputFs
70
48
  });
71
-
72
- const factoryPath = this.pragmas['webpack-config-factory'] as string;
49
+ const factoryPath = this.pragmas['webpack-config-factory'];
73
50
  // eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-require-imports
74
- let factory = require(path.resolve(this.rootDir, factoryPath)) as
75
- (((ops: Configuration) => Configuration) | {
76
- default: (ops: Configuration) => Configuration;
77
- });
51
+ let factory = require(path.resolve(this.rootDir, factoryPath));
78
52
  factory = 'default' in factory ? factory.default : factory;
79
-
80
53
  this.global.webpackConfig = factory(options);
81
-
82
54
  const fs = this.global.webpackOutputFs;
83
55
  let buildInfo = `${options.context}/.build-info`;
84
56
  if (fs.existsSync(buildInfo)) {
85
- buildInfo = fs.readFileSync(buildInfo, 'utf8') as string;
57
+ buildInfo = fs.readFileSync(buildInfo, 'utf8');
86
58
  this.global.buildInfo = JSON.parse(buildInfo);
87
59
  }
88
60
  }
@@ -91,9 +63,8 @@ export default class E2eSsrEnv extends JsdomEnv {
91
63
  * Executes Webpack build.
92
64
  * @return {Promise}
93
65
  */
94
- async runWebpack(): Promise<void> {
66
+ async runWebpack() {
95
67
  this.loadWebpackConfig();
96
-
97
68
  if (!this.global.webpackConfig) throw Error('Failed to load Webpack config');
98
69
  const compiler = webpack(this.global.webpackConfig);
99
70
  if (!compiler) throw Error('Failed to construct Webpack compiler');
@@ -101,10 +72,8 @@ export default class E2eSsrEnv extends JsdomEnv {
101
72
  // TODO: The "as typeof compiler.outputFileSystem" piece below is
102
73
  // a workaround for the Webpack regression:
103
74
  // https://github.com/webpack/webpack/issues/18242
104
- compiler.outputFileSystem = this.global.webpackOutputFs as
105
- typeof compiler.outputFileSystem;
106
-
107
- return new Promise<void>((done, fail) => {
75
+ compiler.outputFileSystem = this.global.webpackOutputFs;
76
+ return new Promise((done, fail) => {
108
77
  compiler.run((err, stats) => {
109
78
  if (err) fail(err);
110
79
  if (stats?.hasErrors()) {
@@ -112,125 +81,92 @@ export default class E2eSsrEnv extends JsdomEnv {
112
81
  console.error(stats.toJson().errors);
113
82
  fail(Error('Webpack compilation failed'));
114
83
  }
115
-
116
84
  this.global.webpackStats = stats?.toJson();
117
85
 
118
86
  // Keeps reference to the raw Webpack stats object, which should be
119
87
  // explicitly passed to the server-side renderer alongside the request,
120
88
  // so that it can to pick up asset paths for different named chunks.
121
89
  this.webpackStats = stats;
122
-
123
90
  done();
124
91
  });
125
92
  });
126
93
  }
127
-
128
- async runSsr(): Promise<void> {
129
- const optionsString = this.pragmas['ssr-options'] as string;
130
- const options = optionsString
131
- ? JSON.parse(optionsString) as Record<string, unknown>
132
- : {};
94
+ async runSsr() {
95
+ const optionsString = this.pragmas['ssr-options'];
96
+ const options = optionsString ? JSON.parse(optionsString) : {};
133
97
 
134
98
  // TODO: This is temporary to shortcut the logging added to SSR.
135
99
  options.logger ??= {
136
100
  debug: noop,
137
101
  info: noop,
138
102
  log: noop,
139
- warn: noop,
103
+ warn: noop
140
104
  };
141
-
142
105
  options.buildInfo ??= this.global.buildInfo;
143
-
144
- let cleanup: (() => void) | undefined;
145
-
106
+ let cleanup;
146
107
  if (options.entry) {
147
- const p = path.resolve(this.testFolder, options.entry as string);
108
+ const p = path.resolve(this.testFolder, options.entry);
148
109
  // TODO: This sure can be replaced by a dynamic import().
149
110
  // eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-require-imports
150
- const module = require(p) as NodeJS.Module;
151
- if ('cleanup' in module) cleanup = module.cleanup as () => void;
152
-
153
- const exportName = (options.entryExportName as string) || 'default';
111
+ const module = require(p);
112
+ if ('cleanup' in module) cleanup = module.cleanup;
113
+ const exportName = options.entryExportName || 'default';
154
114
  if (exportName in module) {
155
- options.Application = (
156
- module as unknown as Record<string, unknown>
157
- )[exportName] as ReactNode;
115
+ options.Application = module[exportName];
158
116
  }
159
117
  }
160
-
161
- const renderer = ssrFactory(this.global.webpackConfig!, options);
118
+ const renderer = ssrFactory(this.global.webpackConfig, options);
162
119
  let status = 200; // OK
163
- const markup = await new Promise<string>((done, fail) => {
164
- void renderer(
165
- this.ssrRequest as Request,
166
-
167
- // TODO: This will do for now, with the current implementation of
168
- // the renderer, but it will require a rework once the renderer is
169
- // updated to do streaming.
170
- ({
171
- cookie: noop,
172
- send: done,
173
- set: noop,
174
- status: (value: number) => {
175
- status = value;
176
- },
177
-
178
- // This is how up-to-date Webpack stats are passed to the server in
179
- // development mode, and we use this here always, instead of having
180
- // to pass some information via filesystem.
181
- locals: {
182
- webpack: {
183
- devMiddleware: {
184
- stats: this.webpackStats,
185
- },
186
- },
187
- },
188
- } as unknown) as Response,
189
-
190
- (error) => {
191
- // TODO: Strictly speaking, that error as Error casting is not all
192
- // correct, but it works, so no need to spend time on it right now.
193
- if (error) fail(error as Error);
194
- else done('');
120
+ const markup = await new Promise((done, fail) => {
121
+ void renderer(this.ssrRequest,
122
+ // TODO: This will do for now, with the current implementation of
123
+ // the renderer, but it will require a rework once the renderer is
124
+ // updated to do streaming.
125
+ {
126
+ cookie: noop,
127
+ send: done,
128
+ set: noop,
129
+ status: value => {
130
+ status = value;
195
131
  },
196
- );
132
+ // This is how up-to-date Webpack stats are passed to the server in
133
+ // development mode, and we use this here always, instead of having
134
+ // to pass some information via filesystem.
135
+ locals: {
136
+ webpack: {
137
+ devMiddleware: {
138
+ stats: this.webpackStats
139
+ }
140
+ }
141
+ }
142
+ }, error => {
143
+ // TODO: Strictly speaking, that error as Error casting is not all
144
+ // correct, but it works, so no need to spend time on it right now.
145
+ if (error) fail(error);else done('');
146
+ });
197
147
  });
198
-
199
148
  this.global.ssrMarkup = markup;
200
149
  this.global.ssrOptions = options;
201
150
  this.global.ssrStatus = status;
202
-
203
151
  if (cleanup) cleanup();
204
152
  }
205
-
206
- constructor(
207
- config: JestEnvironmentConfig,
208
- context: EnvironmentContext,
209
- ) {
153
+ constructor(config, context) {
210
154
  const pragmas = context.docblockPragmas;
211
-
212
- const requestString = pragmas['ssr-request'] as string;
213
- const request = requestString
214
- ? JSON.parse(requestString) as Record<string, unknown>
215
- : {};
216
-
155
+ const requestString = pragmas['ssr-request'];
156
+ const request = requestString ? JSON.parse(requestString) : {};
217
157
  request.url ??= '/';
218
158
  request.csrfToken = noop;
219
159
 
220
160
  // This ensures the initial JsDom URL matches the value we use for SSR.
221
- set(
222
- config.projectConfig,
223
- 'testEnvironmentOptions.url',
224
- `http://localhost${request.url as string}`,
225
- );
226
-
161
+ set(config.projectConfig, 'testEnvironmentOptions.url', `http://localhost${request.url}`);
227
162
  super(config, context);
228
-
229
163
  this.global.dom = this.dom;
230
164
  this.global.webpackOutputFs = createFsFromVolume(new Volume());
231
165
 
232
166
  // Extracts necessary settings from config and context.
233
- const { projectConfig } = config;
167
+ const {
168
+ projectConfig
169
+ } = config;
234
170
  this.rootDir = projectConfig.rootDir;
235
171
  this.testFolder = path.dirname(context.testPath);
236
172
  this.withSsr = !pragmas['no-ssr'];
@@ -239,25 +175,23 @@ export default class E2eSsrEnv extends JsdomEnv {
239
175
 
240
176
  // The usual "babel-jest" transformation setup does not apply to
241
177
  // the environment code and imports from it, this workaround enables it.
242
- const optionsString = this.pragmas['ssr-options'] as string;
243
- const options = optionsString
244
- ? JSON.parse(optionsString) as Record<string, unknown>
245
- : {};
178
+ const optionsString = this.pragmas['ssr-options'];
179
+ const options = optionsString ? JSON.parse(optionsString) : {};
246
180
  let root;
247
181
  switch (options.root) {
248
182
  case 'TEST':
249
183
  root = this.testFolder;
250
184
  break;
251
- default: root = process.cwd();
185
+ default:
186
+ root = process.cwd();
252
187
  }
253
188
  register({
254
- envName: options.babelEnv as string,
189
+ envName: options.babelEnv,
255
190
  extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],
256
- root,
191
+ root
257
192
  });
258
193
  }
259
-
260
- async setup(): Promise<void> {
194
+ async setup() {
261
195
  await super.setup();
262
196
  await this.runWebpack();
263
197
 
@@ -275,12 +209,10 @@ export default class E2eSsrEnv extends JsdomEnv {
275
209
  // TODO: Look for a cleaner solution.
276
210
  require.cache = {};
277
211
  setBuildInfo(undefined, true);
278
-
279
212
  if (this.withSsr) await this.runSsr();
280
213
  this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;
281
214
  }
282
-
283
- async teardown(): Promise<void> {
215
+ async teardown() {
284
216
  delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;
285
217
 
286
218
  // Resets module cache and @babel/register. Effectively this ensures that
@@ -289,10 +221,11 @@ export default class E2eSsrEnv extends JsdomEnv {
289
221
  // Babel config (which may change between different environment instances,
290
222
  // which does not seem to be taken into account by Babel / Node caches
291
223
  // automatically).
292
- Object.keys(require.cache).forEach((key) => {
224
+ Object.keys(require.cache).forEach(key => {
293
225
  delete require.cache[key];
294
226
  });
295
227
  register.revert();
296
228
  await super.teardown();
297
229
  }
298
230
  }
231
+ //# sourceMappingURL=E2eSsrEnv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"E2eSsrEnv.js","names":["path","defaults","set","register","JsdomEnv","Volume","createFsFromVolume","webpack","ssrFactory","setBuildInfo","noop","E2eSsrEnv","loadWebpackConfig","optionsString","pragmas","options","JSON","parse","context","testFolder","fs","global","webpackOutputFs","factoryPath","factory","require","resolve","rootDir","default","webpackConfig","buildInfo","existsSync","readFileSync","runWebpack","Error","compiler","outputFileSystem","Promise","done","fail","run","err","stats","hasErrors","console","error","toJson","errors","webpackStats","runSsr","logger","debug","info","log","warn","cleanup","entry","p","module","exportName","entryExportName","Application","renderer","status","markup","ssrRequest","cookie","send","value","locals","devMiddleware","ssrMarkup","ssrOptions","ssrStatus","constructor","config","docblockPragmas","requestString","request","url","csrfToken","projectConfig","dom","dirname","testPath","withSsr","root","process","cwd","envName","babelEnv","extensions","setup","cache","undefined","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","forEach","key","revert"],"sources":["../../../../../src/shared/utils/jest/E2eSsrEnv.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\nimport path from 'node:path';\n\nimport type { Request, Response } from 'express';\n\nimport { defaults, set } from 'lodash-es';\n\nimport type { ReactNode } from 'react';\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 */\nimport register from '@babel/register/experimental-worker';\n\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { Volume, createFsFromVolume } from 'memfs';\nimport webpack, { type Configuration } from 'webpack';\n/* eslint-enable import/no-extraneous-dependencies */\n\nimport type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\n\nimport ssrFactory from 'server/renderer';\n\nimport { setBuildInfo } from '../isomorphy/buildInfo';\n\nfunction noop() {\n // NOOP\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?: webpack.StatsCompilation;\n\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n private 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 // eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-require-imports\n let factory = require(path.resolve(this.rootDir, factoryPath)) as\n (((ops: Configuration) => Configuration) | {\n default: (ops: Configuration) => Configuration;\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 this.loadWebpackConfig();\n\n if (!this.global.webpackConfig) throw Error('Failed to load Webpack config');\n const compiler = webpack(this.global.webpackConfig);\n if (!compiler) throw Error('Failed to construct Webpack compiler');\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 const optionsString = this.pragmas['ssr-options'] as string;\n const options = optionsString\n ? JSON.parse(optionsString) as Record<string, unknown>\n : {};\n\n // TODO: This is temporary to shortcut the logging added to SSR.\n options.logger ??= {\n debug: noop,\n info: noop,\n log: noop,\n warn: noop,\n };\n\n options.buildInfo ??= this.global.buildInfo;\n\n let cleanup: (() => void) | undefined;\n\n if (options.entry) {\n const p = path.resolve(this.testFolder, options.entry as string);\n // TODO: This sure can be replaced by a dynamic import().\n // eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-require-imports\n const module = require(p) as NodeJS.Module;\n if ('cleanup' in module) cleanup = module.cleanup as () => void;\n\n const exportName = (options.entryExportName as string) || 'default';\n if (exportName in module) {\n options.Application = (\n module as unknown as Record<string, unknown>\n )[exportName] as ReactNode;\n }\n }\n\n const renderer = ssrFactory(this.global.webpackConfig!, options);\n let status = 200; // OK\n const markup = await new Promise<string>((done, fail) => {\n void renderer(\n this.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\n // This is how up-to-date Webpack stats are passed to the server in\n // development mode, and we use this here always, instead of having\n // to pass some information via filesystem.\n locals: {\n webpack: {\n devMiddleware: {\n stats: this.webpackStats,\n },\n },\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 this.global.ssrMarkup = markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = status;\n\n if (cleanup) cleanup();\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 request.csrfToken = noop;\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 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 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 await super.teardown();\n }\n}\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA,OAAOA,IAAI,MAAM,WAAW;AAI5B,SAASC,QAAQ,EAAEC,GAAG,QAAQ,WAAW;AAIzC;AACA;AACA;AACA,OAAOC,QAAQ,MAAM,qCAAqC;AAE1D,OAAOC,QAAQ,MAAM,wBAAwB;AAC7C,SAASC,MAAM,EAAEC,kBAAkB,QAAQ,OAAO;AAClD,OAAOC,OAAO,MAA8B,SAAS;AACrD;;AAOA,OAAOC,UAAU;AAEjB,SAASC,YAAY;AAErB,SAASC,IAAIA,CAAA,EAAG;EACd;AAAA;AAGF,eAAe,MAAMC,SAAS,SAASP,QAAQ,CAAC;EAa9C;AACF;AACA;AACA;EACUQ,iBAAiBA,CAAA,EAAG;IAC1B,MAAMC,aAAa,GAAG,IAAI,CAACC,OAAO,CAAC,wBAAwB,CAAW;IAEtE,MAAMC,OAAO,GAAIF,aAAa,GAAGG,IAAI,CAACC,KAAK,CAACJ,aAAa,CAAC,GAAG,CAAC,CACvC;IAEvBZ,QAAQ,CAACc,OAAO,EAAE;MAChBG,OAAO,EAAE,IAAI,CAACC,UAAU;MACxBC,EAAE,EAAE,IAAI,CAACC,MAAM,CAACC;IAClB,CAAC,CAAC;IAEF,MAAMC,WAAW,GAAG,IAAI,CAACT,OAAO,CAAC,wBAAwB,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,KAAK,CAAC,CAAC;IACnB,MAAM,IAAI,CAAC3D,UAAU,CAAC,CAAC;;IAEvB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACAR,OAAO,CAACoE,KAAK,GAAG,CAAC,CAAC;IAClBpF,YAAY,CAACqF,SAAS,EAAE,IAAI,CAAC;IAE7B,IAAI,IAAI,CAACT,OAAO,EAAE,MAAM,IAAI,CAACpC,MAAM,CAAC,CAAC;IACrC,IAAI,CAAC5B,MAAM,CAAC0E,6BAA6B,GAAG,IAAI;EAClD;EAEA,MAAMC,QAAQA,CAAA,EAAkB;IAC9B,OAAO,IAAI,CAAC3E,MAAM,CAAC0E,6BAA6B;;IAEhD;IACA;IACA;IACA;IACA;IACA;IACAE,MAAM,CAACC,IAAI,CAACzE,OAAO,CAACoE,KAAK,CAAC,CAACM,OAAO,CAAEC,GAAG,IAAK;MAC1C,OAAO3E,OAAO,CAACoE,KAAK,CAACO,GAAG,CAAC;IAC3B,CAAC,CAAC;IACFjG,QAAQ,CAACkG,MAAM,CAAC,CAAC;IACjB,MAAM,KAAK,CAACL,QAAQ,CAAC,CAAC;EACxB;AACF","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ export default function getGlobal() {
2
+ return global;
3
+ }
4
+ //# sourceMappingURL=global.js.map
@@ -0,0 +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,eAAe,SAASA,SAASA,CAAA,EAAW;EAC1C,OAAOC,MAAM;AACf","ignoreList":[]}
@@ -1,46 +1,37 @@
1
1
  /* global jest, document */
2
2
  /* eslint-disable import/no-extraneous-dependencies */
3
3
 
4
- import type {
5
- AxiosRequestConfig,
6
- AxiosResponse,
7
- AxiosStatic,
8
- InternalAxiosRequestConfig,
9
- } from 'axios';
10
-
11
4
  import mockdate from 'mockdate';
12
- import { type ReactElement, type ReactNode, act } from 'react';
13
- import { type Root, createRoot } from 'react-dom/client';
14
-
15
- import { type RenderResult, render } from '@testing-library/react';
5
+ import { act } from 'react';
6
+ import { createRoot } from 'react-dom/client';
7
+ import { render } from '@testing-library/react';
16
8
 
17
9
  /**
18
10
  * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)
19
11
  * from `react`.
20
12
  */
21
13
  export { act };
22
-
23
- export { default as getGlobal } from './global';
24
-
14
+ export { default as getGlobal } from "./global";
25
15
  global.IS_REACT_ACT_ENVIRONMENT = true;
26
-
27
16
  const originalProcessVersions = process.versions;
28
17
 
29
18
  /**
30
19
  * Tricks **react-utils** into thinking the test is running within client-side
31
20
  * (browser) environment.
32
21
  */
33
- export function mockClientSide(): void {
34
- Object.defineProperty(process, 'versions', { value: undefined });
22
+ export function mockClientSide() {
23
+ Object.defineProperty(process, 'versions', {
24
+ value: undefined
25
+ });
35
26
  }
36
27
 
37
28
  /**
38
29
  * Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.
39
30
  */
40
- export function unmockClientSide(): void {
31
+ export function unmockClientSide() {
41
32
  Object.defineProperty(process, 'versions', {
42
33
  value: originalProcessVersions,
43
- writable: false,
34
+ writable: false
44
35
  });
45
36
  }
46
37
 
@@ -50,60 +41,43 @@ export function unmockClientSide(): void {
50
41
  * @param {number} seed
51
42
  * @return {string}
52
43
  */
53
- export function getMockUuid(seed = 0): string {
44
+ export function getMockUuid(seed = 0) {
54
45
  const x = seed.toString(16).padStart(32, '0');
55
46
  return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;
56
47
  }
57
-
58
- export type AxiosRequestHandlerT = (
59
- config: AxiosRequestConfig,
60
- ) => Partial<AxiosResponse> | null | undefined;
61
-
62
- export function mockAxios(handlers: AxiosRequestHandlerT[]): AxiosStatic {
63
- const axios: AxiosStatic = jest.requireActual('axios');
64
-
65
- axios.defaults.adapter = async (
66
- config: AxiosRequestConfig,
67
- ): Promise<AxiosResponse> => {
48
+ export function mockAxios(handlers) {
49
+ const axios = jest.requireActual('axios');
50
+ axios.defaults.adapter = async config => {
68
51
  for (const handler of handlers) {
69
52
  const res = handler(config);
70
53
  if (res) {
71
54
  return {
72
- config: config as InternalAxiosRequestConfig,
55
+ config: config,
73
56
  data: null,
74
57
  headers: {},
75
58
  status: 200,
76
59
  statusText: 'OK',
77
- ...res,
60
+ ...res
78
61
  };
79
62
  }
80
63
  }
81
64
 
82
65
  // Fallback to the regular network request.
83
- let res: AxiosResponse;
66
+ let res;
84
67
  try {
85
- res = await axios({ ...config, adapter: ['xhr', 'http', 'fetch'] });
68
+ res = await axios({
69
+ ...config,
70
+ adapter: ['xhr', 'http', 'fetch']
71
+ });
86
72
  // eslint-disable-next-line no-console
87
- console.warn(
88
- 'Network request has not been mocked for a test.\n\nConfig:\n',
89
- config,
90
- '\n\nResult:\n',
91
- JSON.stringify(res, null, 2),
92
- );
73
+ console.warn('Network request has not been mocked for a test.\n\nConfig:\n', config, '\n\nResult:\n', JSON.stringify(res, null, 2));
93
74
  } catch (e) {
94
75
  // eslint-disable-next-line no-console
95
- console.warn(
96
- 'Network request has not been mocked for a test, and failed.\n\nConfig:\n',
97
- config,
98
- '\n\nError\n',
99
- JSON.stringify(e, null, 2),
100
- );
76
+ 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));
101
77
  throw e;
102
78
  }
103
-
104
79
  return res;
105
80
  };
106
-
107
81
  return axios;
108
82
  }
109
83
 
@@ -113,39 +87,30 @@ export function mockAxios(handlers: AxiosRequestHandlerT[]): AxiosStatic {
113
87
  * @returns {Promise} Wait for this to "jump after" any async code which should
114
88
  * be executed because of the mock time movement.
115
89
  */
116
- export async function mockTimer(time: number): Promise<void> {
90
+ export async function mockTimer(time) {
117
91
  mockdate.set(time + Date.now());
118
92
  await jest.advanceTimersByTimeAsync(time);
119
93
  }
120
-
121
- export type MountedSceneT = HTMLElement & {
122
- destroy: () => void;
123
- snapshot: () => void;
124
- };
125
-
126
94
  /**
127
95
  * Mounts `scene` to the DOM, and returns the root scene element.
128
96
  * @param scene
129
97
  * @return Created container DOM element with destroy() function
130
98
  * attached.
131
99
  */
132
- export function mount(scene: ReactNode): MountedSceneT {
133
- let root: Root;
100
+ export function mount(scene) {
101
+ let root;
134
102
  const element = document.createElement('div');
135
103
  document.body.appendChild(element);
136
-
137
- const res: MountedSceneT = (element as unknown) as MountedSceneT;
104
+ const res = element;
138
105
  res.destroy = () => {
139
106
  // NOTE: As it seems @testing-library may reset this flag to false
140
107
  // when it is simulating user events.
141
108
  global.IS_REACT_ACT_ENVIRONMENT = true;
142
-
143
109
  act(() => {
144
110
  root.unmount();
145
111
  });
146
112
  res.remove();
147
113
  };
148
-
149
114
  res.snapshot = () => {
150
115
  expect(res).toMatchSnapshot();
151
116
  };
@@ -153,7 +118,6 @@ export function mount(scene: ReactNode): MountedSceneT {
153
118
  // NOTE: As it seems @testing-library may reset this flag to false
154
119
  // when it is simulating user events.
155
120
  global.IS_REACT_ACT_ENVIRONMENT = true;
156
-
157
121
  act(() => {
158
122
  root = createRoot(res);
159
123
  root.render(scene);
@@ -164,22 +128,9 @@ export function mount(scene: ReactNode): MountedSceneT {
164
128
  // NOTE: If in future we have additional options here, they should be distributed
165
129
  // across two objects, depending whether they are applicable to the sync, or async
166
130
  // versions of snapshot(), or both.
167
- type AsyncSnapshotOptionsT = {
168
- await?: Promise<void>;
169
- };
170
-
171
- export function snapshot(element: ReactElement): RenderResult;
172
-
173
- export async function snapshot(
174
- element: ReactElement,
175
- options: AsyncSnapshotOptionsT,
176
- ): Promise<RenderResult>;
177
131
 
178
- export function snapshot(
179
- element: React.ReactElement,
180
- options?: AsyncSnapshotOptionsT,
181
- ): Promise<RenderResult> | RenderResult {
182
- let res: RenderResult | undefined;
132
+ export function snapshot(element, options) {
133
+ let res;
183
134
 
184
135
  // TODO: Just adding async to the actor function breaks stuff, as it makes
185
136
  // act() asynchronous no matter the `options.await` value, thus breaking all
@@ -191,25 +142,24 @@ export function snapshot(
191
142
  res = render(element);
192
143
  return options?.await;
193
144
  });
194
-
195
145
  if (res === undefined) throw Error('Render failed');
196
146
  if (options?.await) {
197
147
  // BEWARE: Although `promise` is thenable (i.e. it has .then() method),
198
148
  // it is not an instance of proper Promise class, and returning it directly
199
149
  // breaks some async logic in Jest test or React test functions... thus, we
200
150
  // wrap it into Promise instance here.
201
- return new Promise((resolve) => {
151
+ return new Promise(resolve => {
202
152
  void promise.then(() => {
203
153
  // TODO: These lines are the same as the lines below for sync variant of
204
154
  // the function. We should split and reuse them in both places.
205
- const nodes = res!.asFragment().childNodes;
155
+ const nodes = res.asFragment().childNodes;
206
156
  expect(nodes.length > 1 ? [...nodes] : nodes[0]).toMatchSnapshot();
207
- resolve(res!);
157
+ resolve(res);
208
158
  });
209
159
  });
210
160
  }
211
-
212
161
  const nodes = res.asFragment().childNodes;
213
162
  expect(nodes.length > 1 ? [...nodes] : nodes[0]).toMatchSnapshot();
214
163
  return res;
215
164
  }
165
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["mockdate","act","createRoot","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","jest","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","expect","toMatchSnapshot","options","promise","await","Error","Promise","resolve","then","nodes","asFragment","childNodes","length"],"sources":["../../../../../src/shared/utils/jest/index.ts"],"sourcesContent":["/* global jest, 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 { 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 {\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: React.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) => {\n void promise.then(() => {\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 });\n }\n\n const nodes = res.asFragment().childNodes;\n expect(nodes.length > 1 ? [...nodes] : nodes[0]).toMatchSnapshot();\n return res;\n}\n"],"mappings":"AAAA;AACA;;AASA,OAAOA,QAAQ,MAAM,UAAU;AAC/B,SAA4CC,GAAG,QAAQ,OAAO;AAC9D,SAAoBC,UAAU,QAAQ,kBAAkB;AAExD,SAA4BC,MAAM,QAAQ,wBAAwB;;AAElE;AACA;AACA;AACA;AACA,SAASF,GAAG;AAEZ,SAASG,OAAO,IAAIC,SAAS;AAE7BC,MAAM,CAACC,wBAAwB,GAAG,IAAI;AAEtC,MAAMC,uBAAuB,GAAGC,OAAO,CAACC,QAAQ;;AAEhD;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAA,EAAS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