@shopify/ui-extensions-server-kit 0.0.0-nightly-20250605112924

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 (260) hide show
  1. package/CHANGELOG.md +133 -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 +30 -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 +55 -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 +7 -0
  47. package/dist/state/actions/actions.es.js +44 -0
  48. package/dist/state/actions/index.d.ts +2 -0
  49. package/dist/state/actions/types.d.ts +25 -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 +181 -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.d.ts +3 -0
  189. package/node_modules/@shopify/ui-extensions-test-utils/dist/index.js +3 -0
  190. package/node_modules/@shopify/ui-extensions-test-utils/dist/render.d.ts +2 -0
  191. package/node_modules/@shopify/ui-extensions-test-utils/dist/render.js +5 -0
  192. package/node_modules/@shopify/ui-extensions-test-utils/dist/renderHook.d.ts +17 -0
  193. package/node_modules/@shopify/ui-extensions-test-utils/dist/renderHook.js +20 -0
  194. package/node_modules/@shopify/ui-extensions-test-utils/dist/withProviders.d.ts +9 -0
  195. package/node_modules/@shopify/ui-extensions-test-utils/dist/withProviders.js +7 -0
  196. package/node_modules/@shopify/ui-extensions-test-utils/package.json +40 -0
  197. package/node_modules/@shopify/ui-extensions-test-utils/project.json +39 -0
  198. package/node_modules/@types/react/LICENSE +21 -0
  199. package/node_modules/@types/react/README.md +16 -0
  200. package/node_modules/@types/react/experimental.d.ts +192 -0
  201. package/node_modules/@types/react/global.d.ts +151 -0
  202. package/node_modules/@types/react/index.d.ts +3175 -0
  203. package/node_modules/@types/react/jsx-dev-runtime.d.ts +2 -0
  204. package/node_modules/@types/react/jsx-runtime.d.ts +2 -0
  205. package/node_modules/@types/react/package.json +149 -0
  206. package/node_modules/@vitejs/plugin-react-refresh/LICENSE +21 -0
  207. package/node_modules/@vitejs/plugin-react-refresh/README.md +73 -0
  208. package/node_modules/@vitejs/plugin-react-refresh/index.d.ts +14 -0
  209. package/node_modules/@vitejs/plugin-react-refresh/index.js +239 -0
  210. package/node_modules/@vitejs/plugin-react-refresh/package.json +35 -0
  211. package/package.json +67 -0
  212. package/project.json +72 -0
  213. package/scripts/create-entry-files.ts +44 -0
  214. package/src/ExtensionServerClient/ExtensionServerClient.test.ts +730 -0
  215. package/src/ExtensionServerClient/ExtensionServerClient.ts +311 -0
  216. package/src/ExtensionServerClient/index.ts +2 -0
  217. package/src/ExtensionServerClient/types.ts +161 -0
  218. package/src/context/ExtensionServerProvider.test.tsx +173 -0
  219. package/src/context/ExtensionServerProvider.tsx +48 -0
  220. package/src/context/constants.ts +15 -0
  221. package/src/context/index.ts +3 -0
  222. package/src/context/types.ts +13 -0
  223. package/src/hooks/index.ts +5 -0
  224. package/src/hooks/useExtensionClient.ts +6 -0
  225. package/src/hooks/useExtensionServerContext.ts +4 -0
  226. package/src/hooks/useExtensionServerEvent.ts +11 -0
  227. package/src/hooks/useExtensionServerState.ts +6 -0
  228. package/src/hooks/useIsomorphicLayoutEffect.ts +6 -0
  229. package/src/i18n.test.ts +417 -0
  230. package/src/i18n.ts +208 -0
  231. package/src/index.ts +7 -0
  232. package/src/state/actions/actions.ts +43 -0
  233. package/src/state/actions/index.ts +2 -0
  234. package/src/state/actions/types.ts +37 -0
  235. package/src/state/index.ts +2 -0
  236. package/src/state/reducers/constants.ts +6 -0
  237. package/src/state/reducers/extensionServerReducer.test.ts +174 -0
  238. package/src/state/reducers/extensionServerReducer.ts +87 -0
  239. package/src/state/reducers/index.ts +3 -0
  240. package/src/state/reducers/types.ts +7 -0
  241. package/src/testing/MockExtensionServerProvider.tsx +36 -0
  242. package/src/testing/app.ts +15 -0
  243. package/src/testing/extensions.ts +70 -0
  244. package/src/testing/index.ts +3 -0
  245. package/src/types.ts +180 -0
  246. package/src/utilities/assetToString.test.ts +16 -0
  247. package/src/utilities/assetToString.ts +8 -0
  248. package/src/utilities/groupByKey.ts +3 -0
  249. package/src/utilities/index.ts +7 -0
  250. package/src/utilities/isUIExtension.ts +7 -0
  251. package/src/utilities/isValidSurface.ts +7 -0
  252. package/src/utilities/noop.ts +1 -0
  253. package/src/utilities/replaceUpdated.test.ts +26 -0
  254. package/src/utilities/replaceUpdated.ts +17 -0
  255. package/src/utilities/set.test.ts +19 -0
  256. package/src/utilities/set.ts +30 -0
  257. package/testing.d.ts +1 -0
  258. package/testing.js +1 -0
  259. package/testing.mjs +1 -0
  260. package/tests/setup.ts +6 -0
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
6
+ var root = require('./root.js');
7
+
8
+ function mount(element) {
9
+ return new root.Root(element);
10
+ }
11
+ class CustomRoot extends root.Root {
12
+ constructor(tree, context, options) {
13
+ super(tree, options);
14
+ this.context = context;
15
+ }
16
+
17
+ }
18
+ function createMount({
19
+ render,
20
+ context: createContext = defaultContext,
21
+ afterMount = defaultAfterMount,
22
+ cleanup
23
+ }) {
24
+ function mount(element, options = {}) {
25
+ const context = createContext(options);
26
+ const wrapper = new CustomRoot(element, context, {
27
+ render: element => render(element, context, options),
28
+ resolveRoot: root => root.find(element.type)
29
+ });
30
+
31
+ if (cleanup) {
32
+ const originalDestroy = wrapper.destroy.bind(wrapper);
33
+
34
+ wrapper.destroy = () => {
35
+ cleanup(wrapper, options);
36
+ originalDestroy();
37
+ };
38
+ }
39
+
40
+ const afterMountResult = afterMount(wrapper, options);
41
+ return afterMountResult != null && 'then' in afterMountResult ? afterMountResult.then(() => wrapper) : wrapper;
42
+ }
43
+
44
+ Reflect.defineProperty(mount, 'extend', {
45
+ writable: false,
46
+ value: ({
47
+ context: createAdditionalContext = defaultContext,
48
+ render: additionalRender,
49
+ afterMount: additionalAfterMount = defaultAfterMount
50
+ }) => {
51
+ return createMount({
52
+ context: options => _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, createContext(options)), createAdditionalContext(options)),
53
+ render: (element, context, options) => render(additionalRender(element, context, options), context, options),
54
+ afterMount: (wrapper, options) => {
55
+ const result = additionalAfterMount(wrapper, options);
56
+
57
+ const finalResult = () => afterMount(wrapper, options);
58
+
59
+ return result != null && 'then' in result ? result.then(finalResult) : finalResult();
60
+ }
61
+ });
62
+ }
63
+ });
64
+ return mount;
65
+ }
66
+
67
+ function defaultContext() {
68
+ return {};
69
+ }
70
+
71
+ function defaultAfterMount() {}
72
+
73
+ exports.Root = root.Root;
74
+ exports.CustomRoot = CustomRoot;
75
+ exports.createMount = createMount;
76
+ exports.mount = mount;
@@ -0,0 +1,284 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var reactDom = require('react-dom');
7
+ var testUtils = require('react-dom/test-utils');
8
+ var TestWrapper = require('./TestWrapper.js');
9
+ var element = require('./element.js');
10
+ var compat = require('./compat.js');
11
+ var types = require('./types.js');
12
+
13
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
+
15
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
16
+
17
+ const {
18
+ findCurrentFiberUsingSlowPath
19
+ } = require('react-reconciler/reflection');
20
+
21
+ const connected = new Set();
22
+ class Root {
23
+ get props() {
24
+ return this.withRoot(root => root.props);
25
+ }
26
+
27
+ get isDOM() {
28
+ return this.withRoot(root => root.isDOM);
29
+ }
30
+
31
+ get type() {
32
+ return this.withRoot(root => root.type);
33
+ }
34
+
35
+ get instance() {
36
+ return this.withRoot(root => root.instance);
37
+ }
38
+
39
+ get children() {
40
+ return this.withRoot(root => root.children);
41
+ }
42
+
43
+ get descendants() {
44
+ return this.withRoot(root => root.descendants);
45
+ }
46
+
47
+ get domNodes() {
48
+ return this.withRoot(root => root.domNodes);
49
+ }
50
+
51
+ get domNode() {
52
+ return this.withRoot(root => root.domNode);
53
+ }
54
+
55
+ get mounted() {
56
+ return this.wrapper != null;
57
+ }
58
+
59
+ constructor(tree, {
60
+ render = defaultRender,
61
+ resolveRoot = defaultResolveRoot
62
+ } = {}) {
63
+ this.tree = tree;
64
+ this.wrapper = null;
65
+ this.element = document.createElement('div');
66
+ this.root = null;
67
+ this.acting = false;
68
+ this.render = void 0;
69
+ this.resolveRoot = void 0;
70
+ this.render = render;
71
+ this.resolveRoot = resolveRoot;
72
+ this.mount();
73
+ }
74
+
75
+ act(action, {
76
+ update = true
77
+ } = {}) {
78
+ const updateWrapper = update ? this.update.bind(this) : noop;
79
+ let result;
80
+
81
+ if (this.acting) {
82
+ return action();
83
+ }
84
+
85
+ this.acting = true;
86
+
87
+ const afterResolve = () => {
88
+ updateWrapper();
89
+ this.acting = false;
90
+ return result;
91
+ };
92
+
93
+ const promise = testUtils.act(() => {
94
+ result = action(); // This condition checks the returned value is an actual Promise and returns it
95
+ // to React’s `act()` call, otherwise we just want to return `undefined`
96
+
97
+ if (isPromise(result)) {
98
+ return result;
99
+ }
100
+
101
+ return undefined;
102
+ });
103
+
104
+ if (isPromise(result)) {
105
+ updateWrapper();
106
+ return Promise.resolve(promise).then(afterResolve);
107
+ }
108
+
109
+ return afterResolve();
110
+ }
111
+
112
+ html() {
113
+ return this.withRoot(root => root.html());
114
+ }
115
+
116
+ text() {
117
+ return this.withRoot(root => root.text());
118
+ }
119
+
120
+ is(type) {
121
+ return this.withRoot(root => root.is(type));
122
+ }
123
+
124
+ prop(key) {
125
+ return this.withRoot(root => root.prop(key));
126
+ }
127
+
128
+ data(key) {
129
+ return this.withRoot(root => root.data(key));
130
+ }
131
+
132
+ find(type, props) {
133
+ return this.withRoot(root => root.find(type, props));
134
+ }
135
+
136
+ findAll(type, props) {
137
+ return this.withRoot(root => root.findAll(type, props));
138
+ }
139
+
140
+ findWhere(predicate) {
141
+ return this.withRoot(root => root.findWhere(predicate));
142
+ }
143
+
144
+ findAllWhere(predicate) {
145
+ return this.withRoot(root => root.findAllWhere(predicate));
146
+ }
147
+
148
+ trigger(prop, ...args) {
149
+ return this.withRoot(root => root.trigger(prop, ...args));
150
+ }
151
+
152
+ triggerKeypath(keypath, ...args) {
153
+ return this.withRoot(root => root.triggerKeypath(keypath, ...args));
154
+ }
155
+
156
+ mount() {
157
+ if (this.mounted) {
158
+ throw new Error('Attempted to mount a node that was already mounted');
159
+ }
160
+
161
+ if (this.element.parentNode == null) {
162
+ document.body.appendChild(this.element);
163
+ connected.add(this);
164
+ }
165
+
166
+ this.act(() => {
167
+ reactDom.render( /*#__PURE__*/React__default["default"].createElement(TestWrapper.TestWrapper, {
168
+ render: this.render,
169
+ ref: wrapper => {
170
+ this.wrapper = wrapper;
171
+ }
172
+ }, this.tree), this.element);
173
+ });
174
+ }
175
+
176
+ unmount() {
177
+ if (!this.mounted) {
178
+ throw new Error('You attempted to unmount a node that was already unmounted');
179
+ }
180
+
181
+ this.ensureRoot();
182
+ this.act(() => reactDom.unmountComponentAtNode(this.element));
183
+ }
184
+
185
+ destroy() {
186
+ const {
187
+ element,
188
+ mounted
189
+ } = this;
190
+
191
+ if (mounted) {
192
+ this.unmount();
193
+ }
194
+
195
+ element.remove();
196
+ connected.delete(this);
197
+ }
198
+
199
+ setProps(props) {
200
+ this.ensureRoot();
201
+ this.act(() => this.wrapper.setProps(props));
202
+ }
203
+
204
+ forceUpdate() {
205
+ this.ensureRoot();
206
+ this.act(() => this.wrapper.forceUpdate());
207
+ }
208
+
209
+ debug(options) {
210
+ this.ensureRoot();
211
+ return this.root.debug(options);
212
+ }
213
+
214
+ toString() {
215
+ return this.withRoot(root => root.toString());
216
+ }
217
+
218
+ update() {
219
+ if (this.wrapper == null) {
220
+ this.root = null;
221
+ } else {
222
+ const rootFiber = compat.getInternals(this.wrapper.rootRef);
223
+ const topElement = fiberToElement(findCurrentFiberUsingSlowPath(rootFiber), this);
224
+ this.root = this.resolveRoot(topElement);
225
+ }
226
+ }
227
+
228
+ ensureRoot() {
229
+ if (this.wrapper == null || this.root == null) {
230
+ throw new Error('Attempted to operate on a mounted tree, but the component is no longer mounted');
231
+ }
232
+ }
233
+
234
+ withRoot(withRoot) {
235
+ this.ensureRoot();
236
+ return withRoot(this.root);
237
+ }
238
+
239
+ }
240
+
241
+ function defaultResolveRoot(element) {
242
+ return element.children[0];
243
+ }
244
+
245
+ function defaultRender(element) {
246
+ return element;
247
+ }
248
+
249
+ function fiberToElement(node, root) {
250
+ if (node.tag === types.Tag.HostText) {
251
+ return node.memoizedProps;
252
+ }
253
+
254
+ const props = node.memoizedProps;
255
+ const children = childrenToTree(node.child, root);
256
+ return new element.Element({
257
+ tag: node.tag,
258
+ type: node.type,
259
+ props,
260
+ instance: node.stateNode
261
+ }, children, root);
262
+ }
263
+
264
+ function childrenToTree(fiber, root) {
265
+ let currentFiber = fiber;
266
+ const children = [];
267
+
268
+ while (currentFiber != null) {
269
+ const result = fiberToElement(currentFiber, root);
270
+ children.push(result);
271
+ currentFiber = currentFiber.sibling;
272
+ }
273
+
274
+ return children;
275
+ }
276
+
277
+ function isPromise(promise) {
278
+ return promise != null && typeof promise === 'object' && 'then' in promise;
279
+ }
280
+
281
+ function noop() {}
282
+
283
+ exports.Root = Root;
284
+ exports.connected = connected;
@@ -0,0 +1,86 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jestMatcherUtils = require('jest-matcher-utils');
6
+
7
+ function toReactString(node, options = {}, level = 0) {
8
+ // if this is an array node then print all children at the current level
9
+ if (!node.type && node.children.length > 0) {
10
+ return node.children.map(child => toReactString(child, options, level)).join('\n');
11
+ }
12
+
13
+ const name = nodeName(node);
14
+ const indent = ' '.repeat(level);
15
+ const props = Object.keys(node.props) // we always filter out children no matter what, but unless allProps option
16
+ // is present we will also filter out insigificant props
17
+ .filter(key => options.allProps ? key !== 'children' : !/^(children|className)$|^(aria|data)-/.test(key)).reduce((list, key) => {
18
+ if (!key) {
19
+ return list;
20
+ }
21
+
22
+ const value = node.props[key];
23
+
24
+ if (value === undefined && !options.allProps) {
25
+ return list;
26
+ }
27
+
28
+ list.push(toPropString(key, value, options.verbosity));
29
+ return list;
30
+ }, []);
31
+ const hasChildren = node.children.length > 0 && !['svg'].includes(name);
32
+ const open = `${indent}<${name}${props.length > 0 ? ` ${props.join(' ')}` : ''}${hasChildren ? '>' : ' />'}`;
33
+
34
+ if (!hasChildren) {
35
+ return open;
36
+ }
37
+
38
+ const close = `${indent}</${name}>`;
39
+
40
+ if (options.depth != null && level >= options.depth) {
41
+ return [open, `${indent} {/* <${node.children.length} child${node.children.length === 1 ? '' : 'ren'}... /> */}`, close].join('\n');
42
+ }
43
+
44
+ return [open, ...node.children.map(child => toReactString(child, options, level + 1)), close].join('\n');
45
+ }
46
+ function toPropString(key, value, verbosity = 1) {
47
+ if (value === undefined) {
48
+ return `${key}={undefined}`;
49
+ }
50
+
51
+ if (value === null) {
52
+ return `${key}={null}`;
53
+ }
54
+
55
+ if (typeof value === 'string') {
56
+ return `${key}="${value}"`;
57
+ }
58
+
59
+ if (typeof value === 'boolean' && value) {
60
+ return value ? `${key}` : `${key}={false}`;
61
+ }
62
+
63
+ if (value instanceof Array) {
64
+ return `${key}={${jestMatcherUtils.stringify(value, verbosity + 1)}}`;
65
+ }
66
+
67
+ return `${key}={${jestMatcherUtils.stringify(value, verbosity)}}`;
68
+ }
69
+ function nodeName({
70
+ type
71
+ }) {
72
+ if (type && typeof type === 'object' && '_context' in type) {
73
+ const context = type._context;
74
+ return `${context.displayName || 'Context'}.${type === context.Provider ? 'Provider' : 'Consumer'}`;
75
+ }
76
+
77
+ if (type == null) {
78
+ return 'Node';
79
+ }
80
+
81
+ return typeof type === 'string' ? type : type.displayName || type.name || 'Component';
82
+ }
83
+
84
+ exports.nodeName = nodeName;
85
+ exports.toPropString = toPropString;
86
+ exports.toReactString = toReactString;
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ // https://github.com/facebook/react/blob/master/packages/shared/ReactWorkTag.js
6
+ exports.Tag = void 0;
7
+
8
+ (function (Tag) {
9
+ Tag[Tag["FunctionComponent"] = 0] = "FunctionComponent";
10
+ Tag[Tag["ClassComponent"] = 1] = "ClassComponent";
11
+ Tag[Tag["IndeterminateComponent"] = 2] = "IndeterminateComponent";
12
+ Tag[Tag["HostRoot"] = 3] = "HostRoot";
13
+ Tag[Tag["HostPortal"] = 4] = "HostPortal";
14
+ Tag[Tag["HostComponent"] = 5] = "HostComponent";
15
+ Tag[Tag["HostText"] = 6] = "HostText";
16
+ Tag[Tag["Fragment"] = 7] = "Fragment";
17
+ Tag[Tag["Mode"] = 8] = "Mode";
18
+ Tag[Tag["ContextConsumer"] = 9] = "ContextConsumer";
19
+ Tag[Tag["ContextProvider"] = 10] = "ContextProvider";
20
+ Tag[Tag["ForwardRef"] = 11] = "ForwardRef";
21
+ Tag[Tag["Profiler"] = 12] = "Profiler";
22
+ Tag[Tag["SuspenseComponent"] = 13] = "SuspenseComponent";
23
+ Tag[Tag["MemoComponent"] = 14] = "MemoComponent";
24
+ Tag[Tag["SimpleMemoComponent"] = 15] = "SimpleMemoComponent";
25
+ Tag[Tag["LazyComponent"] = 16] = "LazyComponent";
26
+ Tag[Tag["IncompleteClassComponent"] = 17] = "IncompleteClassComponent";
27
+ Tag[Tag["DehydratedSuspenseComponent"] = 18] = "DehydratedSuspenseComponent";
28
+ })(exports.Tag || (exports.Tag = {}));
@@ -0,0 +1,44 @@
1
+ import React from 'react';
2
+
3
+ class TestWrapper extends React.Component {
4
+ constructor(...args) {
5
+ super(...args);
6
+ this.state = {};
7
+ this.rootRef = null;
8
+
9
+ this.setRef = ref => {
10
+ this.rootRef = ref;
11
+ };
12
+ }
13
+
14
+ // eslint-disable-next-line @shopify/react-prefer-private-members
15
+ setProps(props) {
16
+ this.setState({
17
+ props
18
+ });
19
+ }
20
+
21
+ render() {
22
+ const {
23
+ props
24
+ } = this.state;
25
+ const {
26
+ children,
27
+ render
28
+ } = this.props;
29
+ const rootElement = props ? /*#__PURE__*/React.cloneElement(children, props) : children;
30
+ return render( /*#__PURE__*/React.createElement(TestInnerWrapper, {
31
+ ref: this.setRef
32
+ }, rootElement));
33
+ }
34
+
35
+ }
36
+
37
+ class TestInnerWrapper extends React.Component {
38
+ render() {
39
+ return this.props.children;
40
+ }
41
+
42
+ }
43
+
44
+ export { TestWrapper };
@@ -0,0 +1,42 @@
1
+ function ownKeys(object, enumerableOnly) {
2
+ var keys = Object.keys(object);
3
+
4
+ if (Object.getOwnPropertySymbols) {
5
+ var symbols = Object.getOwnPropertySymbols(object);
6
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
7
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
8
+ })), keys.push.apply(keys, symbols);
9
+ }
10
+
11
+ return keys;
12
+ }
13
+
14
+ function _objectSpread2(target) {
15
+ for (var i = 1; i < arguments.length; i++) {
16
+ var source = null != arguments[i] ? arguments[i] : {};
17
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
18
+ _defineProperty(target, key, source[key]);
19
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
20
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
21
+ });
22
+ }
23
+
24
+ return target;
25
+ }
26
+
27
+ function _defineProperty(obj, key, value) {
28
+ if (key in obj) {
29
+ Object.defineProperty(obj, key, {
30
+ value: value,
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true
34
+ });
35
+ } else {
36
+ obj[key] = value;
37
+ }
38
+
39
+ return obj;
40
+ }
41
+
42
+ export { _defineProperty as defineProperty, _objectSpread2 as objectSpread2 };
@@ -0,0 +1,10 @@
1
+ function getInternals(instance) {
2
+ // In React 17+ _reactInternalFiber was renamed to _reactInternals. As such we need to handle both APIs to maintain support.
3
+ if ('_reactInternalFiber' in instance) {
4
+ return instance._reactInternalFiber;
5
+ }
6
+
7
+ return instance._reactInternals;
8
+ }
9
+
10
+ export { getInternals };
@@ -0,0 +1,9 @@
1
+ import { connected } from './root.mjs';
2
+
3
+ function destroyAll() {
4
+ for (const wrapper of [...connected]) {
5
+ wrapper.destroy();
6
+ }
7
+ }
8
+
9
+ export { destroyAll };