@shopify/ui-extensions-server-kit 5.3.1 → 5.4.1
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 +12 -0
- package/README.md +3 -2
- package/dist/ExtensionServerClient/ExtensionServerClient.d.ts +3 -5
- package/dist/ExtensionServerClient/server-types.d.ts +31 -7
- package/dist/_virtual/jsx-runtime.cjs.js +1 -0
- package/dist/_virtual/jsx-runtime.cjs2.js +1 -0
- package/dist/_virtual/jsx-runtime.es.js +5 -0
- package/dist/_virtual/jsx-runtime.es2.js +4 -0
- package/dist/_virtual/react-jsx-runtime.development.cjs.js +1 -0
- package/dist/_virtual/react-jsx-runtime.development.es.js +4 -0
- package/dist/_virtual/react-jsx-runtime.production.min.cjs.js +1 -0
- package/dist/_virtual/react-jsx-runtime.production.min.es.js +4 -0
- package/dist/context/ExtensionServerProvider.d.ts +2 -1
- package/dist/i18n.d.ts +2 -8
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs2.js +1 -1
- package/dist/index.es.js +18 -18
- package/dist/index.es2.js +3 -3
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.development.cjs.js +22 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.development.es.js +604 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.production.min.cjs.js +9 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.production.min.es.js +28 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.cjs.js +1 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.es.js +10 -0
- package/dist/packages/ui-extensions-server-kit/src/ExtensionServerClient/ExtensionServerClient.cjs.js +1 -0
- package/dist/{ExtensionServerClient → packages/ui-extensions-server-kit/src/ExtensionServerClient}/ExtensionServerClient.es.js +21 -18
- package/dist/packages/ui-extensions-server-kit/src/context/ExtensionServerProvider.cjs.js +1 -0
- package/dist/packages/ui-extensions-server-kit/src/context/ExtensionServerProvider.es.js +30 -0
- package/dist/{context → packages/ui-extensions-server-kit/src/context}/constants.cjs.js +1 -1
- package/dist/packages/ui-extensions-server-kit/src/hooks/useExtensionServerContext.cjs.js +1 -0
- package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useExtensionServerContext.es.js +3 -2
- package/dist/packages/ui-extensions-server-kit/src/testing/MockExtensionServerProvider.cjs.js +1 -0
- package/dist/packages/ui-extensions-server-kit/src/testing/MockExtensionServerProvider.es.js +25 -0
- package/dist/{testing → packages/ui-extensions-server-kit/src/testing}/extensions.cjs.js +1 -1
- package/dist/{testing → packages/ui-extensions-server-kit/src/testing}/extensions.es.js +3 -2
- package/dist/packages/ui-extensions-server-kit/src/utilities/isUIExtension.cjs.js +1 -0
- package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/isUIExtension.es.js +3 -2
- package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/isValidSurface.cjs.js +1 -1
- package/dist/packages/ui-extensions-server-kit/src/utilities/isValidSurface.es.js +7 -0
- package/dist/testing/MockExtensionServerProvider.d.ts +2 -1
- package/dist/types.d.ts +14 -7
- package/dist/utilities/isUIExtension.d.ts +1 -1
- package/dist/utilities/isValidSurface.d.ts +1 -1
- package/dist/utilities/set.d.ts +1 -1
- package/node_modules/{@shopify/react-testing/LICENSE.md → @testing-library/react/LICENSE} +2 -3
- package/node_modules/@testing-library/react/README.md +692 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.cjs.js +537 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.esm.js +497 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.cjs.js +501 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.esm.js +461 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.umd.js +502 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.umd.js.map +1 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.umd.min.js +2 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.pure.umd.min.js.map +1 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.umd.js +538 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.umd.js.map +1 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.umd.min.js +2 -0
- package/node_modules/@testing-library/react/dist/@testing-library/react.umd.min.js.map +1 -0
- package/node_modules/@testing-library/react/dist/act-compat.js +80 -0
- package/node_modules/@testing-library/react/dist/config.js +33 -0
- package/node_modules/@testing-library/react/dist/fire-event.js +70 -0
- package/node_modules/@testing-library/react/dist/index.js +52 -0
- package/node_modules/@testing-library/react/dist/pure.js +356 -0
- package/node_modules/@testing-library/react/dont-cleanup-after-each.js +1 -0
- package/node_modules/@testing-library/react/package.json +116 -0
- package/node_modules/@testing-library/react/pure.d.ts +1 -0
- package/node_modules/@testing-library/react/pure.js +2 -0
- package/node_modules/@testing-library/react/types/index.d.ts +287 -0
- package/node_modules/@testing-library/react/types/pure.d.ts +1 -0
- package/node_modules/@types/react/README.md +4 -5
- package/node_modules/@types/react/canary.d.ts +166 -0
- package/node_modules/@types/react/experimental.d.ts +21 -86
- package/node_modules/@types/react/global.d.ts +146 -137
- package/node_modules/@types/react/index.d.ts +2738 -1370
- package/node_modules/@types/react/jsx-dev-runtime.d.ts +45 -2
- package/node_modules/@types/react/jsx-runtime.d.ts +36 -2
- package/node_modules/@types/react/package.json +111 -54
- package/node_modules/@types/react/ts5.0/canary.d.ts +166 -0
- package/node_modules/@types/react/ts5.0/experimental.d.ts +127 -0
- package/node_modules/@types/react/ts5.0/global.d.ts +160 -0
- package/node_modules/@types/react/ts5.0/index.d.ts +4530 -0
- package/node_modules/@types/react/ts5.0/jsx-dev-runtime.d.ts +44 -0
- package/node_modules/@types/react/ts5.0/jsx-runtime.d.ts +35 -0
- package/node_modules/@vitejs/plugin-react/README.md +159 -0
- package/node_modules/@vitejs/plugin-react/dist/index.d.ts +75 -0
- package/node_modules/@vitejs/plugin-react/dist/index.js +401 -0
- package/node_modules/@vitejs/plugin-react/dist/refresh-runtime.js +663 -0
- package/node_modules/@vitejs/plugin-react/package.json +77 -0
- package/node_modules/@vitejs/plugin-react/types/preamble.d.ts +1 -0
- package/package.json +9 -10
- package/project.json +1 -1
- package/src/ExtensionServerClient/ExtensionServerClient.test.ts +6 -5
- package/src/ExtensionServerClient/ExtensionServerClient.ts +27 -19
- package/src/ExtensionServerClient/server-types.ts +17 -7
- package/src/ExtensionServerClient/types.ts +0 -2
- package/src/context/ExtensionServerProvider.test.tsx +55 -73
- package/src/context/ExtensionServerProvider.tsx +1 -0
- package/src/i18n.ts +2 -5
- package/src/state/reducers/extensionServerReducer.test.ts +2 -2
- package/src/testing/extensions.ts +1 -0
- package/src/types.ts +15 -5
- package/src/utilities/assetToString.ts +0 -1
- package/src/utilities/isUIExtension.ts +5 -4
- package/src/utilities/isValidSurface.ts +2 -3
- package/src/utilities/replaceUpdated.ts +0 -2
- package/src/utilities/set.ts +10 -5
- package/tests/setup.ts +1 -4
- package/vite.config.mts +57 -0
- package/dist/ExtensionServerClient/ExtensionServerClient.cjs.js +0 -1
- package/dist/context/ExtensionServerProvider.cjs.js +0 -1
- package/dist/context/ExtensionServerProvider.es.js +0 -29
- package/dist/hooks/useExtensionServerContext.cjs.js +0 -1
- package/dist/testing/MockExtensionServerProvider.cjs.js +0 -1
- package/dist/testing/MockExtensionServerProvider.es.js +0 -24
- package/dist/utilities/isUIExtension.cjs.js +0 -1
- package/dist/utilities/isValidSurface.es.js +0 -7
- package/node_modules/@shopify/react-testing/README.md +0 -711
- package/node_modules/@shopify/react-testing/build/cjs/TestWrapper.js +0 -52
- package/node_modules/@shopify/react-testing/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -47
- package/node_modules/@shopify/react-testing/build/cjs/compat.js +0 -14
- package/node_modules/@shopify/react-testing/build/cjs/destroy.js +0 -13
- package/node_modules/@shopify/react-testing/build/cjs/element.js +0 -225
- package/node_modules/@shopify/react-testing/build/cjs/index.js +0 -21
- package/node_modules/@shopify/react-testing/build/cjs/matchers/components.js +0 -46
- package/node_modules/@shopify/react-testing/build/cjs/matchers/context.js +0 -25
- package/node_modules/@shopify/react-testing/build/cjs/matchers/index.js +0 -16
- package/node_modules/@shopify/react-testing/build/cjs/matchers/props.js +0 -38
- package/node_modules/@shopify/react-testing/build/cjs/matchers/strings.js +0 -42
- package/node_modules/@shopify/react-testing/build/cjs/matchers/utilities.js +0 -110
- package/node_modules/@shopify/react-testing/build/cjs/mount.js +0 -76
- package/node_modules/@shopify/react-testing/build/cjs/root.js +0 -284
- package/node_modules/@shopify/react-testing/build/cjs/toReactString.js +0 -86
- package/node_modules/@shopify/react-testing/build/cjs/types.js +0 -28
- package/node_modules/@shopify/react-testing/build/esm/TestWrapper.mjs +0 -44
- package/node_modules/@shopify/react-testing/build/esm/_virtual/_rollupPluginBabelHelpers.mjs +0 -42
- package/node_modules/@shopify/react-testing/build/esm/compat.mjs +0 -10
- package/node_modules/@shopify/react-testing/build/esm/destroy.mjs +0 -9
- package/node_modules/@shopify/react-testing/build/esm/element.mjs +0 -221
- package/node_modules/@shopify/react-testing/build/esm/index.mjs +0 -5
- package/node_modules/@shopify/react-testing/build/esm/matchers/components.mjs +0 -41
- package/node_modules/@shopify/react-testing/build/esm/matchers/context.mjs +0 -21
- package/node_modules/@shopify/react-testing/build/esm/matchers/index.mjs +0 -14
- package/node_modules/@shopify/react-testing/build/esm/matchers/props.mjs +0 -33
- package/node_modules/@shopify/react-testing/build/esm/matchers/strings.mjs +0 -37
- package/node_modules/@shopify/react-testing/build/esm/matchers/utilities.mjs +0 -101
- package/node_modules/@shopify/react-testing/build/esm/mount.mjs +0 -70
- package/node_modules/@shopify/react-testing/build/esm/root.mjs +0 -275
- package/node_modules/@shopify/react-testing/build/esm/toReactString.mjs +0 -80
- package/node_modules/@shopify/react-testing/build/esm/types.mjs +0 -26
- package/node_modules/@shopify/react-testing/build/esnext/TestWrapper.esnext +0 -44
- package/node_modules/@shopify/react-testing/build/esnext/compat.esnext +0 -10
- package/node_modules/@shopify/react-testing/build/esnext/destroy.esnext +0 -9
- package/node_modules/@shopify/react-testing/build/esnext/element.esnext +0 -221
- package/node_modules/@shopify/react-testing/build/esnext/index.esnext +0 -5
- package/node_modules/@shopify/react-testing/build/esnext/matchers/components.esnext +0 -41
- package/node_modules/@shopify/react-testing/build/esnext/matchers/context.esnext +0 -21
- package/node_modules/@shopify/react-testing/build/esnext/matchers/index.esnext +0 -14
- package/node_modules/@shopify/react-testing/build/esnext/matchers/props.esnext +0 -33
- package/node_modules/@shopify/react-testing/build/esnext/matchers/strings.esnext +0 -37
- package/node_modules/@shopify/react-testing/build/esnext/matchers/utilities.esnext +0 -99
- package/node_modules/@shopify/react-testing/build/esnext/mount.esnext +0 -71
- package/node_modules/@shopify/react-testing/build/esnext/root.esnext +0 -275
- package/node_modules/@shopify/react-testing/build/esnext/toReactString.esnext +0 -80
- package/node_modules/@shopify/react-testing/build/esnext/types.esnext +0 -26
- package/node_modules/@shopify/react-testing/build/ts/TestWrapper.d.ts +0 -17
- package/node_modules/@shopify/react-testing/build/ts/TestWrapper.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/compat.d.ts +0 -3
- package/node_modules/@shopify/react-testing/build/ts/compat.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/destroy.d.ts +0 -2
- package/node_modules/@shopify/react-testing/build/ts/destroy.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/element.d.ts +0 -42
- package/node_modules/@shopify/react-testing/build/ts/element.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/index.d.ts +0 -7
- package/node_modules/@shopify/react-testing/build/ts/index.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/components.d.ts +0 -12
- package/node_modules/@shopify/react-testing/build/ts/matchers/components.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/context.d.ts +0 -8
- package/node_modules/@shopify/react-testing/build/ts/matchers/context.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/index.d.ts +0 -20
- package/node_modules/@shopify/react-testing/build/ts/matchers/index.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/props.d.ts +0 -10
- package/node_modules/@shopify/react-testing/build/ts/matchers/props.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/strings.d.ts +0 -11
- package/node_modules/@shopify/react-testing/build/ts/matchers/strings.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/matchers/utilities.d.ts +0 -17
- package/node_modules/@shopify/react-testing/build/ts/matchers/utilities.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/mount.d.ts +0 -39
- package/node_modules/@shopify/react-testing/build/ts/mount.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/root.d.ts +0 -55
- package/node_modules/@shopify/react-testing/build/ts/root.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/toReactString.d.ts +0 -5
- package/node_modules/@shopify/react-testing/build/ts/toReactString.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/build/ts/types.d.ts +0 -89
- package/node_modules/@shopify/react-testing/build/ts/types.d.ts.map +0 -1
- package/node_modules/@shopify/react-testing/index.esnext +0 -1
- package/node_modules/@shopify/react-testing/index.js +0 -1
- package/node_modules/@shopify/react-testing/index.mjs +0 -1
- package/node_modules/@shopify/react-testing/matchers.esnext +0 -1
- package/node_modules/@shopify/react-testing/matchers.js +0 -1
- package/node_modules/@shopify/react-testing/matchers.mjs +0 -1
- package/node_modules/@shopify/react-testing/package.json +0 -69
- package/node_modules/@shopify/ui-extensions-test-utils/CHANGELOG.md +0 -66
- package/node_modules/@shopify/ui-extensions-test-utils/dist/index.d.ts +0 -3
- package/node_modules/@shopify/ui-extensions-test-utils/dist/index.js +0 -3
- package/node_modules/@shopify/ui-extensions-test-utils/dist/render.d.ts +0 -2
- package/node_modules/@shopify/ui-extensions-test-utils/dist/render.js +0 -5
- package/node_modules/@shopify/ui-extensions-test-utils/dist/renderHook.d.ts +0 -17
- package/node_modules/@shopify/ui-extensions-test-utils/dist/renderHook.js +0 -20
- package/node_modules/@shopify/ui-extensions-test-utils/dist/withProviders.d.ts +0 -9
- package/node_modules/@shopify/ui-extensions-test-utils/dist/withProviders.js +0 -7
- package/node_modules/@shopify/ui-extensions-test-utils/package.json +0 -40
- package/node_modules/@shopify/ui-extensions-test-utils/project.json +0 -39
- package/node_modules/@vitejs/plugin-react-refresh/README.md +0 -73
- package/node_modules/@vitejs/plugin-react-refresh/index.d.ts +0 -14
- package/node_modules/@vitejs/plugin-react-refresh/index.js +0 -239
- package/node_modules/@vitejs/plugin-react-refresh/package.json +0 -35
- /package/dist/{ExtensionServerClient → packages/ui-extensions-server-kit/src/ExtensionServerClient}/types.cjs.js +0 -0
- /package/dist/{ExtensionServerClient → packages/ui-extensions-server-kit/src/ExtensionServerClient}/types.es.js +0 -0
- /package/dist/{context → packages/ui-extensions-server-kit/src/context}/constants.es.js +0 -0
- /package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useExtensionServerState.cjs.js +0 -0
- /package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useExtensionServerState.es.js +0 -0
- /package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useIsomorphicLayoutEffect.cjs.js +0 -0
- /package/dist/{hooks → packages/ui-extensions-server-kit/src/hooks}/useIsomorphicLayoutEffect.es.js +0 -0
- /package/dist/{i18n.cjs.js → packages/ui-extensions-server-kit/src/i18n.cjs.js} +0 -0
- /package/dist/{i18n.es.js → packages/ui-extensions-server-kit/src/i18n.es.js} +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/actions/actions.cjs.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/actions/actions.es.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/reducers/constants.cjs.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/reducers/constants.es.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/reducers/extensionServerReducer.cjs.js +0 -0
- /package/dist/{state → packages/ui-extensions-server-kit/src/state}/reducers/extensionServerReducer.es.js +0 -0
- /package/dist/{testing → packages/ui-extensions-server-kit/src/testing}/app.cjs.js +0 -0
- /package/dist/{testing → packages/ui-extensions-server-kit/src/testing}/app.es.js +0 -0
- /package/dist/{types.cjs.js → packages/ui-extensions-server-kit/src/types.cjs.js} +0 -0
- /package/dist/{types.es.js → packages/ui-extensions-server-kit/src/types.es.js} +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/assetToString.cjs.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/assetToString.es.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/noop.cjs.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/noop.es.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/replaceUpdated.cjs.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/replaceUpdated.es.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/set.cjs.js +0 -0
- /package/dist/{utilities → packages/ui-extensions-server-kit/src/utilities}/set.es.js +0 -0
- /package/node_modules/@vitejs/{plugin-react-refresh → plugin-react}/LICENSE +0 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import * as ReactDOMClient from 'react-dom/client';
|
|
4
|
+
import { fireEvent as fireEvent$1, getConfig as getConfig$1, configure as configure$1, prettyDOM, getQueriesForElement } from '@testing-library/dom';
|
|
5
|
+
export * from '@testing-library/dom';
|
|
6
|
+
import * as DeprecatedReactTestUtils from 'react-dom/test-utils';
|
|
7
|
+
|
|
8
|
+
const reactAct = typeof React.act === 'function' ? React.act : DeprecatedReactTestUtils.act;
|
|
9
|
+
function getGlobalThis() {
|
|
10
|
+
/* istanbul ignore else */
|
|
11
|
+
if (typeof globalThis !== 'undefined') {
|
|
12
|
+
return globalThis;
|
|
13
|
+
}
|
|
14
|
+
/* istanbul ignore next */
|
|
15
|
+
if (typeof self !== 'undefined') {
|
|
16
|
+
return self;
|
|
17
|
+
}
|
|
18
|
+
/* istanbul ignore next */
|
|
19
|
+
if (typeof window !== 'undefined') {
|
|
20
|
+
return window;
|
|
21
|
+
}
|
|
22
|
+
/* istanbul ignore next */
|
|
23
|
+
if (typeof global !== 'undefined') {
|
|
24
|
+
return global;
|
|
25
|
+
}
|
|
26
|
+
/* istanbul ignore next */
|
|
27
|
+
throw new Error('unable to locate global object');
|
|
28
|
+
}
|
|
29
|
+
function setIsReactActEnvironment(isReactActEnvironment) {
|
|
30
|
+
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment;
|
|
31
|
+
}
|
|
32
|
+
function getIsReactActEnvironment() {
|
|
33
|
+
return getGlobalThis().IS_REACT_ACT_ENVIRONMENT;
|
|
34
|
+
}
|
|
35
|
+
function withGlobalActEnvironment(actImplementation) {
|
|
36
|
+
return callback => {
|
|
37
|
+
const previousActEnvironment = getIsReactActEnvironment();
|
|
38
|
+
setIsReactActEnvironment(true);
|
|
39
|
+
try {
|
|
40
|
+
// The return value of `act` is always a thenable.
|
|
41
|
+
let callbackNeedsToBeAwaited = false;
|
|
42
|
+
const actResult = actImplementation(() => {
|
|
43
|
+
const result = callback();
|
|
44
|
+
if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
|
|
45
|
+
callbackNeedsToBeAwaited = true;
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
});
|
|
49
|
+
if (callbackNeedsToBeAwaited) {
|
|
50
|
+
const thenable = actResult;
|
|
51
|
+
return {
|
|
52
|
+
then: (resolve, reject) => {
|
|
53
|
+
thenable.then(returnValue => {
|
|
54
|
+
setIsReactActEnvironment(previousActEnvironment);
|
|
55
|
+
resolve(returnValue);
|
|
56
|
+
}, error => {
|
|
57
|
+
setIsReactActEnvironment(previousActEnvironment);
|
|
58
|
+
reject(error);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
} else {
|
|
63
|
+
setIsReactActEnvironment(previousActEnvironment);
|
|
64
|
+
return actResult;
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
// Can't be a `finally {}` block since we don't know if we have to immediately restore IS_REACT_ACT_ENVIRONMENT
|
|
68
|
+
// or if we have to await the callback first.
|
|
69
|
+
setIsReactActEnvironment(previousActEnvironment);
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const act = withGlobalActEnvironment(reactAct);
|
|
75
|
+
|
|
76
|
+
/* eslint no-console:0 */
|
|
77
|
+
|
|
78
|
+
// react-testing-library's version of fireEvent will call
|
|
79
|
+
// dom-testing-library's version of fireEvent. The reason
|
|
80
|
+
// we make this distinction however is because we have
|
|
81
|
+
// a few extra events that work a bit differently
|
|
82
|
+
const fireEvent = (...args) => fireEvent$1(...args);
|
|
83
|
+
Object.keys(fireEvent$1).forEach(key => {
|
|
84
|
+
fireEvent[key] = (...args) => fireEvent$1[key](...args);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// React event system tracks native mouseOver/mouseOut events for
|
|
88
|
+
// running onMouseEnter/onMouseLeave handlers
|
|
89
|
+
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/EnterLeaveEventPlugin.js#L24-L31
|
|
90
|
+
const mouseEnter = fireEvent.mouseEnter;
|
|
91
|
+
const mouseLeave = fireEvent.mouseLeave;
|
|
92
|
+
fireEvent.mouseEnter = (...args) => {
|
|
93
|
+
mouseEnter(...args);
|
|
94
|
+
return fireEvent.mouseOver(...args);
|
|
95
|
+
};
|
|
96
|
+
fireEvent.mouseLeave = (...args) => {
|
|
97
|
+
mouseLeave(...args);
|
|
98
|
+
return fireEvent.mouseOut(...args);
|
|
99
|
+
};
|
|
100
|
+
const pointerEnter = fireEvent.pointerEnter;
|
|
101
|
+
const pointerLeave = fireEvent.pointerLeave;
|
|
102
|
+
fireEvent.pointerEnter = (...args) => {
|
|
103
|
+
pointerEnter(...args);
|
|
104
|
+
return fireEvent.pointerOver(...args);
|
|
105
|
+
};
|
|
106
|
+
fireEvent.pointerLeave = (...args) => {
|
|
107
|
+
pointerLeave(...args);
|
|
108
|
+
return fireEvent.pointerOut(...args);
|
|
109
|
+
};
|
|
110
|
+
const select = fireEvent.select;
|
|
111
|
+
fireEvent.select = (node, init) => {
|
|
112
|
+
select(node, init);
|
|
113
|
+
// React tracks this event only on focused inputs
|
|
114
|
+
node.focus();
|
|
115
|
+
|
|
116
|
+
// React creates this event when one of the following native events happens
|
|
117
|
+
// - contextMenu
|
|
118
|
+
// - mouseUp
|
|
119
|
+
// - dragEnd
|
|
120
|
+
// - keyUp
|
|
121
|
+
// - keyDown
|
|
122
|
+
// so we can use any here
|
|
123
|
+
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224
|
|
124
|
+
fireEvent.keyUp(node, init);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// React event system tracks native focusout/focusin events for
|
|
128
|
+
// running blur/focus handlers
|
|
129
|
+
// @link https://github.com/facebook/react/pull/19186
|
|
130
|
+
const blur = fireEvent.blur;
|
|
131
|
+
const focus = fireEvent.focus;
|
|
132
|
+
fireEvent.blur = (...args) => {
|
|
133
|
+
fireEvent.focusOut(...args);
|
|
134
|
+
return blur(...args);
|
|
135
|
+
};
|
|
136
|
+
fireEvent.focus = (...args) => {
|
|
137
|
+
fireEvent.focusIn(...args);
|
|
138
|
+
return focus(...args);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
let configForRTL = {
|
|
142
|
+
reactStrictMode: false
|
|
143
|
+
};
|
|
144
|
+
function getConfig() {
|
|
145
|
+
return {
|
|
146
|
+
...getConfig$1(),
|
|
147
|
+
...configForRTL
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function configure(newConfig) {
|
|
151
|
+
if (typeof newConfig === 'function') {
|
|
152
|
+
// Pass the existing config out to the provided function
|
|
153
|
+
// and accept a delta in return
|
|
154
|
+
newConfig = newConfig(getConfig());
|
|
155
|
+
}
|
|
156
|
+
const {
|
|
157
|
+
reactStrictMode,
|
|
158
|
+
...configForDTL
|
|
159
|
+
} = newConfig;
|
|
160
|
+
configure$1(configForDTL);
|
|
161
|
+
configForRTL = {
|
|
162
|
+
...configForRTL,
|
|
163
|
+
reactStrictMode
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function jestFakeTimersAreEnabled() {
|
|
168
|
+
/* istanbul ignore else */
|
|
169
|
+
if (typeof jest !== 'undefined' && jest !== null) {
|
|
170
|
+
return (
|
|
171
|
+
// legacy timers
|
|
172
|
+
setTimeout._isMockFunction === true ||
|
|
173
|
+
// modern timers
|
|
174
|
+
// eslint-disable-next-line prefer-object-has-own -- No Object.hasOwn in all target environments we support.
|
|
175
|
+
Object.prototype.hasOwnProperty.call(setTimeout, 'clock')
|
|
176
|
+
);
|
|
177
|
+
} // istanbul ignore next
|
|
178
|
+
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
configure$1({
|
|
182
|
+
unstable_advanceTimersWrapper: cb => {
|
|
183
|
+
return act(cb);
|
|
184
|
+
},
|
|
185
|
+
// We just want to run `waitFor` without IS_REACT_ACT_ENVIRONMENT
|
|
186
|
+
// But that's not necessarily how `asyncWrapper` is used since it's a public method.
|
|
187
|
+
// Let's just hope nobody else is using it.
|
|
188
|
+
asyncWrapper: async cb => {
|
|
189
|
+
const previousActEnvironment = getIsReactActEnvironment();
|
|
190
|
+
setIsReactActEnvironment(false);
|
|
191
|
+
try {
|
|
192
|
+
const result = await cb();
|
|
193
|
+
// Drain microtask queue.
|
|
194
|
+
// Otherwise we'll restore the previous act() environment, before we resolve the `waitFor` call.
|
|
195
|
+
// The caller would have no chance to wrap the in-flight Promises in `act()`
|
|
196
|
+
await new Promise(resolve => {
|
|
197
|
+
setTimeout(() => {
|
|
198
|
+
resolve();
|
|
199
|
+
}, 0);
|
|
200
|
+
if (jestFakeTimersAreEnabled()) {
|
|
201
|
+
jest.advanceTimersByTime(0);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
return result;
|
|
205
|
+
} finally {
|
|
206
|
+
setIsReactActEnvironment(previousActEnvironment);
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
eventWrapper: cb => {
|
|
210
|
+
let result;
|
|
211
|
+
act(() => {
|
|
212
|
+
result = cb();
|
|
213
|
+
});
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// Ideally we'd just use a WeakMap where containers are keys and roots are values.
|
|
219
|
+
// We use two variables so that we can bail out in constant time when we render with a new container (most common use case)
|
|
220
|
+
/**
|
|
221
|
+
* @type {Set<import('react-dom').Container>}
|
|
222
|
+
*/
|
|
223
|
+
const mountedContainers = new Set();
|
|
224
|
+
/**
|
|
225
|
+
* @type Array<{container: import('react-dom').Container, root: ReturnType<typeof createConcurrentRoot>}>
|
|
226
|
+
*/
|
|
227
|
+
const mountedRootEntries = [];
|
|
228
|
+
function strictModeIfNeeded(innerElement, reactStrictMode) {
|
|
229
|
+
return reactStrictMode ?? getConfig().reactStrictMode ? /*#__PURE__*/React.createElement(React.StrictMode, null, innerElement) : innerElement;
|
|
230
|
+
}
|
|
231
|
+
function wrapUiIfNeeded(innerElement, wrapperComponent) {
|
|
232
|
+
return wrapperComponent ? /*#__PURE__*/React.createElement(wrapperComponent, null, innerElement) : innerElement;
|
|
233
|
+
}
|
|
234
|
+
function createConcurrentRoot(container, {
|
|
235
|
+
hydrate,
|
|
236
|
+
onCaughtError,
|
|
237
|
+
onRecoverableError,
|
|
238
|
+
ui,
|
|
239
|
+
wrapper: WrapperComponent,
|
|
240
|
+
reactStrictMode
|
|
241
|
+
}) {
|
|
242
|
+
let root;
|
|
243
|
+
if (hydrate) {
|
|
244
|
+
act(() => {
|
|
245
|
+
root = ReactDOMClient.hydrateRoot(container, strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent), reactStrictMode), {
|
|
246
|
+
onCaughtError,
|
|
247
|
+
onRecoverableError
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
} else {
|
|
251
|
+
root = ReactDOMClient.createRoot(container, {
|
|
252
|
+
onCaughtError,
|
|
253
|
+
onRecoverableError
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
hydrate() {
|
|
258
|
+
/* istanbul ignore if */
|
|
259
|
+
if (!hydrate) {
|
|
260
|
+
throw new Error('Attempted to hydrate a non-hydrateable root. This is a bug in `@testing-library/react`.');
|
|
261
|
+
}
|
|
262
|
+
// Nothing to do since hydration happens when creating the root object.
|
|
263
|
+
},
|
|
264
|
+
render(element) {
|
|
265
|
+
root.render(element);
|
|
266
|
+
},
|
|
267
|
+
unmount() {
|
|
268
|
+
root.unmount();
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function createLegacyRoot(container) {
|
|
273
|
+
return {
|
|
274
|
+
hydrate(element) {
|
|
275
|
+
ReactDOM.hydrate(element, container);
|
|
276
|
+
},
|
|
277
|
+
render(element) {
|
|
278
|
+
ReactDOM.render(element, container);
|
|
279
|
+
},
|
|
280
|
+
unmount() {
|
|
281
|
+
ReactDOM.unmountComponentAtNode(container);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
function renderRoot(ui, {
|
|
286
|
+
baseElement,
|
|
287
|
+
container,
|
|
288
|
+
hydrate,
|
|
289
|
+
queries,
|
|
290
|
+
root,
|
|
291
|
+
wrapper: WrapperComponent,
|
|
292
|
+
reactStrictMode
|
|
293
|
+
}) {
|
|
294
|
+
act(() => {
|
|
295
|
+
if (hydrate) {
|
|
296
|
+
root.hydrate(strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent), reactStrictMode), container);
|
|
297
|
+
} else {
|
|
298
|
+
root.render(strictModeIfNeeded(wrapUiIfNeeded(ui, WrapperComponent), reactStrictMode), container);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
return {
|
|
302
|
+
container,
|
|
303
|
+
baseElement,
|
|
304
|
+
debug: (el = baseElement, maxLength, options) => Array.isArray(el) ?
|
|
305
|
+
// eslint-disable-next-line no-console
|
|
306
|
+
el.forEach(e => console.log(prettyDOM(e, maxLength, options))) :
|
|
307
|
+
// eslint-disable-next-line no-console,
|
|
308
|
+
console.log(prettyDOM(el, maxLength, options)),
|
|
309
|
+
unmount: () => {
|
|
310
|
+
act(() => {
|
|
311
|
+
root.unmount();
|
|
312
|
+
});
|
|
313
|
+
},
|
|
314
|
+
rerender: rerenderUi => {
|
|
315
|
+
renderRoot(rerenderUi, {
|
|
316
|
+
container,
|
|
317
|
+
baseElement,
|
|
318
|
+
root,
|
|
319
|
+
wrapper: WrapperComponent,
|
|
320
|
+
reactStrictMode
|
|
321
|
+
});
|
|
322
|
+
// Intentionally do not return anything to avoid unnecessarily complicating the API.
|
|
323
|
+
// folks can use all the same utilities we return in the first place that are bound to the container
|
|
324
|
+
},
|
|
325
|
+
asFragment: () => {
|
|
326
|
+
/* istanbul ignore else (old jsdom limitation) */
|
|
327
|
+
if (typeof document.createRange === 'function') {
|
|
328
|
+
return document.createRange().createContextualFragment(container.innerHTML);
|
|
329
|
+
} else {
|
|
330
|
+
const template = document.createElement('template');
|
|
331
|
+
template.innerHTML = container.innerHTML;
|
|
332
|
+
return template.content;
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
...getQueriesForElement(baseElement, queries)
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function render(ui, {
|
|
339
|
+
container,
|
|
340
|
+
baseElement = container,
|
|
341
|
+
legacyRoot = false,
|
|
342
|
+
onCaughtError,
|
|
343
|
+
onUncaughtError,
|
|
344
|
+
onRecoverableError,
|
|
345
|
+
queries,
|
|
346
|
+
hydrate = false,
|
|
347
|
+
wrapper,
|
|
348
|
+
reactStrictMode
|
|
349
|
+
} = {}) {
|
|
350
|
+
if (onUncaughtError !== undefined) {
|
|
351
|
+
throw new Error('onUncaughtError is not supported. The `render` call will already throw on uncaught errors.');
|
|
352
|
+
}
|
|
353
|
+
if (legacyRoot && typeof ReactDOM.render !== 'function') {
|
|
354
|
+
const error = new Error('`legacyRoot: true` is not supported in this version of React. ' + 'If your app runs React 19 or later, you should remove this flag. ' + 'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.');
|
|
355
|
+
Error.captureStackTrace(error, render);
|
|
356
|
+
throw error;
|
|
357
|
+
}
|
|
358
|
+
if (!baseElement) {
|
|
359
|
+
// default to document.body instead of documentElement to avoid output of potentially-large
|
|
360
|
+
// head elements (such as JSS style blocks) in debug output
|
|
361
|
+
baseElement = document.body;
|
|
362
|
+
}
|
|
363
|
+
if (!container) {
|
|
364
|
+
container = baseElement.appendChild(document.createElement('div'));
|
|
365
|
+
}
|
|
366
|
+
let root;
|
|
367
|
+
// eslint-disable-next-line no-negated-condition -- we want to map the evolution of this over time. The root is created first. Only later is it re-used so we don't want to read the case that happens later first.
|
|
368
|
+
if (!mountedContainers.has(container)) {
|
|
369
|
+
const createRootImpl = legacyRoot ? createLegacyRoot : createConcurrentRoot;
|
|
370
|
+
root = createRootImpl(container, {
|
|
371
|
+
hydrate,
|
|
372
|
+
onCaughtError,
|
|
373
|
+
onRecoverableError,
|
|
374
|
+
ui,
|
|
375
|
+
wrapper,
|
|
376
|
+
reactStrictMode
|
|
377
|
+
});
|
|
378
|
+
mountedRootEntries.push({
|
|
379
|
+
container,
|
|
380
|
+
root
|
|
381
|
+
});
|
|
382
|
+
// we'll add it to the mounted containers regardless of whether it's actually
|
|
383
|
+
// added to document.body so the cleanup method works regardless of whether
|
|
384
|
+
// they're passing us a custom container or not.
|
|
385
|
+
mountedContainers.add(container);
|
|
386
|
+
} else {
|
|
387
|
+
mountedRootEntries.forEach(rootEntry => {
|
|
388
|
+
// Else is unreachable since `mountedContainers` has the `container`.
|
|
389
|
+
// Only reachable if one would accidentally add the container to `mountedContainers` but not the root to `mountedRootEntries`
|
|
390
|
+
/* istanbul ignore else */
|
|
391
|
+
if (rootEntry.container === container) {
|
|
392
|
+
root = rootEntry.root;
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
return renderRoot(ui, {
|
|
397
|
+
container,
|
|
398
|
+
baseElement,
|
|
399
|
+
queries,
|
|
400
|
+
hydrate,
|
|
401
|
+
wrapper,
|
|
402
|
+
root,
|
|
403
|
+
reactStrictMode
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
function cleanup() {
|
|
407
|
+
mountedRootEntries.forEach(({
|
|
408
|
+
root,
|
|
409
|
+
container
|
|
410
|
+
}) => {
|
|
411
|
+
act(() => {
|
|
412
|
+
root.unmount();
|
|
413
|
+
});
|
|
414
|
+
if (container.parentNode === document.body) {
|
|
415
|
+
document.body.removeChild(container);
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
mountedRootEntries.length = 0;
|
|
419
|
+
mountedContainers.clear();
|
|
420
|
+
}
|
|
421
|
+
function renderHook(renderCallback, options = {}) {
|
|
422
|
+
const {
|
|
423
|
+
initialProps,
|
|
424
|
+
...renderOptions
|
|
425
|
+
} = options;
|
|
426
|
+
if (renderOptions.legacyRoot && typeof ReactDOM.render !== 'function') {
|
|
427
|
+
const error = new Error('`legacyRoot: true` is not supported in this version of React. ' + 'If your app runs React 19 or later, you should remove this flag. ' + 'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.');
|
|
428
|
+
Error.captureStackTrace(error, renderHook);
|
|
429
|
+
throw error;
|
|
430
|
+
}
|
|
431
|
+
const result = /*#__PURE__*/React.createRef();
|
|
432
|
+
function TestComponent({
|
|
433
|
+
renderCallbackProps
|
|
434
|
+
}) {
|
|
435
|
+
const pendingResult = renderCallback(renderCallbackProps);
|
|
436
|
+
React.useEffect(() => {
|
|
437
|
+
result.current = pendingResult;
|
|
438
|
+
});
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
const {
|
|
442
|
+
rerender: baseRerender,
|
|
443
|
+
unmount
|
|
444
|
+
} = render(/*#__PURE__*/React.createElement(TestComponent, {
|
|
445
|
+
renderCallbackProps: initialProps
|
|
446
|
+
}), renderOptions);
|
|
447
|
+
function rerender(rerenderCallbackProps) {
|
|
448
|
+
return baseRerender(/*#__PURE__*/React.createElement(TestComponent, {
|
|
449
|
+
renderCallbackProps: rerenderCallbackProps
|
|
450
|
+
}));
|
|
451
|
+
}
|
|
452
|
+
return {
|
|
453
|
+
result,
|
|
454
|
+
rerender,
|
|
455
|
+
unmount
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/* eslint func-name-matching:0 */
|
|
460
|
+
|
|
461
|
+
export { act, cleanup, configure, fireEvent, getConfig, render, renderHook };
|