@shopify/ui-extensions-server-kit 0.0.0-snapshot-20240814205424
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.
- package/CHANGELOG.md +127 -0
- package/README.md +74 -0
- package/dist/ExtensionServerClient/ExtensionServerClient.cjs.js +1 -0
- package/dist/ExtensionServerClient/ExtensionServerClient.d.ts +28 -0
- package/dist/ExtensionServerClient/ExtensionServerClient.es.js +133 -0
- package/dist/ExtensionServerClient/ExtensionServerClient.test.d.ts +1 -0
- package/dist/ExtensionServerClient/index.d.ts +2 -0
- package/dist/ExtensionServerClient/types.cjs.js +1 -0
- package/dist/ExtensionServerClient/types.d.ts +124 -0
- package/dist/ExtensionServerClient/types.es.js +4 -0
- package/dist/context/ExtensionServerProvider.cjs.js +1 -0
- package/dist/context/ExtensionServerProvider.d.ts +2 -0
- package/dist/context/ExtensionServerProvider.es.js +29 -0
- package/dist/context/ExtensionServerProvider.test.d.ts +1 -0
- package/dist/context/constants.cjs.js +1 -0
- package/dist/context/constants.d.ts +3 -0
- package/dist/context/constants.es.js +14 -0
- package/dist/context/index.d.ts +3 -0
- package/dist/context/types.d.ts +11 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/useExtensionClient.cjs.js +1 -0
- package/dist/hooks/useExtensionClient.d.ts +1 -0
- package/dist/hooks/useExtensionClient.es.js +8 -0
- package/dist/hooks/useExtensionServerContext.cjs.js +1 -0
- package/dist/hooks/useExtensionServerContext.d.ts +1 -0
- package/dist/hooks/useExtensionServerContext.es.js +6 -0
- package/dist/hooks/useExtensionServerEvent.cjs.js +1 -0
- package/dist/hooks/useExtensionServerEvent.d.ts +1 -0
- package/dist/hooks/useExtensionServerEvent.es.js +9 -0
- package/dist/hooks/useExtensionServerState.cjs.js +1 -0
- package/dist/hooks/useExtensionServerState.d.ts +1 -0
- package/dist/hooks/useExtensionServerState.es.js +9 -0
- package/dist/hooks/useIsomorphicLayoutEffect.cjs.js +1 -0
- package/dist/hooks/useIsomorphicLayoutEffect.d.ts +2 -0
- package/dist/hooks/useIsomorphicLayoutEffect.es.js +5 -0
- package/dist/i18n.cjs.js +1 -0
- package/dist/i18n.d.ts +93 -0
- package/dist/i18n.es.js +61 -0
- package/dist/i18n.test.d.ts +1 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.cjs2.js +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.es.js +54 -0
- package/dist/index.es2.js +8 -0
- package/dist/state/actions/actions.cjs.js +1 -0
- package/dist/state/actions/actions.d.ts +6 -0
- package/dist/state/actions/actions.es.js +37 -0
- package/dist/state/actions/index.d.ts +2 -0
- package/dist/state/actions/types.d.ts +21 -0
- package/dist/state/index.d.ts +2 -0
- package/dist/state/reducers/constants.cjs.js +1 -0
- package/dist/state/reducers/constants.d.ts +2 -0
- package/dist/state/reducers/constants.es.js +7 -0
- package/dist/state/reducers/extensionServerReducer.cjs.js +1 -0
- package/dist/state/reducers/extensionServerReducer.d.ts +3 -0
- package/dist/state/reducers/extensionServerReducer.es.js +57 -0
- package/dist/state/reducers/extensionServerReducer.test.d.ts +1 -0
- package/dist/state/reducers/index.d.ts +3 -0
- package/dist/state/reducers/types.d.ts +6 -0
- package/dist/testing/MockExtensionServerProvider.cjs.js +1 -0
- package/dist/testing/MockExtensionServerProvider.d.ts +7 -0
- package/dist/testing/MockExtensionServerProvider.es.js +24 -0
- package/dist/testing/app.cjs.js +1 -0
- package/dist/testing/app.d.ts +2 -0
- package/dist/testing/app.es.js +16 -0
- package/dist/testing/extensions.cjs.js +1 -0
- package/dist/testing/extensions.d.ts +6 -0
- package/dist/testing/extensions.es.js +65 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/types.cjs.js +1 -0
- package/dist/types.d.ts +173 -0
- package/dist/types.es.js +4 -0
- package/dist/utilities/assetToString.cjs.js +1 -0
- package/dist/utilities/assetToString.d.ts +2 -0
- package/dist/utilities/assetToString.es.js +7 -0
- package/dist/utilities/assetToString.test.d.ts +1 -0
- package/dist/utilities/groupByKey.cjs.js +1 -0
- package/dist/utilities/groupByKey.d.ts +3 -0
- package/dist/utilities/groupByKey.es.js +6 -0
- package/dist/utilities/index.d.ts +7 -0
- package/dist/utilities/isUIExtension.cjs.js +1 -0
- package/dist/utilities/isUIExtension.d.ts +1 -0
- package/dist/utilities/isUIExtension.es.js +6 -0
- package/dist/utilities/isValidSurface.cjs.js +1 -0
- package/dist/utilities/isValidSurface.d.ts +2 -0
- package/dist/utilities/isValidSurface.es.js +7 -0
- package/dist/utilities/noop.cjs.js +1 -0
- package/dist/utilities/noop.d.ts +1 -0
- package/dist/utilities/noop.es.js +5 -0
- package/dist/utilities/replaceUpdated.cjs.js +1 -0
- package/dist/utilities/replaceUpdated.d.ts +1 -0
- package/dist/utilities/replaceUpdated.es.js +14 -0
- package/dist/utilities/replaceUpdated.test.d.ts +1 -0
- package/dist/utilities/set.cjs.js +1 -0
- package/dist/utilities/set.d.ts +4 -0
- package/dist/utilities/set.es.js +18 -0
- package/dist/utilities/set.test.d.ts +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.mjs +1 -0
- package/node_modules/@shopify/react-testing/LICENSE.md +21 -0
- package/node_modules/@shopify/react-testing/README.md +711 -0
- package/node_modules/@shopify/react-testing/build/cjs/TestWrapper.js +52 -0
- package/node_modules/@shopify/react-testing/build/cjs/_virtual/_rollupPluginBabelHelpers.js +47 -0
- package/node_modules/@shopify/react-testing/build/cjs/compat.js +14 -0
- package/node_modules/@shopify/react-testing/build/cjs/destroy.js +13 -0
- package/node_modules/@shopify/react-testing/build/cjs/element.js +225 -0
- package/node_modules/@shopify/react-testing/build/cjs/index.js +21 -0
- package/node_modules/@shopify/react-testing/build/cjs/matchers/components.js +46 -0
- package/node_modules/@shopify/react-testing/build/cjs/matchers/context.js +25 -0
- package/node_modules/@shopify/react-testing/build/cjs/matchers/index.js +16 -0
- package/node_modules/@shopify/react-testing/build/cjs/matchers/props.js +38 -0
- package/node_modules/@shopify/react-testing/build/cjs/matchers/strings.js +42 -0
- package/node_modules/@shopify/react-testing/build/cjs/matchers/utilities.js +110 -0
- package/node_modules/@shopify/react-testing/build/cjs/mount.js +76 -0
- package/node_modules/@shopify/react-testing/build/cjs/root.js +284 -0
- package/node_modules/@shopify/react-testing/build/cjs/toReactString.js +86 -0
- package/node_modules/@shopify/react-testing/build/cjs/types.js +28 -0
- package/node_modules/@shopify/react-testing/build/esm/TestWrapper.mjs +44 -0
- package/node_modules/@shopify/react-testing/build/esm/_virtual/_rollupPluginBabelHelpers.mjs +42 -0
- package/node_modules/@shopify/react-testing/build/esm/compat.mjs +10 -0
- package/node_modules/@shopify/react-testing/build/esm/destroy.mjs +9 -0
- package/node_modules/@shopify/react-testing/build/esm/element.mjs +221 -0
- package/node_modules/@shopify/react-testing/build/esm/index.mjs +5 -0
- package/node_modules/@shopify/react-testing/build/esm/matchers/components.mjs +41 -0
- package/node_modules/@shopify/react-testing/build/esm/matchers/context.mjs +21 -0
- package/node_modules/@shopify/react-testing/build/esm/matchers/index.mjs +14 -0
- package/node_modules/@shopify/react-testing/build/esm/matchers/props.mjs +33 -0
- package/node_modules/@shopify/react-testing/build/esm/matchers/strings.mjs +37 -0
- package/node_modules/@shopify/react-testing/build/esm/matchers/utilities.mjs +101 -0
- package/node_modules/@shopify/react-testing/build/esm/mount.mjs +70 -0
- package/node_modules/@shopify/react-testing/build/esm/root.mjs +275 -0
- package/node_modules/@shopify/react-testing/build/esm/toReactString.mjs +80 -0
- package/node_modules/@shopify/react-testing/build/esm/types.mjs +26 -0
- package/node_modules/@shopify/react-testing/build/esnext/TestWrapper.esnext +44 -0
- package/node_modules/@shopify/react-testing/build/esnext/compat.esnext +10 -0
- package/node_modules/@shopify/react-testing/build/esnext/destroy.esnext +9 -0
- package/node_modules/@shopify/react-testing/build/esnext/element.esnext +221 -0
- package/node_modules/@shopify/react-testing/build/esnext/index.esnext +5 -0
- package/node_modules/@shopify/react-testing/build/esnext/matchers/components.esnext +41 -0
- package/node_modules/@shopify/react-testing/build/esnext/matchers/context.esnext +21 -0
- package/node_modules/@shopify/react-testing/build/esnext/matchers/index.esnext +14 -0
- package/node_modules/@shopify/react-testing/build/esnext/matchers/props.esnext +33 -0
- package/node_modules/@shopify/react-testing/build/esnext/matchers/strings.esnext +37 -0
- package/node_modules/@shopify/react-testing/build/esnext/matchers/utilities.esnext +99 -0
- package/node_modules/@shopify/react-testing/build/esnext/mount.esnext +71 -0
- package/node_modules/@shopify/react-testing/build/esnext/root.esnext +275 -0
- package/node_modules/@shopify/react-testing/build/esnext/toReactString.esnext +80 -0
- package/node_modules/@shopify/react-testing/build/esnext/types.esnext +26 -0
- package/node_modules/@shopify/react-testing/build/ts/TestWrapper.d.ts +17 -0
- package/node_modules/@shopify/react-testing/build/ts/TestWrapper.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/build/ts/compat.d.ts +3 -0
- package/node_modules/@shopify/react-testing/build/ts/compat.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/build/ts/destroy.d.ts +2 -0
- package/node_modules/@shopify/react-testing/build/ts/destroy.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/build/ts/element.d.ts +42 -0
- package/node_modules/@shopify/react-testing/build/ts/element.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/build/ts/index.d.ts +7 -0
- package/node_modules/@shopify/react-testing/build/ts/index.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/build/ts/matchers/components.d.ts +12 -0
- package/node_modules/@shopify/react-testing/build/ts/matchers/components.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/build/ts/matchers/context.d.ts +8 -0
- package/node_modules/@shopify/react-testing/build/ts/matchers/context.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/build/ts/matchers/index.d.ts +20 -0
- package/node_modules/@shopify/react-testing/build/ts/matchers/index.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/build/ts/matchers/props.d.ts +10 -0
- package/node_modules/@shopify/react-testing/build/ts/matchers/props.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/build/ts/matchers/strings.d.ts +11 -0
- package/node_modules/@shopify/react-testing/build/ts/matchers/strings.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/build/ts/matchers/utilities.d.ts +17 -0
- package/node_modules/@shopify/react-testing/build/ts/matchers/utilities.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/build/ts/mount.d.ts +39 -0
- package/node_modules/@shopify/react-testing/build/ts/mount.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/build/ts/root.d.ts +55 -0
- package/node_modules/@shopify/react-testing/build/ts/root.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/build/ts/toReactString.d.ts +5 -0
- package/node_modules/@shopify/react-testing/build/ts/toReactString.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/build/ts/types.d.ts +89 -0
- package/node_modules/@shopify/react-testing/build/ts/types.d.ts.map +1 -0
- package/node_modules/@shopify/react-testing/index.esnext +1 -0
- package/node_modules/@shopify/react-testing/index.js +1 -0
- package/node_modules/@shopify/react-testing/index.mjs +1 -0
- package/node_modules/@shopify/react-testing/matchers.esnext +1 -0
- package/node_modules/@shopify/react-testing/matchers.js +1 -0
- package/node_modules/@shopify/react-testing/matchers.mjs +1 -0
- package/node_modules/@shopify/react-testing/package.json +69 -0
- package/node_modules/@shopify/ui-extensions-test-utils/CHANGELOG.md +66 -0
- package/node_modules/@shopify/ui-extensions-test-utils/dist/index.js +3 -0
- package/node_modules/@shopify/ui-extensions-test-utils/dist/render.js +5 -0
- package/node_modules/@shopify/ui-extensions-test-utils/dist/renderHook.js +20 -0
- package/node_modules/@shopify/ui-extensions-test-utils/dist/withProviders.js +6 -0
- package/node_modules/@shopify/ui-extensions-test-utils/package.json +41 -0
- package/node_modules/@shopify/ui-extensions-test-utils/project.json +39 -0
- package/node_modules/@types/node/LICENSE +21 -0
- package/node_modules/@types/node/README.md +15 -0
- package/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/node_modules/@types/node/assert.d.ts +985 -0
- package/node_modules/@types/node/async_hooks.d.ts +522 -0
- package/node_modules/@types/node/buffer.d.ts +2321 -0
- package/node_modules/@types/node/child_process.d.ts +1544 -0
- package/node_modules/@types/node/cluster.d.ts +432 -0
- package/node_modules/@types/node/console.d.ts +412 -0
- package/node_modules/@types/node/constants.d.ts +19 -0
- package/node_modules/@types/node/crypto.d.ts +4451 -0
- package/node_modules/@types/node/dgram.d.ts +586 -0
- package/node_modules/@types/node/diagnostics_channel.d.ts +192 -0
- package/node_modules/@types/node/dns/promises.d.ts +381 -0
- package/node_modules/@types/node/dns.d.ts +809 -0
- package/node_modules/@types/node/dom-events.d.ts +122 -0
- package/node_modules/@types/node/domain.d.ts +170 -0
- package/node_modules/@types/node/events.d.ts +803 -0
- package/node_modules/@types/node/fs/promises.d.ts +1205 -0
- package/node_modules/@types/node/fs.d.ts +4211 -0
- package/node_modules/@types/node/globals.d.ts +377 -0
- package/node_modules/@types/node/globals.global.d.ts +1 -0
- package/node_modules/@types/node/http.d.ts +1801 -0
- package/node_modules/@types/node/http2.d.ts +2386 -0
- package/node_modules/@types/node/https.d.ts +544 -0
- package/node_modules/@types/node/index.d.ts +88 -0
- package/node_modules/@types/node/inspector.d.ts +2739 -0
- package/node_modules/@types/node/module.d.ts +298 -0
- package/node_modules/@types/node/net.d.ts +913 -0
- package/node_modules/@types/node/os.d.ts +473 -0
- package/node_modules/@types/node/package.json +235 -0
- package/node_modules/@types/node/path.d.ts +191 -0
- package/node_modules/@types/node/perf_hooks.d.ts +626 -0
- package/node_modules/@types/node/process.d.ts +1531 -0
- package/node_modules/@types/node/punycode.d.ts +117 -0
- package/node_modules/@types/node/querystring.d.ts +141 -0
- package/node_modules/@types/node/readline/promises.d.ts +143 -0
- package/node_modules/@types/node/readline.d.ts +666 -0
- package/node_modules/@types/node/repl.d.ts +430 -0
- package/node_modules/@types/node/stream/consumers.d.ts +12 -0
- package/node_modules/@types/node/stream/promises.d.ts +83 -0
- package/node_modules/@types/node/stream/web.d.ts +336 -0
- package/node_modules/@types/node/stream.d.ts +1731 -0
- package/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/node_modules/@types/node/test.d.ts +1113 -0
- package/node_modules/@types/node/timers/promises.d.ts +93 -0
- package/node_modules/@types/node/timers.d.ts +126 -0
- package/node_modules/@types/node/tls.d.ts +1203 -0
- package/node_modules/@types/node/trace_events.d.ts +171 -0
- package/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
- package/node_modules/@types/node/ts4.8/assert.d.ts +985 -0
- package/node_modules/@types/node/ts4.8/async_hooks.d.ts +522 -0
- package/node_modules/@types/node/ts4.8/buffer.d.ts +2321 -0
- package/node_modules/@types/node/ts4.8/child_process.d.ts +1544 -0
- package/node_modules/@types/node/ts4.8/cluster.d.ts +432 -0
- package/node_modules/@types/node/ts4.8/console.d.ts +412 -0
- package/node_modules/@types/node/ts4.8/constants.d.ts +19 -0
- package/node_modules/@types/node/ts4.8/crypto.d.ts +4450 -0
- package/node_modules/@types/node/ts4.8/dgram.d.ts +586 -0
- package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +192 -0
- package/node_modules/@types/node/ts4.8/dns/promises.d.ts +381 -0
- package/node_modules/@types/node/ts4.8/dns.d.ts +809 -0
- package/node_modules/@types/node/ts4.8/dom-events.d.ts +122 -0
- package/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
- package/node_modules/@types/node/ts4.8/events.d.ts +754 -0
- package/node_modules/@types/node/ts4.8/fs/promises.d.ts +1205 -0
- package/node_modules/@types/node/ts4.8/fs.d.ts +4211 -0
- package/node_modules/@types/node/ts4.8/globals.d.ts +377 -0
- package/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
- package/node_modules/@types/node/ts4.8/http.d.ts +1801 -0
- package/node_modules/@types/node/ts4.8/http2.d.ts +2386 -0
- package/node_modules/@types/node/ts4.8/https.d.ts +544 -0
- package/node_modules/@types/node/ts4.8/index.d.ts +88 -0
- package/node_modules/@types/node/ts4.8/inspector.d.ts +2739 -0
- package/node_modules/@types/node/ts4.8/module.d.ts +298 -0
- package/node_modules/@types/node/ts4.8/net.d.ts +913 -0
- package/node_modules/@types/node/ts4.8/os.d.ts +473 -0
- package/node_modules/@types/node/ts4.8/path.d.ts +191 -0
- package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +626 -0
- package/node_modules/@types/node/ts4.8/process.d.ts +1531 -0
- package/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
- package/node_modules/@types/node/ts4.8/querystring.d.ts +141 -0
- package/node_modules/@types/node/ts4.8/readline/promises.d.ts +143 -0
- package/node_modules/@types/node/ts4.8/readline.d.ts +666 -0
- package/node_modules/@types/node/ts4.8/repl.d.ts +430 -0
- package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
- package/node_modules/@types/node/ts4.8/stream/promises.d.ts +83 -0
- package/node_modules/@types/node/ts4.8/stream/web.d.ts +336 -0
- package/node_modules/@types/node/ts4.8/stream.d.ts +1731 -0
- package/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
- package/node_modules/@types/node/ts4.8/test.d.ts +1113 -0
- package/node_modules/@types/node/ts4.8/timers/promises.d.ts +93 -0
- package/node_modules/@types/node/ts4.8/timers.d.ts +126 -0
- package/node_modules/@types/node/ts4.8/tls.d.ts +1203 -0
- package/node_modules/@types/node/ts4.8/trace_events.d.ts +171 -0
- package/node_modules/@types/node/ts4.8/tty.d.ts +206 -0
- package/node_modules/@types/node/ts4.8/url.d.ts +937 -0
- package/node_modules/@types/node/ts4.8/util.d.ts +2075 -0
- package/node_modules/@types/node/ts4.8/v8.d.ts +541 -0
- package/node_modules/@types/node/ts4.8/vm.d.ts +667 -0
- package/node_modules/@types/node/ts4.8/wasi.d.ts +158 -0
- package/node_modules/@types/node/ts4.8/worker_threads.d.ts +692 -0
- package/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
- package/node_modules/@types/node/tty.d.ts +206 -0
- package/node_modules/@types/node/url.d.ts +937 -0
- package/node_modules/@types/node/util.d.ts +2075 -0
- package/node_modules/@types/node/v8.d.ts +541 -0
- package/node_modules/@types/node/vm.d.ts +667 -0
- package/node_modules/@types/node/wasi.d.ts +158 -0
- package/node_modules/@types/node/worker_threads.d.ts +692 -0
- package/node_modules/@types/node/zlib.d.ts +517 -0
- package/node_modules/@types/react/LICENSE +21 -0
- package/node_modules/@types/react/README.md +16 -0
- package/node_modules/@types/react/experimental.d.ts +192 -0
- package/node_modules/@types/react/global.d.ts +151 -0
- package/node_modules/@types/react/index.d.ts +3175 -0
- package/node_modules/@types/react/jsx-dev-runtime.d.ts +2 -0
- package/node_modules/@types/react/jsx-runtime.d.ts +2 -0
- package/node_modules/@types/react/package.json +149 -0
- package/node_modules/@vitejs/plugin-react-refresh/LICENSE +21 -0
- package/node_modules/@vitejs/plugin-react-refresh/README.md +73 -0
- package/node_modules/@vitejs/plugin-react-refresh/index.d.ts +14 -0
- package/node_modules/@vitejs/plugin-react-refresh/index.js +239 -0
- package/node_modules/@vitejs/plugin-react-refresh/package.json +35 -0
- package/package.json +64 -0
- package/project.json +74 -0
- package/scripts/create-entry-files.ts +44 -0
- package/src/ExtensionServerClient/ExtensionServerClient.test.ts +730 -0
- package/src/ExtensionServerClient/ExtensionServerClient.ts +310 -0
- package/src/ExtensionServerClient/index.ts +2 -0
- package/src/ExtensionServerClient/types.ts +159 -0
- package/src/context/ExtensionServerProvider.test.tsx +173 -0
- package/src/context/ExtensionServerProvider.tsx +46 -0
- package/src/context/constants.ts +15 -0
- package/src/context/index.ts +3 -0
- package/src/context/types.ts +13 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/useExtensionClient.ts +6 -0
- package/src/hooks/useExtensionServerContext.ts +4 -0
- package/src/hooks/useExtensionServerEvent.ts +11 -0
- package/src/hooks/useExtensionServerState.ts +6 -0
- package/src/hooks/useIsomorphicLayoutEffect.ts +6 -0
- package/src/i18n.test.ts +417 -0
- package/src/i18n.ts +208 -0
- package/src/index.ts +7 -0
- package/src/state/actions/actions.ts +36 -0
- package/src/state/actions/index.ts +2 -0
- package/src/state/actions/types.ts +26 -0
- package/src/state/index.ts +2 -0
- package/src/state/reducers/constants.ts +6 -0
- package/src/state/reducers/extensionServerReducer.test.ts +160 -0
- package/src/state/reducers/extensionServerReducer.ts +87 -0
- package/src/state/reducers/index.ts +3 -0
- package/src/state/reducers/types.ts +7 -0
- package/src/testing/MockExtensionServerProvider.tsx +36 -0
- package/src/testing/app.ts +15 -0
- package/src/testing/extensions.ts +70 -0
- package/src/testing/index.ts +3 -0
- package/src/types.ts +177 -0
- package/src/utilities/assetToString.test.ts +16 -0
- package/src/utilities/assetToString.ts +8 -0
- package/src/utilities/groupByKey.ts +3 -0
- package/src/utilities/index.ts +7 -0
- package/src/utilities/isUIExtension.ts +7 -0
- package/src/utilities/isValidSurface.ts +7 -0
- package/src/utilities/noop.ts +1 -0
- package/src/utilities/replaceUpdated.test.ts +26 -0
- package/src/utilities/replaceUpdated.ts +16 -0
- package/src/utilities/set.test.ts +19 -0
- package/src/utilities/set.ts +29 -0
- package/testing.d.ts +1 -0
- package/testing.js +1 -0
- package/testing.mjs +1 -0
- package/tests/setup.ts +6 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { matcherHint, RECEIVED_COLOR, EXPECTED_COLOR, printExpected } from 'jest-matcher-utils';
|
|
2
|
+
import { assertIsNode, assertIsType, printType, diffs, pluralize } from './utilities.esnext';
|
|
3
|
+
|
|
4
|
+
function toContainReactComponent(node, type, props) {
|
|
5
|
+
assertIsNode(node, {
|
|
6
|
+
expectation: 'toContainReactComponent',
|
|
7
|
+
isNot: this.isNot
|
|
8
|
+
});
|
|
9
|
+
assertIsType(type, {
|
|
10
|
+
expectation: 'toContainReactComponent',
|
|
11
|
+
isNot: this.isNot
|
|
12
|
+
});
|
|
13
|
+
const foundByType = node.findAll(type);
|
|
14
|
+
const foundByProps = props == null ? foundByType : foundByType.filter(element => Object.keys(props).every(key => this.equals(props[key], element.props[key])));
|
|
15
|
+
const pass = foundByProps.length > 0;
|
|
16
|
+
const message = pass ? () => `${matcherHint('.not.toContainReactComponent')}\n\n` + `Expected the React element:\n ${RECEIVED_COLOR(node.toString())}\n` + `Not to contain component:\n ${EXPECTED_COLOR(printType(type))}\n${props ? `With props matching:\n ${printExpected(props)}\n` : ''}` + `But ${foundByProps.length} matching ${printType(type)} ${foundByProps.length === 1 ? 'elements were' : 'element was'} found.\n` : () => `${`${matcherHint('.toContainReactComponent')}\n\n` + `Expected the React element:\n ${RECEIVED_COLOR(node.toString())}\n` + `To contain component:\n ${EXPECTED_COLOR(printType(type))}\n${props ? `With props matching:\n ${printExpected(props)}\n` : ''}`}${foundByType.length === 0 ? `But no matching ${printType(type)} elements were found.\n` : `But the ${foundByType.length === 1 ? 'found element has' : 'found elements have'} the following prop differences:\n\n${diffs(foundByType, props, this.expand)}`}`;
|
|
17
|
+
return {
|
|
18
|
+
pass,
|
|
19
|
+
message
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function toContainReactComponentTimes(node, type, times, props) {
|
|
23
|
+
assertIsNode(node, {
|
|
24
|
+
expectation: 'toContainReactComponentTimes',
|
|
25
|
+
isNot: this.isNot
|
|
26
|
+
});
|
|
27
|
+
assertIsType(type, {
|
|
28
|
+
expectation: 'toContainReactComponent',
|
|
29
|
+
isNot: this.isNot
|
|
30
|
+
});
|
|
31
|
+
const foundByType = node.findAll(type);
|
|
32
|
+
const foundByProps = props == null ? foundByType : foundByType.filter(element => Object.keys(props).every(key => this.equals(props[key], element.props[key])));
|
|
33
|
+
const pass = foundByProps.length === times;
|
|
34
|
+
const message = pass ? () => [`${matcherHint('.not.toContainReactComponentTimes')}\n`, `Expected the React element:\n ${RECEIVED_COLOR(node.toString())}`, `Not to contain component:\n ${EXPECTED_COLOR(printType(type))}`, `${times} ${pluralize('time', times)}, but it did.`].join('\n') : () => [`${matcherHint('.toContainReactComponentTimes')}\n`, `Expected the React element:\n ${RECEIVED_COLOR(node.toString())}`, `To contain component:\n ${EXPECTED_COLOR(printType(type))}`, `${times} ${pluralize('time', times)}, but it was found ${foundByProps.length}.`].join('\n');
|
|
35
|
+
return {
|
|
36
|
+
pass,
|
|
37
|
+
message
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { toContainReactComponent, toContainReactComponentTimes };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { matcherHint, RECEIVED_COLOR, EXPECTED_COLOR, printExpected } from 'jest-matcher-utils';
|
|
2
|
+
import { assertIsNode, printType, diffs } from './utilities.esnext';
|
|
3
|
+
|
|
4
|
+
function toProvideReactContext(node, Context, value) {
|
|
5
|
+
assertIsNode(node, {
|
|
6
|
+
expectation: 'toProvideReactContext',
|
|
7
|
+
isNot: this.isNot
|
|
8
|
+
});
|
|
9
|
+
const foundByType = node.findAll(Context.Provider);
|
|
10
|
+
const foundByValue = value == null ? foundByType : foundByType.filter(element => this.equals(value, element.prop('value')));
|
|
11
|
+
const pass = foundByValue.length > 0;
|
|
12
|
+
const message = pass ? () => `${matcherHint('.not.toProvideReactContext')}\n\n` + `Expected the React element:\n ${RECEIVED_COLOR(node.toString())}\n` + `Not to contain context provider:\n ${EXPECTED_COLOR(printType(Context.Provider))}\n${value ? `With value matching:\n ${printExpected(value)}\n` : ''}` + `But ${foundByValue.length} matching ${printType(Context.Provider)}${foundByValue.length === 1 ? 's were' : ' was'} found.\n` : () => `${`${matcherHint('.toProvideReactContext')}\n\n` + `Expected the React element:\n ${RECEIVED_COLOR(node.toString())}\n` + `To contain context provider:\n ${EXPECTED_COLOR(printType(Context.Provider))}\n${value ? `With value matching:\n ${printExpected(value)}\n` : ''}`}${foundByType.length === 0 ? `But no matching ${printType(Context.Provider)}s were found.\n` : `But the ${foundByType.length === 1 ? 'found provider has' : 'found provider have'} had different values:\n\n${diffs(foundByType, {
|
|
13
|
+
value
|
|
14
|
+
}, this.expand)}`}`;
|
|
15
|
+
return {
|
|
16
|
+
pass,
|
|
17
|
+
message
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { toProvideReactContext };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { toHaveReactProps, toHaveReactDataProps } from './props.esnext';
|
|
2
|
+
import { toContainReactComponent, toContainReactComponentTimes } from './components.esnext';
|
|
3
|
+
import { toProvideReactContext } from './context.esnext';
|
|
4
|
+
import { toContainReactText, toContainReactHtml } from './strings.esnext';
|
|
5
|
+
|
|
6
|
+
expect.extend({
|
|
7
|
+
toHaveReactProps,
|
|
8
|
+
toHaveReactDataProps,
|
|
9
|
+
toContainReactComponent,
|
|
10
|
+
toContainReactComponentTimes,
|
|
11
|
+
toContainReactText,
|
|
12
|
+
toContainReactHtml,
|
|
13
|
+
toProvideReactContext
|
|
14
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { matcherHint, RECEIVED_COLOR, printExpected, printReceived } from 'jest-matcher-utils';
|
|
2
|
+
import { assertIsNode, diffPropsForNode } from './utilities.esnext';
|
|
3
|
+
|
|
4
|
+
function toHaveReactProps(node, props) {
|
|
5
|
+
assertIsNode(node, {
|
|
6
|
+
expectation: 'toHaveReactProps',
|
|
7
|
+
isNot: this.isNot
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
if (props == null || typeof props !== 'object') {
|
|
11
|
+
return {
|
|
12
|
+
pass: false,
|
|
13
|
+
message: () => `You passed ${props == null ? String(props) : `a ${typeof props}`} as props, but it must be an object.`
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const pass = Object.keys(props).every(key => this.equals(props[key], node.props[key]));
|
|
18
|
+
const message = pass ? () => `${matcherHint('.not.toHaveReactProps', node.toString())}\n\n` + `Expected the React element:\n ${RECEIVED_COLOR(node.toString())}\n` + `Not to have props:\n ${printExpected(props)}\n` + `Received:\n ${printReceived(node.props)}\n` : () => {
|
|
19
|
+
const diffString = diffPropsForNode(node, props, {
|
|
20
|
+
expand: this.expand
|
|
21
|
+
});
|
|
22
|
+
return `${matcherHint('.toHaveReactProps', node.toString())}\n\n` + `Expected the React element:\n ${RECEIVED_COLOR(node.toString())}\n` + `To have props:\n ${printExpected(props)}\n` + `Received:\n ${printReceived(node.props)}\n${diffString ? `Difference:\n${diffString}\n` : ''}`;
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
pass,
|
|
26
|
+
message
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function toHaveReactDataProps(node, data) {
|
|
30
|
+
return toHaveReactProps.call(this, node, data);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { toHaveReactDataProps, toHaveReactProps };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { matcherHint, RECEIVED_COLOR, printExpected, INVERTED_COLOR, printReceived } from 'jest-matcher-utils';
|
|
2
|
+
import { assertIsNode } from './utilities.esnext';
|
|
3
|
+
|
|
4
|
+
function toContainReactText(node, text) {
|
|
5
|
+
assertIsNode(node, {
|
|
6
|
+
expectation: 'toContainReactText',
|
|
7
|
+
isNot: this.isNot
|
|
8
|
+
});
|
|
9
|
+
const nodeText = node.text();
|
|
10
|
+
const matchIndex = nodeText.indexOf(text);
|
|
11
|
+
const pass = matchIndex >= 0;
|
|
12
|
+
const message = pass ? () => `${matcherHint('.not.toContainReactText', node.toString())}\n\n` + `Expected the React element:\n ${RECEIVED_COLOR(node.toString())}\n` + `Not to contain text:\n ${printExpected(text)}\n` + `But it did:\n ${printReceivedWithHighlight(nodeText, matchIndex, text.length)}\n` : () => `${matcherHint('.not.toContainReactText', node.toString())}\n\n` + `Expected the React element:\n ${RECEIVED_COLOR(node.toString())}\n` + `With text content:\n ${printReceived(nodeText)}\n` + `To contain string:\n ${printExpected(text)}\n`;
|
|
13
|
+
return {
|
|
14
|
+
pass,
|
|
15
|
+
message
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function toContainReactHtml(node, text) {
|
|
19
|
+
assertIsNode(node, {
|
|
20
|
+
expectation: 'toContainReactHtml',
|
|
21
|
+
isNot: this.isNot
|
|
22
|
+
});
|
|
23
|
+
const nodeHtml = node.html();
|
|
24
|
+
const matchIndex = nodeHtml.indexOf(text);
|
|
25
|
+
const pass = matchIndex >= 0;
|
|
26
|
+
const message = pass ? () => `${matcherHint('.not.toContainReactHtml', node.toString())}\n\n` + `Expected the React element:\n ${RECEIVED_COLOR(node.toString())}\n` + `Not to contain HTML:\n ${printExpected(text)}\n` + `But it did:\n ${printReceivedWithHighlight(nodeHtml, matchIndex, text.length)}\n` : () => `${matcherHint('.not.toContainReactHtml', node.toString())}\n\n` + `Expected the React element:\n ${RECEIVED_COLOR(node.toString())}\n` + `With HTML content:\n ${printReceived(nodeHtml)}\n` + `To contain HTML:\n ${printExpected(text)}\n`;
|
|
27
|
+
return {
|
|
28
|
+
pass,
|
|
29
|
+
message
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function printReceivedWithHighlight(text, start, length) {
|
|
34
|
+
return RECEIVED_COLOR(`"${text.slice(0, start)}${INVERTED_COLOR(text.slice(start, start + length))}${text.slice(start + length)}"`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { toContainReactHtml, toContainReactText };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { diff, matcherErrorMessage, matcherHint, RECEIVED_COLOR, printWithType, printReceived, printExpected } from 'jest-matcher-utils';
|
|
2
|
+
import { Root } from '../root.esnext';
|
|
3
|
+
import { Element } from '../element.esnext';
|
|
4
|
+
|
|
5
|
+
function assertIsNode(node, {
|
|
6
|
+
expectation,
|
|
7
|
+
isNot
|
|
8
|
+
}) {
|
|
9
|
+
if (node == null) {
|
|
10
|
+
throw new Error(matcherErrorMessage(matcherHint(`.${expectation}`, undefined, undefined, {
|
|
11
|
+
isNot
|
|
12
|
+
}), `${RECEIVED_COLOR('received')} value must be an @shopify/react-testing Root or Element object`, `Received ${RECEIVED_COLOR('null')}.\nThis usually means that your \`.findX\` method failed to find any matching elements.`));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (Array.isArray(node) && node.length > 1 && (node[0] instanceof Root || node[0] instanceof Element)) {
|
|
16
|
+
throw new Error(matcherErrorMessage(matcherHint(`.${expectation}`, undefined, undefined, {
|
|
17
|
+
isNot
|
|
18
|
+
}), `${RECEIVED_COLOR('received')} value must be an @shopify/react-testing Root or Element object`, `Received an ${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.`));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!(node instanceof Root) && !(node instanceof Element)) {
|
|
22
|
+
throw new Error(matcherErrorMessage(matcherHint(`.${expectation}`, undefined, undefined, {
|
|
23
|
+
isNot
|
|
24
|
+
}), `${RECEIVED_COLOR('received')} value must be an @shopify/react-testing Root or Element object`, printWithType('Received', node, printReceived)));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function assertIsType(type, {
|
|
28
|
+
expectation,
|
|
29
|
+
isNot
|
|
30
|
+
}) {
|
|
31
|
+
if (type == null) {
|
|
32
|
+
throw new Error(matcherErrorMessage(matcherHint(`.${expectation}`, undefined, undefined, {
|
|
33
|
+
isNot
|
|
34
|
+
}), `${RECEIVED_COLOR('expected')} value must be a string or a valid React component.`, printWithType('Expected', type, printExpected)));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function diffs(element, props, expand) {
|
|
38
|
+
return element.reduce((diffs, element, index) => {
|
|
39
|
+
const separator = index === 0 ? '' : '\n\n';
|
|
40
|
+
return `${diffs}${separator}${normalizedDiff(element, props, {
|
|
41
|
+
expand,
|
|
42
|
+
showLegend: index === 0
|
|
43
|
+
})}`;
|
|
44
|
+
}, '');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function normalizedDiff(element, props, {
|
|
48
|
+
expand = false,
|
|
49
|
+
showLegend = false
|
|
50
|
+
}) {
|
|
51
|
+
const result = diffPropsForNode(element, props, {
|
|
52
|
+
expand
|
|
53
|
+
}) || '';
|
|
54
|
+
return showLegend ? result : result.split('\n\n')[1];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function printType(type) {
|
|
58
|
+
if (typeof type === 'object' && '_context' in type) {
|
|
59
|
+
const context = type._context;
|
|
60
|
+
const componentName = type === context.Provider ? 'Provider' : 'Consumer';
|
|
61
|
+
const displayName = context.displayName || 'Context';
|
|
62
|
+
return `<${displayName}.${componentName} />`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const displayName = typeof type === 'string' ? type : type.displayName || type.name || 'Component';
|
|
66
|
+
return `<${displayName} />`;
|
|
67
|
+
}
|
|
68
|
+
function diffPropsForNode(node, props, {
|
|
69
|
+
expand = false
|
|
70
|
+
}) {
|
|
71
|
+
return diff(props, getObjectSubset(node.props, props), {
|
|
72
|
+
expand
|
|
73
|
+
});
|
|
74
|
+
} // Original from https://github.com/facebook/jest/blob/master/packages/expect/src/utils.ts#L107
|
|
75
|
+
|
|
76
|
+
function getObjectSubset(object, subset) {
|
|
77
|
+
if (Array.isArray(object)) {
|
|
78
|
+
if (Array.isArray(subset) && subset.length === object.length) {
|
|
79
|
+
return subset.map((sub, i) => getObjectSubset(object[i], sub));
|
|
80
|
+
}
|
|
81
|
+
} else if (object instanceof Date) {
|
|
82
|
+
return object;
|
|
83
|
+
} else if (typeof object === 'object' && object !== null && typeof subset === 'object' && subset !== null) {
|
|
84
|
+
const trimmed = {};
|
|
85
|
+
Object.keys(subset).filter(key => Reflect.has(object, key)).forEach(key => trimmed[key] = getObjectSubset(object[key], subset[key]));
|
|
86
|
+
|
|
87
|
+
if (Object.keys(trimmed).length > 0) {
|
|
88
|
+
return trimmed;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return object;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function pluralize(word, count) {
|
|
96
|
+
return count === 1 ? word : `${word}s`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { assertIsNode, assertIsType, diffPropsForNode, diffs, pluralize, printType };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Root } from './root.esnext';
|
|
2
|
+
export { Root } from './root.esnext';
|
|
3
|
+
|
|
4
|
+
function mount(element) {
|
|
5
|
+
return new Root(element);
|
|
6
|
+
}
|
|
7
|
+
class CustomRoot extends Root {
|
|
8
|
+
constructor(tree, context, options) {
|
|
9
|
+
super(tree, options);
|
|
10
|
+
this.context = context;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
function createMount({
|
|
15
|
+
render,
|
|
16
|
+
context: createContext = defaultContext,
|
|
17
|
+
afterMount = defaultAfterMount,
|
|
18
|
+
cleanup
|
|
19
|
+
}) {
|
|
20
|
+
function mount(element, options = {}) {
|
|
21
|
+
const context = createContext(options);
|
|
22
|
+
const wrapper = new CustomRoot(element, context, {
|
|
23
|
+
render: element => render(element, context, options),
|
|
24
|
+
resolveRoot: root => root.find(element.type)
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (cleanup) {
|
|
28
|
+
const originalDestroy = wrapper.destroy.bind(wrapper);
|
|
29
|
+
|
|
30
|
+
wrapper.destroy = () => {
|
|
31
|
+
cleanup(wrapper, options);
|
|
32
|
+
originalDestroy();
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const afterMountResult = afterMount(wrapper, options);
|
|
37
|
+
return afterMountResult != null && 'then' in afterMountResult ? afterMountResult.then(() => wrapper) : wrapper;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
Reflect.defineProperty(mount, 'extend', {
|
|
41
|
+
writable: false,
|
|
42
|
+
value: ({
|
|
43
|
+
context: createAdditionalContext = defaultContext,
|
|
44
|
+
render: additionalRender,
|
|
45
|
+
afterMount: additionalAfterMount = defaultAfterMount
|
|
46
|
+
}) => {
|
|
47
|
+
return createMount({
|
|
48
|
+
context: options => ({ ...createContext(options),
|
|
49
|
+
...createAdditionalContext(options)
|
|
50
|
+
}),
|
|
51
|
+
render: (element, context, options) => render(additionalRender(element, context, options), context, options),
|
|
52
|
+
afterMount: (wrapper, options) => {
|
|
53
|
+
const result = additionalAfterMount(wrapper, options);
|
|
54
|
+
|
|
55
|
+
const finalResult = () => afterMount(wrapper, options);
|
|
56
|
+
|
|
57
|
+
return result != null && 'then' in result ? result.then(finalResult) : finalResult();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return mount;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function defaultContext() {
|
|
66
|
+
return {};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function defaultAfterMount() {}
|
|
70
|
+
|
|
71
|
+
export { CustomRoot, createMount, mount };
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, unmountComponentAtNode } from 'react-dom';
|
|
3
|
+
import { act } from 'react-dom/test-utils';
|
|
4
|
+
import { TestWrapper } from './TestWrapper.esnext';
|
|
5
|
+
import { Element } from './element.esnext';
|
|
6
|
+
import { getInternals } from './compat.esnext';
|
|
7
|
+
import { Tag } from './types.esnext';
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
findCurrentFiberUsingSlowPath
|
|
11
|
+
} = require('react-reconciler/reflection');
|
|
12
|
+
|
|
13
|
+
const connected = new Set();
|
|
14
|
+
class Root {
|
|
15
|
+
get props() {
|
|
16
|
+
return this.withRoot(root => root.props);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get isDOM() {
|
|
20
|
+
return this.withRoot(root => root.isDOM);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get type() {
|
|
24
|
+
return this.withRoot(root => root.type);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get instance() {
|
|
28
|
+
return this.withRoot(root => root.instance);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get children() {
|
|
32
|
+
return this.withRoot(root => root.children);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get descendants() {
|
|
36
|
+
return this.withRoot(root => root.descendants);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get domNodes() {
|
|
40
|
+
return this.withRoot(root => root.domNodes);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get domNode() {
|
|
44
|
+
return this.withRoot(root => root.domNode);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get mounted() {
|
|
48
|
+
return this.wrapper != null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
constructor(tree, {
|
|
52
|
+
render = defaultRender,
|
|
53
|
+
resolveRoot = defaultResolveRoot
|
|
54
|
+
} = {}) {
|
|
55
|
+
this.tree = tree;
|
|
56
|
+
this.wrapper = null;
|
|
57
|
+
this.element = document.createElement('div');
|
|
58
|
+
this.root = null;
|
|
59
|
+
this.acting = false;
|
|
60
|
+
this.render = void 0;
|
|
61
|
+
this.resolveRoot = void 0;
|
|
62
|
+
this.render = render;
|
|
63
|
+
this.resolveRoot = resolveRoot;
|
|
64
|
+
this.mount();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
act(action, {
|
|
68
|
+
update = true
|
|
69
|
+
} = {}) {
|
|
70
|
+
const updateWrapper = update ? this.update.bind(this) : noop;
|
|
71
|
+
let result;
|
|
72
|
+
|
|
73
|
+
if (this.acting) {
|
|
74
|
+
return action();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
this.acting = true;
|
|
78
|
+
|
|
79
|
+
const afterResolve = () => {
|
|
80
|
+
updateWrapper();
|
|
81
|
+
this.acting = false;
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const promise = act(() => {
|
|
86
|
+
result = action(); // This condition checks the returned value is an actual Promise and returns it
|
|
87
|
+
// to React’s `act()` call, otherwise we just want to return `undefined`
|
|
88
|
+
|
|
89
|
+
if (isPromise(result)) {
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return undefined;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (isPromise(result)) {
|
|
97
|
+
updateWrapper();
|
|
98
|
+
return Promise.resolve(promise).then(afterResolve);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return afterResolve();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
html() {
|
|
105
|
+
return this.withRoot(root => root.html());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
text() {
|
|
109
|
+
return this.withRoot(root => root.text());
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
is(type) {
|
|
113
|
+
return this.withRoot(root => root.is(type));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
prop(key) {
|
|
117
|
+
return this.withRoot(root => root.prop(key));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
data(key) {
|
|
121
|
+
return this.withRoot(root => root.data(key));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
find(type, props) {
|
|
125
|
+
return this.withRoot(root => root.find(type, props));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
findAll(type, props) {
|
|
129
|
+
return this.withRoot(root => root.findAll(type, props));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
findWhere(predicate) {
|
|
133
|
+
return this.withRoot(root => root.findWhere(predicate));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
findAllWhere(predicate) {
|
|
137
|
+
return this.withRoot(root => root.findAllWhere(predicate));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
trigger(prop, ...args) {
|
|
141
|
+
return this.withRoot(root => root.trigger(prop, ...args));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
triggerKeypath(keypath, ...args) {
|
|
145
|
+
return this.withRoot(root => root.triggerKeypath(keypath, ...args));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
mount() {
|
|
149
|
+
if (this.mounted) {
|
|
150
|
+
throw new Error('Attempted to mount a node that was already mounted');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (this.element.parentNode == null) {
|
|
154
|
+
document.body.appendChild(this.element);
|
|
155
|
+
connected.add(this);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
this.act(() => {
|
|
159
|
+
render( /*#__PURE__*/React.createElement(TestWrapper, {
|
|
160
|
+
render: this.render,
|
|
161
|
+
ref: wrapper => {
|
|
162
|
+
this.wrapper = wrapper;
|
|
163
|
+
}
|
|
164
|
+
}, this.tree), this.element);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
unmount() {
|
|
169
|
+
if (!this.mounted) {
|
|
170
|
+
throw new Error('You attempted to unmount a node that was already unmounted');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
this.ensureRoot();
|
|
174
|
+
this.act(() => unmountComponentAtNode(this.element));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
destroy() {
|
|
178
|
+
const {
|
|
179
|
+
element,
|
|
180
|
+
mounted
|
|
181
|
+
} = this;
|
|
182
|
+
|
|
183
|
+
if (mounted) {
|
|
184
|
+
this.unmount();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
element.remove();
|
|
188
|
+
connected.delete(this);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
setProps(props) {
|
|
192
|
+
this.ensureRoot();
|
|
193
|
+
this.act(() => this.wrapper.setProps(props));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
forceUpdate() {
|
|
197
|
+
this.ensureRoot();
|
|
198
|
+
this.act(() => this.wrapper.forceUpdate());
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
debug(options) {
|
|
202
|
+
this.ensureRoot();
|
|
203
|
+
return this.root.debug(options);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
toString() {
|
|
207
|
+
return this.withRoot(root => root.toString());
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
update() {
|
|
211
|
+
if (this.wrapper == null) {
|
|
212
|
+
this.root = null;
|
|
213
|
+
} else {
|
|
214
|
+
const rootFiber = getInternals(this.wrapper.rootRef);
|
|
215
|
+
const topElement = fiberToElement(findCurrentFiberUsingSlowPath(rootFiber), this);
|
|
216
|
+
this.root = this.resolveRoot(topElement);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
ensureRoot() {
|
|
221
|
+
if (this.wrapper == null || this.root == null) {
|
|
222
|
+
throw new Error('Attempted to operate on a mounted tree, but the component is no longer mounted');
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
withRoot(withRoot) {
|
|
227
|
+
this.ensureRoot();
|
|
228
|
+
return withRoot(this.root);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function defaultResolveRoot(element) {
|
|
234
|
+
return element.children[0];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function defaultRender(element) {
|
|
238
|
+
return element;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function fiberToElement(node, root) {
|
|
242
|
+
if (node.tag === Tag.HostText) {
|
|
243
|
+
return node.memoizedProps;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const props = node.memoizedProps;
|
|
247
|
+
const children = childrenToTree(node.child, root);
|
|
248
|
+
return new Element({
|
|
249
|
+
tag: node.tag,
|
|
250
|
+
type: node.type,
|
|
251
|
+
props,
|
|
252
|
+
instance: node.stateNode
|
|
253
|
+
}, children, root);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function childrenToTree(fiber, root) {
|
|
257
|
+
let currentFiber = fiber;
|
|
258
|
+
const children = [];
|
|
259
|
+
|
|
260
|
+
while (currentFiber != null) {
|
|
261
|
+
const result = fiberToElement(currentFiber, root);
|
|
262
|
+
children.push(result);
|
|
263
|
+
currentFiber = currentFiber.sibling;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return children;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function isPromise(promise) {
|
|
270
|
+
return promise != null && typeof promise === 'object' && 'then' in promise;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function noop() {}
|
|
274
|
+
|
|
275
|
+
export { Root, connected };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { stringify } from 'jest-matcher-utils';
|
|
2
|
+
|
|
3
|
+
function toReactString(node, options = {}, level = 0) {
|
|
4
|
+
// if this is an array node then print all children at the current level
|
|
5
|
+
if (!node.type && node.children.length > 0) {
|
|
6
|
+
return node.children.map(child => toReactString(child, options, level)).join('\n');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const name = nodeName(node);
|
|
10
|
+
const indent = ' '.repeat(level);
|
|
11
|
+
const props = Object.keys(node.props) // we always filter out children no matter what, but unless allProps option
|
|
12
|
+
// is present we will also filter out insigificant props
|
|
13
|
+
.filter(key => options.allProps ? key !== 'children' : !/^(children|className)$|^(aria|data)-/.test(key)).reduce((list, key) => {
|
|
14
|
+
if (!key) {
|
|
15
|
+
return list;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const value = node.props[key];
|
|
19
|
+
|
|
20
|
+
if (value === undefined && !options.allProps) {
|
|
21
|
+
return list;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
list.push(toPropString(key, value, options.verbosity));
|
|
25
|
+
return list;
|
|
26
|
+
}, []);
|
|
27
|
+
const hasChildren = node.children.length > 0 && !['svg'].includes(name);
|
|
28
|
+
const open = `${indent}<${name}${props.length > 0 ? ` ${props.join(' ')}` : ''}${hasChildren ? '>' : ' />'}`;
|
|
29
|
+
|
|
30
|
+
if (!hasChildren) {
|
|
31
|
+
return open;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const close = `${indent}</${name}>`;
|
|
35
|
+
|
|
36
|
+
if (options.depth != null && level >= options.depth) {
|
|
37
|
+
return [open, `${indent} {/* <${node.children.length} child${node.children.length === 1 ? '' : 'ren'}... /> */}`, close].join('\n');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return [open, ...node.children.map(child => toReactString(child, options, level + 1)), close].join('\n');
|
|
41
|
+
}
|
|
42
|
+
function toPropString(key, value, verbosity = 1) {
|
|
43
|
+
if (value === undefined) {
|
|
44
|
+
return `${key}={undefined}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (value === null) {
|
|
48
|
+
return `${key}={null}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (typeof value === 'string') {
|
|
52
|
+
return `${key}="${value}"`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (typeof value === 'boolean' && value) {
|
|
56
|
+
return value ? `${key}` : `${key}={false}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (value instanceof Array) {
|
|
60
|
+
return `${key}={${stringify(value, verbosity + 1)}}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return `${key}={${stringify(value, verbosity)}}`;
|
|
64
|
+
}
|
|
65
|
+
function nodeName({
|
|
66
|
+
type
|
|
67
|
+
}) {
|
|
68
|
+
if (type && typeof type === 'object' && '_context' in type) {
|
|
69
|
+
const context = type._context;
|
|
70
|
+
return `${context.displayName || 'Context'}.${type === context.Provider ? 'Provider' : 'Consumer'}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (type == null) {
|
|
74
|
+
return 'Node';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return typeof type === 'string' ? type : type.displayName || type.name || 'Component';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { nodeName, toPropString, toReactString };
|