@shopify/ui-extensions-server-kit 5.2.0

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 (367) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/README.md +74 -0
  3. package/dist/ExtensionServerClient/ExtensionServerClient.cjs.js +1 -0
  4. package/dist/ExtensionServerClient/ExtensionServerClient.d.ts +28 -0
  5. package/dist/ExtensionServerClient/ExtensionServerClient.es.js +133 -0
  6. package/dist/ExtensionServerClient/ExtensionServerClient.test.d.ts +1 -0
  7. package/dist/ExtensionServerClient/index.d.ts +2 -0
  8. package/dist/ExtensionServerClient/types.cjs.js +1 -0
  9. package/dist/ExtensionServerClient/types.d.ts +124 -0
  10. package/dist/ExtensionServerClient/types.es.js +4 -0
  11. package/dist/context/ExtensionServerProvider.cjs.js +1 -0
  12. package/dist/context/ExtensionServerProvider.d.ts +2 -0
  13. package/dist/context/ExtensionServerProvider.es.js +29 -0
  14. package/dist/context/ExtensionServerProvider.test.d.ts +1 -0
  15. package/dist/context/constants.cjs.js +1 -0
  16. package/dist/context/constants.d.ts +3 -0
  17. package/dist/context/constants.es.js +14 -0
  18. package/dist/context/index.d.ts +3 -0
  19. package/dist/context/types.d.ts +11 -0
  20. package/dist/hooks/index.d.ts +5 -0
  21. package/dist/hooks/useExtensionClient.cjs.js +1 -0
  22. package/dist/hooks/useExtensionClient.d.ts +1 -0
  23. package/dist/hooks/useExtensionClient.es.js +8 -0
  24. package/dist/hooks/useExtensionServerContext.cjs.js +1 -0
  25. package/dist/hooks/useExtensionServerContext.d.ts +1 -0
  26. package/dist/hooks/useExtensionServerContext.es.js +6 -0
  27. package/dist/hooks/useExtensionServerEvent.cjs.js +1 -0
  28. package/dist/hooks/useExtensionServerEvent.d.ts +1 -0
  29. package/dist/hooks/useExtensionServerEvent.es.js +9 -0
  30. package/dist/hooks/useExtensionServerState.cjs.js +1 -0
  31. package/dist/hooks/useExtensionServerState.d.ts +1 -0
  32. package/dist/hooks/useExtensionServerState.es.js +9 -0
  33. package/dist/hooks/useIsomorphicLayoutEffect.cjs.js +1 -0
  34. package/dist/hooks/useIsomorphicLayoutEffect.d.ts +2 -0
  35. package/dist/hooks/useIsomorphicLayoutEffect.es.js +5 -0
  36. package/dist/i18n.cjs.js +1 -0
  37. package/dist/i18n.d.ts +93 -0
  38. package/dist/i18n.es.js +61 -0
  39. package/dist/i18n.test.d.ts +1 -0
  40. package/dist/index.cjs.js +1 -0
  41. package/dist/index.cjs2.js +1 -0
  42. package/dist/index.d.ts +7 -0
  43. package/dist/index.es.js +54 -0
  44. package/dist/index.es2.js +8 -0
  45. package/dist/state/actions/actions.cjs.js +1 -0
  46. package/dist/state/actions/actions.d.ts +6 -0
  47. package/dist/state/actions/actions.es.js +37 -0
  48. package/dist/state/actions/index.d.ts +2 -0
  49. package/dist/state/actions/types.d.ts +21 -0
  50. package/dist/state/index.d.ts +2 -0
  51. package/dist/state/reducers/constants.cjs.js +1 -0
  52. package/dist/state/reducers/constants.d.ts +2 -0
  53. package/dist/state/reducers/constants.es.js +7 -0
  54. package/dist/state/reducers/extensionServerReducer.cjs.js +1 -0
  55. package/dist/state/reducers/extensionServerReducer.d.ts +3 -0
  56. package/dist/state/reducers/extensionServerReducer.es.js +57 -0
  57. package/dist/state/reducers/extensionServerReducer.test.d.ts +1 -0
  58. package/dist/state/reducers/index.d.ts +3 -0
  59. package/dist/state/reducers/types.d.ts +6 -0
  60. package/dist/testing/MockExtensionServerProvider.cjs.js +1 -0
  61. package/dist/testing/MockExtensionServerProvider.d.ts +7 -0
  62. package/dist/testing/MockExtensionServerProvider.es.js +24 -0
  63. package/dist/testing/app.cjs.js +1 -0
  64. package/dist/testing/app.d.ts +2 -0
  65. package/dist/testing/app.es.js +16 -0
  66. package/dist/testing/extensions.cjs.js +1 -0
  67. package/dist/testing/extensions.d.ts +6 -0
  68. package/dist/testing/extensions.es.js +65 -0
  69. package/dist/testing/index.d.ts +3 -0
  70. package/dist/types.cjs.js +1 -0
  71. package/dist/types.d.ts +169 -0
  72. package/dist/types.es.js +4 -0
  73. package/dist/utilities/assetToString.cjs.js +1 -0
  74. package/dist/utilities/assetToString.d.ts +2 -0
  75. package/dist/utilities/assetToString.es.js +7 -0
  76. package/dist/utilities/assetToString.test.d.ts +1 -0
  77. package/dist/utilities/groupByKey.cjs.js +1 -0
  78. package/dist/utilities/groupByKey.d.ts +3 -0
  79. package/dist/utilities/groupByKey.es.js +6 -0
  80. package/dist/utilities/index.d.ts +7 -0
  81. package/dist/utilities/isUIExtension.cjs.js +1 -0
  82. package/dist/utilities/isUIExtension.d.ts +1 -0
  83. package/dist/utilities/isUIExtension.es.js +6 -0
  84. package/dist/utilities/isValidSurface.cjs.js +1 -0
  85. package/dist/utilities/isValidSurface.d.ts +2 -0
  86. package/dist/utilities/isValidSurface.es.js +7 -0
  87. package/dist/utilities/noop.cjs.js +1 -0
  88. package/dist/utilities/noop.d.ts +1 -0
  89. package/dist/utilities/noop.es.js +5 -0
  90. package/dist/utilities/replaceUpdated.cjs.js +1 -0
  91. package/dist/utilities/replaceUpdated.d.ts +1 -0
  92. package/dist/utilities/replaceUpdated.es.js +14 -0
  93. package/dist/utilities/replaceUpdated.test.d.ts +1 -0
  94. package/dist/utilities/set.cjs.js +1 -0
  95. package/dist/utilities/set.d.ts +4 -0
  96. package/dist/utilities/set.es.js +18 -0
  97. package/dist/utilities/set.test.d.ts +1 -0
  98. package/index.d.ts +1 -0
  99. package/index.js +1 -0
  100. package/index.mjs +1 -0
  101. package/node_modules/@shopify/react-testing/LICENSE.md +21 -0
  102. package/node_modules/@shopify/react-testing/README.md +711 -0
  103. package/node_modules/@shopify/react-testing/build/cjs/TestWrapper.js +52 -0
  104. package/node_modules/@shopify/react-testing/build/cjs/_virtual/_rollupPluginBabelHelpers.js +47 -0
  105. package/node_modules/@shopify/react-testing/build/cjs/compat.js +14 -0
  106. package/node_modules/@shopify/react-testing/build/cjs/destroy.js +13 -0
  107. package/node_modules/@shopify/react-testing/build/cjs/element.js +225 -0
  108. package/node_modules/@shopify/react-testing/build/cjs/index.js +21 -0
  109. package/node_modules/@shopify/react-testing/build/cjs/matchers/components.js +46 -0
  110. package/node_modules/@shopify/react-testing/build/cjs/matchers/context.js +25 -0
  111. package/node_modules/@shopify/react-testing/build/cjs/matchers/index.js +16 -0
  112. package/node_modules/@shopify/react-testing/build/cjs/matchers/props.js +38 -0
  113. package/node_modules/@shopify/react-testing/build/cjs/matchers/strings.js +42 -0
  114. package/node_modules/@shopify/react-testing/build/cjs/matchers/utilities.js +110 -0
  115. package/node_modules/@shopify/react-testing/build/cjs/mount.js +76 -0
  116. package/node_modules/@shopify/react-testing/build/cjs/root.js +284 -0
  117. package/node_modules/@shopify/react-testing/build/cjs/toReactString.js +86 -0
  118. package/node_modules/@shopify/react-testing/build/cjs/types.js +28 -0
  119. package/node_modules/@shopify/react-testing/build/esm/TestWrapper.mjs +44 -0
  120. package/node_modules/@shopify/react-testing/build/esm/_virtual/_rollupPluginBabelHelpers.mjs +42 -0
  121. package/node_modules/@shopify/react-testing/build/esm/compat.mjs +10 -0
  122. package/node_modules/@shopify/react-testing/build/esm/destroy.mjs +9 -0
  123. package/node_modules/@shopify/react-testing/build/esm/element.mjs +221 -0
  124. package/node_modules/@shopify/react-testing/build/esm/index.mjs +5 -0
  125. package/node_modules/@shopify/react-testing/build/esm/matchers/components.mjs +41 -0
  126. package/node_modules/@shopify/react-testing/build/esm/matchers/context.mjs +21 -0
  127. package/node_modules/@shopify/react-testing/build/esm/matchers/index.mjs +14 -0
  128. package/node_modules/@shopify/react-testing/build/esm/matchers/props.mjs +33 -0
  129. package/node_modules/@shopify/react-testing/build/esm/matchers/strings.mjs +37 -0
  130. package/node_modules/@shopify/react-testing/build/esm/matchers/utilities.mjs +101 -0
  131. package/node_modules/@shopify/react-testing/build/esm/mount.mjs +70 -0
  132. package/node_modules/@shopify/react-testing/build/esm/root.mjs +275 -0
  133. package/node_modules/@shopify/react-testing/build/esm/toReactString.mjs +80 -0
  134. package/node_modules/@shopify/react-testing/build/esm/types.mjs +26 -0
  135. package/node_modules/@shopify/react-testing/build/esnext/TestWrapper.esnext +44 -0
  136. package/node_modules/@shopify/react-testing/build/esnext/compat.esnext +10 -0
  137. package/node_modules/@shopify/react-testing/build/esnext/destroy.esnext +9 -0
  138. package/node_modules/@shopify/react-testing/build/esnext/element.esnext +221 -0
  139. package/node_modules/@shopify/react-testing/build/esnext/index.esnext +5 -0
  140. package/node_modules/@shopify/react-testing/build/esnext/matchers/components.esnext +41 -0
  141. package/node_modules/@shopify/react-testing/build/esnext/matchers/context.esnext +21 -0
  142. package/node_modules/@shopify/react-testing/build/esnext/matchers/index.esnext +14 -0
  143. package/node_modules/@shopify/react-testing/build/esnext/matchers/props.esnext +33 -0
  144. package/node_modules/@shopify/react-testing/build/esnext/matchers/strings.esnext +37 -0
  145. package/node_modules/@shopify/react-testing/build/esnext/matchers/utilities.esnext +99 -0
  146. package/node_modules/@shopify/react-testing/build/esnext/mount.esnext +71 -0
  147. package/node_modules/@shopify/react-testing/build/esnext/root.esnext +275 -0
  148. package/node_modules/@shopify/react-testing/build/esnext/toReactString.esnext +80 -0
  149. package/node_modules/@shopify/react-testing/build/esnext/types.esnext +26 -0
  150. package/node_modules/@shopify/react-testing/build/ts/TestWrapper.d.ts +17 -0
  151. package/node_modules/@shopify/react-testing/build/ts/TestWrapper.d.ts.map +1 -0
  152. package/node_modules/@shopify/react-testing/build/ts/compat.d.ts +3 -0
  153. package/node_modules/@shopify/react-testing/build/ts/compat.d.ts.map +1 -0
  154. package/node_modules/@shopify/react-testing/build/ts/destroy.d.ts +2 -0
  155. package/node_modules/@shopify/react-testing/build/ts/destroy.d.ts.map +1 -0
  156. package/node_modules/@shopify/react-testing/build/ts/element.d.ts +42 -0
  157. package/node_modules/@shopify/react-testing/build/ts/element.d.ts.map +1 -0
  158. package/node_modules/@shopify/react-testing/build/ts/index.d.ts +7 -0
  159. package/node_modules/@shopify/react-testing/build/ts/index.d.ts.map +1 -0
  160. package/node_modules/@shopify/react-testing/build/ts/matchers/components.d.ts +12 -0
  161. package/node_modules/@shopify/react-testing/build/ts/matchers/components.d.ts.map +1 -0
  162. package/node_modules/@shopify/react-testing/build/ts/matchers/context.d.ts +8 -0
  163. package/node_modules/@shopify/react-testing/build/ts/matchers/context.d.ts.map +1 -0
  164. package/node_modules/@shopify/react-testing/build/ts/matchers/index.d.ts +20 -0
  165. package/node_modules/@shopify/react-testing/build/ts/matchers/index.d.ts.map +1 -0
  166. package/node_modules/@shopify/react-testing/build/ts/matchers/props.d.ts +10 -0
  167. package/node_modules/@shopify/react-testing/build/ts/matchers/props.d.ts.map +1 -0
  168. package/node_modules/@shopify/react-testing/build/ts/matchers/strings.d.ts +11 -0
  169. package/node_modules/@shopify/react-testing/build/ts/matchers/strings.d.ts.map +1 -0
  170. package/node_modules/@shopify/react-testing/build/ts/matchers/utilities.d.ts +17 -0
  171. package/node_modules/@shopify/react-testing/build/ts/matchers/utilities.d.ts.map +1 -0
  172. package/node_modules/@shopify/react-testing/build/ts/mount.d.ts +39 -0
  173. package/node_modules/@shopify/react-testing/build/ts/mount.d.ts.map +1 -0
  174. package/node_modules/@shopify/react-testing/build/ts/root.d.ts +55 -0
  175. package/node_modules/@shopify/react-testing/build/ts/root.d.ts.map +1 -0
  176. package/node_modules/@shopify/react-testing/build/ts/toReactString.d.ts +5 -0
  177. package/node_modules/@shopify/react-testing/build/ts/toReactString.d.ts.map +1 -0
  178. package/node_modules/@shopify/react-testing/build/ts/types.d.ts +89 -0
  179. package/node_modules/@shopify/react-testing/build/ts/types.d.ts.map +1 -0
  180. package/node_modules/@shopify/react-testing/index.esnext +1 -0
  181. package/node_modules/@shopify/react-testing/index.js +1 -0
  182. package/node_modules/@shopify/react-testing/index.mjs +1 -0
  183. package/node_modules/@shopify/react-testing/matchers.esnext +1 -0
  184. package/node_modules/@shopify/react-testing/matchers.js +1 -0
  185. package/node_modules/@shopify/react-testing/matchers.mjs +1 -0
  186. package/node_modules/@shopify/react-testing/package.json +69 -0
  187. package/node_modules/@shopify/ui-extensions-test-utils/CHANGELOG.md +66 -0
  188. package/node_modules/@shopify/ui-extensions-test-utils/dist/index.js +3 -0
  189. package/node_modules/@shopify/ui-extensions-test-utils/dist/render.js +5 -0
  190. package/node_modules/@shopify/ui-extensions-test-utils/dist/renderHook.js +20 -0
  191. package/node_modules/@shopify/ui-extensions-test-utils/dist/withProviders.js +6 -0
  192. package/node_modules/@shopify/ui-extensions-test-utils/package.json +41 -0
  193. package/node_modules/@shopify/ui-extensions-test-utils/project.json +39 -0
  194. package/node_modules/@types/node/LICENSE +21 -0
  195. package/node_modules/@types/node/README.md +15 -0
  196. package/node_modules/@types/node/assert/strict.d.ts +8 -0
  197. package/node_modules/@types/node/assert.d.ts +985 -0
  198. package/node_modules/@types/node/async_hooks.d.ts +522 -0
  199. package/node_modules/@types/node/buffer.d.ts +2321 -0
  200. package/node_modules/@types/node/child_process.d.ts +1544 -0
  201. package/node_modules/@types/node/cluster.d.ts +432 -0
  202. package/node_modules/@types/node/console.d.ts +412 -0
  203. package/node_modules/@types/node/constants.d.ts +19 -0
  204. package/node_modules/@types/node/crypto.d.ts +4451 -0
  205. package/node_modules/@types/node/dgram.d.ts +586 -0
  206. package/node_modules/@types/node/diagnostics_channel.d.ts +192 -0
  207. package/node_modules/@types/node/dns/promises.d.ts +381 -0
  208. package/node_modules/@types/node/dns.d.ts +809 -0
  209. package/node_modules/@types/node/dom-events.d.ts +122 -0
  210. package/node_modules/@types/node/domain.d.ts +170 -0
  211. package/node_modules/@types/node/events.d.ts +803 -0
  212. package/node_modules/@types/node/fs/promises.d.ts +1205 -0
  213. package/node_modules/@types/node/fs.d.ts +4211 -0
  214. package/node_modules/@types/node/globals.d.ts +377 -0
  215. package/node_modules/@types/node/globals.global.d.ts +1 -0
  216. package/node_modules/@types/node/http.d.ts +1801 -0
  217. package/node_modules/@types/node/http2.d.ts +2386 -0
  218. package/node_modules/@types/node/https.d.ts +544 -0
  219. package/node_modules/@types/node/index.d.ts +88 -0
  220. package/node_modules/@types/node/inspector.d.ts +2739 -0
  221. package/node_modules/@types/node/module.d.ts +298 -0
  222. package/node_modules/@types/node/net.d.ts +913 -0
  223. package/node_modules/@types/node/os.d.ts +473 -0
  224. package/node_modules/@types/node/package.json +235 -0
  225. package/node_modules/@types/node/path.d.ts +191 -0
  226. package/node_modules/@types/node/perf_hooks.d.ts +626 -0
  227. package/node_modules/@types/node/process.d.ts +1531 -0
  228. package/node_modules/@types/node/punycode.d.ts +117 -0
  229. package/node_modules/@types/node/querystring.d.ts +141 -0
  230. package/node_modules/@types/node/readline/promises.d.ts +143 -0
  231. package/node_modules/@types/node/readline.d.ts +666 -0
  232. package/node_modules/@types/node/repl.d.ts +430 -0
  233. package/node_modules/@types/node/stream/consumers.d.ts +12 -0
  234. package/node_modules/@types/node/stream/promises.d.ts +83 -0
  235. package/node_modules/@types/node/stream/web.d.ts +336 -0
  236. package/node_modules/@types/node/stream.d.ts +1731 -0
  237. package/node_modules/@types/node/string_decoder.d.ts +67 -0
  238. package/node_modules/@types/node/test.d.ts +1113 -0
  239. package/node_modules/@types/node/timers/promises.d.ts +93 -0
  240. package/node_modules/@types/node/timers.d.ts +126 -0
  241. package/node_modules/@types/node/tls.d.ts +1203 -0
  242. package/node_modules/@types/node/trace_events.d.ts +171 -0
  243. package/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
  244. package/node_modules/@types/node/ts4.8/assert.d.ts +985 -0
  245. package/node_modules/@types/node/ts4.8/async_hooks.d.ts +522 -0
  246. package/node_modules/@types/node/ts4.8/buffer.d.ts +2321 -0
  247. package/node_modules/@types/node/ts4.8/child_process.d.ts +1544 -0
  248. package/node_modules/@types/node/ts4.8/cluster.d.ts +432 -0
  249. package/node_modules/@types/node/ts4.8/console.d.ts +412 -0
  250. package/node_modules/@types/node/ts4.8/constants.d.ts +19 -0
  251. package/node_modules/@types/node/ts4.8/crypto.d.ts +4450 -0
  252. package/node_modules/@types/node/ts4.8/dgram.d.ts +586 -0
  253. package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +192 -0
  254. package/node_modules/@types/node/ts4.8/dns/promises.d.ts +381 -0
  255. package/node_modules/@types/node/ts4.8/dns.d.ts +809 -0
  256. package/node_modules/@types/node/ts4.8/dom-events.d.ts +122 -0
  257. package/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
  258. package/node_modules/@types/node/ts4.8/events.d.ts +754 -0
  259. package/node_modules/@types/node/ts4.8/fs/promises.d.ts +1205 -0
  260. package/node_modules/@types/node/ts4.8/fs.d.ts +4211 -0
  261. package/node_modules/@types/node/ts4.8/globals.d.ts +377 -0
  262. package/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
  263. package/node_modules/@types/node/ts4.8/http.d.ts +1801 -0
  264. package/node_modules/@types/node/ts4.8/http2.d.ts +2386 -0
  265. package/node_modules/@types/node/ts4.8/https.d.ts +544 -0
  266. package/node_modules/@types/node/ts4.8/index.d.ts +88 -0
  267. package/node_modules/@types/node/ts4.8/inspector.d.ts +2739 -0
  268. package/node_modules/@types/node/ts4.8/module.d.ts +298 -0
  269. package/node_modules/@types/node/ts4.8/net.d.ts +913 -0
  270. package/node_modules/@types/node/ts4.8/os.d.ts +473 -0
  271. package/node_modules/@types/node/ts4.8/path.d.ts +191 -0
  272. package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +626 -0
  273. package/node_modules/@types/node/ts4.8/process.d.ts +1531 -0
  274. package/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
  275. package/node_modules/@types/node/ts4.8/querystring.d.ts +141 -0
  276. package/node_modules/@types/node/ts4.8/readline/promises.d.ts +143 -0
  277. package/node_modules/@types/node/ts4.8/readline.d.ts +666 -0
  278. package/node_modules/@types/node/ts4.8/repl.d.ts +430 -0
  279. package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
  280. package/node_modules/@types/node/ts4.8/stream/promises.d.ts +83 -0
  281. package/node_modules/@types/node/ts4.8/stream/web.d.ts +336 -0
  282. package/node_modules/@types/node/ts4.8/stream.d.ts +1731 -0
  283. package/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
  284. package/node_modules/@types/node/ts4.8/test.d.ts +1113 -0
  285. package/node_modules/@types/node/ts4.8/timers/promises.d.ts +93 -0
  286. package/node_modules/@types/node/ts4.8/timers.d.ts +126 -0
  287. package/node_modules/@types/node/ts4.8/tls.d.ts +1203 -0
  288. package/node_modules/@types/node/ts4.8/trace_events.d.ts +171 -0
  289. package/node_modules/@types/node/ts4.8/tty.d.ts +206 -0
  290. package/node_modules/@types/node/ts4.8/url.d.ts +937 -0
  291. package/node_modules/@types/node/ts4.8/util.d.ts +2075 -0
  292. package/node_modules/@types/node/ts4.8/v8.d.ts +541 -0
  293. package/node_modules/@types/node/ts4.8/vm.d.ts +667 -0
  294. package/node_modules/@types/node/ts4.8/wasi.d.ts +158 -0
  295. package/node_modules/@types/node/ts4.8/worker_threads.d.ts +692 -0
  296. package/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
  297. package/node_modules/@types/node/tty.d.ts +206 -0
  298. package/node_modules/@types/node/url.d.ts +937 -0
  299. package/node_modules/@types/node/util.d.ts +2075 -0
  300. package/node_modules/@types/node/v8.d.ts +541 -0
  301. package/node_modules/@types/node/vm.d.ts +667 -0
  302. package/node_modules/@types/node/wasi.d.ts +158 -0
  303. package/node_modules/@types/node/worker_threads.d.ts +692 -0
  304. package/node_modules/@types/node/zlib.d.ts +517 -0
  305. package/node_modules/@types/react/LICENSE +21 -0
  306. package/node_modules/@types/react/README.md +16 -0
  307. package/node_modules/@types/react/experimental.d.ts +192 -0
  308. package/node_modules/@types/react/global.d.ts +151 -0
  309. package/node_modules/@types/react/index.d.ts +3175 -0
  310. package/node_modules/@types/react/jsx-dev-runtime.d.ts +2 -0
  311. package/node_modules/@types/react/jsx-runtime.d.ts +2 -0
  312. package/node_modules/@types/react/package.json +149 -0
  313. package/node_modules/@vitejs/plugin-react-refresh/LICENSE +21 -0
  314. package/node_modules/@vitejs/plugin-react-refresh/README.md +73 -0
  315. package/node_modules/@vitejs/plugin-react-refresh/index.d.ts +14 -0
  316. package/node_modules/@vitejs/plugin-react-refresh/index.js +239 -0
  317. package/node_modules/@vitejs/plugin-react-refresh/package.json +35 -0
  318. package/package.json +65 -0
  319. package/project.json +74 -0
  320. package/scripts/create-entry-files.ts +44 -0
  321. package/src/ExtensionServerClient/ExtensionServerClient.test.ts +730 -0
  322. package/src/ExtensionServerClient/ExtensionServerClient.ts +310 -0
  323. package/src/ExtensionServerClient/index.ts +2 -0
  324. package/src/ExtensionServerClient/types.ts +159 -0
  325. package/src/context/ExtensionServerProvider.test.tsx +173 -0
  326. package/src/context/ExtensionServerProvider.tsx +46 -0
  327. package/src/context/constants.ts +15 -0
  328. package/src/context/index.ts +3 -0
  329. package/src/context/types.ts +13 -0
  330. package/src/hooks/index.ts +5 -0
  331. package/src/hooks/useExtensionClient.ts +6 -0
  332. package/src/hooks/useExtensionServerContext.ts +4 -0
  333. package/src/hooks/useExtensionServerEvent.ts +11 -0
  334. package/src/hooks/useExtensionServerState.ts +6 -0
  335. package/src/hooks/useIsomorphicLayoutEffect.ts +6 -0
  336. package/src/i18n.test.ts +417 -0
  337. package/src/i18n.ts +208 -0
  338. package/src/index.ts +7 -0
  339. package/src/state/actions/actions.ts +36 -0
  340. package/src/state/actions/index.ts +2 -0
  341. package/src/state/actions/types.ts +26 -0
  342. package/src/state/index.ts +2 -0
  343. package/src/state/reducers/constants.ts +6 -0
  344. package/src/state/reducers/extensionServerReducer.test.ts +160 -0
  345. package/src/state/reducers/extensionServerReducer.ts +87 -0
  346. package/src/state/reducers/index.ts +3 -0
  347. package/src/state/reducers/types.ts +7 -0
  348. package/src/testing/MockExtensionServerProvider.tsx +36 -0
  349. package/src/testing/app.ts +15 -0
  350. package/src/testing/extensions.ts +70 -0
  351. package/src/testing/index.ts +3 -0
  352. package/src/types.ts +172 -0
  353. package/src/utilities/assetToString.test.ts +16 -0
  354. package/src/utilities/assetToString.ts +8 -0
  355. package/src/utilities/groupByKey.ts +3 -0
  356. package/src/utilities/index.ts +7 -0
  357. package/src/utilities/isUIExtension.ts +7 -0
  358. package/src/utilities/isValidSurface.ts +7 -0
  359. package/src/utilities/noop.ts +1 -0
  360. package/src/utilities/replaceUpdated.test.ts +26 -0
  361. package/src/utilities/replaceUpdated.ts +16 -0
  362. package/src/utilities/set.test.ts +19 -0
  363. package/src/utilities/set.ts +29 -0
  364. package/testing.d.ts +1 -0
  365. package/testing.js +1 -0
  366. package/testing.mjs +1 -0
  367. package/tests/setup.ts +6 -0
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
10
+
11
+ class TestWrapper extends React__default["default"].Component {
12
+ constructor(...args) {
13
+ super(...args);
14
+ this.state = {};
15
+ this.rootRef = null;
16
+
17
+ this.setRef = ref => {
18
+ this.rootRef = ref;
19
+ };
20
+ }
21
+
22
+ // eslint-disable-next-line @shopify/react-prefer-private-members
23
+ setProps(props) {
24
+ this.setState({
25
+ props
26
+ });
27
+ }
28
+
29
+ render() {
30
+ const {
31
+ props
32
+ } = this.state;
33
+ const {
34
+ children,
35
+ render
36
+ } = this.props;
37
+ const rootElement = props ? /*#__PURE__*/React__default["default"].cloneElement(children, props) : children;
38
+ return render( /*#__PURE__*/React__default["default"].createElement(TestInnerWrapper, {
39
+ ref: this.setRef
40
+ }, rootElement));
41
+ }
42
+
43
+ }
44
+
45
+ class TestInnerWrapper extends React__default["default"].Component {
46
+ render() {
47
+ return this.props.children;
48
+ }
49
+
50
+ }
51
+
52
+ exports.TestWrapper = TestWrapper;
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function ownKeys(object, enumerableOnly) {
6
+ var keys = Object.keys(object);
7
+
8
+ if (Object.getOwnPropertySymbols) {
9
+ var symbols = Object.getOwnPropertySymbols(object);
10
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
11
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
12
+ })), keys.push.apply(keys, symbols);
13
+ }
14
+
15
+ return keys;
16
+ }
17
+
18
+ function _objectSpread2(target) {
19
+ for (var i = 1; i < arguments.length; i++) {
20
+ var source = null != arguments[i] ? arguments[i] : {};
21
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
22
+ _defineProperty(target, key, source[key]);
23
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
24
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
25
+ });
26
+ }
27
+
28
+ return target;
29
+ }
30
+
31
+ function _defineProperty(obj, key, value) {
32
+ if (key in obj) {
33
+ Object.defineProperty(obj, key, {
34
+ value: value,
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true
38
+ });
39
+ } else {
40
+ obj[key] = value;
41
+ }
42
+
43
+ return obj;
44
+ }
45
+
46
+ exports.defineProperty = _defineProperty;
47
+ exports.objectSpread2 = _objectSpread2;
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function getInternals(instance) {
6
+ // In React 17+ _reactInternalFiber was renamed to _reactInternals. As such we need to handle both APIs to maintain support.
7
+ if ('_reactInternalFiber' in instance) {
8
+ return instance._reactInternalFiber;
9
+ }
10
+
11
+ return instance._reactInternals;
12
+ }
13
+
14
+ exports.getInternals = getInternals;
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var root = require('./root.js');
6
+
7
+ function destroyAll() {
8
+ for (const wrapper of [...root.connected]) {
9
+ wrapper.destroy();
10
+ }
11
+ }
12
+
13
+ exports.destroyAll = destroyAll;
@@ -0,0 +1,225 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var toReactString = require('./toReactString.js');
6
+ var types = require('./types.js');
7
+
8
+ class Element {
9
+ get props() {
10
+ return this.tree.props;
11
+ }
12
+
13
+ get type() {
14
+ return this.tree.type;
15
+ }
16
+
17
+ get isDOM() {
18
+ return this.tree.tag === types.Tag.HostComponent;
19
+ }
20
+
21
+ get instance() {
22
+ return this.tree.instance;
23
+ }
24
+
25
+ get children() {
26
+ return this.elementChildren;
27
+ }
28
+
29
+ get elementDescendants() {
30
+ if (!this.descendantsCache) {
31
+ this.descendantsCache = getDescendants(this);
32
+ }
33
+
34
+ return this.descendantsCache;
35
+ }
36
+
37
+ get elementChildren() {
38
+ if (!this.elementChildrenCache) {
39
+ this.elementChildrenCache = this.allChildren.filter(element => typeof element !== 'string');
40
+ }
41
+
42
+ return this.elementChildrenCache;
43
+ }
44
+
45
+ get descendants() {
46
+ return this.elementDescendants;
47
+ }
48
+
49
+ get domNodes() {
50
+ if (this.isDOM) {
51
+ return [this.instance];
52
+ }
53
+
54
+ return this.elementChildren.filter(element => element.isDOM).map(element => element.instance);
55
+ }
56
+
57
+ get domNode() {
58
+ const {
59
+ domNodes
60
+ } = this;
61
+
62
+ if (domNodes.length > 1) {
63
+ throw new Error('You can’t call getDOMNode() on an element that returns multiple HTML elements. Call getDOMNodes() to retrieve all of the elements instead.');
64
+ }
65
+
66
+ return domNodes[0] || null;
67
+ }
68
+
69
+ constructor(tree, allChildren, root) {
70
+ this.tree = tree;
71
+ this.allChildren = allChildren;
72
+ this.root = root;
73
+ this.descendantsCache = null;
74
+ this.elementChildrenCache = null;
75
+ }
76
+
77
+ data(key) {
78
+ return this.props[key.startsWith('data-') ? key : `data-${key}`];
79
+ }
80
+
81
+ prop(key) {
82
+ return this.props[key];
83
+ }
84
+
85
+ text() {
86
+ const {
87
+ instance,
88
+ allChildren,
89
+ tree: {
90
+ tag
91
+ }
92
+ } = this;
93
+
94
+ if (tag === types.Tag.HostPortal) {
95
+ return '';
96
+ }
97
+
98
+ if (instance instanceof HTMLElement) {
99
+ return instance.textContent || '';
100
+ }
101
+
102
+ return allChildren.reduce((text, child) => text + (typeof child === 'string' ? child : child.text()), '');
103
+ }
104
+
105
+ html() {
106
+ const {
107
+ instance,
108
+ allChildren,
109
+ tree: {
110
+ tag
111
+ }
112
+ } = this;
113
+
114
+ if (tag === types.Tag.HostPortal) {
115
+ return '';
116
+ }
117
+
118
+ if (instance instanceof HTMLElement) {
119
+ return instance.outerHTML;
120
+ }
121
+
122
+ return allChildren.reduce((text, child) => text + (typeof child === 'string' ? child : child.html()), '');
123
+ }
124
+
125
+ is(type) {
126
+ return isMatchingType(this.type, type);
127
+ }
128
+
129
+ find(type, props) {
130
+ return this.elementDescendants.find(element => isMatchingType(element.type, type) && (props == null || equalSubset(props, element.props))) || null;
131
+ }
132
+
133
+ findAll(type, props) {
134
+ return this.elementDescendants.filter(element => isMatchingType(element.type, type) && (props == null || equalSubset(props, element.props)));
135
+ }
136
+
137
+ findWhere(predicate) {
138
+ return this.elementDescendants.find(element => predicate(element)) || null;
139
+ }
140
+
141
+ findAllWhere(predicate) {
142
+ return this.elementDescendants.filter(element => predicate(element));
143
+ }
144
+
145
+ trigger(prop, ...args) {
146
+ return this.root.act(() => {
147
+ const propValue = this.props[prop];
148
+
149
+ if (propValue == null) {
150
+ throw new Error(`Attempted to call prop ${prop} but it was not defined.`);
151
+ }
152
+
153
+ return propValue(...args);
154
+ });
155
+ }
156
+
157
+ triggerKeypath(keypath, ...args) {
158
+ return this.root.act(() => {
159
+ const {
160
+ props
161
+ } = this;
162
+ const parts = keypath.split(/[.[\]]/g).filter(Boolean);
163
+ let currentProp = props;
164
+ const currentKeypath = [];
165
+
166
+ for (const part of parts) {
167
+ if (currentProp == null || typeof currentProp !== 'object') {
168
+ throw new Error(`Attempted to access field keypath '${currentKeypath.join('.')}', but it was not an object.`);
169
+ }
170
+
171
+ currentProp = currentProp[part];
172
+ currentKeypath.push(part);
173
+ }
174
+
175
+ if (typeof currentProp !== 'function') {
176
+ throw new Error(`Value at keypath '${keypath}' is not a function.`);
177
+ }
178
+
179
+ return currentProp(...args);
180
+ });
181
+ }
182
+
183
+ debug(options) {
184
+ return toReactString.toReactString(this, options);
185
+ }
186
+
187
+ toString() {
188
+ return `<${toReactString.nodeName(this)} />`;
189
+ }
190
+
191
+ }
192
+
193
+ function isMatchingType(type, test) {
194
+ if (type === test) {
195
+ return true;
196
+ }
197
+
198
+ if (test == null) {
199
+ return false;
200
+ }
201
+
202
+ return test.type != null && isMatchingType(type, test.type);
203
+ }
204
+
205
+ function equalSubset(subset, full) {
206
+ return Object.keys(subset).every(key => key in full && full[key] === subset[key]);
207
+ }
208
+
209
+ function getDescendants(element) {
210
+ const descendants = []; // eslint-disable-next-line @typescript-eslint/prefer-for-of
211
+
212
+ for (let i = 0; i < element.allChildren.length; i++) {
213
+ const child = element.allChildren[i];
214
+
215
+ if (typeof child !== 'string') {
216
+ descendants.push(child); // eslint-disable-next-line prefer-spread
217
+
218
+ descendants.push.apply(descendants, child.elementDescendants);
219
+ }
220
+ }
221
+
222
+ return descendants;
223
+ }
224
+
225
+ exports.Element = Element;
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var root = require('./root.js');
6
+ var element = require('./element.js');
7
+ var mount = require('./mount.js');
8
+ var destroy = require('./destroy.js');
9
+ var toReactString = require('./toReactString.js');
10
+
11
+
12
+
13
+ exports.Root = root.Root;
14
+ exports.Element = element.Element;
15
+ exports.CustomRoot = mount.CustomRoot;
16
+ exports.createMount = mount.createMount;
17
+ exports.mount = mount.mount;
18
+ exports.destroyAll = destroy.destroyAll;
19
+ exports.nodeName = toReactString.nodeName;
20
+ exports.toPropString = toReactString.toPropString;
21
+ exports.toReactString = toReactString.toReactString;
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jestMatcherUtils = require('jest-matcher-utils');
6
+ var utilities = require('./utilities.js');
7
+
8
+ function toContainReactComponent(node, type, props) {
9
+ utilities.assertIsNode(node, {
10
+ expectation: 'toContainReactComponent',
11
+ isNot: this.isNot
12
+ });
13
+ utilities.assertIsType(type, {
14
+ expectation: 'toContainReactComponent',
15
+ isNot: this.isNot
16
+ });
17
+ const foundByType = node.findAll(type);
18
+ const foundByProps = props == null ? foundByType : foundByType.filter(element => Object.keys(props).every(key => this.equals(props[key], element.props[key])));
19
+ const pass = foundByProps.length > 0;
20
+ const message = pass ? () => `${jestMatcherUtils.matcherHint('.not.toContainReactComponent')}\n\n` + `Expected the React element:\n ${jestMatcherUtils.RECEIVED_COLOR(node.toString())}\n` + `Not to contain component:\n ${jestMatcherUtils.EXPECTED_COLOR(utilities.printType(type))}\n${props ? `With props matching:\n ${jestMatcherUtils.printExpected(props)}\n` : ''}` + `But ${foundByProps.length} matching ${utilities.printType(type)} ${foundByProps.length === 1 ? 'elements were' : 'element was'} found.\n` : () => `${`${jestMatcherUtils.matcherHint('.toContainReactComponent')}\n\n` + `Expected the React element:\n ${jestMatcherUtils.RECEIVED_COLOR(node.toString())}\n` + `To contain component:\n ${jestMatcherUtils.EXPECTED_COLOR(utilities.printType(type))}\n${props ? `With props matching:\n ${jestMatcherUtils.printExpected(props)}\n` : ''}`}${foundByType.length === 0 ? `But no matching ${utilities.printType(type)} elements were found.\n` : `But the ${foundByType.length === 1 ? 'found element has' : 'found elements have'} the following prop differences:\n\n${utilities.diffs(foundByType, props, this.expand)}`}`;
21
+ return {
22
+ pass,
23
+ message
24
+ };
25
+ }
26
+ function toContainReactComponentTimes(node, type, times, props) {
27
+ utilities.assertIsNode(node, {
28
+ expectation: 'toContainReactComponentTimes',
29
+ isNot: this.isNot
30
+ });
31
+ utilities.assertIsType(type, {
32
+ expectation: 'toContainReactComponent',
33
+ isNot: this.isNot
34
+ });
35
+ const foundByType = node.findAll(type);
36
+ const foundByProps = props == null ? foundByType : foundByType.filter(element => Object.keys(props).every(key => this.equals(props[key], element.props[key])));
37
+ const pass = foundByProps.length === times;
38
+ const message = pass ? () => [`${jestMatcherUtils.matcherHint('.not.toContainReactComponentTimes')}\n`, `Expected the React element:\n ${jestMatcherUtils.RECEIVED_COLOR(node.toString())}`, `Not to contain component:\n ${jestMatcherUtils.EXPECTED_COLOR(utilities.printType(type))}`, `${times} ${utilities.pluralize('time', times)}, but it did.`].join('\n') : () => [`${jestMatcherUtils.matcherHint('.toContainReactComponentTimes')}\n`, `Expected the React element:\n ${jestMatcherUtils.RECEIVED_COLOR(node.toString())}`, `To contain component:\n ${jestMatcherUtils.EXPECTED_COLOR(utilities.printType(type))}`, `${times} ${utilities.pluralize('time', times)}, but it was found ${foundByProps.length}.`].join('\n');
39
+ return {
40
+ pass,
41
+ message
42
+ };
43
+ }
44
+
45
+ exports.toContainReactComponent = toContainReactComponent;
46
+ exports.toContainReactComponentTimes = toContainReactComponentTimes;
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jestMatcherUtils = require('jest-matcher-utils');
6
+ var utilities = require('./utilities.js');
7
+
8
+ function toProvideReactContext(node, Context, value) {
9
+ utilities.assertIsNode(node, {
10
+ expectation: 'toProvideReactContext',
11
+ isNot: this.isNot
12
+ });
13
+ const foundByType = node.findAll(Context.Provider);
14
+ const foundByValue = value == null ? foundByType : foundByType.filter(element => this.equals(value, element.prop('value')));
15
+ const pass = foundByValue.length > 0;
16
+ const message = pass ? () => `${jestMatcherUtils.matcherHint('.not.toProvideReactContext')}\n\n` + `Expected the React element:\n ${jestMatcherUtils.RECEIVED_COLOR(node.toString())}\n` + `Not to contain context provider:\n ${jestMatcherUtils.EXPECTED_COLOR(utilities.printType(Context.Provider))}\n${value ? `With value matching:\n ${jestMatcherUtils.printExpected(value)}\n` : ''}` + `But ${foundByValue.length} matching ${utilities.printType(Context.Provider)}${foundByValue.length === 1 ? 's were' : ' was'} found.\n` : () => `${`${jestMatcherUtils.matcherHint('.toProvideReactContext')}\n\n` + `Expected the React element:\n ${jestMatcherUtils.RECEIVED_COLOR(node.toString())}\n` + `To contain context provider:\n ${jestMatcherUtils.EXPECTED_COLOR(utilities.printType(Context.Provider))}\n${value ? `With value matching:\n ${jestMatcherUtils.printExpected(value)}\n` : ''}`}${foundByType.length === 0 ? `But no matching ${utilities.printType(Context.Provider)}s were found.\n` : `But the ${foundByType.length === 1 ? 'found provider has' : 'found provider have'} had different values:\n\n${utilities.diffs(foundByType, {
17
+ value
18
+ }, this.expand)}`}`;
19
+ return {
20
+ pass,
21
+ message
22
+ };
23
+ }
24
+
25
+ exports.toProvideReactContext = toProvideReactContext;
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ var props = require('./props.js');
4
+ var components = require('./components.js');
5
+ var context = require('./context.js');
6
+ var strings = require('./strings.js');
7
+
8
+ expect.extend({
9
+ toHaveReactProps: props.toHaveReactProps,
10
+ toHaveReactDataProps: props.toHaveReactDataProps,
11
+ toContainReactComponent: components.toContainReactComponent,
12
+ toContainReactComponentTimes: components.toContainReactComponentTimes,
13
+ toContainReactText: strings.toContainReactText,
14
+ toContainReactHtml: strings.toContainReactHtml,
15
+ toProvideReactContext: context.toProvideReactContext
16
+ });
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jestMatcherUtils = require('jest-matcher-utils');
6
+ var utilities = require('./utilities.js');
7
+
8
+ function toHaveReactProps(node, props) {
9
+ utilities.assertIsNode(node, {
10
+ expectation: 'toHaveReactProps',
11
+ isNot: this.isNot
12
+ });
13
+
14
+ if (props == null || typeof props !== 'object') {
15
+ return {
16
+ pass: false,
17
+ message: () => `You passed ${props == null ? String(props) : `a ${typeof props}`} as props, but it must be an object.`
18
+ };
19
+ }
20
+
21
+ const pass = Object.keys(props).every(key => this.equals(props[key], node.props[key]));
22
+ const message = pass ? () => `${jestMatcherUtils.matcherHint('.not.toHaveReactProps', node.toString())}\n\n` + `Expected the React element:\n ${jestMatcherUtils.RECEIVED_COLOR(node.toString())}\n` + `Not to have props:\n ${jestMatcherUtils.printExpected(props)}\n` + `Received:\n ${jestMatcherUtils.printReceived(node.props)}\n` : () => {
23
+ const diffString = utilities.diffPropsForNode(node, props, {
24
+ expand: this.expand
25
+ });
26
+ return `${jestMatcherUtils.matcherHint('.toHaveReactProps', node.toString())}\n\n` + `Expected the React element:\n ${jestMatcherUtils.RECEIVED_COLOR(node.toString())}\n` + `To have props:\n ${jestMatcherUtils.printExpected(props)}\n` + `Received:\n ${jestMatcherUtils.printReceived(node.props)}\n${diffString ? `Difference:\n${diffString}\n` : ''}`;
27
+ };
28
+ return {
29
+ pass,
30
+ message
31
+ };
32
+ }
33
+ function toHaveReactDataProps(node, data) {
34
+ return toHaveReactProps.call(this, node, data);
35
+ }
36
+
37
+ exports.toHaveReactDataProps = toHaveReactDataProps;
38
+ exports.toHaveReactProps = toHaveReactProps;
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jestMatcherUtils = require('jest-matcher-utils');
6
+ var utilities = require('./utilities.js');
7
+
8
+ function toContainReactText(node, text) {
9
+ utilities.assertIsNode(node, {
10
+ expectation: 'toContainReactText',
11
+ isNot: this.isNot
12
+ });
13
+ const nodeText = node.text();
14
+ const matchIndex = nodeText.indexOf(text);
15
+ const pass = matchIndex >= 0;
16
+ const message = pass ? () => `${jestMatcherUtils.matcherHint('.not.toContainReactText', node.toString())}\n\n` + `Expected the React element:\n ${jestMatcherUtils.RECEIVED_COLOR(node.toString())}\n` + `Not to contain text:\n ${jestMatcherUtils.printExpected(text)}\n` + `But it did:\n ${printReceivedWithHighlight(nodeText, matchIndex, text.length)}\n` : () => `${jestMatcherUtils.matcherHint('.not.toContainReactText', node.toString())}\n\n` + `Expected the React element:\n ${jestMatcherUtils.RECEIVED_COLOR(node.toString())}\n` + `With text content:\n ${jestMatcherUtils.printReceived(nodeText)}\n` + `To contain string:\n ${jestMatcherUtils.printExpected(text)}\n`;
17
+ return {
18
+ pass,
19
+ message
20
+ };
21
+ }
22
+ function toContainReactHtml(node, text) {
23
+ utilities.assertIsNode(node, {
24
+ expectation: 'toContainReactHtml',
25
+ isNot: this.isNot
26
+ });
27
+ const nodeHtml = node.html();
28
+ const matchIndex = nodeHtml.indexOf(text);
29
+ const pass = matchIndex >= 0;
30
+ const message = pass ? () => `${jestMatcherUtils.matcherHint('.not.toContainReactHtml', node.toString())}\n\n` + `Expected the React element:\n ${jestMatcherUtils.RECEIVED_COLOR(node.toString())}\n` + `Not to contain HTML:\n ${jestMatcherUtils.printExpected(text)}\n` + `But it did:\n ${printReceivedWithHighlight(nodeHtml, matchIndex, text.length)}\n` : () => `${jestMatcherUtils.matcherHint('.not.toContainReactHtml', node.toString())}\n\n` + `Expected the React element:\n ${jestMatcherUtils.RECEIVED_COLOR(node.toString())}\n` + `With HTML content:\n ${jestMatcherUtils.printReceived(nodeHtml)}\n` + `To contain HTML:\n ${jestMatcherUtils.printExpected(text)}\n`;
31
+ return {
32
+ pass,
33
+ message
34
+ };
35
+ }
36
+
37
+ function printReceivedWithHighlight(text, start, length) {
38
+ return jestMatcherUtils.RECEIVED_COLOR(`"${text.slice(0, start)}${jestMatcherUtils.INVERTED_COLOR(text.slice(start, start + length))}${text.slice(start + length)}"`);
39
+ }
40
+
41
+ exports.toContainReactHtml = toContainReactHtml;
42
+ exports.toContainReactText = toContainReactText;
@@ -0,0 +1,110 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jestMatcherUtils = require('jest-matcher-utils');
6
+ var root = require('../root.js');
7
+ var element = require('../element.js');
8
+
9
+ function assertIsNode(node, {
10
+ expectation,
11
+ isNot
12
+ }) {
13
+ if (node == null) {
14
+ throw new Error(jestMatcherUtils.matcherErrorMessage(jestMatcherUtils.matcherHint(`.${expectation}`, undefined, undefined, {
15
+ isNot
16
+ }), `${jestMatcherUtils.RECEIVED_COLOR('received')} value must be an @shopify/react-testing Root or Element object`, `Received ${jestMatcherUtils.RECEIVED_COLOR('null')}.\nThis usually means that your \`.findX\` method failed to find any matching elements.`));
17
+ }
18
+
19
+ if (Array.isArray(node) && node.length > 1 && (node[0] instanceof root.Root || node[0] instanceof element.Element)) {
20
+ throw new Error(jestMatcherUtils.matcherErrorMessage(jestMatcherUtils.matcherHint(`.${expectation}`, undefined, undefined, {
21
+ isNot
22
+ }), `${jestMatcherUtils.RECEIVED_COLOR('received')} value must be an @shopify/react-testing Root or Element object`, `Received an ${jestMatcherUtils.RECEIVED_COLOR('array of Root or Element objects')}.\nThis usually means that you passed in the result of \`.findAllX\`. Pass the result of \`.findX\` instead.`));
23
+ }
24
+
25
+ if (!(node instanceof root.Root) && !(node instanceof element.Element)) {
26
+ throw new Error(jestMatcherUtils.matcherErrorMessage(jestMatcherUtils.matcherHint(`.${expectation}`, undefined, undefined, {
27
+ isNot
28
+ }), `${jestMatcherUtils.RECEIVED_COLOR('received')} value must be an @shopify/react-testing Root or Element object`, jestMatcherUtils.printWithType('Received', node, jestMatcherUtils.printReceived)));
29
+ }
30
+ }
31
+ function assertIsType(type, {
32
+ expectation,
33
+ isNot
34
+ }) {
35
+ if (type == null) {
36
+ throw new Error(jestMatcherUtils.matcherErrorMessage(jestMatcherUtils.matcherHint(`.${expectation}`, undefined, undefined, {
37
+ isNot
38
+ }), `${jestMatcherUtils.RECEIVED_COLOR('expected')} value must be a string or a valid React component.`, jestMatcherUtils.printWithType('Expected', type, jestMatcherUtils.printExpected)));
39
+ }
40
+ }
41
+ function diffs(element, props, expand) {
42
+ return element.reduce((diffs, element, index) => {
43
+ const separator = index === 0 ? '' : '\n\n';
44
+ return `${diffs}${separator}${normalizedDiff(element, props, {
45
+ expand,
46
+ showLegend: index === 0
47
+ })}`;
48
+ }, '');
49
+ }
50
+
51
+ function normalizedDiff(element, props, {
52
+ expand = false,
53
+ showLegend = false
54
+ }) {
55
+ const result = diffPropsForNode(element, props, {
56
+ expand
57
+ }) || '';
58
+ return showLegend ? result : result.split('\n\n')[1];
59
+ }
60
+
61
+ function printType(type) {
62
+ if (typeof type === 'object' && '_context' in type) {
63
+ const context = type._context;
64
+ const componentName = type === context.Provider ? 'Provider' : 'Consumer';
65
+
66
+ const _displayName = context.displayName || 'Context';
67
+
68
+ return `<${_displayName}.${componentName} />`;
69
+ }
70
+
71
+ const displayName = typeof type === 'string' ? type : type.displayName || type.name || 'Component';
72
+ return `<${displayName} />`;
73
+ }
74
+ function diffPropsForNode(node, props, {
75
+ expand = false
76
+ }) {
77
+ return jestMatcherUtils.diff(props, getObjectSubset(node.props, props), {
78
+ expand
79
+ });
80
+ } // Original from https://github.com/facebook/jest/blob/master/packages/expect/src/utils.ts#L107
81
+
82
+ function getObjectSubset(object, subset) {
83
+ if (Array.isArray(object)) {
84
+ if (Array.isArray(subset) && subset.length === object.length) {
85
+ return subset.map((sub, i) => getObjectSubset(object[i], sub));
86
+ }
87
+ } else if (object instanceof Date) {
88
+ return object;
89
+ } else if (typeof object === 'object' && object !== null && typeof subset === 'object' && subset !== null) {
90
+ const trimmed = {};
91
+ Object.keys(subset).filter(key => Reflect.has(object, key)).forEach(key => trimmed[key] = getObjectSubset(object[key], subset[key]));
92
+
93
+ if (Object.keys(trimmed).length > 0) {
94
+ return trimmed;
95
+ }
96
+ }
97
+
98
+ return object;
99
+ }
100
+
101
+ function pluralize(word, count) {
102
+ return count === 1 ? word : `${word}s`;
103
+ }
104
+
105
+ exports.assertIsNode = assertIsNode;
106
+ exports.assertIsType = assertIsType;
107
+ exports.diffPropsForNode = diffPropsForNode;
108
+ exports.diffs = diffs;
109
+ exports.pluralize = pluralize;
110
+ exports.printType = printType;