@apollo/client 0.0.0-pr-10521-20230206180228
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/LICENSE +22 -0
- package/README.md +45 -0
- package/apollo-client.cjs +7614 -0
- package/apollo-client.cjs.map +1 -0
- package/apollo-client.min.cjs +1 -0
- package/cache/cache.cjs +2425 -0
- package/cache/cache.cjs.map +1 -0
- package/cache/cache.cjs.native.js +2425 -0
- package/cache/core/cache.d.ts +32 -0
- package/cache/core/cache.d.ts.map +1 -0
- package/cache/core/cache.js +84 -0
- package/cache/core/cache.js.map +1 -0
- package/cache/core/types/Cache.d.ts +55 -0
- package/cache/core/types/Cache.d.ts.map +1 -0
- package/cache/core/types/Cache.js +4 -0
- package/cache/core/types/Cache.js.map +1 -0
- package/cache/core/types/DataProxy.d.ts +52 -0
- package/cache/core/types/DataProxy.d.ts.map +1 -0
- package/cache/core/types/DataProxy.js +2 -0
- package/cache/core/types/DataProxy.js.map +1 -0
- package/cache/core/types/common.d.ts +47 -0
- package/cache/core/types/common.d.ts.map +1 -0
- package/cache/core/types/common.js +26 -0
- package/cache/core/types/common.js.map +1 -0
- package/cache/index.d.ts +15 -0
- package/cache/index.d.ts.map +1 -0
- package/cache/index.js +14 -0
- package/cache/index.js.map +1 -0
- package/cache/inmemory/__mocks__/optimism.d.ts +2 -0
- package/cache/inmemory/__mocks__/optimism.d.ts.map +1 -0
- package/cache/inmemory/__mocks__/optimism.js +14 -0
- package/cache/inmemory/__mocks__/optimism.js.map +1 -0
- package/cache/inmemory/entityStore.d.ts +83 -0
- package/cache/inmemory/entityStore.d.ts.map +1 -0
- package/cache/inmemory/entityStore.js +467 -0
- package/cache/inmemory/entityStore.js.map +1 -0
- package/cache/inmemory/fixPolyfills.d.ts +1 -0
- package/cache/inmemory/fixPolyfills.d.ts.map +1 -0
- package/cache/inmemory/fixPolyfills.js +1 -0
- package/cache/inmemory/fixPolyfills.js.map +1 -0
- package/cache/inmemory/fixPolyfills.native.d.ts +2 -0
- package/cache/inmemory/fixPolyfills.native.d.ts.map +1 -0
- package/cache/inmemory/fixPolyfills.native.js +48 -0
- package/cache/inmemory/fixPolyfills.native.js.map +1 -0
- package/cache/inmemory/fragmentRegistry.d.ts +8 -0
- package/cache/inmemory/fragmentRegistry.d.ts.map +1 -0
- package/cache/inmemory/fragmentRegistry.js +113 -0
- package/cache/inmemory/fragmentRegistry.js.map +1 -0
- package/cache/inmemory/helpers.d.ts +27 -0
- package/cache/inmemory/helpers.d.ts.map +1 -0
- package/cache/inmemory/helpers.js +85 -0
- package/cache/inmemory/helpers.js.map +1 -0
- package/cache/inmemory/inMemoryCache.d.ts +52 -0
- package/cache/inmemory/inMemoryCache.d.ts.map +1 -0
- package/cache/inmemory/inMemoryCache.js +316 -0
- package/cache/inmemory/inMemoryCache.js.map +1 -0
- package/cache/inmemory/key-extractor.d.ts +9 -0
- package/cache/inmemory/key-extractor.d.ts.map +1 -0
- package/cache/inmemory/key-extractor.js +118 -0
- package/cache/inmemory/key-extractor.js.map +1 -0
- package/cache/inmemory/object-canon.d.ts +17 -0
- package/cache/inmemory/object-canon.d.ts.map +1 -0
- package/cache/inmemory/object-canon.js +120 -0
- package/cache/inmemory/object-canon.js.map +1 -0
- package/cache/inmemory/policies.d.ts +96 -0
- package/cache/inmemory/policies.d.ts.map +1 -0
- package/cache/inmemory/policies.js +416 -0
- package/cache/inmemory/policies.js.map +1 -0
- package/cache/inmemory/reactiveVars.d.ts +18 -0
- package/cache/inmemory/reactiveVars.d.ts.map +1 -0
- package/cache/inmemory/reactiveVars.js +65 -0
- package/cache/inmemory/reactiveVars.js.map +1 -0
- package/cache/inmemory/readFromStore.d.ts +36 -0
- package/cache/inmemory/readFromStore.d.ts.map +1 -0
- package/cache/inmemory/readFromStore.js +267 -0
- package/cache/inmemory/readFromStore.js.map +1 -0
- package/cache/inmemory/types.d.ts +81 -0
- package/cache/inmemory/types.d.ts.map +1 -0
- package/cache/inmemory/types.js +4 -0
- package/cache/inmemory/types.js.map +1 -0
- package/cache/inmemory/writeToStore.d.ts +37 -0
- package/cache/inmemory/writeToStore.d.ts.map +1 -0
- package/cache/inmemory/writeToStore.js +394 -0
- package/cache/inmemory/writeToStore.js.map +1 -0
- package/cache/package.json +8 -0
- package/config/jest/setup.d.ts +2 -0
- package/config/jest/setup.d.ts.map +1 -0
- package/config/jest/setup.js +5 -0
- package/config/jest/setup.js.map +1 -0
- package/core/ApolloClient.d.ts +76 -0
- package/core/ApolloClient.d.ts.map +1 -0
- package/core/ApolloClient.js +240 -0
- package/core/ApolloClient.js.map +1 -0
- package/core/LocalState.d.ts +69 -0
- package/core/LocalState.d.ts.map +1 -0
- package/core/LocalState.js +321 -0
- package/core/LocalState.js.map +1 -0
- package/core/ObservableQuery.d.ts +74 -0
- package/core/ObservableQuery.d.ts.map +1 -0
- package/core/ObservableQuery.js +507 -0
- package/core/ObservableQuery.js.map +1 -0
- package/core/QueryInfo.d.ts +62 -0
- package/core/QueryInfo.d.ts.map +1 -0
- package/core/QueryInfo.js +287 -0
- package/core/QueryInfo.js.map +1 -0
- package/core/QueryManager.d.ts +120 -0
- package/core/QueryManager.d.ts.map +1 -0
- package/core/QueryManager.js +890 -0
- package/core/QueryManager.js.map +1 -0
- package/core/core.cjs +2349 -0
- package/core/core.cjs.map +1 -0
- package/core/core.cjs.native.js +2349 -0
- package/core/index.d.ts +17 -0
- package/core/index.d.ts.map +1 -0
- package/core/index.js +17 -0
- package/core/index.js.map +1 -0
- package/core/networkStatus.d.ts +11 -0
- package/core/networkStatus.d.ts.map +1 -0
- package/core/networkStatus.js +14 -0
- package/core/networkStatus.js.map +1 -0
- package/core/package.json +8 -0
- package/core/types.d.ts +74 -0
- package/core/types.d.ts.map +1 -0
- package/core/types.js +3 -0
- package/core/types.js.map +1 -0
- package/core/watchQueryOptions.d.ts +78 -0
- package/core/watchQueryOptions.d.ts.map +1 -0
- package/core/watchQueryOptions.js +2 -0
- package/core/watchQueryOptions.js.map +1 -0
- package/errors/errors.cjs +49 -0
- package/errors/errors.cjs.map +1 -0
- package/errors/errors.cjs.native.js +49 -0
- package/errors/index.d.ts +23 -0
- package/errors/index.d.ts.map +1 -0
- package/errors/index.js +42 -0
- package/errors/index.js.map +1 -0
- package/errors/package.json +8 -0
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -0
- package/index.js +3 -0
- package/index.js.map +1 -0
- package/invariantErrorCodes.js +339 -0
- package/link/batch/batch.cjs +159 -0
- package/link/batch/batch.cjs.map +1 -0
- package/link/batch/batch.cjs.native.js +159 -0
- package/link/batch/batchLink.d.ts +19 -0
- package/link/batch/batchLink.d.ts.map +1 -0
- package/link/batch/batchLink.js +31 -0
- package/link/batch/batchLink.js.map +1 -0
- package/link/batch/batching.d.ts +27 -0
- package/link/batch/batching.d.ts.map +1 -0
- package/link/batch/batching.js +125 -0
- package/link/batch/batching.js.map +1 -0
- package/link/batch/index.d.ts +2 -0
- package/link/batch/index.d.ts.map +1 -0
- package/link/batch/index.js +2 -0
- package/link/batch/index.js.map +1 -0
- package/link/batch/package.json +8 -0
- package/link/batch-http/batch-http.cjs +137 -0
- package/link/batch-http/batch-http.cjs.map +1 -0
- package/link/batch-http/batch-http.cjs.native.js +137 -0
- package/link/batch-http/batchHttpLink.d.ts +16 -0
- package/link/batch-http/batchHttpLink.d.ts.map +1 -0
- package/link/batch-http/batchHttpLink.js +131 -0
- package/link/batch-http/batchHttpLink.js.map +1 -0
- package/link/batch-http/index.d.ts +2 -0
- package/link/batch-http/index.d.ts.map +1 -0
- package/link/batch-http/index.js +2 -0
- package/link/batch-http/index.js.map +1 -0
- package/link/batch-http/package.json +8 -0
- package/link/context/context.cjs +38 -0
- package/link/context/context.cjs.map +1 -0
- package/link/context/context.cjs.native.js +38 -0
- package/link/context/index.d.ts +5 -0
- package/link/context/index.d.ts.map +1 -0
- package/link/context/index.js +31 -0
- package/link/context/index.js.map +1 -0
- package/link/context/package.json +8 -0
- package/link/core/ApolloLink.d.ts +16 -0
- package/link/core/ApolloLink.d.ts.map +1 -0
- package/link/core/ApolloLink.js +100 -0
- package/link/core/ApolloLink.js.map +1 -0
- package/link/core/concat.d.ts +3 -0
- package/link/core/concat.d.ts.map +1 -0
- package/link/core/concat.js +3 -0
- package/link/core/concat.js.map +1 -0
- package/link/core/core.cjs +121 -0
- package/link/core/core.cjs.map +1 -0
- package/link/core/core.cjs.native.js +121 -0
- package/link/core/empty.d.ts +3 -0
- package/link/core/empty.d.ts.map +1 -0
- package/link/core/empty.js +3 -0
- package/link/core/empty.js.map +1 -0
- package/link/core/execute.d.ts +3 -0
- package/link/core/execute.d.ts.map +1 -0
- package/link/core/execute.js +3 -0
- package/link/core/execute.js.map +1 -0
- package/link/core/from.d.ts +3 -0
- package/link/core/from.d.ts.map +1 -0
- package/link/core/from.js +3 -0
- package/link/core/from.js.map +1 -0
- package/link/core/index.d.ts +9 -0
- package/link/core/index.d.ts.map +1 -0
- package/link/core/index.js +9 -0
- package/link/core/index.js.map +1 -0
- package/link/core/package.json +8 -0
- package/link/core/split.d.ts +3 -0
- package/link/core/split.d.ts.map +1 -0
- package/link/core/split.js +3 -0
- package/link/core/split.js.map +1 -0
- package/link/core/types.d.ts +52 -0
- package/link/core/types.d.ts.map +1 -0
- package/link/core/types.js +2 -0
- package/link/core/types.js.map +1 -0
- package/link/error/error.cjs +90 -0
- package/link/error/error.cjs.map +1 -0
- package/link/error/error.cjs.native.js +90 -0
- package/link/error/index.d.ts +24 -0
- package/link/error/index.d.ts.map +1 -0
- package/link/error/index.js +83 -0
- package/link/error/index.js.map +1 -0
- package/link/error/package.json +8 -0
- package/link/http/HttpLink.d.ts +8 -0
- package/link/http/HttpLink.d.ts.map +1 -0
- package/link/http/HttpLink.js +15 -0
- package/link/http/HttpLink.js.map +1 -0
- package/link/http/checkFetcher.d.ts +2 -0
- package/link/http/checkFetcher.d.ts.map +1 -0
- package/link/http/checkFetcher.js +7 -0
- package/link/http/checkFetcher.js.map +1 -0
- package/link/http/createHttpLink.d.ts +4 -0
- package/link/http/createHttpLink.d.ts.map +1 -0
- package/link/http/createHttpLink.js +127 -0
- package/link/http/createHttpLink.js.map +1 -0
- package/link/http/createSignalIfSupported.d.ts +8 -0
- package/link/http/createSignalIfSupported.d.ts.map +1 -0
- package/link/http/createSignalIfSupported.js +8 -0
- package/link/http/createSignalIfSupported.js.map +1 -0
- package/link/http/http.cjs +593 -0
- package/link/http/http.cjs.map +1 -0
- package/link/http/http.cjs.native.js +593 -0
- package/link/http/index.d.ts +11 -0
- package/link/http/index.d.ts.map +1 -0
- package/link/http/index.js +11 -0
- package/link/http/index.js.map +1 -0
- package/link/http/iterators/async.d.ts +2 -0
- package/link/http/iterators/async.d.ts.map +1 -0
- package/link/http/iterators/async.js +14 -0
- package/link/http/iterators/async.js.map +1 -0
- package/link/http/iterators/nodeStream.d.ts +4 -0
- package/link/http/iterators/nodeStream.d.ts.map +1 -0
- package/link/http/iterators/nodeStream.js +71 -0
- package/link/http/iterators/nodeStream.js.map +1 -0
- package/link/http/iterators/promise.d.ts +2 -0
- package/link/http/iterators/promise.d.ts.map +1 -0
- package/link/http/iterators/promise.js +28 -0
- package/link/http/iterators/promise.js.map +1 -0
- package/link/http/iterators/reader.d.ts +2 -0
- package/link/http/iterators/reader.d.ts.map +1 -0
- package/link/http/iterators/reader.js +15 -0
- package/link/http/iterators/reader.js.map +1 -0
- package/link/http/package.json +8 -0
- package/link/http/parseAndCheckHttpResponse.d.ts +14 -0
- package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -0
- package/link/http/parseAndCheckHttpResponse.js +148 -0
- package/link/http/parseAndCheckHttpResponse.js.map +1 -0
- package/link/http/responseIterator.d.ts +3 -0
- package/link/http/responseIterator.d.ts.map +1 -0
- package/link/http/responseIterator.js +23 -0
- package/link/http/responseIterator.js.map +1 -0
- package/link/http/rewriteURIForGET.d.ts +9 -0
- package/link/http/rewriteURIForGET.d.ts.map +1 -0
- package/link/http/rewriteURIForGET.js +43 -0
- package/link/http/rewriteURIForGET.js.map +1 -0
- package/link/http/selectHttpOptionsAndBody.d.ts +57 -0
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -0
- package/link/http/selectHttpOptionsAndBody.js +78 -0
- package/link/http/selectHttpOptionsAndBody.js.map +1 -0
- package/link/http/selectURI.d.ts +3 -0
- package/link/http/selectURI.d.ts.map +1 -0
- package/link/http/selectURI.js +14 -0
- package/link/http/selectURI.js.map +1 -0
- package/link/http/serializeFetchParameter.d.ts +6 -0
- package/link/http/serializeFetchParameter.d.ts.map +1 -0
- package/link/http/serializeFetchParameter.js +14 -0
- package/link/http/serializeFetchParameter.js.map +1 -0
- package/link/persisted-queries/index.d.ts +31 -0
- package/link/persisted-queries/index.d.ts.map +1 -0
- package/link/persisted-queries/index.js +170 -0
- package/link/persisted-queries/index.js.map +1 -0
- package/link/persisted-queries/package.json +8 -0
- package/link/persisted-queries/persisted-queries.cjs +174 -0
- package/link/persisted-queries/persisted-queries.cjs.map +1 -0
- package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
- package/link/retry/delayFunction.d.ts +11 -0
- package/link/retry/delayFunction.d.ts.map +1 -0
- package/link/retry/delayFunction.js +12 -0
- package/link/retry/delayFunction.js.map +1 -0
- package/link/retry/index.d.ts +2 -0
- package/link/retry/index.d.ts.map +1 -0
- package/link/retry/index.js +2 -0
- package/link/retry/index.js.map +1 -0
- package/link/retry/package.json +8 -0
- package/link/retry/retry.cjs +170 -0
- package/link/retry/retry.cjs.map +1 -0
- package/link/retry/retry.cjs.native.js +170 -0
- package/link/retry/retryFunction.d.ts +10 -0
- package/link/retry/retryFunction.d.ts.map +1 -0
- package/link/retry/retryFunction.js +9 -0
- package/link/retry/retryFunction.js.map +1 -0
- package/link/retry/retryLink.d.ts +17 -0
- package/link/retry/retryLink.d.ts.map +1 -0
- package/link/retry/retryLink.js +145 -0
- package/link/retry/retryLink.js.map +1 -0
- package/link/schema/index.d.ts +22 -0
- package/link/schema/index.d.ts.map +1 -0
- package/link/schema/index.js +50 -0
- package/link/schema/index.js.map +1 -0
- package/link/schema/package.json +8 -0
- package/link/schema/schema.cjs +56 -0
- package/link/schema/schema.cjs.map +1 -0
- package/link/schema/schema.cjs.native.js +56 -0
- package/link/subscriptions/index.d.ts +9 -0
- package/link/subscriptions/index.d.ts.map +1 -0
- package/link/subscriptions/index.js +39 -0
- package/link/subscriptions/index.js.map +1 -0
- package/link/subscriptions/package.json +8 -0
- package/link/subscriptions/subscriptions.cjs +45 -0
- package/link/subscriptions/subscriptions.cjs.map +1 -0
- package/link/subscriptions/subscriptions.cjs.native.js +45 -0
- package/link/utils/createOperation.d.ts +3 -0
- package/link/utils/createOperation.d.ts.map +1 -0
- package/link/utils/createOperation.js +23 -0
- package/link/utils/createOperation.js.map +1 -0
- package/link/utils/fromError.d.ts +3 -0
- package/link/utils/fromError.d.ts.map +1 -0
- package/link/utils/fromError.js +7 -0
- package/link/utils/fromError.js.map +1 -0
- package/link/utils/fromPromise.d.ts +3 -0
- package/link/utils/fromPromise.d.ts.map +1 -0
- package/link/utils/fromPromise.js +12 -0
- package/link/utils/fromPromise.js.map +1 -0
- package/link/utils/index.d.ts +9 -0
- package/link/utils/index.d.ts.map +1 -0
- package/link/utils/index.js +9 -0
- package/link/utils/index.js.map +1 -0
- package/link/utils/package.json +8 -0
- package/link/utils/throwServerError.d.ts +7 -0
- package/link/utils/throwServerError.d.ts.map +1 -0
- package/link/utils/throwServerError.js +9 -0
- package/link/utils/throwServerError.js.map +1 -0
- package/link/utils/toPromise.d.ts +3 -0
- package/link/utils/toPromise.d.ts.map +1 -0
- package/link/utils/toPromise.js +19 -0
- package/link/utils/toPromise.js.map +1 -0
- package/link/utils/transformOperation.d.ts +3 -0
- package/link/utils/transformOperation.d.ts.map +1 -0
- package/link/utils/transformOperation.js +17 -0
- package/link/utils/transformOperation.js.map +1 -0
- package/link/utils/utils.cjs +115 -0
- package/link/utils/utils.cjs.map +1 -0
- package/link/utils/utils.cjs.native.js +115 -0
- package/link/utils/validateOperation.d.ts +3 -0
- package/link/utils/validateOperation.d.ts.map +1 -0
- package/link/utils/validateOperation.js +18 -0
- package/link/utils/validateOperation.js.map +1 -0
- package/link/ws/index.d.ts +17 -0
- package/link/ws/index.d.ts.map +1 -0
- package/link/ws/index.js +22 -0
- package/link/ws/index.js.map +1 -0
- package/link/ws/package.json +8 -0
- package/link/ws/ws.cjs +28 -0
- package/link/ws/ws.cjs.map +1 -0
- package/link/ws/ws.cjs.native.js +28 -0
- package/main.cjs +16 -0
- package/main.cjs.map +1 -0
- package/main.cjs.native.js +16 -0
- package/package.json +141 -0
- package/react/cache/SuspenseCache.d.ts +18 -0
- package/react/cache/SuspenseCache.d.ts.map +1 -0
- package/react/cache/SuspenseCache.js +49 -0
- package/react/cache/SuspenseCache.js.map +1 -0
- package/react/cache/index.d.ts +2 -0
- package/react/cache/index.d.ts.map +1 -0
- package/react/cache/index.js +2 -0
- package/react/cache/index.js.map +1 -0
- package/react/components/Mutation.d.ts +12 -0
- package/react/components/Mutation.d.ts.map +1 -0
- package/react/components/Mutation.js +22 -0
- package/react/components/Mutation.js.map +1 -0
- package/react/components/Query.d.ts +12 -0
- package/react/components/Query.d.ts.map +1 -0
- package/react/components/Query.js +23 -0
- package/react/components/Query.js.map +1 -0
- package/react/components/Subscription.d.ts +12 -0
- package/react/components/Subscription.d.ts.map +1 -0
- package/react/components/Subscription.js +17 -0
- package/react/components/Subscription.js.map +1 -0
- package/react/components/components.cjs +81 -0
- package/react/components/components.cjs.map +1 -0
- package/react/components/components.cjs.native.js +81 -0
- package/react/components/index.d.ts +5 -0
- package/react/components/index.d.ts.map +1 -0
- package/react/components/index.js +5 -0
- package/react/components/index.js.map +1 -0
- package/react/components/package.json +8 -0
- package/react/components/types.d.ts +18 -0
- package/react/components/types.d.ts.map +1 -0
- package/react/components/types.js +2 -0
- package/react/components/types.js.map +1 -0
- package/react/context/ApolloConsumer.d.ts +7 -0
- package/react/context/ApolloConsumer.d.ts.map +1 -0
- package/react/context/ApolloConsumer.js +12 -0
- package/react/context/ApolloConsumer.js.map +1 -0
- package/react/context/ApolloContext.d.ts +12 -0
- package/react/context/ApolloContext.d.ts.map +1 -0
- package/react/context/ApolloContext.js +20 -0
- package/react/context/ApolloContext.js.map +1 -0
- package/react/context/ApolloProvider.d.ts +10 -0
- package/react/context/ApolloProvider.d.ts.map +1 -0
- package/react/context/ApolloProvider.js +20 -0
- package/react/context/ApolloProvider.js.map +1 -0
- package/react/context/context.cjs +70 -0
- package/react/context/context.cjs.map +1 -0
- package/react/context/context.cjs.native.js +70 -0
- package/react/context/index.d.ts +5 -0
- package/react/context/index.d.ts.map +1 -0
- package/react/context/index.js +5 -0
- package/react/context/index.js.map +1 -0
- package/react/context/package.json +8 -0
- package/react/hoc/graphql.d.ts +6 -0
- package/react/hoc/graphql.d.ts.map +1 -0
- package/react/hoc/graphql.js +17 -0
- package/react/hoc/graphql.js.map +1 -0
- package/react/hoc/hoc-utils.d.ts +17 -0
- package/react/hoc/hoc-utils.d.ts.map +1 -0
- package/react/hoc/hoc-utils.js +47 -0
- package/react/hoc/hoc-utils.js.map +1 -0
- package/react/hoc/hoc.cjs +325 -0
- package/react/hoc/hoc.cjs.map +1 -0
- package/react/hoc/hoc.cjs.native.js +325 -0
- package/react/hoc/index.d.ts +8 -0
- package/react/hoc/index.d.ts.map +1 -0
- package/react/hoc/index.js +8 -0
- package/react/hoc/index.js.map +1 -0
- package/react/hoc/mutation-hoc.d.ts +7 -0
- package/react/hoc/mutation-hoc.d.ts.map +1 -0
- package/react/hoc/mutation-hoc.js +63 -0
- package/react/hoc/mutation-hoc.js.map +1 -0
- package/react/hoc/package.json +8 -0
- package/react/hoc/query-hoc.d.ts +5 -0
- package/react/hoc/query-hoc.d.ts.map +1 -0
- package/react/hoc/query-hoc.js +70 -0
- package/react/hoc/query-hoc.js.map +1 -0
- package/react/hoc/subscription-hoc.d.ts +5 -0
- package/react/hoc/subscription-hoc.d.ts.map +1 -0
- package/react/hoc/subscription-hoc.js +80 -0
- package/react/hoc/subscription-hoc.js.map +1 -0
- package/react/hoc/types.d.ts +43 -0
- package/react/hoc/types.d.ts.map +1 -0
- package/react/hoc/types.js +2 -0
- package/react/hoc/types.js.map +1 -0
- package/react/hoc/withApollo.d.ts +4 -0
- package/react/hoc/withApollo.d.ts.map +1 -0
- package/react/hoc/withApollo.js +45 -0
- package/react/hoc/withApollo.js.map +1 -0
- package/react/hooks/compareResults.d.ts +3 -0
- package/react/hooks/compareResults.d.ts.map +1 -0
- package/react/hooks/compareResults.js +63 -0
- package/react/hooks/compareResults.js.map +1 -0
- package/react/hooks/hooks.cjs +913 -0
- package/react/hooks/hooks.cjs.map +1 -0
- package/react/hooks/hooks.cjs.native.js +913 -0
- package/react/hooks/index.d.ts +10 -0
- package/react/hooks/index.d.ts.map +1 -0
- package/react/hooks/index.js +10 -0
- package/react/hooks/index.js.map +1 -0
- package/react/hooks/internal/index.d.ts +3 -0
- package/react/hooks/internal/index.d.ts.map +1 -0
- package/react/hooks/internal/index.js +3 -0
- package/react/hooks/internal/index.js.map +1 -0
- package/react/hooks/internal/useDeepMemo.d.ts +3 -0
- package/react/hooks/internal/useDeepMemo.d.ts.map +1 -0
- package/react/hooks/internal/useDeepMemo.js +10 -0
- package/react/hooks/internal/useDeepMemo.js.map +1 -0
- package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts +3 -0
- package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +1 -0
- package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -0
- package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -0
- package/react/hooks/package.json +8 -0
- package/react/hooks/useApolloClient.d.ts +3 -0
- package/react/hooks/useApolloClient.d.ts.map +1 -0
- package/react/hooks/useApolloClient.js +12 -0
- package/react/hooks/useApolloClient.js.map +1 -0
- package/react/hooks/useFragment.d.ts +13 -0
- package/react/hooks/useFragment.d.ts.map +1 -0
- package/react/hooks/useFragment.js +39 -0
- package/react/hooks/useFragment.js.map +1 -0
- package/react/hooks/useLazyQuery.d.ts +6 -0
- package/react/hooks/useLazyQuery.d.ts.map +1 -0
- package/react/hooks/useLazyQuery.js +71 -0
- package/react/hooks/useLazyQuery.js.map +1 -0
- package/react/hooks/useMutation.d.ts +6 -0
- package/react/hooks/useMutation.d.ts.map +1 -0
- package/react/hooks/useMutation.js +100 -0
- package/react/hooks/useMutation.js.map +1 -0
- package/react/hooks/useQuery.d.ts +41 -0
- package/react/hooks/useQuery.d.ts.map +1 -0
- package/react/hooks/useQuery.js +302 -0
- package/react/hooks/useQuery.js.map +1 -0
- package/react/hooks/useReactiveVar.d.ts +3 -0
- package/react/hooks/useReactiveVar.d.ts.map +1 -0
- package/react/hooks/useReactiveVar.js +16 -0
- package/react/hooks/useReactiveVar.js.map +1 -0
- package/react/hooks/useSubscription.d.ts +6 -0
- package/react/hooks/useSubscription.d.ts.map +1 -0
- package/react/hooks/useSubscription.js +141 -0
- package/react/hooks/useSubscription.js.map +1 -0
- package/react/hooks/useSuspenseCache.d.ts +2 -0
- package/react/hooks/useSuspenseCache.d.ts.map +1 -0
- package/react/hooks/useSuspenseCache.js +10 -0
- package/react/hooks/useSuspenseCache.js.map +1 -0
- package/react/hooks/useSuspenseQuery.d.ts +12 -0
- package/react/hooks/useSuspenseQuery.d.ts.map +1 -0
- package/react/hooks/useSuspenseQuery.js +181 -0
- package/react/hooks/useSuspenseQuery.js.map +1 -0
- package/react/hooks/useSyncExternalStore.d.ts +4 -0
- package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
- package/react/hooks/useSyncExternalStore.js +48 -0
- package/react/hooks/useSyncExternalStore.js.map +1 -0
- package/react/index.d.ts +7 -0
- package/react/index.d.ts.map +1 -0
- package/react/index.js +7 -0
- package/react/index.js.map +1 -0
- package/react/package.json +8 -0
- package/react/parser/index.d.ts +15 -0
- package/react/parser/index.d.ts.map +1 -0
- package/react/parser/index.js +94 -0
- package/react/parser/index.js.map +1 -0
- package/react/parser/package.json +8 -0
- package/react/parser/parser.cjs +103 -0
- package/react/parser/parser.cjs.map +1 -0
- package/react/parser/parser.cjs.native.js +103 -0
- package/react/react.cjs +69 -0
- package/react/react.cjs.map +1 -0
- package/react/react.cjs.native.js +69 -0
- package/react/ssr/RenderPromises.d.ts +22 -0
- package/react/ssr/RenderPromises.d.ts.map +1 -0
- package/react/ssr/RenderPromises.js +90 -0
- package/react/ssr/RenderPromises.js.map +1 -0
- package/react/ssr/getDataFromTree.d.ts +13 -0
- package/react/ssr/getDataFromTree.d.ts.map +1 -0
- package/react/ssr/getDataFromTree.js +32 -0
- package/react/ssr/getDataFromTree.js.map +1 -0
- package/react/ssr/index.d.ts +4 -0
- package/react/ssr/index.d.ts.map +1 -0
- package/react/ssr/index.js +4 -0
- package/react/ssr/index.js.map +1 -0
- package/react/ssr/package.json +8 -0
- package/react/ssr/renderToStringWithData.d.ts +3 -0
- package/react/ssr/renderToStringWithData.d.ts.map +1 -0
- package/react/ssr/renderToStringWithData.js +9 -0
- package/react/ssr/renderToStringWithData.js.map +1 -0
- package/react/ssr/ssr.cjs +151 -0
- package/react/ssr/ssr.cjs.map +1 -0
- package/react/ssr/ssr.cjs.native.js +151 -0
- package/react/types/types.d.ts +130 -0
- package/react/types/types.d.ts.map +1 -0
- package/react/types/types.js +2 -0
- package/react/types/types.js.map +1 -0
- package/testing/core/core.cjs +315 -0
- package/testing/core/core.cjs.map +1 -0
- package/testing/core/core.cjs.native.js +315 -0
- package/testing/core/index.d.ts +8 -0
- package/testing/core/index.d.ts.map +1 -0
- package/testing/core/index.js +8 -0
- package/testing/core/index.js.map +1 -0
- package/testing/core/itAsync.d.ts +6 -0
- package/testing/core/itAsync.d.ts.map +1 -0
- package/testing/core/itAsync.js +19 -0
- package/testing/core/itAsync.js.map +1 -0
- package/testing/core/mocking/mockClient.d.ts +5 -0
- package/testing/core/mocking/mockClient.d.ts.map +1 -0
- package/testing/core/mocking/mockClient.js +14 -0
- package/testing/core/mocking/mockClient.js.map +1 -0
- package/testing/core/mocking/mockFetch.d.ts +24 -0
- package/testing/core/mocking/mockFetch.d.ts.map +1 -0
- package/testing/core/mocking/mockFetch.js +83 -0
- package/testing/core/mocking/mockFetch.js.map +1 -0
- package/testing/core/mocking/mockLink.d.ts +28 -0
- package/testing/core/mocking/mockLink.d.ts.map +1 -0
- package/testing/core/mocking/mockLink.js +139 -0
- package/testing/core/mocking/mockLink.js.map +1 -0
- package/testing/core/mocking/mockQueryManager.d.ts +5 -0
- package/testing/core/mocking/mockQueryManager.d.ts.map +1 -0
- package/testing/core/mocking/mockQueryManager.js +14 -0
- package/testing/core/mocking/mockQueryManager.js.map +1 -0
- package/testing/core/mocking/mockSubscriptionLink.d.ts +24 -0
- package/testing/core/mocking/mockSubscriptionLink.d.ts.map +1 -0
- package/testing/core/mocking/mockSubscriptionLink.js +62 -0
- package/testing/core/mocking/mockSubscriptionLink.js.map +1 -0
- package/testing/core/mocking/mockWatchQuery.d.ts +5 -0
- package/testing/core/mocking/mockWatchQuery.d.ts.map +1 -0
- package/testing/core/mocking/mockWatchQuery.js +15 -0
- package/testing/core/mocking/mockWatchQuery.js.map +1 -0
- package/testing/core/observableToPromise.d.ts +15 -0
- package/testing/core/observableToPromise.d.ts.map +1 -0
- package/testing/core/observableToPromise.js +65 -0
- package/testing/core/observableToPromise.js.map +1 -0
- package/testing/core/package.json +8 -0
- package/testing/core/subscribeAndCount.d.ts +3 -0
- package/testing/core/subscribeAndCount.d.ts.map +1 -0
- package/testing/core/subscribeAndCount.js +16 -0
- package/testing/core/subscribeAndCount.js.map +1 -0
- package/testing/core/wait.d.ts +3 -0
- package/testing/core/wait.d.ts.map +1 -0
- package/testing/core/wait.js +16 -0
- package/testing/core/wait.js.map +1 -0
- package/testing/core/withConsoleSpy.d.ts +4 -0
- package/testing/core/withConsoleSpy.d.ts.map +1 -0
- package/testing/core/withConsoleSpy.js +39 -0
- package/testing/core/withConsoleSpy.js.map +1 -0
- package/testing/core/wrap.d.ts +4 -0
- package/testing/core/wrap.d.ts.map +1 -0
- package/testing/core/wrap.js +26 -0
- package/testing/core/wrap.js.map +1 -0
- package/testing/index.d.ts +4 -0
- package/testing/index.d.ts.map +1 -0
- package/testing/index.js +4 -0
- package/testing/index.js.map +1 -0
- package/testing/package.json +8 -0
- package/testing/react/MockedProvider.d.ts +30 -0
- package/testing/react/MockedProvider.d.ts.map +1 -0
- package/testing/react/MockedProvider.js +39 -0
- package/testing/react/MockedProvider.js.map +1 -0
- package/testing/testing.cjs +109 -0
- package/testing/testing.cjs.map +1 -0
- package/testing/testing.cjs.native.js +109 -0
- package/utilities/common/arrays.d.ts +2 -0
- package/utilities/common/arrays.d.ts.map +1 -0
- package/utilities/common/arrays.js +4 -0
- package/utilities/common/arrays.js.map +1 -0
- package/utilities/common/canUse.d.ts +7 -0
- package/utilities/common/canUse.d.ts.map +1 -0
- package/utilities/common/canUse.js +11 -0
- package/utilities/common/canUse.js.map +1 -0
- package/utilities/common/cloneDeep.d.ts +2 -0
- package/utilities/common/cloneDeep.d.ts.map +1 -0
- package/utilities/common/cloneDeep.js +33 -0
- package/utilities/common/cloneDeep.js.map +1 -0
- package/utilities/common/compact.d.ts +3 -0
- package/utilities/common/compact.d.ts.map +1 -0
- package/utilities/common/compact.js +19 -0
- package/utilities/common/compact.js.map +1 -0
- package/utilities/common/errorHandling.d.ts +4 -0
- package/utilities/common/errorHandling.d.ts.map +1 -0
- package/utilities/common/errorHandling.js +21 -0
- package/utilities/common/errorHandling.js.map +1 -0
- package/utilities/common/filterInPlace.d.ts +2 -0
- package/utilities/common/filterInPlace.d.ts.map +1 -0
- package/utilities/common/filterInPlace.js +11 -0
- package/utilities/common/filterInPlace.js.map +1 -0
- package/utilities/common/incrementalResult.d.ts +6 -0
- package/utilities/common/incrementalResult.d.ts.map +1 -0
- package/utilities/common/incrementalResult.js +32 -0
- package/utilities/common/incrementalResult.js.map +1 -0
- package/utilities/common/makeUniqueId.d.ts +2 -0
- package/utilities/common/makeUniqueId.d.ts.map +1 -0
- package/utilities/common/makeUniqueId.js +7 -0
- package/utilities/common/makeUniqueId.js.map +1 -0
- package/utilities/common/maybeDeepFreeze.d.ts +2 -0
- package/utilities/common/maybeDeepFreeze.d.ts.map +1 -0
- package/utilities/common/maybeDeepFreeze.js +34 -0
- package/utilities/common/maybeDeepFreeze.js.map +1 -0
- package/utilities/common/mergeDeep.d.ts +14 -0
- package/utilities/common/mergeDeep.d.ts.map +1 -0
- package/utilities/common/mergeDeep.js +76 -0
- package/utilities/common/mergeDeep.js.map +1 -0
- package/utilities/common/mergeOptions.d.ts +5 -0
- package/utilities/common/mergeOptions.d.ts.map +1 -0
- package/utilities/common/mergeOptions.js +8 -0
- package/utilities/common/mergeOptions.js.map +1 -0
- package/utilities/common/objects.d.ts +2 -0
- package/utilities/common/objects.d.ts.map +1 -0
- package/utilities/common/objects.js +4 -0
- package/utilities/common/objects.js.map +1 -0
- package/utilities/common/responseIterator.d.ts +10 -0
- package/utilities/common/responseIterator.d.ts.map +1 -0
- package/utilities/common/responseIterator.js +21 -0
- package/utilities/common/responseIterator.js.map +1 -0
- package/utilities/common/stringifyForDisplay.d.ts +2 -0
- package/utilities/common/stringifyForDisplay.d.ts.map +1 -0
- package/utilities/common/stringifyForDisplay.js +8 -0
- package/utilities/common/stringifyForDisplay.js.map +1 -0
- package/utilities/globals/DEV.d.ts +3 -0
- package/utilities/globals/DEV.d.ts.map +1 -0
- package/utilities/globals/DEV.js +9 -0
- package/utilities/globals/DEV.js.map +1 -0
- package/utilities/globals/fix-graphql.d.ts +2 -0
- package/utilities/globals/fix-graphql.d.ts.map +1 -0
- package/utilities/globals/fix-graphql.js +6 -0
- package/utilities/globals/fix-graphql.js.map +1 -0
- package/utilities/globals/global.d.ts +5 -0
- package/utilities/globals/global.d.ts.map +1 -0
- package/utilities/globals/global.js +6 -0
- package/utilities/globals/global.js.map +1 -0
- package/utilities/globals/globals.cjs +42 -0
- package/utilities/globals/globals.cjs.map +1 -0
- package/utilities/globals/globals.cjs.native.js +42 -0
- package/utilities/globals/index.d.ts +8 -0
- package/utilities/globals/index.d.ts.map +1 -0
- package/utilities/globals/index.js +10 -0
- package/utilities/globals/index.js.map +1 -0
- package/utilities/globals/maybe.d.ts +2 -0
- package/utilities/globals/maybe.d.ts.map +1 -0
- package/utilities/globals/maybe.js +7 -0
- package/utilities/globals/maybe.js.map +1 -0
- package/utilities/globals/package.json +8 -0
- package/utilities/graphql/directives.d.ts +18 -0
- package/utilities/graphql/directives.d.ts.map +1 -0
- package/utilities/graphql/directives.js +72 -0
- package/utilities/graphql/directives.js.map +1 -0
- package/utilities/graphql/fragments.d.ts +9 -0
- package/utilities/graphql/fragments.d.ts.map +1 -0
- package/utilities/graphql/fragments.js +64 -0
- package/utilities/graphql/fragments.js.map +1 -0
- package/utilities/graphql/getFromAST.d.ts +10 -0
- package/utilities/graphql/getFromAST.d.ts.map +1 -0
- package/utilities/graphql/getFromAST.js +76 -0
- package/utilities/graphql/getFromAST.js.map +1 -0
- package/utilities/graphql/storeUtils.d.ts +32 -0
- package/utilities/graphql/storeUtils.d.ts.map +1 -0
- package/utilities/graphql/storeUtils.js +208 -0
- package/utilities/graphql/storeUtils.js.map +1 -0
- package/utilities/graphql/transform.d.ts +27 -0
- package/utilities/graphql/transform.d.ts.map +1 -0
- package/utilities/graphql/transform.js +281 -0
- package/utilities/graphql/transform.js.map +1 -0
- package/utilities/index.d.ts +27 -0
- package/utilities/index.d.ts.map +1 -0
- package/utilities/index.js +27 -0
- package/utilities/index.js.map +1 -0
- package/utilities/observables/Concast.d.ts +27 -0
- package/utilities/observables/Concast.d.ts.map +1 -0
- package/utilities/observables/Concast.js +137 -0
- package/utilities/observables/Concast.js.map +1 -0
- package/utilities/observables/Observable.d.ts +5 -0
- package/utilities/observables/Observable.d.ts.map +1 -0
- package/utilities/observables/Observable.js +9 -0
- package/utilities/observables/Observable.js.map +1 -0
- package/utilities/observables/asyncMap.d.ts +3 -0
- package/utilities/observables/asyncMap.d.ts.map +1 -0
- package/utilities/observables/asyncMap.js +49 -0
- package/utilities/observables/asyncMap.js.map +1 -0
- package/utilities/observables/iteration.d.ts +3 -0
- package/utilities/observables/iteration.d.ts.map +1 -0
- package/utilities/observables/iteration.js +6 -0
- package/utilities/observables/iteration.js.map +1 -0
- package/utilities/observables/subclassing.d.ts +3 -0
- package/utilities/observables/subclassing.d.ts.map +1 -0
- package/utilities/observables/subclassing.js +13 -0
- package/utilities/observables/subclassing.js.map +1 -0
- package/utilities/package.json +8 -0
- package/utilities/policies/pagination.d.ts +28 -0
- package/utilities/policies/pagination.d.ts.map +1 -0
- package/utilities/policies/pagination.js +151 -0
- package/utilities/policies/pagination.js.map +1 -0
- package/utilities/types/IsStrictlyAny.d.ts +5 -0
- package/utilities/types/IsStrictlyAny.d.ts.map +1 -0
- package/utilities/types/IsStrictlyAny.js +2 -0
- package/utilities/types/IsStrictlyAny.js.map +1 -0
- package/utilities/utilities.cjs +1371 -0
- package/utilities/utilities.cjs.map +1 -0
- package/utilities/utilities.cjs.native.js +1371 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +2 -0
- package/version.js.map +1 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { invariant, __DEV__ } from "../../../utilities/globals/index.js";
|
|
3
|
+
import { print } from 'graphql';
|
|
4
|
+
import { equal } from '@wry/equality';
|
|
5
|
+
import { ApolloLink, } from "../../../link/core/index.js";
|
|
6
|
+
import { Observable, addTypenameToDocument, removeClientSetsFromDocument, removeConnectionDirectiveFromDocument, cloneDeep, stringifyForDisplay, } from "../../../utilities/index.js";
|
|
7
|
+
function requestToKey(request, addTypename) {
|
|
8
|
+
var queryString = request.query &&
|
|
9
|
+
print(addTypename ? addTypenameToDocument(request.query) : request.query);
|
|
10
|
+
var requestKey = { query: queryString };
|
|
11
|
+
return JSON.stringify(requestKey);
|
|
12
|
+
}
|
|
13
|
+
var MockLink = (function (_super) {
|
|
14
|
+
__extends(MockLink, _super);
|
|
15
|
+
function MockLink(mockedResponses, addTypename, options) {
|
|
16
|
+
if (addTypename === void 0) { addTypename = true; }
|
|
17
|
+
if (options === void 0) { options = Object.create(null); }
|
|
18
|
+
var _this = this;
|
|
19
|
+
var _a;
|
|
20
|
+
_this = _super.call(this) || this;
|
|
21
|
+
_this.addTypename = true;
|
|
22
|
+
_this.showWarnings = true;
|
|
23
|
+
_this.mockedResponsesByKey = {};
|
|
24
|
+
_this.addTypename = addTypename;
|
|
25
|
+
_this.showWarnings = (_a = options.showWarnings) !== null && _a !== void 0 ? _a : true;
|
|
26
|
+
if (mockedResponses) {
|
|
27
|
+
mockedResponses.forEach(function (mockedResponse) {
|
|
28
|
+
_this.addMockedResponse(mockedResponse);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return _this;
|
|
32
|
+
}
|
|
33
|
+
MockLink.prototype.addMockedResponse = function (mockedResponse) {
|
|
34
|
+
var normalizedMockedResponse = this.normalizeMockedResponse(mockedResponse);
|
|
35
|
+
var key = requestToKey(normalizedMockedResponse.request, this.addTypename);
|
|
36
|
+
var mockedResponses = this.mockedResponsesByKey[key];
|
|
37
|
+
if (!mockedResponses) {
|
|
38
|
+
mockedResponses = [];
|
|
39
|
+
this.mockedResponsesByKey[key] = mockedResponses;
|
|
40
|
+
}
|
|
41
|
+
mockedResponses.push(normalizedMockedResponse);
|
|
42
|
+
};
|
|
43
|
+
MockLink.prototype.request = function (operation) {
|
|
44
|
+
var _this = this;
|
|
45
|
+
this.operation = operation;
|
|
46
|
+
var key = requestToKey(operation, this.addTypename);
|
|
47
|
+
var unmatchedVars = [];
|
|
48
|
+
var requestVariables = operation.variables || {};
|
|
49
|
+
var mockedResponses = this.mockedResponsesByKey[key];
|
|
50
|
+
var responseIndex = mockedResponses ? mockedResponses.findIndex(function (res, index) {
|
|
51
|
+
var mockedResponseVars = res.request.variables || {};
|
|
52
|
+
if (equal(requestVariables, mockedResponseVars)) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
unmatchedVars.push(mockedResponseVars);
|
|
56
|
+
return false;
|
|
57
|
+
}) : -1;
|
|
58
|
+
var response = responseIndex >= 0
|
|
59
|
+
? mockedResponses[responseIndex]
|
|
60
|
+
: void 0;
|
|
61
|
+
var configError;
|
|
62
|
+
if (!response) {
|
|
63
|
+
configError = new Error("No more mocked responses for the query: ".concat(print(operation.query), "\nExpected variables: ").concat(stringifyForDisplay(operation.variables), "\n").concat(unmatchedVars.length > 0 ? "\nFailed to match ".concat(unmatchedVars.length, " mock").concat(unmatchedVars.length === 1 ? "" : "s", " for this query. The mocked response had the following variables:\n").concat(unmatchedVars.map(function (d) { return " ".concat(stringifyForDisplay(d)); }).join('\n'), "\n") : ""));
|
|
64
|
+
if (this.showWarnings) {
|
|
65
|
+
console.warn(configError.message +
|
|
66
|
+
'\nThis typically indicates a configuration error in your mocks ' +
|
|
67
|
+
'setup, usually due to a typo or mismatched variable.');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
mockedResponses.splice(responseIndex, 1);
|
|
72
|
+
var newData = response.newData;
|
|
73
|
+
if (newData) {
|
|
74
|
+
response.result = newData();
|
|
75
|
+
mockedResponses.push(response);
|
|
76
|
+
}
|
|
77
|
+
if (!response.result && !response.error) {
|
|
78
|
+
configError = new Error("Mocked response should contain either result or error: ".concat(key));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return new Observable(function (observer) {
|
|
82
|
+
var timer = setTimeout(function () {
|
|
83
|
+
if (configError) {
|
|
84
|
+
try {
|
|
85
|
+
if (_this.onError(configError, observer) !== false) {
|
|
86
|
+
throw configError;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
observer.error(error);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (response) {
|
|
94
|
+
if (response.error) {
|
|
95
|
+
observer.error(response.error);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
if (response.result) {
|
|
99
|
+
observer.next(typeof response.result === 'function'
|
|
100
|
+
? response.result()
|
|
101
|
+
: response.result);
|
|
102
|
+
}
|
|
103
|
+
observer.complete();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}, response && response.delay || 0);
|
|
107
|
+
return function () {
|
|
108
|
+
clearTimeout(timer);
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
MockLink.prototype.normalizeMockedResponse = function (mockedResponse) {
|
|
113
|
+
var newMockedResponse = cloneDeep(mockedResponse);
|
|
114
|
+
var queryWithoutConnection = removeConnectionDirectiveFromDocument(newMockedResponse.request.query);
|
|
115
|
+
__DEV__ ? invariant(queryWithoutConnection, "query is required") : invariant(queryWithoutConnection, 40);
|
|
116
|
+
newMockedResponse.request.query = queryWithoutConnection;
|
|
117
|
+
var query = removeClientSetsFromDocument(newMockedResponse.request.query);
|
|
118
|
+
if (query) {
|
|
119
|
+
newMockedResponse.request.query = query;
|
|
120
|
+
}
|
|
121
|
+
return newMockedResponse;
|
|
122
|
+
};
|
|
123
|
+
return MockLink;
|
|
124
|
+
}(ApolloLink));
|
|
125
|
+
export { MockLink };
|
|
126
|
+
export function mockSingleLink() {
|
|
127
|
+
var mockedResponses = [];
|
|
128
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
129
|
+
mockedResponses[_i] = arguments[_i];
|
|
130
|
+
}
|
|
131
|
+
var maybeTypename = mockedResponses[mockedResponses.length - 1];
|
|
132
|
+
var mocks = mockedResponses.slice(0, mockedResponses.length - 1);
|
|
133
|
+
if (typeof maybeTypename !== 'boolean') {
|
|
134
|
+
mocks = mockedResponses;
|
|
135
|
+
maybeTypename = true;
|
|
136
|
+
}
|
|
137
|
+
return new MockLink(mocks, maybeTypename);
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=mockLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockLink.js","sourceRoot":"","sources":["../../../../src/testing/core/mocking/m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E;YACT,iBAAiB,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;SACzC;QACD,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IACH,eAAC;AAAD,CAAC,AAjJD,CAA8B,UAAU,GAiJvC;;AASD,MAAM,UAAU,cAAc;IAC5B,yBAA8B;SAA9B,UAA8B,EAA9B,qBAA8B,EAA9B,IAA8B;QAA9B,oCAA8B;;IAI9B,IAAI,aAAa,GAAG,eAAe,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAChE,IAAI,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAEjE,IAAI,OAAO,aAAa,KAAK,SAAS,EAAE;QACtC,KAAK,GAAG,eAAe,CAAC;QACxB,aAAa,GAAG,IAAI,CAAC;KACtB;IAED,OAAO,IAAI,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["import { invariant } from '../../../utilities/globals';\n\nimport { print } from 'graphql';\nimport { equal } from '@wry/equality';\n\nimport {\n ApolloLink,\n Operation,\n GraphQLRequest,\n FetchResult,\n} from '../../../link/core';\n\nimport {\n Observable,\n addTypenameToDocument,\n removeClientSetsFromDocument,\n removeConnectionDirectiveFromDocument,\n cloneDeep,\n stringifyForDisplay,\n} from '../../../utilities';\n\nexport type ResultFunction<T> = () => T;\n\nexport interface MockedResponse<\n TData = Record<string, any>,\n TVariables = Record<string, any>\n> {\n request: GraphQLRequest<TVariables>;\n result?: FetchResult<TData> | ResultFunction<FetchResult<TData>>;\n error?: Error;\n delay?: number;\n newData?: ResultFunction<FetchResult>;\n}\n\nexport interface MockLinkOptions {\n showWarnings?: boolean;\n}\n\nfunction requestToKey(request: GraphQLRequest, addTypename: Boolean): string {\n const queryString =\n request.query &&\n print(addTypename ? addTypenameToDocument(request.query) : request.query);\n const requestKey = { query: queryString };\n return JSON.stringify(requestKey);\n}\n\nexport class MockLink extends ApolloLink {\n public operation: Operation;\n public addTypename: Boolean = true;\n public showWarnings: boolean = true;\n private mockedResponsesByKey: { [key: string]: MockedResponse[] } = {};\n\n constructor(\n mockedResponses: ReadonlyArray<MockedResponse>,\n addTypename: Boolean = true,\n options: MockLinkOptions = Object.create(null)\n ) {\n super();\n this.addTypename = addTypename;\n this.showWarnings = options.showWarnings ?? true;\n\n if (mockedResponses) {\n mockedResponses.forEach(mockedResponse => {\n this.addMockedResponse(mockedResponse);\n });\n }\n }\n\n public addMockedResponse(mockedResponse: MockedResponse) {\n const normalizedMockedResponse = this.normalizeMockedResponse(\n mockedResponse\n );\n const key = requestToKey(\n normalizedMockedResponse.request,\n this.addTypename\n );\n let mockedResponses = this.mockedResponsesByKey[key];\n if (!mockedResponses) {\n mockedResponses = [];\n this.mockedResponsesByKey[key] = mockedResponses;\n }\n mockedResponses.push(normalizedMockedResponse);\n }\n\n public request(operation: Operation): Observable<FetchResult> | null {\n this.operation = operation;\n const key = requestToKey(operation, this.addTypename);\n const unmatchedVars: Array<Record<string, any>> = [];\n const requestVariables = operation.variables || {};\n const mockedResponses = this.mockedResponsesByKey[key];\n const responseIndex = mockedResponses ? mockedResponses.findIndex((res, index) => {\n const mockedResponseVars = res.request.variables || {};\n if (equal(requestVariables, mockedResponseVars)) {\n return true;\n }\n unmatchedVars.push(mockedResponseVars);\n return false;\n }) : -1;\n\n const response = responseIndex >= 0\n ? mockedResponses[responseIndex]\n : void 0;\n\n let configError: Error;\n\n if (!response) {\n configError = new Error(\n`No more mocked responses for the query: ${print(operation.query)}\nExpected variables: ${stringifyForDisplay(operation.variables)}\n${unmatchedVars.length > 0 ? `\nFailed to match ${unmatchedVars.length} mock${\n unmatchedVars.length === 1 ? \"\" : \"s\"\n} for this query. The mocked response had the following variables:\n${unmatchedVars.map(d => ` ${stringifyForDisplay(d)}`).join('\\n')}\n` : \"\"}`);\n\n if (this.showWarnings) {\n console.warn(\n configError.message + \n '\\nThis typically indicates a configuration error in your mocks ' +\n 'setup, usually due to a typo or mismatched variable.'\n );\n }\n } else {\n mockedResponses.splice(responseIndex, 1);\n\n const { newData } = response;\n if (newData) {\n response.result = newData();\n mockedResponses.push(response);\n }\n\n if (!response.result && !response.error) {\n configError = new Error(\n `Mocked response should contain either result or error: ${key}`\n );\n }\n }\n\n return new Observable(observer => {\n const timer = setTimeout(() => {\n if (configError) {\n try {\n // The onError function can return false to indicate that\n // configError need not be passed to observer.error. For\n // example, the default implementation of onError calls\n // observer.error(configError) and then returns false to\n // prevent this extra (harmless) observer.error call.\n if (this.onError(configError, observer) !== false) {\n throw configError;\n }\n } catch (error) {\n observer.error(error);\n }\n } else if (response) {\n if (response.error) {\n observer.error(response.error);\n } else {\n if (response.result) {\n observer.next(\n typeof response.result === 'function'\n ? (response.result as ResultFunction<FetchResult>)()\n : response.result\n );\n }\n observer.complete();\n }\n }\n }, response && response.delay || 0);\n\n return () => {\n clearTimeout(timer);\n };\n });\n }\n\n private normalizeMockedResponse(\n mockedResponse: MockedResponse\n ): MockedResponse {\n const newMockedResponse = cloneDeep(mockedResponse);\n const queryWithoutConnection = removeConnectionDirectiveFromDocument(\n newMockedResponse.request.query\n );\n invariant(queryWithoutConnection, \"query is required\");\n newMockedResponse.request.query = queryWithoutConnection!;\n const query = removeClientSetsFromDocument(newMockedResponse.request.query);\n if (query) {\n newMockedResponse.request.query = query;\n }\n return newMockedResponse;\n }\n}\n\nexport interface MockApolloLink extends ApolloLink {\n operation?: Operation;\n}\n\n// Pass in multiple mocked responses, so that you can test flows that end up\n// making multiple queries to the server.\n// NOTE: The last arg can optionally be an `addTypename` arg.\nexport function mockSingleLink(\n ...mockedResponses: Array<any>\n): MockApolloLink {\n // To pull off the potential typename. If this isn't a boolean, we'll just\n // set it true later.\n let maybeTypename = mockedResponses[mockedResponses.length - 1];\n let mocks = mockedResponses.slice(0, mockedResponses.length - 1);\n\n if (typeof maybeTypename !== 'boolean') {\n mocks = mockedResponses;\n maybeTypename = true;\n }\n\n return new MockLink(mocks, maybeTypename);\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { QueryManager } from '../../../core/QueryManager';
|
|
2
|
+
import { MockedResponse } from './mockLink';
|
|
3
|
+
declare const _default: (...mockedResponses: MockedResponse[]) => QueryManager<import("../../../cache").NormalizedCacheObject>;
|
|
4
|
+
export default _default;
|
|
5
|
+
//# sourceMappingURL=mockQueryManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockQueryManager.d.ts","sourceRoot":"","sources":["../../../../src/testing/core/mocking/mockQueryManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAkB,cAAc,EAAE,MAAM,YAAY,CAAC;6CAKxB,cAAc,EAAE;AAApD,wBAKE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { QueryManager } from "../../../core/QueryManager.js";
|
|
2
|
+
import { mockSingleLink } from "./mockLink.js";
|
|
3
|
+
import { InMemoryCache } from "../../../cache/index.js";
|
|
4
|
+
export default (function() {
|
|
5
|
+
var mockedResponses = [];
|
|
6
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
7
|
+
mockedResponses[_i] = arguments[_i];
|
|
8
|
+
}
|
|
9
|
+
return new QueryManager({
|
|
10
|
+
link: mockSingleLink.apply(void 0, mockedResponses),
|
|
11
|
+
cache: new InMemoryCache({ addTypename: false }),
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=mockQueryManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockQueryManager.js","sourceRoot":"","sources":["../../../../src/testing/core/mocking/mockQueryManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAkB,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAI/C,gBAAe;IAAC,yBAAoC;SAApC,UAAoC,EAApC,qBAAoC,EAApC,IAAoC;QAApC,oCAAoC;;IAClD,OAAO,IAAI,YAAY,CAAC;QACtB,IAAI,EAAE,cAAc,eAAI,eAAe,CAAC;QACxC,KAAK,EAAE,IAAI,aAAa,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;KACjD,CAAC,CAAC;AACL,CAAC,EAAC","sourcesContent":["import { QueryManager } from '../../../core/QueryManager';\nimport { mockSingleLink, MockedResponse } from './mockLink';\nimport { InMemoryCache } from '../../../cache';\n\n// Helper method for the tests that construct a query manager out of a\n// a list of mocked responses for a mocked network interface.\nexport default (...mockedResponses: MockedResponse[]) => {\n return new QueryManager({\n link: mockSingleLink(...mockedResponses),\n cache: new InMemoryCache({ addTypename: false }),\n });\n};\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Observable } from '../../../utilities';
|
|
2
|
+
import { ApolloLink, FetchResult, Operation } from '../../../link/core';
|
|
3
|
+
export interface MockedSubscription {
|
|
4
|
+
request: Operation;
|
|
5
|
+
}
|
|
6
|
+
export interface MockedSubscriptionResult {
|
|
7
|
+
result?: FetchResult;
|
|
8
|
+
error?: Error;
|
|
9
|
+
delay?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class MockSubscriptionLink extends ApolloLink {
|
|
12
|
+
unsubscribers: any[];
|
|
13
|
+
setups: any[];
|
|
14
|
+
operation: Operation;
|
|
15
|
+
private observers;
|
|
16
|
+
constructor();
|
|
17
|
+
request(operation: Operation): Observable<FetchResult<Record<string, any>, Record<string, any>, Record<string, any>>>;
|
|
18
|
+
simulateResult(result: MockedSubscriptionResult, complete?: boolean): void;
|
|
19
|
+
simulateComplete(): void;
|
|
20
|
+
onSetup(listener: any): void;
|
|
21
|
+
onUnsubscribe(listener: any): void;
|
|
22
|
+
}
|
|
23
|
+
export declare function mockObservableLink(): MockSubscriptionLink;
|
|
24
|
+
//# sourceMappingURL=mockSubscriptionLink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockSubscriptionLink.d.ts","sourceRoot":"","sources":["../../../../src/testing/core/mocking/mockSubscriptionLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,SAAS,CAAC;CACpB;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,oBAAqB,SAAQ,UAAU;IAC3C,aAAa,EAAE,GAAG,EAAE,CAAM;IAC1B,MAAM,EAAE,GAAG,EAAE,CAAM;IACnB,SAAS,EAAE,SAAS,CAAC;IAE5B,OAAO,CAAC,SAAS,CAAa;;IAMvB,OAAO,CAAC,SAAS,EAAE,SAAS;IAW5B,cAAc,CAAC,MAAM,EAAE,wBAAwB,EAAE,QAAQ,UAAQ;IAYjE,gBAAgB;IAQhB,OAAO,CAAC,QAAQ,EAAE,GAAG,GAAG,IAAI;IAI5B,aAAa,CAAC,QAAQ,EAAE,GAAG,GAAG,IAAI;CAG1C;AAED,wBAAgB,kBAAkB,IAAI,oBAAoB,CAEzD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { __extends } from "tslib";
|
|
2
|
+
import { Observable } from "../../../utilities/index.js";
|
|
3
|
+
import { ApolloLink } from "../../../link/core/index.js";
|
|
4
|
+
var MockSubscriptionLink = (function (_super) {
|
|
5
|
+
__extends(MockSubscriptionLink, _super);
|
|
6
|
+
function MockSubscriptionLink() {
|
|
7
|
+
var _this = _super.call(this) || this;
|
|
8
|
+
_this.unsubscribers = [];
|
|
9
|
+
_this.setups = [];
|
|
10
|
+
_this.observers = [];
|
|
11
|
+
return _this;
|
|
12
|
+
}
|
|
13
|
+
MockSubscriptionLink.prototype.request = function (operation) {
|
|
14
|
+
var _this = this;
|
|
15
|
+
this.operation = operation;
|
|
16
|
+
return new Observable(function (observer) {
|
|
17
|
+
_this.setups.forEach(function (x) { return x(); });
|
|
18
|
+
_this.observers.push(observer);
|
|
19
|
+
return function () {
|
|
20
|
+
_this.unsubscribers.forEach(function (x) { return x(); });
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
MockSubscriptionLink.prototype.simulateResult = function (result, complete) {
|
|
25
|
+
var _this = this;
|
|
26
|
+
if (complete === void 0) { complete = false; }
|
|
27
|
+
setTimeout(function () {
|
|
28
|
+
var observers = _this.observers;
|
|
29
|
+
if (!observers.length)
|
|
30
|
+
throw new Error('subscription torn down');
|
|
31
|
+
observers.forEach(function (observer) {
|
|
32
|
+
if (result.result && observer.next)
|
|
33
|
+
observer.next(result.result);
|
|
34
|
+
if (result.error && observer.error)
|
|
35
|
+
observer.error(result.error);
|
|
36
|
+
if (complete && observer.complete)
|
|
37
|
+
observer.complete();
|
|
38
|
+
});
|
|
39
|
+
}, result.delay || 0);
|
|
40
|
+
};
|
|
41
|
+
MockSubscriptionLink.prototype.simulateComplete = function () {
|
|
42
|
+
var observers = this.observers;
|
|
43
|
+
if (!observers.length)
|
|
44
|
+
throw new Error('subscription torn down');
|
|
45
|
+
observers.forEach(function (observer) {
|
|
46
|
+
if (observer.complete)
|
|
47
|
+
observer.complete();
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
MockSubscriptionLink.prototype.onSetup = function (listener) {
|
|
51
|
+
this.setups = this.setups.concat([listener]);
|
|
52
|
+
};
|
|
53
|
+
MockSubscriptionLink.prototype.onUnsubscribe = function (listener) {
|
|
54
|
+
this.unsubscribers = this.unsubscribers.concat([listener]);
|
|
55
|
+
};
|
|
56
|
+
return MockSubscriptionLink;
|
|
57
|
+
}(ApolloLink));
|
|
58
|
+
export { MockSubscriptionLink };
|
|
59
|
+
export function mockObservableLink() {
|
|
60
|
+
return new MockSubscriptionLink();
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=mockSubscriptionLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockSubscriptionLink.js","sourceRoot":"","sources":["../../../../src/testing/core/mocking/mockSubscriptionLink.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,UAAU,EAA0B,MAAM,oBAAoB,CAAC;AAYxE;IAA0C,wCAAU;IAOlD;QAAA,YACE,iBAAO,SACR;QARM,mBAAa,GAAU,EAAE,CAAC;QAC1B,YAAM,GAAU,EAAE,CAAC;QAGlB,eAAS,GAAU,EAAE,CAAC;;IAI9B,CAAC;IAEM,sCAAO,GAAd,UAAe,SAAoB;QAAnC,iBASC;QARC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,OAAO,IAAI,UAAU,CAAc,UAAA,QAAQ;YACzC,KAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,EAAE,EAAH,CAAG,CAAC,CAAC;YAC9B,KAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC9B,OAAO;gBACL,KAAI,CAAC,aAAa,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,EAAE,EAAH,CAAG,CAAC,CAAC;YACvC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,6CAAc,GAArB,UAAsB,MAAgC,EAAE,QAAgB;QAAxE,iBAUC;QAVuD,yBAAA,EAAA,gBAAgB;QACtE,UAAU,CAAC;YACD,IAAA,SAAS,GAAK,KAAI,UAAT,CAAU;YAC3B,IAAI,CAAC,SAAS,CAAC,MAAM;gBAAE,MAAM,IAAI,KAAK,CA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ities';\nimport { ApolloLink, FetchResult, Operation } from '../../../link/core';\n\nexport interface MockedSubscription {\n request: Operation;\n}\n\nexport interface MockedSubscriptionResult {\n result?: FetchResult;\n error?: Error;\n delay?: number;\n}\n\nexport class MockSubscriptionLink extends ApolloLink {\n public unsubscribers: any[] = [];\n public setups: any[] = [];\n public operation: Operation;\n\n private observers: any[] = [];\n\n constructor() {\n super();\n }\n\n public request(operation: Operation) {\n this.operation = operation;\n return new Observable<FetchResult>(observer => {\n this.setups.forEach(x => x());\n this.observers.push(observer);\n return () => {\n this.unsubscribers.forEach(x => x());\n };\n });\n }\n\n public simulateResult(result: MockedSubscriptionResult, complete = false) {\n setTimeout(() => {\n const { observers } = this;\n if (!observers.length) throw new Error('subscription torn down');\n observers.forEach(observer => {\n if (result.result && observer.next) observer.next(result.result);\n if (result.error && observer.error) observer.error(result.error);\n if (complete && observer.complete) observer.complete();\n });\n }, result.delay || 0);\n }\n\n public simulateComplete() {\n const { observers } = this;\n if (!observers.length) throw new Error('subscription torn down');\n observers.forEach(observer => {\n if (observer.complete) observer.complete();\n })\n }\n\n public onSetup(listener: any): void {\n this.setups = this.setups.concat([listener]);\n }\n\n public onUnsubscribe(listener: any): void {\n this.unsubscribers = this.unsubscribers.concat([listener]);\n }\n}\n\nexport function mockObservableLink(): MockSubscriptionLink {\n return new MockSubscriptionLink();\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockWatchQuery.d.ts","sourceRoot":"","sources":["../../../../src/testing/core/mocking/mockWatchQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;6CAEZ,cAAc,EAAE,KAAG,gBAAgB,GAAG,CAAC;AAA3E,wBAQE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import mockQueryManager from "./mockQueryManager.js";
|
|
2
|
+
export default (function() {
|
|
3
|
+
var mockedResponses = [];
|
|
4
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
5
|
+
mockedResponses[_i] = arguments[_i];
|
|
6
|
+
}
|
|
7
|
+
var queryManager = mockQueryManager.apply(void 0, mockedResponses);
|
|
8
|
+
var firstRequest = mockedResponses[0].request;
|
|
9
|
+
return queryManager.watchQuery({
|
|
10
|
+
query: firstRequest.query,
|
|
11
|
+
variables: firstRequest.variables,
|
|
12
|
+
notifyOnNetworkStatusChange: false
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=mockWatchQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockWatchQuery.js","sourceRoot":"","sources":["../../../../src/testing/core/mocking/mockWatchQuery.ts"],"names":[],"mappings":"AACA,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAGlD,gBAAe;IAAC,yBAAoC;SAApC,UAAoC,EAApC,qBAAoC,EAApC,IAAoC;QAApC,oCAAoC;;IAClD,IAAM,YAAY,GAAG,gBAAgB,eAAI,eAAe,CAAC,CAAC;IAC1D,IAAM,YAAY,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,OAAO,YAAY,CAAC,UAAU,CAAC;QAC7B,KAAK,EAAE,YAAY,CAAC,KAAM;QAC1B,SAAS,EAAE,YAAY,CAAC,SAAS;QACjC,2BAA2B,EAAE,KAAK;KACnC,CAAC,CAAC;AACL,CAAC,EAAC","sourcesContent":["import { MockedResponse } from './mockLink';\nimport mockQueryManager from './mockQueryManager';\nimport { ObservableQuery } from '../../../core';\n\nexport default (...mockedResponses: MockedResponse[]): ObservableQuery<any> => {\n const queryManager = mockQueryManager(...mockedResponses);\n const firstRequest = mockedResponses[0].request;\n return queryManager.watchQuery({\n query: firstRequest.query!,\n variables: firstRequest.variables,\n notifyOnNetworkStatusChange: false // XXX might not always be the right option. Set for legacy reasons.\n });\n};\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ObservableQuery, ApolloQueryResult } from '../../core';
|
|
2
|
+
import { ObservableSubscription } from '../../utilities';
|
|
3
|
+
export type Options = {
|
|
4
|
+
observable: ObservableQuery<any>;
|
|
5
|
+
shouldResolve?: boolean;
|
|
6
|
+
wait?: number;
|
|
7
|
+
errorCallbacks?: ((error: Error) => any)[];
|
|
8
|
+
};
|
|
9
|
+
export type ResultCallback = ((result: ApolloQueryResult<any>) => any);
|
|
10
|
+
export declare function observableToPromiseAndSubscription({ observable, shouldResolve, wait, errorCallbacks }: Options, ...cbs: ResultCallback[]): {
|
|
11
|
+
promise: Promise<any[]>;
|
|
12
|
+
subscription: ObservableSubscription;
|
|
13
|
+
};
|
|
14
|
+
export default function (options: Options, ...cbs: ResultCallback[]): Promise<any[]>;
|
|
15
|
+
//# sourceMappingURL=observableToPromise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observableToPromise.d.ts","sourceRoot":"","sources":["../../../src/testing/core/observableToPromise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAWzD,MAAM,MAAM,OAAO,GAAG;IACpB,UAAU,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC;IACjC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,GAAG,CAAC,EAAE,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC;AAMvE,wBAAgB,kCAAkC,CAChD,EAAE,UAAU,EAAE,aAAoB,EAAE,IAAS,EAAE,cAAmB,EAAE,EAAE,OAAO,EAC7E,GAAG,GAAG,EAAE,cAAc,EAAE,GACvB;IAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAAC,YAAY,EAAE,sBAAsB,CAAA;CAAE,CA4DnE;AAED,MAAM,CAAC,OAAO,WACZ,OAAO,EAAE,OAAO,EAChB,GAAG,GAAG,EAAE,cAAc,EAAE,GACvB,OAAO,CAAC,GAAG,EAAE,CAAC,CAEhB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { __spreadArray } from "tslib";
|
|
2
|
+
export function observableToPromiseAndSubscription(_a) {
|
|
3
|
+
var observable = _a.observable, _b = _a.shouldResolve, shouldResolve = _b === void 0 ? true : _b, _c = _a.wait, wait = _c === void 0 ? -1 : _c, _d = _a.errorCallbacks, errorCallbacks = _d === void 0 ? [] : _d;
|
|
4
|
+
var cbs = [];
|
|
5
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
6
|
+
cbs[_i - 1] = arguments[_i];
|
|
7
|
+
}
|
|
8
|
+
var subscription = null;
|
|
9
|
+
var promise = new Promise(function (resolve, reject) {
|
|
10
|
+
var errorIndex = 0;
|
|
11
|
+
var cbIndex = 0;
|
|
12
|
+
var results = [];
|
|
13
|
+
var tryToResolve = function () {
|
|
14
|
+
if (!shouldResolve) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
var done = function () {
|
|
18
|
+
subscription.unsubscribe();
|
|
19
|
+
resolve(results);
|
|
20
|
+
};
|
|
21
|
+
if (cbIndex === cbs.length && errorIndex === errorCallbacks.length) {
|
|
22
|
+
if (wait === -1) {
|
|
23
|
+
done();
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
setTimeout(done, wait);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var queue = Promise.resolve();
|
|
31
|
+
subscription = observable.subscribe({
|
|
32
|
+
next: function (result) {
|
|
33
|
+
queue = queue.then(function () {
|
|
34
|
+
var cb = cbs[cbIndex++];
|
|
35
|
+
if (cb)
|
|
36
|
+
return cb(result);
|
|
37
|
+
reject(new Error("Observable 'next' method called more than ".concat(cbs.length, " times")));
|
|
38
|
+
}).then(function (res) {
|
|
39
|
+
results.push(res);
|
|
40
|
+
tryToResolve();
|
|
41
|
+
}, reject);
|
|
42
|
+
},
|
|
43
|
+
error: function (error) {
|
|
44
|
+
queue = queue.then(function () {
|
|
45
|
+
var errorCb = errorCallbacks[errorIndex++];
|
|
46
|
+
if (errorCb)
|
|
47
|
+
return errorCb(error);
|
|
48
|
+
reject(error);
|
|
49
|
+
}).then(tryToResolve, reject);
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
promise: promise,
|
|
55
|
+
subscription: subscription,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export default function (options) {
|
|
59
|
+
var cbs = [];
|
|
60
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
61
|
+
cbs[_i - 1] = arguments[_i];
|
|
62
|
+
}
|
|
63
|
+
return observableToPromiseAndSubscription.apply(void 0, __spreadArray([options], cbs, false)).promise;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=observableToPromise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observableToPromise.js","sourceRoot":"","sources":["../../../src/testing/core/observableToPromise.ts"],"names":[],"mappings":";AAyBA,MAAM,UAAU,kCAAkC,CAChD,EAA6E;QAA3E,UAAU,gBAAA,EAAE,qBAAoB,EAApB,aAAa,mBAAG,IAAI,KAAA,EAAE,YAAS,EAAT,IAAI,mBAAG,CAAC,CAAC,KAAA,EAAE,sBAAmB,EAAnB,cAAc,mBAAG,EAAE,KAAA;IAClE,aAAwB;SAAxB,UAAwB,EAAxB,qBAAwB,EAAxB,IAAwB;QAAxB,4BAAwB;;IAExB,IAAI,YAAY,GAA2B,IAAa,CAAC;IACzD,IAAM,OAAO,GAAG,IAAI,OAAO,CAAQ,UAAC,OAAO,EAAE,M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AI,OAAO;wBAAE,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;oBACnC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAChB,CAAC,CAAC,CAAC,IAAI,CACL,YAAY,EACZ,MAAM,CACP,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,OAAO,SAAA;QACP,YAAY,cAAA;KACb,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,OAAO,WACZ,OAAgB;IAChB,aAAwB;SAAxB,UAAwB,EAAxB,qBAAwB,EAAxB,IAAwB;QAAxB,4BAAwB;;IAExB,OAAO,kCAAkC,8BAAC,OAAO,GAAK,GAAG,UAAE,OAAO,CAAC;AACrE,CAAC","sourcesContent":["import { ObservableQuery, ApolloQueryResult } from '../../core';\nimport { ObservableSubscription } from '../../utilities';\n\n/**\n *\n * @param observable the observable query to subscribe to\n * @param shouldResolve should we resolve after seeing all our callbacks [default: true]\n * (use this if you are racing the promise against another)\n * @param wait how long to wait after seeing desired callbacks before resolving\n * [default: -1 => don't wait]\n * @param errorCallbacks an expected set of errors\n */\nexport type Options = {\n observable: ObservableQuery<any>;\n shouldResolve?: boolean;\n wait?: number;\n errorCallbacks?: ((error: Error) => any)[];\n};\n\nexport type ResultCallback = ((result: ApolloQueryResult<any>) => any);\n\n// Take an observable and N callbacks, and observe the observable,\n// ensuring it is called exactly N times, resolving once it has done so.\n// Optionally takes a timeout, which it will wait X ms after the Nth callback\n// to ensure it is not called again.\nexport function observableToPromiseAndSubscription(\n { observable, shouldResolve = true, wait = -1, errorCallbacks = [] }: Options,\n ...cbs: ResultCallback[]\n): { promise: Promise<any[]>; subscription: ObservableSubscription } {\n let subscription: ObservableSubscription = null as never;\n const promise = new Promise<any[]>((resolve, reject) => {\n let errorIndex = 0;\n let cbIndex = 0;\n const results: any[] = [];\n\n const tryToResolve = () => {\n if (!shouldResolve) {\n return;\n }\n\n const done = () => {\n subscription.unsubscribe();\n // XXX: we could pass a few other things out here?\n resolve(results);\n };\n\n if (cbIndex === cbs.length && errorIndex === errorCallbacks.length) {\n if (wait === -1) {\n done();\n } else {\n setTimeout(done, wait);\n }\n }\n };\n\n let queue = Promise.resolve();\n\n subscription = observable.subscribe({\n next(result: ApolloQueryResult<any>) {\n queue = queue.then(() => {\n const cb = cbs[cbIndex++];\n if (cb) return cb(result);\n reject(new Error(`Observable 'next' method called more than ${cbs.length} times`));\n }).then(\n res => {\n results.push(res);\n tryToResolve();\n },\n reject,\n );\n },\n error(error: Error) {\n queue = queue.then(() => {\n const errorCb = errorCallbacks[errorIndex++];\n if (errorCb) return errorCb(error);\n reject(error);\n }).then(\n tryToResolve,\n reject,\n );\n },\n });\n });\n\n return {\n promise,\n subscription,\n };\n}\n\nexport default function(\n options: Options,\n ...cbs: ResultCallback[]\n): Promise<any[]> {\n return observableToPromiseAndSubscription(options, ...cbs).promise;\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ObservableSubscription, Observable } from '../../utilities';
|
|
2
|
+
export default function subscribeAndCount<TResult>(reject: (reason: any) => any, observable: Observable<TResult>, cb: (handleCount: number, result: TResult) => any): ObservableSubscription;
|
|
3
|
+
//# sourceMappingURL=subscribeAndCount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribeAndCount.d.ts","sourceRoot":"","sources":["../../../src/testing/core/subscribeAndCount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAY,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE/E,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,OAAO,EAC/C,MAAM,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,EAC5B,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,EAC/B,EAAE,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,GAAG,GAChD,sBAAsB,CAmBxB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { asyncMap } from "../../utilities/index.js";
|
|
2
|
+
export default function subscribeAndCount(reject, observable, cb) {
|
|
3
|
+
var queue = Promise.resolve();
|
|
4
|
+
var handleCount = 0;
|
|
5
|
+
var subscription = asyncMap(observable, function (result) {
|
|
6
|
+
return queue = queue.then(function () {
|
|
7
|
+
return cb(++handleCount, result);
|
|
8
|
+
}).catch(error);
|
|
9
|
+
}).subscribe({ error: error });
|
|
10
|
+
function error(e) {
|
|
11
|
+
subscription.unsubscribe();
|
|
12
|
+
reject(e);
|
|
13
|
+
}
|
|
14
|
+
return subscription;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=subscribeAndCount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribeAndCount.js","sourceRoot":"","sources":["../../../src/testing/core/subscribeAndCount.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,QAAQ,EAAc,MAAM,iBAAiB,CAAC;AAE/E,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,MAA4B,EAC5B,UAA+B,EAC/B,EAAiD;IAGjD,IAAI,KAAK,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAC9B,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,IAAM,YAAY,GAAG,QAAQ,CAAC,UAAU,EAAE,UAAA,MAAM;QAG9C,OAAO,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC;YACxB,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,KAAK,OAAA,EAAE,CAAC,CAAC;IAExB,SAAS,KAAK,CAAC,CAAM;QACnB,YAAY,CAAC,WAAW,EAAE,CAAC;QAC3B,MAAM,CAAC,CAAC,CAAC,CAAC;IACZ,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import { ObservableSubscription, asyncMap, Observable } from '../../utilities';\n\nexport default function subscribeAndCount<TResult>(\n reject: (reason: any) => any,\n observable: Observable<TResult>,\n cb: (handleCount: number, result: TResult) => any,\n): ObservableSubscription {\n // Use a Promise queue to prevent callbacks from being run out of order.\n let queue = Promise.resolve();\n let handleCount = 0;\n\n const subscription = asyncMap(observable, result => {\n // All previous asynchronous callbacks must complete before cb can\n // be invoked with this result.\n return queue = queue.then(() => {\n return cb(++handleCount, result);\n }).catch(error);\n }).subscribe({ error });\n\n function error(e: any) {\n subscription.unsubscribe();\n reject(e);\n }\n\n return subscription;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait.d.ts","sourceRoot":"","sources":["../../../src/testing/core/wait.ts"],"names":[],"mappings":"AAAA,wBAAsB,IAAI,CAAC,EAAE,EAAE,MAAM,iBAEpC;AAED,wBAAsB,IAAI,kBAEzB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { __awaiter, __generator } from "tslib";
|
|
2
|
+
export function wait(ms) {
|
|
3
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4
|
+
return __generator(this, function (_a) {
|
|
5
|
+
return [2, new Promise(function (resolve) { return setTimeout(resolve, ms); })];
|
|
6
|
+
});
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
export function tick() {
|
|
10
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
11
|
+
return __generator(this, function (_a) {
|
|
12
|
+
return [2, wait(0)];
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=wait.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait.js","sourceRoot":"","sources":["../../../src/testing/core/wait.ts"],"names":[],"mappings":";AAAA,MAAM,UAAgB,IAAI,CAAC,EAAU;;;YACnC,WAAO,IAAI,OAAO,CAAO,UAAA,OAAO,IAAI,OAAA,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,EAAvB,CAAuB,CAAC,EAAC;;;CAC9D;AAED,MAAM,UAAgB,IAAI;;;YACxB,WAAO,IAAI,CAAC,CAAC,CAAC,EAAC;;;CAChB","sourcesContent":["export async function wait(ms: number) {\n return new Promise<void>(resolve => setTimeout(resolve, ms));\n}\n\nexport async function tick() {\n return wait(0);\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function withErrorSpy<TArgs extends any[], TResult>(it: (...args: TArgs) => TResult, ...args: TArgs): TResult;
|
|
2
|
+
export declare function withWarningSpy<TArgs extends any[], TResult>(it: (...args: TArgs) => TResult, ...args: TArgs): TResult;
|
|
3
|
+
export declare function withLogSpy<TArgs extends any[], TResult>(it: (...args: TArgs) => TResult, ...args: TArgs): TResult;
|
|
4
|
+
//# sourceMappingURL=withConsoleSpy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withConsoleSpy.d.ts","sourceRoot":"","sources":["../../../src/testing/core/withConsoleSpy.ts"],"names":[],"mappings":"AAiBA,wBAAgB,YAAY,CAC1B,KAAK,SAAS,GAAG,EAAE,EACnB,OAAO,EAEP,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,EAC/B,GAAG,IAAI,EAAE,KAAK,WAIf;AAED,wBAAgB,cAAc,CAC5B,KAAK,SAAS,GAAG,EAAE,EACnB,OAAO,EAEP,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,EAC/B,GAAG,IAAI,EAAE,KAAK,WAIf;AAED,wBAAgB,UAAU,CACxB,KAAK,SAAS,GAAG,EAAE,EACnB,OAAO,EAEP,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,EAC/B,GAAG,IAAI,EAAE,KAAK,WAIf"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function wrapTestFunction(fn, consoleMethodName) {
|
|
2
|
+
return function () {
|
|
3
|
+
var _this = this;
|
|
4
|
+
var args = arguments;
|
|
5
|
+
var spy = jest.spyOn(console, consoleMethodName);
|
|
6
|
+
spy.mockImplementation(function () { });
|
|
7
|
+
return new Promise(function (resolve) {
|
|
8
|
+
resolve(fn === null || fn === void 0 ? void 0 : fn.apply(_this, args));
|
|
9
|
+
}).finally(function () {
|
|
10
|
+
expect(spy).toMatchSnapshot();
|
|
11
|
+
spy.mockReset();
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function withErrorSpy(it) {
|
|
16
|
+
var args = [];
|
|
17
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
18
|
+
args[_i - 1] = arguments[_i];
|
|
19
|
+
}
|
|
20
|
+
args[1] = wrapTestFunction(args[1], "error");
|
|
21
|
+
return it.apply(void 0, args);
|
|
22
|
+
}
|
|
23
|
+
export function withWarningSpy(it) {
|
|
24
|
+
var args = [];
|
|
25
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
26
|
+
args[_i - 1] = arguments[_i];
|
|
27
|
+
}
|
|
28
|
+
args[1] = wrapTestFunction(args[1], "warn");
|
|
29
|
+
return it.apply(void 0, args);
|
|
30
|
+
}
|
|
31
|
+
export function withLogSpy(it) {
|
|
32
|
+
var args = [];
|
|
33
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
34
|
+
args[_i - 1] = arguments[_i];
|
|
35
|
+
}
|
|
36
|
+
args[1] = wrapTestFunction(args[1], "log");
|
|
37
|
+
return it.apply(void 0, args);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=withConsoleSpy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withConsoleSpy.js","sourceRoot":"","sources":["../../../src/testing/core/withConsoleSpy.ts"],"names":[],"mappings":"AAAA,SAAS,gBAAgB,CACvB,EAA2B,EAC3B,iBAA2C;IAE3C,OAAO;QAAA,iBAUN;QATC,IAAM,IAAI,GAAG,SAAS,CAAC;Q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(\n fn: (...args: any[]) => any,\n consoleMethodName: \"log\" | \"warn\" | \"error\",\n) {\n return function () {\n const args = arguments;\n const spy = jest.spyOn(console, consoleMethodName);\n spy.mockImplementation(() => {});\n return new Promise(resolve => {\n resolve(fn?.apply(this, args));\n }).finally(() => {\n expect(spy).toMatchSnapshot();\n spy.mockReset();\n });\n };\n}\n\nexport function withErrorSpy<\n TArgs extends any[],\n TResult,\n>(\n it: (...args: TArgs) => TResult,\n ...args: TArgs\n) {\n args[1] = wrapTestFunction(args[1], \"error\");\n return it(...args);\n}\n\nexport function withWarningSpy<\n TArgs extends any[],\n TResult,\n>(\n it: (...args: TArgs) => TResult,\n ...args: TArgs\n) {\n args[1] = wrapTestFunction(args[1], \"warn\");\n return it(...args);\n}\n\nexport function withLogSpy<\n TArgs extends any[],\n TResult,\n>(\n it: (...args: TArgs) => TResult,\n ...args: TArgs\n) {\n args[1] = wrapTestFunction(args[1], \"log\");\n return it(...args);\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const _default: <TArgs extends any[], TResult>(reject: (reason: any) => any, cb: (...args: TArgs) => TResult) => (...args: TArgs) => TResult | undefined;
|
|
2
|
+
export default _default;
|
|
3
|
+
export declare function withError(func: Function, regex: RegExp): any;
|
|
4
|
+
//# sourceMappingURL=wrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../../src/testing/core/wrap.ts"],"names":[],"mappings":"wEAGmB,GAAG,KAAK,GAAG;AAD9B,wBASE;AAEF,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,OAatD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default (function(reject, cb) { return function () {
|
|
2
|
+
var args = [];
|
|
3
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
4
|
+
args[_i] = arguments[_i];
|
|
5
|
+
}
|
|
6
|
+
try {
|
|
7
|
+
return cb.apply(void 0, args);
|
|
8
|
+
}
|
|
9
|
+
catch (e) {
|
|
10
|
+
reject(e);
|
|
11
|
+
}
|
|
12
|
+
}; });
|
|
13
|
+
export function withError(func, regex) {
|
|
14
|
+
var message = null;
|
|
15
|
+
var oldError = console.error;
|
|
16
|
+
console.error = function (m) { return (message = m); };
|
|
17
|
+
try {
|
|
18
|
+
var result = func();
|
|
19
|
+
expect(message).toMatch(regex);
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
console.error = oldError;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=wrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap.js","sourceRoot":"","sources":["../../../src/testing/core/wrap.ts"],"names":[],"mappings":"AAEA,gBAAe,UACb,MAA4B,EAC5B,EAA+B,IAC5B,OAAA;IAAC,cAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,yBAAc;;IAClB,IAAI;QACF,OAAO,EAAE,eAAI,IAAI,EAAE;KACpB;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,CAAC,CAAC,CAAC,CAAC;KACX;AACH,CAAC,EANI,CAMJ,EAAC;AAEF,MAAM,UAAU,SAAS,CAAC,IAAc,EAAE,KAAa;IACrD,IAAI,OAAO,GAAW,IAAa,CAAC;IACpC,IAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC;IAE/B,OAAO,CAAC,KAAK,GAAG,UAAC,CAAS,IAAK,OAAA,CAAC,OAAO,GAAG,CAAC,CAAC,EAAb,CAAa,CAAC;IAE7C,IAAI;QACF,IAAM,MAAM,GAAG,IAAI,EAAE,CAAC;QACtB,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC/B,OAAO,MAAM,CAAC;KACf;YAAS;QACR,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC;KAC1B;AACH,CAAC","sourcesContent":["// I'm not sure why mocha doesn't provide something like this, you can't\n// always use promises\nexport default <TArgs extends any[], TResult>(\n reject: (reason: any) => any,\n cb: (...args: TArgs) => TResult,\n) => (...args: TArgs) => {\n try {\n return cb(...args);\n } catch (e) {\n reject(e);\n }\n};\n\nexport function withError(func: Function, regex: RegExp) {\n let message: string = null as never;\n const oldError = console.error;\n\n console.error = (m: string) => (message = m);\n\n try {\n const result = func();\n expect(message).toMatch(regex);\n return result;\n } finally {\n console.error = oldError;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7E,cAAc,QAAQ,CAAC"}
|
package/testing/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAuB,MAAM,wBAAwB,CAAC;AAC7E,cAAc,QAAQ,CAAC","sourcesContent":["import '../utilities/globals';\nexport { MockedProvider, MockedProviderProps } from './react/MockedProvider';\nexport * from './core';\n"]}
|