@apollo/client 3.8.7 → 3.8.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (614) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/config.json +14 -0
  3. package/CHANGELOG.md +3369 -0
  4. package/apollo-client.cjs +356 -354
  5. package/apollo-client.cjs.map +1 -1
  6. package/apollo-client.min.cjs +1 -1
  7. package/cache/cache.cjs +133 -152
  8. package/cache/cache.cjs.map +1 -1
  9. package/cache/cache.cjs.native.js +133 -152
  10. package/cache/core/cache.d.ts +10 -0
  11. package/cache/core/cache.js +17 -5
  12. package/cache/core/cache.js.map +1 -1
  13. package/cache/core/types/Cache.d.ts +1 -1
  14. package/cache/core/types/Cache.js.map +1 -1
  15. package/cache/core/types/DataProxy.d.ts +92 -0
  16. package/cache/core/types/common.js +4 -1
  17. package/cache/core/types/common.js.map +1 -1
  18. package/cache/inmemory/entityStore.d.ts +1 -1
  19. package/cache/inmemory/entityStore.js +190 -29
  20. package/cache/inmemory/entityStore.js.map +1 -1
  21. package/cache/inmemory/fixPolyfills.js +9 -0
  22. package/cache/inmemory/fixPolyfills.js.map +1 -1
  23. package/cache/inmemory/fixPolyfills.native.js +12 -0
  24. package/cache/inmemory/fixPolyfills.native.js.map +1 -1
  25. package/cache/inmemory/fragmentRegistry.js +23 -12
  26. package/cache/inmemory/fragmentRegistry.js.map +1 -1
  27. package/cache/inmemory/helpers.js +20 -11
  28. package/cache/inmemory/helpers.js.map +1 -1
  29. package/cache/inmemory/inMemoryCache.js +161 -8
  30. package/cache/inmemory/inMemoryCache.js.map +1 -1
  31. package/cache/inmemory/key-extractor.js +72 -4
  32. package/cache/inmemory/key-extractor.js.map +1 -1
  33. package/cache/inmemory/object-canon.js +91 -3
  34. package/cache/inmemory/object-canon.js.map +1 -1
  35. package/cache/inmemory/policies.js +193 -43
  36. package/cache/inmemory/policies.js.map +1 -1
  37. package/cache/inmemory/reactiveVars.js +20 -2
  38. package/cache/inmemory/reactiveVars.js.map +1 -1
  39. package/cache/inmemory/readFromStore.d.ts +4 -0
  40. package/cache/inmemory/readFromStore.js +54 -9
  41. package/cache/inmemory/readFromStore.js.map +1 -1
  42. package/cache/inmemory/types.d.ts +28 -0
  43. package/cache/inmemory/types.js.map +1 -1
  44. package/cache/inmemory/writeToStore.js +152 -25
  45. package/cache/inmemory/writeToStore.js.map +1 -1
  46. package/config/jest/setup.js +2 -0
  47. package/config/jest/setup.js.map +1 -1
  48. package/core/ApolloClient.d.ts +264 -3
  49. package/core/ApolloClient.js +235 -7
  50. package/core/ApolloClient.js.map +1 -1
  51. package/core/LocalState.d.ts +4 -6
  52. package/core/LocalState.js +56 -18
  53. package/core/LocalState.js.map +1 -1
  54. package/core/ObservableQuery.d.ts +25 -0
  55. package/core/ObservableQuery.js +239 -30
  56. package/core/ObservableQuery.js.map +1 -1
  57. package/core/QueryInfo.d.ts +3 -3
  58. package/core/QueryInfo.js +116 -13
  59. package/core/QueryInfo.js.map +1 -1
  60. package/core/QueryManager.d.ts +4 -0
  61. package/core/QueryManager.js +229 -33
  62. package/core/QueryManager.js.map +1 -1
  63. package/core/core.cjs +112 -103
  64. package/core/core.cjs.map +1 -1
  65. package/core/core.cjs.native.js +112 -103
  66. package/core/equalByQuery.js +20 -1
  67. package/core/equalByQuery.js.map +1 -1
  68. package/core/index.d.ts +1 -1
  69. package/core/index.js +19 -0
  70. package/core/index.js.map +1 -1
  71. package/core/networkStatus.d.ts +39 -0
  72. package/core/networkStatus.js +39 -0
  73. package/core/networkStatus.js.map +1 -1
  74. package/core/types.d.ts +9 -0
  75. package/core/types.js.map +1 -1
  76. package/core/watchQueryOptions.d.ts +225 -1
  77. package/core/watchQueryOptions.js.map +1 -1
  78. package/dev/dev.cjs +5 -111
  79. package/dev/dev.cjs.map +1 -1
  80. package/dev/dev.cjs.native.js +5 -111
  81. package/dev/loadErrorMessageHandler.js.map +1 -1
  82. package/errors/errors.cjs +1 -1
  83. package/errors/errors.cjs.map +1 -1
  84. package/errors/errors.cjs.native.js +1 -1
  85. package/errors/index.js +14 -1
  86. package/errors/index.js.map +1 -1
  87. package/invariantErrorCodes.js +1 -0
  88. package/link/batch/batch.cjs +2 -2
  89. package/link/batch/batch.cjs.map +1 -1
  90. package/link/batch/batch.cjs.native.js +2 -2
  91. package/link/batch/batchLink.d.ts +21 -0
  92. package/link/batch/batchLink.js +2 -1
  93. package/link/batch/batchLink.js.map +1 -1
  94. package/link/batch/batching.js +24 -1
  95. package/link/batch/batching.js.map +1 -1
  96. package/link/batch-http/batch-http.cjs +3 -2
  97. package/link/batch-http/batch-http.cjs.map +1 -1
  98. package/link/batch-http/batch-http.cjs.native.js +3 -2
  99. package/link/batch-http/batchHttpLink.d.ts +4 -0
  100. package/link/batch-http/batchHttpLink.js +53 -2
  101. package/link/batch-http/batchHttpLink.js.map +1 -1
  102. package/link/context/context.cjs.map +1 -1
  103. package/link/context/index.js +1 -0
  104. package/link/context/index.js.map +1 -1
  105. package/link/core/ApolloLink.js +12 -5
  106. package/link/core/ApolloLink.js.map +1 -1
  107. package/link/core/core.cjs +5 -5
  108. package/link/core/core.cjs.map +1 -1
  109. package/link/core/core.cjs.native.js +5 -5
  110. package/link/error/error.cjs +1 -1
  111. package/link/error/error.cjs.map +1 -1
  112. package/link/error/error.cjs.native.js +1 -1
  113. package/link/error/index.d.ts +3 -0
  114. package/link/error/index.js +4 -1
  115. package/link/error/index.js.map +1 -1
  116. package/link/http/HttpLink.d.ts +0 -2
  117. package/link/http/HttpLink.js +1 -1
  118. package/link/http/HttpLink.js.map +1 -1
  119. package/link/http/checkFetcher.d.ts +1 -1
  120. package/link/http/checkFetcher.js.map +1 -1
  121. package/link/http/createHttpLink.js +23 -1
  122. package/link/http/createHttpLink.js.map +1 -1
  123. package/link/http/createSignalIfSupported.d.ts +5 -0
  124. package/link/http/createSignalIfSupported.js +5 -0
  125. package/link/http/createSignalIfSupported.js.map +1 -1
  126. package/link/http/http.cjs +14 -15
  127. package/link/http/http.cjs.map +1 -1
  128. package/link/http/http.cjs.native.js +14 -15
  129. package/link/http/index.js +2 -1
  130. package/link/http/index.js.map +1 -1
  131. package/link/http/iterators/async.d.ts +4 -0
  132. package/link/http/iterators/async.js +4 -0
  133. package/link/http/iterators/async.js.map +1 -1
  134. package/link/http/iterators/nodeStream.d.ts +4 -0
  135. package/link/http/iterators/nodeStream.js +4 -0
  136. package/link/http/iterators/nodeStream.js.map +1 -1
  137. package/link/http/iterators/promise.d.ts +4 -0
  138. package/link/http/iterators/promise.js +4 -0
  139. package/link/http/iterators/promise.js.map +1 -1
  140. package/link/http/iterators/reader.d.ts +4 -0
  141. package/link/http/iterators/reader.js +4 -0
  142. package/link/http/iterators/reader.js.map +1 -1
  143. package/link/http/parseAndCheckHttpResponse.js +50 -13
  144. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  145. package/link/http/responseIterator.d.ts +4 -0
  146. package/link/http/responseIterator.js +6 -0
  147. package/link/http/responseIterator.js.map +1 -1
  148. package/link/http/rewriteURIForGET.d.ts +1 -1
  149. package/link/http/rewriteURIForGET.js +10 -0
  150. package/link/http/rewriteURIForGET.js.map +1 -1
  151. package/link/http/selectHttpOptionsAndBody.d.ts +46 -1
  152. package/link/http/selectHttpOptionsAndBody.js +23 -0
  153. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  154. package/link/http/selectURI.js.map +1 -1
  155. package/link/http/serializeFetchParameter.js.map +1 -1
  156. package/link/persisted-queries/index.js +34 -4
  157. package/link/persisted-queries/index.js.map +1 -1
  158. package/link/persisted-queries/persisted-queries.cjs +4 -4
  159. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  160. package/link/persisted-queries/persisted-queries.cjs.native.js +4 -4
  161. package/link/remove-typename/remove-typename.cjs +12 -9
  162. package/link/remove-typename/remove-typename.cjs.map +1 -1
  163. package/link/remove-typename/remove-typename.cjs.native.js +12 -9
  164. package/link/remove-typename/removeTypenameFromVariables.js +12 -9
  165. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  166. package/link/retry/delayFunction.d.ts +29 -0
  167. package/link/retry/delayFunction.js +6 -0
  168. package/link/retry/delayFunction.js.map +1 -1
  169. package/link/retry/retry.cjs +5 -5
  170. package/link/retry/retry.cjs.map +1 -1
  171. package/link/retry/retry.cjs.native.js +5 -5
  172. package/link/retry/retryFunction.d.ts +20 -0
  173. package/link/retry/retryLink.d.ts +6 -0
  174. package/link/retry/retryLink.js +31 -6
  175. package/link/retry/retryLink.js.map +1 -1
  176. package/link/schema/index.d.ts +13 -0
  177. package/link/schema/index.js +3 -3
  178. package/link/schema/index.js.map +1 -1
  179. package/link/schema/schema.cjs +3 -3
  180. package/link/schema/schema.cjs.map +1 -1
  181. package/link/schema/schema.cjs.native.js +3 -3
  182. package/link/subscriptions/index.js +35 -2
  183. package/link/subscriptions/index.js.map +1 -1
  184. package/link/subscriptions/subscriptions.cjs +3 -2
  185. package/link/subscriptions/subscriptions.cjs.map +1 -1
  186. package/link/subscriptions/subscriptions.cjs.native.js +3 -2
  187. package/link/utils/createOperation.js.map +1 -1
  188. package/link/utils/filterOperationVariables.js +4 -0
  189. package/link/utils/filterOperationVariables.js.map +1 -1
  190. package/link/utils/toPromise.js.map +1 -1
  191. package/link/utils/transformOperation.js +3 -2
  192. package/link/utils/transformOperation.js.map +1 -1
  193. package/link/utils/utils.cjs +2 -2
  194. package/link/utils/utils.cjs.map +1 -1
  195. package/link/utils/utils.cjs.native.js +2 -2
  196. package/link/utils/validateOperation.js.map +1 -1
  197. package/link/ws/index.d.ts +12 -0
  198. package/link/ws/index.js +1 -1
  199. package/link/ws/index.js.map +1 -1
  200. package/link/ws/ws.cjs +1 -1
  201. package/link/ws/ws.cjs.map +1 -1
  202. package/link/ws/ws.cjs.native.js +1 -1
  203. package/package.json +56 -45
  204. package/react/cache/QueryReference.d.ts +6 -1
  205. package/react/cache/QueryReference.js +26 -1
  206. package/react/cache/QueryReference.js.map +1 -1
  207. package/react/cache/SuspenseCache.d.ts +10 -0
  208. package/react/cache/SuspenseCache.js +1 -1
  209. package/react/cache/SuspenseCache.js.map +1 -1
  210. package/react/cache/getSuspenseCache.js.map +1 -1
  211. package/react/context/ApolloContext.d.ts +5 -0
  212. package/react/context/ApolloContext.js +10 -3
  213. package/react/context/ApolloContext.js.map +1 -1
  214. package/react/context/context.cjs +1 -3
  215. package/react/context/context.cjs.map +1 -1
  216. package/react/context/context.cjs.native.js +1 -3
  217. package/react/hoc/graphql.js.map +1 -1
  218. package/react/hoc/hoc-utils.js +3 -1
  219. package/react/hoc/hoc-utils.js.map +1 -1
  220. package/react/hoc/hoc.cjs +9 -17
  221. package/react/hoc/hoc.cjs.map +1 -1
  222. package/react/hoc/hoc.cjs.native.js +9 -17
  223. package/react/hoc/mutation-hoc.js +9 -4
  224. package/react/hoc/mutation-hoc.js.map +1 -1
  225. package/react/hoc/query-hoc.js +10 -4
  226. package/react/hoc/query-hoc.js.map +1 -1
  227. package/react/hoc/subscription-hoc.js +10 -4
  228. package/react/hoc/subscription-hoc.js.map +1 -1
  229. package/react/hoc/withApollo.js +3 -4
  230. package/react/hoc/withApollo.js.map +1 -1
  231. package/react/hooks/hooks.cjs +72 -57
  232. package/react/hooks/hooks.cjs.map +1 -1
  233. package/react/hooks/hooks.cjs.native.js +72 -57
  234. package/react/hooks/internal/__use.js +5 -0
  235. package/react/hooks/internal/__use.js.map +1 -1
  236. package/react/hooks/internal/index.d.ts +1 -0
  237. package/react/hooks/internal/index.js +2 -0
  238. package/react/hooks/internal/index.js.map +1 -1
  239. package/react/hooks/internal/useDeepMemo.js.map +1 -1
  240. package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -3
  241. package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
  242. package/react/hooks/internal/useLazyRef.d.ts +3 -0
  243. package/react/hooks/internal/useLazyRef.js +10 -0
  244. package/react/hooks/internal/useLazyRef.js.map +1 -0
  245. package/react/hooks/useBackgroundQuery.js +6 -0
  246. package/react/hooks/useBackgroundQuery.js.map +1 -1
  247. package/react/hooks/useFragment.js +21 -17
  248. package/react/hooks/useFragment.js.map +1 -1
  249. package/react/hooks/useLazyQuery.js +13 -4
  250. package/react/hooks/useLazyQuery.js.map +1 -1
  251. package/react/hooks/useMutation.js +8 -3
  252. package/react/hooks/useMutation.js.map +1 -1
  253. package/react/hooks/useQuery.d.ts +11 -0
  254. package/react/hooks/useQuery.js +137 -5
  255. package/react/hooks/useQuery.js.map +1 -1
  256. package/react/hooks/useReactiveVar.js +5 -0
  257. package/react/hooks/useReactiveVar.js.map +1 -1
  258. package/react/hooks/useReadQuery.d.ts +19 -0
  259. package/react/hooks/useReadQuery.js.map +1 -1
  260. package/react/hooks/useSubscription.js +5 -0
  261. package/react/hooks/useSubscription.js.map +1 -1
  262. package/react/hooks/useSuspenseQuery.js +11 -5
  263. package/react/hooks/useSuspenseQuery.js.map +1 -1
  264. package/react/hooks/useSyncExternalStore.js +53 -1
  265. package/react/hooks/useSyncExternalStore.js.map +1 -1
  266. package/react/parser/index.js +4 -5
  267. package/react/parser/index.js.map +1 -1
  268. package/react/parser/parser.cjs +2 -4
  269. package/react/parser/parser.cjs.map +1 -1
  270. package/react/parser/parser.cjs.native.js +2 -4
  271. package/react/ssr/RenderPromises.js +21 -1
  272. package/react/ssr/RenderPromises.js.map +1 -1
  273. package/react/ssr/getDataFromTree.js +18 -3
  274. package/react/ssr/getDataFromTree.js.map +1 -1
  275. package/react/ssr/ssr.cjs +6 -4
  276. package/react/ssr/ssr.cjs.map +1 -1
  277. package/react/ssr/ssr.cjs.native.js +6 -4
  278. package/react/types/types.d.ts +66 -0
  279. package/testing/core/core.cjs +18 -13
  280. package/testing/core/core.cjs.map +1 -1
  281. package/testing/core/core.cjs.native.js +18 -13
  282. package/testing/core/itAsync.d.ts +1 -1
  283. package/testing/core/itAsync.js.map +1 -1
  284. package/testing/core/mocking/mockFetch.d.ts +2 -2
  285. package/testing/core/mocking/mockFetch.js +8 -4
  286. package/testing/core/mocking/mockFetch.js.map +1 -1
  287. package/testing/core/mocking/mockLink.js +25 -9
  288. package/testing/core/mocking/mockLink.js.map +1 -1
  289. package/testing/core/mocking/mockQueryManager.js +2 -0
  290. package/testing/core/mocking/mockQueryManager.js.map +1 -1
  291. package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
  292. package/testing/core/mocking/mockSubscriptionLink.js +1 -1
  293. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
  294. package/testing/core/mocking/mockWatchQuery.js +1 -1
  295. package/testing/core/mocking/mockWatchQuery.js.map +1 -1
  296. package/testing/core/observableToPromise.d.ts +17 -3
  297. package/testing/core/observableToPromise.js +5 -0
  298. package/testing/core/observableToPromise.js.map +1 -1
  299. package/testing/core/subscribeAndCount.js +3 -0
  300. package/testing/core/subscribeAndCount.js.map +1 -1
  301. package/testing/core/wait.js +2 -2
  302. package/testing/core/wait.js.map +1 -1
  303. package/testing/core/withConsoleSpy.d.ts +3 -0
  304. package/testing/core/withConsoleSpy.js +7 -1
  305. package/testing/core/withConsoleSpy.js.map +1 -1
  306. package/testing/core/wrap.js +2 -0
  307. package/testing/core/wrap.js.map +1 -1
  308. package/testing/internal/ObservableStream.js +14 -14
  309. package/testing/internal/ObservableStream.js.map +1 -1
  310. package/testing/internal/disposables/spyOnConsole.d.ts +1 -0
  311. package/testing/internal/disposables/spyOnConsole.js +2 -0
  312. package/testing/internal/disposables/spyOnConsole.js.map +1 -1
  313. package/testing/internal/disposables/withCleanup.d.ts +1 -0
  314. package/testing/internal/disposables/withCleanup.js +3 -0
  315. package/testing/internal/disposables/withCleanup.js.map +1 -1
  316. package/testing/internal/profile/Render.d.ts +28 -0
  317. package/testing/internal/profile/Render.js +12 -1
  318. package/testing/internal/profile/Render.js.map +1 -1
  319. package/testing/internal/profile/profile.d.ts +44 -7
  320. package/testing/internal/profile/profile.js +63 -51
  321. package/testing/internal/profile/profile.js.map +1 -1
  322. package/testing/internal/profile/traces.d.ts +4 -0
  323. package/testing/internal/profile/traces.js +9 -5
  324. package/testing/internal/profile/traces.js.map +1 -1
  325. package/testing/matchers/ProfiledComponent.js +27 -22
  326. package/testing/matchers/ProfiledComponent.js.map +1 -1
  327. package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
  328. package/testing/matchers/toMatchDocument.js.map +1 -1
  329. package/testing/react/MockedProvider.d.ts +4 -0
  330. package/testing/react/MockedProvider.js +6 -2
  331. package/testing/react/MockedProvider.js.map +1 -1
  332. package/testing/testing.cjs +4 -2
  333. package/testing/testing.cjs.map +1 -1
  334. package/testing/testing.cjs.native.js +4 -2
  335. package/utilities/common/arrays.js +1 -0
  336. package/utilities/common/arrays.js.map +1 -1
  337. package/utilities/common/canUse.js +16 -1
  338. package/utilities/common/canUse.js.map +1 -1
  339. package/utilities/common/cloneDeep.d.ts +3 -0
  340. package/utilities/common/cloneDeep.js +5 -0
  341. package/utilities/common/cloneDeep.js.map +1 -1
  342. package/utilities/common/compact.d.ts +4 -0
  343. package/utilities/common/compact.js +4 -0
  344. package/utilities/common/compact.js.map +1 -1
  345. package/utilities/common/errorHandling.js +1 -3
  346. package/utilities/common/errorHandling.js.map +1 -1
  347. package/utilities/common/incrementalResult.js +3 -0
  348. package/utilities/common/incrementalResult.js.map +1 -1
  349. package/utilities/common/makeUniqueId.js +2 -0
  350. package/utilities/common/makeUniqueId.js.map +1 -1
  351. package/utilities/common/maybeDeepFreeze.js +3 -0
  352. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  353. package/utilities/common/mergeDeep.js +12 -1
  354. package/utilities/common/mergeDeep.js.map +1 -1
  355. package/utilities/common/mergeOptions.d.ts +1 -1
  356. package/utilities/common/mergeOptions.js.map +1 -1
  357. package/utilities/common/omitDeep.js.map +1 -1
  358. package/utilities/globals/global.js +7 -1
  359. package/utilities/globals/global.js.map +1 -1
  360. package/utilities/globals/globals.cjs +4 -5
  361. package/utilities/globals/globals.cjs.map +1 -1
  362. package/utilities/globals/globals.cjs.native.js +4 -5
  363. package/utilities/globals/index.d.ts +4 -0
  364. package/utilities/globals/index.js +7 -0
  365. package/utilities/globals/index.js.map +1 -1
  366. package/utilities/globals/invariantWrappers.d.ts +40 -0
  367. package/utilities/globals/invariantWrappers.js +11 -3
  368. package/utilities/globals/invariantWrappers.js.map +1 -1
  369. package/utilities/globals/maybe.js.map +1 -1
  370. package/utilities/graphql/DocumentTransform.js +19 -6
  371. package/utilities/graphql/DocumentTransform.js.map +1 -1
  372. package/utilities/graphql/directives.js +3 -0
  373. package/utilities/graphql/directives.js.map +1 -1
  374. package/utilities/graphql/fragments.d.ts +25 -0
  375. package/utilities/graphql/fragments.js +36 -0
  376. package/utilities/graphql/fragments.js.map +1 -1
  377. package/utilities/graphql/getFromAST.d.ts +5 -0
  378. package/utilities/graphql/getFromAST.js +9 -0
  379. package/utilities/graphql/getFromAST.js.map +1 -1
  380. package/utilities/graphql/print.js.map +1 -1
  381. package/utilities/graphql/storeUtils.d.ts +14 -0
  382. package/utilities/graphql/storeUtils.js +7 -2
  383. package/utilities/graphql/storeUtils.js.map +1 -1
  384. package/utilities/graphql/transform.js +106 -7
  385. package/utilities/graphql/transform.js.map +1 -1
  386. package/utilities/observables/Concast.d.ts +1 -1
  387. package/utilities/observables/Concast.js +84 -1
  388. package/utilities/observables/Concast.js.map +1 -1
  389. package/utilities/observables/Observable.js +6 -0
  390. package/utilities/observables/Observable.js.map +1 -1
  391. package/utilities/observables/asyncMap.js +12 -3
  392. package/utilities/observables/asyncMap.js.map +1 -1
  393. package/utilities/observables/iteration.js +3 -0
  394. package/utilities/observables/iteration.js.map +1 -1
  395. package/utilities/observables/subclassing.js +14 -0
  396. package/utilities/observables/subclassing.js.map +1 -1
  397. package/utilities/policies/pagination.js +47 -3
  398. package/utilities/policies/pagination.js.map +1 -1
  399. package/utilities/promises/decoration.js +1 -0
  400. package/utilities/promises/decoration.js.map +1 -1
  401. package/utilities/types/DeepOmit.js.map +1 -1
  402. package/utilities/types/DeepPartial.d.ts +1 -1
  403. package/utilities/types/DeepPartial.js +4 -0
  404. package/utilities/types/DeepPartial.js.map +1 -1
  405. package/utilities/types/IsStrictlyAny.js.map +1 -1
  406. package/utilities/types/TODO.d.ts +3 -0
  407. package/utilities/types/TODO.js +2 -0
  408. package/utilities/types/TODO.js.map +1 -0
  409. package/utilities/utilities.cjs +31 -27
  410. package/utilities/utilities.cjs.map +1 -1
  411. package/utilities/utilities.cjs.native.js +31 -27
  412. package/version.js +1 -1
  413. package/cache/core/cache.d.ts.map +0 -1
  414. package/cache/core/types/Cache.d.ts.map +0 -1
  415. package/cache/core/types/DataProxy.d.ts.map +0 -1
  416. package/cache/core/types/common.d.ts.map +0 -1
  417. package/cache/index.d.ts.map +0 -1
  418. package/cache/inmemory/entityStore.d.ts.map +0 -1
  419. package/cache/inmemory/fixPolyfills.d.ts.map +0 -1
  420. package/cache/inmemory/fixPolyfills.native.d.ts.map +0 -1
  421. package/cache/inmemory/fragmentRegistry.d.ts.map +0 -1
  422. package/cache/inmemory/helpers.d.ts.map +0 -1
  423. package/cache/inmemory/inMemoryCache.d.ts.map +0 -1
  424. package/cache/inmemory/key-extractor.d.ts.map +0 -1
  425. package/cache/inmemory/object-canon.d.ts.map +0 -1
  426. package/cache/inmemory/policies.d.ts.map +0 -1
  427. package/cache/inmemory/reactiveVars.d.ts.map +0 -1
  428. package/cache/inmemory/readFromStore.d.ts.map +0 -1
  429. package/cache/inmemory/types.d.ts.map +0 -1
  430. package/cache/inmemory/writeToStore.d.ts.map +0 -1
  431. package/config/jest/setup.d.ts.map +0 -1
  432. package/core/ApolloClient.d.ts.map +0 -1
  433. package/core/LocalState.d.ts.map +0 -1
  434. package/core/ObservableQuery.d.ts.map +0 -1
  435. package/core/QueryInfo.d.ts.map +0 -1
  436. package/core/QueryManager.d.ts.map +0 -1
  437. package/core/equalByQuery.d.ts.map +0 -1
  438. package/core/index.d.ts.map +0 -1
  439. package/core/networkStatus.d.ts.map +0 -1
  440. package/core/types.d.ts.map +0 -1
  441. package/core/watchQueryOptions.d.ts.map +0 -1
  442. package/dev/index.d.ts.map +0 -1
  443. package/dev/loadDevMessages.d.ts.map +0 -1
  444. package/dev/loadErrorMessageHandler.d.ts.map +0 -1
  445. package/dev/loadErrorMessages.d.ts.map +0 -1
  446. package/errors/index.d.ts.map +0 -1
  447. package/index.d.ts.map +0 -1
  448. package/invariantErrorCodes.d.ts.map +0 -1
  449. package/link/batch/batchLink.d.ts.map +0 -1
  450. package/link/batch/batching.d.ts.map +0 -1
  451. package/link/batch/index.d.ts.map +0 -1
  452. package/link/batch-http/batchHttpLink.d.ts.map +0 -1
  453. package/link/batch-http/index.d.ts.map +0 -1
  454. package/link/context/index.d.ts.map +0 -1
  455. package/link/core/ApolloLink.d.ts.map +0 -1
  456. package/link/core/concat.d.ts.map +0 -1
  457. package/link/core/empty.d.ts.map +0 -1
  458. package/link/core/execute.d.ts.map +0 -1
  459. package/link/core/from.d.ts.map +0 -1
  460. package/link/core/index.d.ts.map +0 -1
  461. package/link/core/split.d.ts.map +0 -1
  462. package/link/core/types.d.ts.map +0 -1
  463. package/link/error/index.d.ts.map +0 -1
  464. package/link/http/HttpLink.d.ts.map +0 -1
  465. package/link/http/checkFetcher.d.ts.map +0 -1
  466. package/link/http/createHttpLink.d.ts.map +0 -1
  467. package/link/http/createSignalIfSupported.d.ts.map +0 -1
  468. package/link/http/index.d.ts.map +0 -1
  469. package/link/http/iterators/async.d.ts.map +0 -1
  470. package/link/http/iterators/nodeStream.d.ts.map +0 -1
  471. package/link/http/iterators/promise.d.ts.map +0 -1
  472. package/link/http/iterators/reader.d.ts.map +0 -1
  473. package/link/http/parseAndCheckHttpResponse.d.ts.map +0 -1
  474. package/link/http/responseIterator.d.ts.map +0 -1
  475. package/link/http/rewriteURIForGET.d.ts.map +0 -1
  476. package/link/http/selectHttpOptionsAndBody.d.ts.map +0 -1
  477. package/link/http/selectURI.d.ts.map +0 -1
  478. package/link/http/serializeFetchParameter.d.ts.map +0 -1
  479. package/link/persisted-queries/index.d.ts.map +0 -1
  480. package/link/remove-typename/index.d.ts.map +0 -1
  481. package/link/remove-typename/removeTypenameFromVariables.d.ts.map +0 -1
  482. package/link/retry/delayFunction.d.ts.map +0 -1
  483. package/link/retry/index.d.ts.map +0 -1
  484. package/link/retry/retryFunction.d.ts.map +0 -1
  485. package/link/retry/retryLink.d.ts.map +0 -1
  486. package/link/schema/index.d.ts.map +0 -1
  487. package/link/subscriptions/index.d.ts.map +0 -1
  488. package/link/utils/createOperation.d.ts.map +0 -1
  489. package/link/utils/filterOperationVariables.d.ts.map +0 -1
  490. package/link/utils/fromError.d.ts.map +0 -1
  491. package/link/utils/fromPromise.d.ts.map +0 -1
  492. package/link/utils/index.d.ts.map +0 -1
  493. package/link/utils/throwServerError.d.ts.map +0 -1
  494. package/link/utils/toPromise.d.ts.map +0 -1
  495. package/link/utils/transformOperation.d.ts.map +0 -1
  496. package/link/utils/validateOperation.d.ts.map +0 -1
  497. package/link/ws/index.d.ts.map +0 -1
  498. package/react/cache/QueryReference.d.ts.map +0 -1
  499. package/react/cache/SuspenseCache.d.ts.map +0 -1
  500. package/react/cache/getSuspenseCache.d.ts.map +0 -1
  501. package/react/cache/index.d.ts.map +0 -1
  502. package/react/cache/types.d.ts.map +0 -1
  503. package/react/components/Mutation.d.ts.map +0 -1
  504. package/react/components/Query.d.ts.map +0 -1
  505. package/react/components/Subscription.d.ts.map +0 -1
  506. package/react/components/index.d.ts.map +0 -1
  507. package/react/components/types.d.ts.map +0 -1
  508. package/react/context/ApolloConsumer.d.ts.map +0 -1
  509. package/react/context/ApolloContext.d.ts.map +0 -1
  510. package/react/context/ApolloProvider.d.ts.map +0 -1
  511. package/react/context/index.d.ts.map +0 -1
  512. package/react/hoc/graphql.d.ts.map +0 -1
  513. package/react/hoc/hoc-utils.d.ts.map +0 -1
  514. package/react/hoc/index.d.ts.map +0 -1
  515. package/react/hoc/mutation-hoc.d.ts.map +0 -1
  516. package/react/hoc/query-hoc.d.ts.map +0 -1
  517. package/react/hoc/subscription-hoc.d.ts.map +0 -1
  518. package/react/hoc/types.d.ts.map +0 -1
  519. package/react/hoc/withApollo.d.ts.map +0 -1
  520. package/react/hooks/constants.d.ts.map +0 -1
  521. package/react/hooks/index.d.ts.map +0 -1
  522. package/react/hooks/internal/__use.d.ts.map +0 -1
  523. package/react/hooks/internal/index.d.ts.map +0 -1
  524. package/react/hooks/internal/useDeepMemo.d.ts.map +0 -1
  525. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +0 -1
  526. package/react/hooks/useApolloClient.d.ts.map +0 -1
  527. package/react/hooks/useBackgroundQuery.d.ts.map +0 -1
  528. package/react/hooks/useFragment.d.ts.map +0 -1
  529. package/react/hooks/useLazyQuery.d.ts.map +0 -1
  530. package/react/hooks/useMutation.d.ts.map +0 -1
  531. package/react/hooks/useQuery.d.ts.map +0 -1
  532. package/react/hooks/useReactiveVar.d.ts.map +0 -1
  533. package/react/hooks/useReadQuery.d.ts.map +0 -1
  534. package/react/hooks/useSubscription.d.ts.map +0 -1
  535. package/react/hooks/useSuspenseQuery.d.ts.map +0 -1
  536. package/react/hooks/useSyncExternalStore.d.ts.map +0 -1
  537. package/react/index.d.ts.map +0 -1
  538. package/react/parser/index.d.ts.map +0 -1
  539. package/react/ssr/RenderPromises.d.ts.map +0 -1
  540. package/react/ssr/getDataFromTree.d.ts.map +0 -1
  541. package/react/ssr/index.d.ts.map +0 -1
  542. package/react/ssr/renderToStringWithData.d.ts.map +0 -1
  543. package/react/types/types.d.ts.map +0 -1
  544. package/testing/core/index.d.ts.map +0 -1
  545. package/testing/core/itAsync.d.ts.map +0 -1
  546. package/testing/core/mocking/mockClient.d.ts.map +0 -1
  547. package/testing/core/mocking/mockFetch.d.ts.map +0 -1
  548. package/testing/core/mocking/mockLink.d.ts.map +0 -1
  549. package/testing/core/mocking/mockQueryManager.d.ts.map +0 -1
  550. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +0 -1
  551. package/testing/core/mocking/mockWatchQuery.d.ts.map +0 -1
  552. package/testing/core/observableToPromise.d.ts.map +0 -1
  553. package/testing/core/subscribeAndCount.d.ts.map +0 -1
  554. package/testing/core/wait.d.ts.map +0 -1
  555. package/testing/core/withConsoleSpy.d.ts.map +0 -1
  556. package/testing/core/wrap.d.ts.map +0 -1
  557. package/testing/index.d.ts.map +0 -1
  558. package/testing/internal/ObservableStream.d.ts.map +0 -1
  559. package/testing/internal/disposables/index.d.ts.map +0 -1
  560. package/testing/internal/disposables/spyOnConsole.d.ts.map +0 -1
  561. package/testing/internal/disposables/withCleanup.d.ts.map +0 -1
  562. package/testing/internal/index.d.ts.map +0 -1
  563. package/testing/internal/profile/Render.d.ts.map +0 -1
  564. package/testing/internal/profile/index.d.ts.map +0 -1
  565. package/testing/internal/profile/profile.d.ts.map +0 -1
  566. package/testing/internal/profile/traces.d.ts.map +0 -1
  567. package/testing/matchers/ProfiledComponent.d.ts.map +0 -1
  568. package/testing/matchers/index.d.ts.map +0 -1
  569. package/testing/matchers/toHaveSuspenseCacheEntryUsing.d.ts.map +0 -1
  570. package/testing/matchers/toMatchDocument.d.ts.map +0 -1
  571. package/testing/react/MockedProvider.d.ts.map +0 -1
  572. package/utilities/common/arrays.d.ts.map +0 -1
  573. package/utilities/common/canUse.d.ts.map +0 -1
  574. package/utilities/common/cloneDeep.d.ts.map +0 -1
  575. package/utilities/common/compact.d.ts.map +0 -1
  576. package/utilities/common/errorHandling.d.ts.map +0 -1
  577. package/utilities/common/filterInPlace.d.ts +0 -2
  578. package/utilities/common/filterInPlace.d.ts.map +0 -1
  579. package/utilities/common/filterInPlace.js +0 -11
  580. package/utilities/common/filterInPlace.js.map +0 -1
  581. package/utilities/common/incrementalResult.d.ts.map +0 -1
  582. package/utilities/common/makeUniqueId.d.ts.map +0 -1
  583. package/utilities/common/maybeDeepFreeze.d.ts.map +0 -1
  584. package/utilities/common/mergeDeep.d.ts.map +0 -1
  585. package/utilities/common/mergeOptions.d.ts.map +0 -1
  586. package/utilities/common/objects.d.ts.map +0 -1
  587. package/utilities/common/omitDeep.d.ts.map +0 -1
  588. package/utilities/common/stringifyForDisplay.d.ts.map +0 -1
  589. package/utilities/common/stripTypename.d.ts.map +0 -1
  590. package/utilities/globals/global.d.ts.map +0 -1
  591. package/utilities/globals/index.d.ts.map +0 -1
  592. package/utilities/globals/invariantWrappers.d.ts.map +0 -1
  593. package/utilities/globals/maybe.d.ts.map +0 -1
  594. package/utilities/graphql/DocumentTransform.d.ts.map +0 -1
  595. package/utilities/graphql/directives.d.ts.map +0 -1
  596. package/utilities/graphql/fragments.d.ts.map +0 -1
  597. package/utilities/graphql/getFromAST.d.ts.map +0 -1
  598. package/utilities/graphql/operations.d.ts.map +0 -1
  599. package/utilities/graphql/print.d.ts.map +0 -1
  600. package/utilities/graphql/storeUtils.d.ts.map +0 -1
  601. package/utilities/graphql/transform.d.ts.map +0 -1
  602. package/utilities/index.d.ts.map +0 -1
  603. package/utilities/observables/Concast.d.ts.map +0 -1
  604. package/utilities/observables/Observable.d.ts.map +0 -1
  605. package/utilities/observables/asyncMap.d.ts.map +0 -1
  606. package/utilities/observables/iteration.d.ts.map +0 -1
  607. package/utilities/observables/subclassing.d.ts.map +0 -1
  608. package/utilities/policies/pagination.d.ts.map +0 -1
  609. package/utilities/promises/decoration.d.ts.map +0 -1
  610. package/utilities/types/DeepOmit.d.ts.map +0 -1
  611. package/utilities/types/DeepPartial.d.ts.map +0 -1
  612. package/utilities/types/IsStrictlyAny.d.ts.map +0 -1
  613. package/utilities/types/Primitive.d.ts.map +0 -1
  614. package/version.d.ts.map +0 -1
@@ -3,29 +3,35 @@ import { __assign, __awaiter, __extends, __generator } from "tslib";
3
3
  import * as React from "react";
4
4
  import { TextEncoder, TextDecoder } from "util";
5
5
  (_a = global.TextEncoder) !== null && _a !== void 0 ? _a : (global.TextEncoder = TextEncoder);
6
+ // @ts-ignore
6
7
  (_b = global.TextDecoder) !== null && _b !== void 0 ? _b : (global.TextDecoder = TextDecoder);
7
8
  import { RenderInstance } from "./Render.js";
8
9
  import { applyStackTrace, captureStackTrace } from "./traces.js";
10
+ /** only used for passing around data internally */
9
11
  var _stackTrace = Symbol();
12
+ /** @internal */
10
13
  export function profile(_a) {
11
14
  var Component = _a.Component, onRender = _a.onRender, _b = _a.snapshotDOM, snapshotDOM = _b === void 0 ? false : _b, initialSnapshot = _a.initialSnapshot;
12
- var currentRender;
13
15
  var nextRender;
14
16
  var resolveNextRender;
15
17
  var rejectNextRender;
16
18
  var snapshotRef = { current: initialSnapshot };
17
- var updateSnapshot = function (snap) {
19
+ var replaceSnapshot = function (snap) {
18
20
  if (typeof snap === "function") {
19
21
  if (!initialSnapshot) {
20
22
  throw new Error("Cannot use a function to update the snapshot if no initial snapshot was provided.");
21
23
  }
22
- snapshotRef.current = snap(typeof snapshotRef.current === "object"
23
- ? __assign({}, snapshotRef.current) : snapshotRef.current);
24
+ snapshotRef.current = snap(typeof snapshotRef.current === "object" ? __assign({}, snapshotRef.current) : snapshotRef.current);
24
25
  }
25
26
  else {
26
27
  snapshotRef.current = snap;
27
28
  }
28
29
  };
30
+ var mergeSnapshot = function (partialSnapshot) {
31
+ replaceSnapshot(function (snapshot) { return (__assign(__assign({}, snapshot), (typeof partialSnapshot === "function" ?
32
+ partialSnapshot(snapshot)
33
+ : partialSnapshot))); });
34
+ };
29
35
  var profilerOnRender = function (id, phase, actualDuration, baseDuration, startTime, commitTime) {
30
36
  var baseRender = {
31
37
  id: id,
@@ -37,13 +43,17 @@ export function profile(_a) {
37
43
  count: Profiled.renders.length + 1,
38
44
  };
39
45
  try {
40
- onRender === null || onRender === void 0 ? void 0 : onRender(__assign(__assign({}, baseRender), { updateSnapshot: updateSnapshot, snapshot: snapshotRef.current }));
46
+ /*
47
+ * The `onRender` function could contain `expect` calls that throw
48
+ * `JestAssertionError`s - but we are still inside of React, where errors
49
+ * might be swallowed.
50
+ * So we record them and re-throw them in `takeRender`
51
+ * Additionally, we reject the `waitForNextRender` promise.
52
+ */
53
+ onRender === null || onRender === void 0 ? void 0 : onRender(__assign(__assign({}, baseRender), { replaceSnapshot: replaceSnapshot, mergeSnapshot: mergeSnapshot, snapshot: snapshotRef.current }));
41
54
  var snapshot = snapshotRef.current;
42
- var domSnapshot = snapshotDOM
43
- ? window.document.body.innerHTML
44
- : undefined;
55
+ var domSnapshot = snapshotDOM ? window.document.body.innerHTML : undefined;
45
56
  var render = new RenderInstance(baseRender, snapshot, domSnapshot);
46
- currentRender = render;
47
57
  Profiled.renders.push(render);
48
58
  resolveNextRender === null || resolveNextRender === void 0 ? void 0 : resolveNextRender(render);
49
59
  }
@@ -62,27 +72,27 @@ export function profile(_a) {
62
72
  var iteratorPosition = 0;
63
73
  var Profiled = Object.assign(function (props) { return (React.createElement(React.Profiler, { id: "test", onRender: profilerOnRender },
64
74
  React.createElement(Component, __assign({}, props)))); }, {
65
- updateSnapshot: updateSnapshot,
75
+ replaceSnapshot: replaceSnapshot,
76
+ mergeSnapshot: mergeSnapshot,
66
77
  }, {
67
78
  renders: new Array(),
68
- currentRenderCount: function () {
79
+ totalRenderCount: function () {
69
80
  return Profiled.renders.length;
70
81
  },
71
82
  peekRender: function (options) {
72
83
  if (options === void 0) { options = {}; }
73
84
  return __awaiter(this, void 0, void 0, function () {
74
- var render_1, render;
85
+ var render;
75
86
  var _a;
76
87
  return __generator(this, function (_b) {
77
88
  if (iteratorPosition < Profiled.renders.length) {
78
- render_1 = Profiled.renders[iteratorPosition];
79
- if (render_1.phase === "snapshotError") {
80
- throw render_1.error;
89
+ render = Profiled.renders[iteratorPosition];
90
+ if (render.phase === "snapshotError") {
91
+ throw render.error;
81
92
  }
82
- return [2, render_1];
93
+ return [2 /*return*/, render];
83
94
  }
84
- render = Profiled.waitForNextRender(__assign((_a = {}, _a[_stackTrace] = captureStackTrace(Profiled.peekRender), _a), options));
85
- return [2, render];
95
+ return [2 /*return*/, Profiled.waitForNextRender(__assign((_a = {}, _a[_stackTrace] = captureStackTrace(Profiled.peekRender), _a), options))];
86
96
  });
87
97
  });
88
98
  },
@@ -98,8 +108,8 @@ export function profile(_a) {
98
108
  _b.label = 1;
99
109
  case 1:
100
110
  _b.trys.push([1, 3, 4, 5]);
101
- return [4, Profiled.peekRender(__assign((_a = {}, _a[_stackTrace] = captureStackTrace(Profiled.takeRender), _a), options))];
102
- case 2: return [2, _b.sent()];
111
+ return [4 /*yield*/, Profiled.peekRender(__assign((_a = {}, _a[_stackTrace] = captureStackTrace(Profiled.takeRender), _a), options))];
112
+ case 2: return [2 /*return*/, _b.sent()];
103
113
  case 3:
104
114
  e_1 = _b.sent();
105
115
  error = e_1;
@@ -108,35 +118,36 @@ export function profile(_a) {
108
118
  if (!(error && error instanceof WaitForRenderTimeoutError)) {
109
119
  iteratorPosition++;
110
120
  }
111
- return [7];
112
- case 5: return [2];
121
+ return [7 /*endfinally*/];
122
+ case 5: return [2 /*return*/];
113
123
  }
114
124
  });
115
125
  });
116
126
  },
117
127
  getCurrentRender: function () {
118
- if (!currentRender) {
119
- throw new Error("Has not been rendered yet!");
128
+ // The "current" render should point at the same render that the most
129
+ // recent `takeRender` call returned, so we need to get the "previous"
130
+ // iterator position, otherwise `takeRender` advances the iterator
131
+ // to the next render. This means we need to call `takeRender` at least
132
+ // once before we can get a current render.
133
+ var currentPosition = iteratorPosition - 1;
134
+ if (currentPosition < 0) {
135
+ throw new Error("No current render available. You need to call `takeRender` before you can get the current render.");
120
136
  }
121
- return currentRender;
122
- },
123
- takeUntilRenderCount: function (count, optionsPerRender) {
124
- return __awaiter(this, void 0, void 0, function () {
125
- return __generator(this, function (_a) {
126
- switch (_a.label) {
127
- case 0:
128
- if (!(Profiled.renders.length < count)) return [3, 2];
129
- return [4, Profiled.takeRender(optionsPerRender)];
130
- case 1:
131
- _a.sent();
132
- return [3, 0];
133
- case 2: return [2];
134
- }
135
- });
136
- });
137
+ var render = Profiled.renders[currentPosition];
138
+ if (render.phase === "snapshotError") {
139
+ throw render.error;
140
+ }
141
+ return render;
137
142
  },
138
143
  waitForNextRender: function (_a) {
139
- var _b = _a === void 0 ? {} : _a, _c = _b.timeout, timeout = _c === void 0 ? 1000 : _c, _d = _stackTrace, _e = _b[_d], stackTrace = _e === void 0 ? captureStackTrace(Profiled.waitForNextRender) : _e;
144
+ var _b = _a === void 0 ? {} : _a, _c = _b.timeout, timeout = _c === void 0 ? 1000 : _c,
145
+ // capture the stack trace here so its stack trace is as close to the calling code as possible
146
+ _d = _stackTrace,
147
+ // capture the stack trace here so its stack trace is as close to the calling code as possible
148
+ _e = _b[_d],
149
+ // capture the stack trace here so its stack trace is as close to the calling code as possible
150
+ stackTrace = _e === void 0 ? captureStackTrace(Profiled.waitForNextRender) : _e;
140
151
  if (!nextRender) {
141
152
  nextRender = Promise.race([
142
153
  new Promise(function (resolve, reject) {
@@ -155,7 +166,8 @@ export function profile(_a) {
155
166
  });
156
167
  return Profiled;
157
168
  }
158
- var WaitForRenderTimeoutError = (function (_super) {
169
+ /** @internal */
170
+ var WaitForRenderTimeoutError = /** @class */ (function (_super) {
159
171
  __extends(WaitForRenderTimeoutError, _super);
160
172
  function WaitForRenderTimeoutError() {
161
173
  var _newTarget = this.constructor;
@@ -166,10 +178,11 @@ var WaitForRenderTimeoutError = (function (_super) {
166
178
  return WaitForRenderTimeoutError;
167
179
  }(Error));
168
180
  export { WaitForRenderTimeoutError };
181
+ /** @internal */
169
182
  export function profileHook(renderCallback) {
170
183
  var returnValue;
171
184
  var Component = function (props) {
172
- ProfiledComponent.updateSnapshot(renderCallback(props));
185
+ ProfiledComponent.replaceSnapshot(renderCallback(props));
173
186
  return null;
174
187
  };
175
188
  var ProfiledComponent = profile({
@@ -182,13 +195,13 @@ export function profileHook(renderCallback) {
182
195
  ProfiledComponent: ProfiledComponent,
183
196
  }, {
184
197
  renders: ProfiledComponent.renders,
185
- currentSnapshotCount: ProfiledComponent.currentRenderCount,
198
+ totalSnapshotCount: ProfiledComponent.totalRenderCount,
186
199
  peekSnapshot: function (options) {
187
200
  return __awaiter(this, void 0, void 0, function () {
188
201
  return __generator(this, function (_a) {
189
202
  switch (_a.label) {
190
- case 0: return [4, ProfiledComponent.peekRender(options)];
191
- case 1: return [2, (_a.sent()).snapshot];
203
+ case 0: return [4 /*yield*/, ProfiledComponent.peekRender(options)];
204
+ case 1: return [2 /*return*/, (_a.sent()).snapshot];
192
205
  }
193
206
  });
194
207
  });
@@ -197,8 +210,8 @@ export function profileHook(renderCallback) {
197
210
  return __awaiter(this, void 0, void 0, function () {
198
211
  return __generator(this, function (_a) {
199
212
  switch (_a.label) {
200
- case 0: return [4, ProfiledComponent.takeRender(options)];
201
- case 1: return [2, (_a.sent()).snapshot];
213
+ case 0: return [4 /*yield*/, ProfiledComponent.takeRender(options)];
214
+ case 1: return [2 /*return*/, (_a.sent()).snapshot];
202
215
  }
203
216
  });
204
217
  });
@@ -206,13 +219,12 @@ export function profileHook(renderCallback) {
206
219
  getCurrentSnapshot: function () {
207
220
  return ProfiledComponent.getCurrentRender().snapshot;
208
221
  },
209
- takeUntilSnapshotCount: ProfiledComponent.takeUntilRenderCount,
210
222
  waitForNextSnapshot: function (options) {
211
223
  return __awaiter(this, void 0, void 0, function () {
212
224
  return __generator(this, function (_a) {
213
225
  switch (_a.label) {
214
- case 0: return [4, ProfiledComponent.waitForNextRender(options)];
215
- case 1: return [2, (_a.sent()).snapshot];
226
+ case 0: return [4 /*yield*/, ProfiledComponent.waitForNextRender(options)];
227
+ case 1: return [2 /*return*/, (_a.sent()).snapshot];
216
228
  }
217
229
  });
218
230
  });
@@ -1 +1 @@
1
- {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/profile.tsx"],"names":[],"mappings":";;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAEhD,MAAA,MAAM,CAAC,WAAW,oCAAlB,MAAM,CAAC,WAAW,GAAK,WAAW,EAAC;AAEnC,MAAA,MAAM,CAAC,WAAW,oCAAlB,MAAM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AAM,OAAA,WAAW,EAAX,CAAW;KAC5B,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAClB,SAAS,YAAY,CAAC,KAAY;QAChC,OAAO,oBAAC,iBAAiB,eAAM,KAAa,EAAI,CAAC;IACnD,CAAC,EACD;QACE,iBAAiB,mBAAA;KAClB,EACD;QACE,OAAO,EAAE,iBAAiB,CAAC,OAAO;QAClC,oBAAoB,EAAE,iBAAiB,CAAC,kBAAkB;QACpD,YAAY,YAAC,OAAO;;;;gCAChB,WAAM,iBAAiB,CAAC,UAAU,CAAC,OAAO,CAAC,EAAA;gCAAnD,WAAO,CAAC,SAA2C,CAAC,CAAC,QAAQ,EAAC;;;;SAC/D;QACK,YAAY,YAAC,OAAO;;;;gCAChB,WAAM,iBAAiB,CAAC,UAAU,CAAC,OAAO,CAAC,EAAA;gCAAnD,WAAO,CAAC,SAA2C,CAAC,CAAC,QAAQ,EAAC;;;;SAC/D;QACD,kBAAkB;YAChB,OAAO,iBAAiB,CAAC,gBAAgB,EAAE,CAAC,QAAQ,CAAC;QACvD,CAAC;QACD,sBAAsB,EAAE,iBAAiB,CAAC,oBAAoB;QACxD,mBAAmB,YAAC,OAAO;;;;gCACvB,WAAM,iBAAiB,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAA;gCAA1D,WAAO,CAAC,SAAkD,CAAC,CAAC,QAAQ,EAAC;;;;SACtE;KAC+C,CACnD,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport { TextEncoder, TextDecoder } from \"util\";\n\nglobal.TextEncoder ??= TextEncoder;\n// @ts-ignore\nglobal.TextDecoder ??= TextDecoder;\nimport type { Render, BaseRender } from \"./Render.js\";\nimport { RenderInstance } from \"./Render.js\";\nimport { applyStackTrace, captureStackTrace } from \"./traces.js\";\n\ntype ValidSnapshot = void | (object & { /* not a function */ call?: never });\n\n/** only used for passing around data internally */\nconst _stackTrace = Symbol();\n/** @internal */\nexport interface NextRenderOptions {\n timeout?: number;\n [_stackTrace]?: string;\n}\n\n/** @internal */\nexport interface ProfiledComponent<Props, Snapshot>\n extends React.FC<Props>,\n ProfiledComponentFields<Props, Snapshot>,\n ProfiledComponenOnlyFields<Props, Snapshot> {}\n\ninterface UpdateSnapshot<Snapshot> {\n (newSnapshot: Snapshot): void;\n (updateSnapshot: (lastSnapshot: Readonly<Snapshot>) => Snapshot): void;\n}\n\ninterface ProfiledComponenOnlyFields<Props, Snapshot> {\n updateSnapshot: UpdateSnapshot<Snapshot>;\n}\ninterface ProfiledComponentFields<Props, Snapshot> {\n /**\n * An array of all renders that have happened so far.\n * Errors thrown during component render will be captured here, too.\n */\n renders: Array<\n Render<Snapshot> | { phase: \"snapshotError\"; count: number; error: unknown }\n >;\n /**\n * Peeks the next render from the current iterator position, without advancing the iterator.\n * If no render has happened yet, it will wait for the next render to happen.\n * @throws {WaitForRenderTimeoutError} if no render happens within the timeout\n */\n peekRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n /**\n * Iterates to the next render and returns it.\n * If no render has happened yet, it will wait for the next render to happen.\n * @throws {WaitForRenderTimeoutError} if no render happens within the timeout\n */\n takeRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n /**\n * Returns the current render count.\n */\n currentRenderCount(): number;\n /**\n * Returns the current render.\n * @throws {Error} if no render has happened yet\n */\n getCurrentRender(): Render<Snapshot>;\n /**\n * Iterates the renders until the render count is reached.\n */\n takeUntilRenderCount(\n count: number,\n optionsPerRender?: NextRenderOptions\n ): Promise<void>;\n /**\n * Waits for the next render to happen.\n * Does not advance the render iterator.\n */\n waitForNextRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n}\n\n/** @internal */\nexport function profile<\n Snapshot extends ValidSnapshot = void,\n Props = Record<string, never>,\n>({\n Component,\n onRender,\n snapshotDOM = false,\n initialSnapshot,\n}: {\n Component: React.ComponentType<Props>;\n onRender?: (\n info: BaseRender & {\n snapshot: Snapshot;\n updateSnapshot: UpdateSnapshot<Snapshot>;\n }\n ) => void;\n snapshotDOM?: boolean;\n initialSnapshot?: Snapshot;\n}) {\n let currentRender: Render<Snapshot> | undefined;\n let nextRender: Promise<Render<Snapshot>> | undefined;\n let resolveNextRender: ((render: Render<Snapshot>) => void) | undefined;\n let rejectNextRender: ((error: unknown) => void) | undefined;\n const snapshotRef = { current: initialSnapshot };\n const updateSnapshot: UpdateSnapshot<Snapshot> = (snap) => {\n if (typeof snap === \"function\") {\n if (!initialSnapshot) {\n throw new Error(\n \"Cannot use a function to update the snapshot if no initial snapshot was provided.\"\n );\n }\n snapshotRef.current = snap(\n typeof snapshotRef.current === \"object\"\n ? // \"cheap best effort\" to prevent accidental mutation of the last snapshot\n { ...snapshotRef.current! }\n : snapshotRef.current!\n );\n } else {\n snapshotRef.current = snap;\n }\n };\n const profilerOnRender: React.ProfilerOnRenderCallback = (\n id,\n phase,\n actualDuration,\n baseDuration,\n startTime,\n commitTime\n ) => {\n const baseRender = {\n id,\n phase,\n actualDuration,\n baseDuration,\n startTime,\n commitTime,\n count: Profiled.renders.length + 1,\n };\n try {\n /*\n * The `onRender` function could contain `expect` calls that throw\n * `JestAssertionError`s - but we are still inside of React, where errors\n * might be swallowed.\n * So we record them and re-throw them in `takeRender`\n * Additionally, we reject the `waitForNextRender` promise.\n */\n onRender?.({\n ...baseRender,\n updateSnapshot,\n snapshot: snapshotRef.current!,\n });\n\n const snapshot = snapshotRef.current as Snapshot;\n const domSnapshot = snapshotDOM\n ? window.document.body.innerHTML\n : undefined;\n const render = new RenderInstance(baseRender, snapshot, domSnapshot);\n // eslint-disable-next-line testing-library/render-result-naming-convention\n currentRender = render;\n Profiled.renders.push(render);\n resolveNextRender?.(render);\n } catch (error) {\n Profiled.renders.push({\n phase: \"snapshotError\",\n count: Profiled.renders.length,\n error,\n });\n rejectNextRender?.(error);\n } finally {\n nextRender = resolveNextRender = rejectNextRender = undefined;\n }\n };\n\n let iteratorPosition = 0;\n const Profiled: ProfiledComponent<Props, Snapshot> = Object.assign(\n (props: Props) => (\n <React.Profiler id=\"test\" onRender={profilerOnRender}>\n <Component {...(props as any)} />\n </React.Profiler>\n ),\n {\n updateSnapshot,\n } satisfies ProfiledComponenOnlyFields<Props, Snapshot>,\n {\n renders: new Array<\n | Render<Snapshot>\n | { phase: \"snapshotError\"; count: number; error: unknown }\n >(),\n currentRenderCount() {\n return Profiled.renders.length;\n },\n async peekRender(options: NextRenderOptions = {}) {\n if (iteratorPosition < Profiled.renders.length) {\n const render = Profiled.renders[iteratorPosition];\n if (render.phase === \"snapshotError\") {\n throw render.error;\n }\n return render;\n }\n const render = Profiled.waitForNextRender({\n [_stackTrace]: captureStackTrace(Profiled.peekRender),\n ...options,\n });\n return render;\n },\n async takeRender(options: NextRenderOptions = {}) {\n let error: { message?: string } | undefined = undefined;\n try {\n return await Profiled.peekRender({\n [_stackTrace]: captureStackTrace(Profiled.takeRender),\n ...options,\n });\n } catch (e) {\n error = e;\n throw e;\n } finally {\n if (!(error && error instanceof WaitForRenderTimeoutError)) {\n iteratorPosition++;\n }\n }\n },\n getCurrentRender() {\n if (!currentRender) {\n throw new Error(\"Has not been rendered yet!\");\n }\n return currentRender;\n },\n async takeUntilRenderCount(\n count: number,\n optionsPerRender?: NextRenderOptions\n ) {\n while (Profiled.renders.length < count) {\n await Profiled.takeRender(optionsPerRender);\n }\n },\n waitForNextRender({\n timeout = 1000,\n // capture the stack trace here so its stack trace is as close to the calling code as possible\n [_stackTrace]: stackTrace = captureStackTrace(\n Profiled.waitForNextRender\n ),\n }: NextRenderOptions = {}) {\n if (!nextRender) {\n nextRender = Promise.race<Render<Snapshot>>([\n new Promise<Render<Snapshot>>((resolve, reject) => {\n resolveNextRender = resolve;\n rejectNextRender = reject;\n }),\n new Promise<Render<Snapshot>>((_, reject) =>\n setTimeout(\n () =>\n reject(\n applyStackTrace(new WaitForRenderTimeoutError(), stackTrace)\n ),\n timeout\n )\n ),\n ]);\n }\n return nextRender;\n },\n } satisfies ProfiledComponentFields<Props, Snapshot>\n );\n return Profiled;\n}\n\n/** @internal */\nexport class WaitForRenderTimeoutError extends Error {\n constructor() {\n super(\"Exceeded timeout waiting for next render.\");\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\ntype StringReplaceRenderWithSnapshot<T extends string> =\n T extends `${infer Pre}Render${infer Post}` ? `${Pre}Snapshot${Post}` : T;\n\ntype ResultReplaceRenderWithSnapshot<T> = T extends (\n ...args: infer Args\n) => Render<infer Snapshot>\n ? (...args: Args) => Snapshot\n : T extends (...args: infer Args) => Promise<Render<infer Snapshot>>\n ? (...args: Args) => Promise<Snapshot>\n : T;\n\ntype ProfiledHookFields<Props, ReturnValue> = ProfiledComponentFields<\n Props,\n ReturnValue\n> extends infer PC\n ? {\n [K in keyof PC as StringReplaceRenderWithSnapshot<\n K & string\n >]: ResultReplaceRenderWithSnapshot<PC[K]>;\n }\n : never;\n\n/** @internal */\nexport interface ProfiledHook<Props, ReturnValue>\n extends React.FC<Props>,\n ProfiledHookFields<Props, ReturnValue> {\n ProfiledComponent: ProfiledComponent<Props, ReturnValue>;\n}\n\n/** @internal */\nexport function profileHook<ReturnValue extends ValidSnapshot, Props>(\n renderCallback: (props: Props) => ReturnValue\n): ProfiledHook<Props, ReturnValue> {\n let returnValue: ReturnValue;\n const Component = (props: Props) => {\n ProfiledComponent.updateSnapshot(renderCallback(props));\n return null;\n };\n const ProfiledComponent = profile<ReturnValue, Props>({\n Component,\n onRender: () => returnValue,\n });\n return Object.assign(\n function ProfiledHook(props: Props) {\n return <ProfiledComponent {...(props as any)} />;\n },\n {\n ProfiledComponent,\n },\n {\n renders: ProfiledComponent.renders,\n currentSnapshotCount: ProfiledComponent.currentRenderCount,\n async peekSnapshot(options) {\n return (await ProfiledComponent.peekRender(options)).snapshot;\n },\n async takeSnapshot(options) {\n return (await ProfiledComponent.takeRender(options)).snapshot;\n },\n getCurrentSnapshot() {\n return ProfiledComponent.getCurrentRender().snapshot;\n },\n takeUntilSnapshotCount: ProfiledComponent.takeUntilRenderCount,\n async waitForNextSnapshot(options) {\n return (await ProfiledComponent.waitForNextRender(options)).snapshot;\n },\n } satisfies ProfiledHookFields<Props, ReturnValue>\n );\n}\n"]}
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/profile.tsx"],"names":[],"mappings":";;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAEhD,MAAA,MAAM,CAAC,WAAW,oCAAlB,MAAM,CAAC,WAAW,GAAK,WAAW,EAAC;AACnC,aAAa;AACb,MAAA,MAAM,CAAC,WAAW,oCAAlB,MAAM,CAAC,WAAW,GAAK,WAAW,EAAC;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIjE,mDAAmD;AACnD,IAAM,WAAW,GAAG,MAAM,EAAE,CAAC;AAqE7B,gBAAgB;AAChB,MAAM,UAAU,OAAO,CAGrB,EAgBD;QAfC,SAAS,eAAA,EACT,QAAQ,cAAA,EACR,mBAAmB,EAAnB,WAAW,mBAAG,KAAK,KAAA,EACnB,eAAe,qBAAA;IAaf,IAAI,UAAiD,CAAC;IACtD,IAAI,iBAAmE,CAAC;IACxE,IAAI,gBAAwD,CAAC;IAC7D,IAAM,WAAW,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;IACjD,IAAM,eAAe,GAA8B,UAAC,IAAI;QACtD,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;YAC/B,IAAI,CAAC,eAAe,EAAE,CAAC;gBACrB,MAAM,IAAI,KAAK,CACb,mFAAmF,CACpF,CAAC;YACJ,CAAC;YACD,WAAW,CAAC,OAAO,GAAG,IAAI,CACxB,OAAO,WAAW,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,cAElC,WAAW,CAAC,OAAQ,EAC3B,CAAC,CAAC,W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BAAkB,EAAE,iBAAiB,CAAC,gBAAgB;QAChD,YAAY,YAAC,OAAO;;;;gCAChB,qBAAM,iBAAiB,CAAC,UAAU,CAAC,OAAO,CAAC,EAAA;gCAAnD,sBAAO,CAAC,SAA2C,CAAC,CAAC,QAAQ,EAAC;;;;SAC/D;QACK,YAAY,YAAC,OAAO;;;;gCAChB,qBAAM,iBAAiB,CAAC,UAAU,CAAC,OAAO,CAAC,EAAA;gCAAnD,sBAAO,CAAC,SAA2C,CAAC,CAAC,QAAQ,EAAC;;;;SAC/D;QACD,kBAAkB;YAChB,OAAO,iBAAiB,CAAC,gBAAgB,EAAE,CAAC,QAAQ,CAAC;QACvD,CAAC;QACK,mBAAmB,YAAC,OAAO;;;;gCACvB,qBAAM,iBAAiB,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAA;gCAA1D,sBAAO,CAAC,SAAkD,CAAC,CAAC,QAAQ,EAAC;;;;SACtE;KAC+C,CACnD,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport { TextEncoder, TextDecoder } from \"util\";\n\nglobal.TextEncoder ??= TextEncoder;\n// @ts-ignore\nglobal.TextDecoder ??= TextDecoder;\nimport type { Render, BaseRender } from \"./Render.js\";\nimport { RenderInstance } from \"./Render.js\";\nimport { applyStackTrace, captureStackTrace } from \"./traces.js\";\n\ntype ValidSnapshot = void | (object & { /* not a function */ call?: never });\n\n/** only used for passing around data internally */\nconst _stackTrace = Symbol();\n/** @internal */\nexport interface NextRenderOptions {\n timeout?: number;\n [_stackTrace]?: string;\n}\n\n/** @internal */\nexport interface ProfiledComponent<Props, Snapshot>\n extends React.FC<Props>,\n ProfiledComponentFields<Props, Snapshot>,\n ProfiledComponentOnlyFields<Props, Snapshot> {}\n\ninterface ReplaceSnapshot<Snapshot> {\n (newSnapshot: Snapshot): void;\n (updateSnapshot: (lastSnapshot: Readonly<Snapshot>) => Snapshot): void;\n}\n\ninterface MergeSnapshot<Snapshot> {\n (partialSnapshot: Partial<Snapshot>): void;\n (\n updatePartialSnapshot: (\n lastSnapshot: Readonly<Snapshot>\n ) => Partial<Snapshot>\n ): void;\n}\n\ninterface ProfiledComponentOnlyFields<Props, Snapshot> {\n // Allows for partial updating of the snapshot by shallow merging the results\n mergeSnapshot: MergeSnapshot<Snapshot>;\n // Performs a full replacement of the snapshot\n replaceSnapshot: ReplaceSnapshot<Snapshot>;\n}\ninterface ProfiledComponentFields<Props, Snapshot> {\n /**\n * An array of all renders that have happened so far.\n * Errors thrown during component render will be captured here, too.\n */\n renders: Array<\n Render<Snapshot> | { phase: \"snapshotError\"; count: number; error: unknown }\n >;\n /**\n * Peeks the next render from the current iterator position, without advancing the iterator.\n * If no render has happened yet, it will wait for the next render to happen.\n * @throws {WaitForRenderTimeoutError} if no render happens within the timeout\n */\n peekRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n /**\n * Iterates to the next render and returns it.\n * If no render has happened yet, it will wait for the next render to happen.\n * @throws {WaitForRenderTimeoutError} if no render happens within the timeout\n */\n takeRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n /**\n * Returns the total number of renders.\n */\n totalRenderCount(): number;\n /**\n * Returns the current render.\n * @throws {Error} if no render has happened yet\n */\n getCurrentRender(): Render<Snapshot>;\n /**\n * Waits for the next render to happen.\n * Does not advance the render iterator.\n */\n waitForNextRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n}\n\n/** @internal */\nexport function profile<\n Snapshot extends ValidSnapshot = void,\n Props = Record<string, never>,\n>({\n Component,\n onRender,\n snapshotDOM = false,\n initialSnapshot,\n}: {\n Component: React.ComponentType<Props>;\n onRender?: (\n info: BaseRender & {\n snapshot: Snapshot;\n replaceSnapshot: ReplaceSnapshot<Snapshot>;\n mergeSnapshot: MergeSnapshot<Snapshot>;\n }\n ) => void;\n snapshotDOM?: boolean;\n initialSnapshot?: Snapshot;\n}) {\n let nextRender: Promise<Render<Snapshot>> | undefined;\n let resolveNextRender: ((render: Render<Snapshot>) => void) | undefined;\n let rejectNextRender: ((error: unknown) => void) | undefined;\n const snapshotRef = { current: initialSnapshot };\n const replaceSnapshot: ReplaceSnapshot<Snapshot> = (snap) => {\n if (typeof snap === \"function\") {\n if (!initialSnapshot) {\n throw new Error(\n \"Cannot use a function to update the snapshot if no initial snapshot was provided.\"\n );\n }\n snapshotRef.current = snap(\n typeof snapshotRef.current === \"object\" ?\n // \"cheap best effort\" to prevent accidental mutation of the last snapshot\n { ...snapshotRef.current! }\n : snapshotRef.current!\n );\n } else {\n snapshotRef.current = snap;\n }\n };\n\n const mergeSnapshot: MergeSnapshot<Snapshot> = (partialSnapshot) => {\n replaceSnapshot((snapshot) => ({\n ...snapshot,\n ...(typeof partialSnapshot === \"function\" ?\n partialSnapshot(snapshot)\n : partialSnapshot),\n }));\n };\n\n const profilerOnRender: React.ProfilerOnRenderCallback = (\n id,\n phase,\n actualDuration,\n baseDuration,\n startTime,\n commitTime\n ) => {\n const baseRender = {\n id,\n phase,\n actualDuration,\n baseDuration,\n startTime,\n commitTime,\n count: Profiled.renders.length + 1,\n };\n try {\n /*\n * The `onRender` function could contain `expect` calls that throw\n * `JestAssertionError`s - but we are still inside of React, where errors\n * might be swallowed.\n * So we record them and re-throw them in `takeRender`\n * Additionally, we reject the `waitForNextRender` promise.\n */\n onRender?.({\n ...baseRender,\n replaceSnapshot,\n mergeSnapshot,\n snapshot: snapshotRef.current!,\n });\n\n const snapshot = snapshotRef.current as Snapshot;\n const domSnapshot =\n snapshotDOM ? window.document.body.innerHTML : undefined;\n const render = new RenderInstance(baseRender, snapshot, domSnapshot);\n Profiled.renders.push(render);\n resolveNextRender?.(render);\n } catch (error) {\n Profiled.renders.push({\n phase: \"snapshotError\",\n count: Profiled.renders.length,\n error,\n });\n rejectNextRender?.(error);\n } finally {\n nextRender = resolveNextRender = rejectNextRender = undefined;\n }\n };\n\n let iteratorPosition = 0;\n const Profiled: ProfiledComponent<Props, Snapshot> = Object.assign(\n (props: Props) => (\n <React.Profiler id=\"test\" onRender={profilerOnRender}>\n <Component {...(props as any)} />\n </React.Profiler>\n ),\n {\n replaceSnapshot,\n mergeSnapshot,\n } satisfies ProfiledComponentOnlyFields<Props, Snapshot>,\n {\n renders: new Array<\n | Render<Snapshot>\n | { phase: \"snapshotError\"; count: number; error: unknown }\n >(),\n totalRenderCount() {\n return Profiled.renders.length;\n },\n async peekRender(options: NextRenderOptions = {}) {\n if (iteratorPosition < Profiled.renders.length) {\n const render = Profiled.renders[iteratorPosition];\n\n if (render.phase === \"snapshotError\") {\n throw render.error;\n }\n\n return render;\n }\n return Profiled.waitForNextRender({\n [_stackTrace]: captureStackTrace(Profiled.peekRender),\n ...options,\n });\n },\n async takeRender(options: NextRenderOptions = {}) {\n let error: unknown = undefined;\n try {\n return await Profiled.peekRender({\n [_stackTrace]: captureStackTrace(Profiled.takeRender),\n ...options,\n });\n } catch (e) {\n error = e;\n throw e;\n } finally {\n if (!(error && error instanceof WaitForRenderTimeoutError)) {\n iteratorPosition++;\n }\n }\n },\n getCurrentRender() {\n // The \"current\" render should point at the same render that the most\n // recent `takeRender` call returned, so we need to get the \"previous\"\n // iterator position, otherwise `takeRender` advances the iterator\n // to the next render. This means we need to call `takeRender` at least\n // once before we can get a current render.\n const currentPosition = iteratorPosition - 1;\n\n if (currentPosition < 0) {\n throw new Error(\n \"No current render available. You need to call `takeRender` before you can get the current render.\"\n );\n }\n\n const render = Profiled.renders[currentPosition];\n\n if (render.phase === \"snapshotError\") {\n throw render.error;\n }\n return render;\n },\n waitForNextRender({\n timeout = 1000,\n // capture the stack trace here so its stack trace is as close to the calling code as possible\n [_stackTrace]: stackTrace = captureStackTrace(\n Profiled.waitForNextRender\n ),\n }: NextRenderOptions = {}) {\n if (!nextRender) {\n nextRender = Promise.race<Render<Snapshot>>([\n new Promise<Render<Snapshot>>((resolve, reject) => {\n resolveNextRender = resolve;\n rejectNextRender = reject;\n }),\n new Promise<Render<Snapshot>>((_, reject) =>\n setTimeout(\n () =>\n reject(\n applyStackTrace(new WaitForRenderTimeoutError(), stackTrace)\n ),\n timeout\n )\n ),\n ]);\n }\n return nextRender;\n },\n } satisfies ProfiledComponentFields<Props, Snapshot>\n );\n return Profiled;\n}\n\n/** @internal */\nexport class WaitForRenderTimeoutError extends Error {\n constructor() {\n super(\"Exceeded timeout waiting for next render.\");\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\ntype StringReplaceRenderWithSnapshot<T extends string> =\n T extends `${infer Pre}Render${infer Post}` ? `${Pre}Snapshot${Post}` : T;\n\ntype ResultReplaceRenderWithSnapshot<T> =\n T extends (...args: infer Args) => Render<infer Snapshot> ?\n (...args: Args) => Snapshot\n : T extends (...args: infer Args) => Promise<Render<infer Snapshot>> ?\n (...args: Args) => Promise<Snapshot>\n : T;\n\ntype ProfiledHookFields<Props, ReturnValue> =\n ProfiledComponentFields<Props, ReturnValue> extends infer PC ?\n {\n [K in keyof PC as StringReplaceRenderWithSnapshot<\n K & string\n >]: ResultReplaceRenderWithSnapshot<PC[K]>;\n }\n : never;\n\n/** @internal */\nexport interface ProfiledHook<Props, ReturnValue>\n extends React.FC<Props>,\n ProfiledHookFields<Props, ReturnValue> {\n ProfiledComponent: ProfiledComponent<Props, ReturnValue>;\n}\n\n/** @internal */\nexport function profileHook<ReturnValue extends ValidSnapshot, Props>(\n renderCallback: (props: Props) => ReturnValue\n): ProfiledHook<Props, ReturnValue> {\n let returnValue: ReturnValue;\n const Component = (props: Props) => {\n ProfiledComponent.replaceSnapshot(renderCallback(props));\n return null;\n };\n const ProfiledComponent = profile<ReturnValue, Props>({\n Component,\n onRender: () => returnValue,\n });\n return Object.assign(\n function ProfiledHook(props: Props) {\n return <ProfiledComponent {...(props as any)} />;\n },\n {\n ProfiledComponent,\n },\n {\n renders: ProfiledComponent.renders,\n totalSnapshotCount: ProfiledComponent.totalRenderCount,\n async peekSnapshot(options) {\n return (await ProfiledComponent.peekRender(options)).snapshot;\n },\n async takeSnapshot(options) {\n return (await ProfiledComponent.takeRender(options)).snapshot;\n },\n getCurrentSnapshot() {\n return ProfiledComponent.getCurrentRender().snapshot;\n },\n async waitForNextSnapshot(options) {\n return (await ProfiledComponent.waitForNextRender(options)).snapshot;\n },\n } satisfies ProfiledHookFields<Props, ReturnValue>\n );\n}\n"]}
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Captures a StackTrace and (if passed) cuts off
3
+ * the first lines including the calling function.
4
+ */
1
5
  export declare function captureStackTrace(callingFunction?: string | (() => {})): string;
2
6
  export declare function applyStackTrace(error: Error, stackTrace: string): Error;
3
7
  //# sourceMappingURL=traces.d.ts.map
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Captures a StackTrace and (if passed) cuts off
3
+ * the first lines including the calling function.
4
+ */
1
5
  export function captureStackTrace(callingFunction) {
2
6
  var stack = "";
3
7
  try {
@@ -6,15 +10,15 @@ export function captureStackTrace(callingFunction) {
6
10
  catch (e) {
7
11
  (stack = e.stack);
8
12
  }
9
- var callerName = typeof callingFunction === "string"
10
- ? callingFunction
11
- : callingFunction
12
- ? callingFunction.name
13
+ var callerName = typeof callingFunction === "string" ? callingFunction
14
+ : callingFunction ? callingFunction.name
13
15
  : undefined;
14
16
  if (callerName && stack.includes(callerName)) {
15
17
  var lines = stack.split("\n");
16
18
  stack = lines
17
- .slice(lines.findLastIndex(function (line) { return line.includes(callerName); }) + 1)
19
+ .slice(
20
+ // @ts-expect-error this is too old of a TS target, but node has it
21
+ lines.findLastIndex(function (line) { return line.includes(callerName); }) + 1)
18
22
  .join("\n");
19
23
  }
20
24
  return stack;
@@ -1 +1 @@
1
- {"version":3,"file":"traces.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/traces.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,iBAAiB,CAAC,eAAqC;IACrE,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,IAAI;QACF,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC;KACrB;IAAC,OAAO,CAAM,EAAE;QACf,CAAG,KAAK,GAAK,CAAC,MAAN,CAAO,CAAC;KACjB;IAED,IAAM,UAAU,GACd,OAAO,eAAe,KAAK,QAAQ;QACjC,CAAC,CAAC,eAAe;QACjB,CAAC,CAAC,eAAe;YACjB,CAAC,CAAC,eAAe,CAAC,IAAI;YACtB,CAAC,CAAC,SAAS,CAAC;IAEhB,IAAI,UAAU,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QAC5C,IAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEhC,KAAK,GAAG,KAAK;aACV,KAAK,CAEJ,KAAK,CAAC,aAAa,CAAC,UAAC,IAAY,IAAK,OAAA,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAzB,CAAyB,CAAC,GAAG,CAAC,CACrE;aACA,IAAI,CAAC,IAAI,CAAC,CAAC;KACf;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAY,EAAE,UAAkB;IAC9D,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,IAAI,GAAG,UAAU,CAAC;IAChD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Captures a StackTrace and (if passed) cuts off\n * the first lines including the calling function.\n */\nexport function captureStackTrace(callingFunction?: string | (() => {})) {\n let stack = \"\";\n try {\n throw new Error(\"\");\n } catch (e: any) {\n ({ stack } = e);\n }\n\n const callerName =\n typeof callingFunction === \"string\"\n ? callingFunction\n : callingFunction\n ? callingFunction.name\n : undefined;\n\n if (callerName && stack.includes(callerName)) {\n const lines = stack.split(\"\\n\");\n\n stack = lines\n .slice(\n // @ts-expect-error this is too old of a TS target, but node has it\n lines.findLastIndex((line: string) => line.includes(callerName)) + 1\n )\n .join(\"\\n\");\n }\n\n return stack;\n}\n\nexport function applyStackTrace(error: Error, stackTrace: string) {\n error.stack = error.message + \"\\n\" + stackTrace;\n return error;\n}\n"]}
1
+ {"version":3,"file":"traces.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/traces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,eAAqC;IACrE,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,IAAI,CAAC;QACH,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,CAAG,KAAK,GAAK,CAAC,MAAN,CAAO,CAAC;IAClB,CAAC;IAED,IAAM,UAAU,GACd,OAAO,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe;QACrD,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI;YACxC,CAAC,CAAC,SAAS,CAAC;IAEd,IAAI,UAAU,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7C,IAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEhC,KAAK,GAAG,KAAK;aACV,KAAK;QACJ,mEAAmE;QACnE,KAAK,CAAC,aAAa,CAAC,UAAC,IAAY,IAAK,OAAA,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAzB,CAAyB,CAAC,GAAG,CAAC,CACrE;aACA,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAY,EAAE,UAAkB;IAC9D,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,IAAI,GAAG,UAAU,CAAC;IAChD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Captures a StackTrace and (if passed) cuts off\n * the first lines including the calling function.\n */\nexport function captureStackTrace(callingFunction?: string | (() => {})) {\n let stack = \"\";\n try {\n throw new Error(\"\");\n } catch (e: any) {\n ({ stack } = e);\n }\n\n const callerName =\n typeof callingFunction === \"string\" ? callingFunction\n : callingFunction ? callingFunction.name\n : undefined;\n\n if (callerName && stack.includes(callerName)) {\n const lines = stack.split(\"\\n\");\n\n stack = lines\n .slice(\n // @ts-expect-error this is too old of a TS target, but node has it\n lines.findLastIndex((line: string) => line.includes(callerName)) + 1\n )\n .join(\"\\n\");\n }\n\n return stack;\n}\n\nexport function applyStackTrace(error: Error, stackTrace: string) {\n error.stack = error.message + \"\\n\" + stackTrace;\n return error;\n}\n"]}
@@ -1,23 +1,24 @@
1
1
  import { __assign, __awaiter, __generator } from "tslib";
2
2
  import { WaitForRenderTimeoutError } from "../internal/index.js";
3
- export var toRerender = function (_profiled, options) {
3
+ export var toRerender = function (actual, options) {
4
4
  return __awaiter(this, void 0, void 0, function () {
5
- var profiled, hint, pass, e_1;
5
+ var _profiled, profiled, hint, pass, e_1;
6
6
  return __generator(this, function (_a) {
7
7
  switch (_a.label) {
8
8
  case 0:
9
- profiled = "ProfiledComponent" in _profiled
10
- ? _profiled.ProfiledComponent
9
+ _profiled = actual;
10
+ profiled = "ProfiledComponent" in _profiled ?
11
+ _profiled.ProfiledComponent
11
12
  : _profiled;
12
13
  hint = this.utils.matcherHint("toRerender");
13
14
  pass = true;
14
15
  _a.label = 1;
15
16
  case 1:
16
17
  _a.trys.push([1, 3, , 4]);
17
- return [4, profiled.peekRender(__assign({ timeout: 100 }, options))];
18
+ return [4 /*yield*/, profiled.peekRender(__assign({ timeout: 100 }, options))];
18
19
  case 2:
19
20
  _a.sent();
20
- return [3, 4];
21
+ return [3 /*break*/, 4];
21
22
  case 3:
22
23
  e_1 = _a.sent();
23
24
  if (e_1 instanceof WaitForRenderTimeoutError) {
@@ -26,8 +27,8 @@ export var toRerender = function (_profiled, options) {
26
27
  else {
27
28
  throw e_1;
28
29
  }
29
- return [3, 4];
30
- case 4: return [2, {
30
+ return [3 /*break*/, 4];
31
+ case 4: return [2 /*return*/, {
31
32
  pass: pass,
32
33
  message: function () {
33
34
  return (hint +
@@ -39,13 +40,15 @@ export var toRerender = function (_profiled, options) {
39
40
  });
40
41
  });
41
42
  };
43
+ /** to be thrown to "break" test execution and fail it */
42
44
  var failed = {};
43
- export var toRenderExactlyTimes = function (_profiled, times, optionsPerRender) {
45
+ export var toRenderExactlyTimes = function (actual, times, optionsPerRender) {
44
46
  return __awaiter(this, void 0, void 0, function () {
45
- var profiled, options, hint, pass, e_2, e_3, e_4;
47
+ var _profiled, profiled, options, hint, pass, e_2, e_3, e_4;
46
48
  return __generator(this, function (_a) {
47
49
  switch (_a.label) {
48
50
  case 0:
51
+ _profiled = actual;
49
52
  profiled = "ProfiledComponent" in _profiled ? _profiled.ProfiledComponent : _profiled;
50
53
  options = __assign({ timeout: 100 }, optionsPerRender);
51
54
  hint = this.utils.matcherHint("toRenderExactlyTimes");
@@ -53,7 +56,7 @@ export var toRenderExactlyTimes = function (_profiled, times, optionsPerRender)
53
56
  _a.label = 1;
54
57
  case 1:
55
58
  _a.trys.push([1, 11, , 12]);
56
- if (profiled.currentRenderCount() > times) {
59
+ if (profiled.totalRenderCount() > times) {
57
60
  throw failed;
58
61
  }
59
62
  _a.label = 2;
@@ -61,28 +64,30 @@ export var toRenderExactlyTimes = function (_profiled, times, optionsPerRender)
61
64
  _a.trys.push([2, 6, , 7]);
62
65
  _a.label = 3;
63
66
  case 3:
64
- if (!(profiled.currentRenderCount() < times)) return [3, 5];
65
- return [4, profiled.waitForNextRender(options)];
67
+ if (!(profiled.totalRenderCount() < times)) return [3 /*break*/, 5];
68
+ return [4 /*yield*/, profiled.waitForNextRender(options)];
66
69
  case 4:
67
70
  _a.sent();
68
- return [3, 3];
69
- case 5: return [3, 7];
71
+ return [3 /*break*/, 3];
72
+ case 5: return [3 /*break*/, 7];
70
73
  case 6:
71
74
  e_2 = _a.sent();
75
+ // timeouts here should just fail the test, rethrow other errors
72
76
  throw e_2 instanceof WaitForRenderTimeoutError ? failed : e_2;
73
77
  case 7:
74
78
  _a.trys.push([7, 9, , 10]);
75
- return [4, profiled.waitForNextRender(options)];
79
+ return [4 /*yield*/, profiled.waitForNextRender(options)];
76
80
  case 8:
77
81
  _a.sent();
78
- return [3, 10];
82
+ return [3 /*break*/, 10];
79
83
  case 9:
80
84
  e_3 = _a.sent();
85
+ // we are expecting a timeout here, so swallow that error, rethrow others
81
86
  if (!(e_3 instanceof WaitForRenderTimeoutError)) {
82
87
  throw e_3;
83
88
  }
84
- return [3, 10];
85
- case 10: return [3, 12];
89
+ return [3 /*break*/, 10];
90
+ case 10: return [3 /*break*/, 12];
86
91
  case 11:
87
92
  e_4 = _a.sent();
88
93
  if (e_4 === failed) {
@@ -91,13 +96,13 @@ export var toRenderExactlyTimes = function (_profiled, times, optionsPerRender)
91
96
  else {
92
97
  throw e_4;
93
98
  }
94
- return [3, 12];
95
- case 12: return [2, {
99
+ return [3 /*break*/, 12];
100
+ case 12: return [2 /*return*/, {
96
101
  pass: pass,
97
102
  message: function () {
98
103
  return (hint +
99
104
  " Expected component to".concat(pass ? " not" : "", " render exactly ").concat(times, ".") +
100
- " It rendered ".concat(profiled.currentRenderCount(), " times."));
105
+ " It rendered ".concat(profiled.totalRenderCount(), " times."));
101
106
  },
102
107
  }];
103
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ProfiledComponent.js","sourceRoot":"","sources":["../../../src/testing/matchers/ProfiledComponent.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAMjE,MAAM,CAAC,IAAM,UAAU,GACrB,UACE,SAA+D,EAC/D,OAA2B;;;;;;oBAErB,QAAQ,GACZ,mBAAmB,IAAI,SAAS;wBAC9B,CAAC,CAAC,SAAS,CAAC,iBAAiB;wBAC7B,CAAC,CAAC,SAAS,CAAC;oBACV,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;oBAC9C,IAAI,GAAG,IAAI,CAAC;;;;oBAEd,WAAM,QAAQ,CAAC,UAAU,YAAG,OAAO,EAAE,GAAG,IAAK,OAAO,EAAG,EAAA;;oBA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C;;;;oBAG1C,IAAI,CAAC,CAAC,GAAC,YAAY,yBAAyB,CAAC,EAAE;wBAC7C,MAAM,GAAC,CAAC;qBACT;;;;;oBAGH,IAAI,GAAC,KAAK,MAAM,EAAE;wBAChB,IAAI,GAAG,KAAK,CAAC;qBACd;yBAAM;wBACL,MAAM,GAAC,CAAC;qBACT;;yBAEH,WAAO;wBACL,IAAI,MAAA;wBACJ,OAAO;4BACL,OAAO,CACL,IAAI;gCACJ,gCAAyB,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,6BAAmB,KAAK,MAAG;gCACtE,uBAAgB,QAAQ,CAAC,kBAAkB,EAAE,YAAS,CACvD,CAAC;wBACJ,CAAC;qBACF,EAAC;;;;CACH,CAAC","sourcesContent":["import type { MatcherFunction } from \"expect\";\nimport { WaitForRenderTimeoutError } from \"../internal/index.js\";\nimport type {\n NextRenderOptions,\n ProfiledComponent,\n ProfiledHook,\n} from \"../internal/index.js\";\nexport const toRerender: MatcherFunction<[options?: NextRenderOptions]> =\n async function (\n _profiled: ProfiledComponent<any, any> | ProfiledHook<any, any>,\n options?: NextRenderOptions\n ) {\n const profiled =\n \"ProfiledComponent\" in _profiled\n ? _profiled.ProfiledComponent\n : _profiled;\n const hint = this.utils.matcherHint(\"toRerender\");\n let pass = true;\n try {\n await profiled.peekRender({ timeout: 100, ...options });\n } catch (e) {\n if (e instanceof WaitForRenderTimeoutError) {\n pass = false;\n } else {\n throw e;\n }\n }\n return {\n pass,\n message() {\n return (\n hint +\n ` Expected component to${pass ? \" not\" : \"\"} rerender, ` +\n `but it did${pass ? \"\" : \" not\"}.`\n );\n },\n };\n };\n\n/** to be thrown to \"break\" test execution and fail it */\nconst failed = {};\n\nexport const toRenderExactlyTimes: MatcherFunction<\n [times: number, options?: NextRenderOptions]\n> = async function (\n _profiled: ProfiledComponent<any, any> | ProfiledHook<any, any>,\n times: number,\n optionsPerRender?: NextRenderOptions\n) {\n const profiled =\n \"ProfiledComponent\" in _profiled ? _profiled.ProfiledComponent : _profiled;\n const options = { timeout: 100, ...optionsPerRender };\n const hint = this.utils.matcherHint(\"toRenderExactlyTimes\");\n let pass = true;\n try {\n if (profiled.currentRenderCount() > times) {\n throw failed;\n }\n try {\n while (profiled.currentRenderCount() < times) {\n await profiled.waitForNextRender(options);\n }\n } catch (e) {\n // timeouts here should just fail the test, rethrow other errors\n throw e instanceof WaitForRenderTimeoutError ? failed : e;\n }\n try {\n await profiled.waitForNextRender(options);\n } catch (e) {\n // we are expecting a timeout here, so swallow that error, rethrow others\n if (!(e instanceof WaitForRenderTimeoutError)) {\n throw e;\n }\n }\n } catch (e) {\n if (e === failed) {\n pass = false;\n } else {\n throw e;\n }\n }\n return {\n pass,\n message() {\n return (\n hint +\n ` Expected component to${pass ? \" not\" : \"\"} render exactly ${times}.` +\n ` It rendered ${profiled.currentRenderCount()} times.`\n );\n },\n };\n};\n"]}
1
+ {"version":3,"file":"ProfiledComponent.js","sourceRoot":"","sources":["../../../src/testing/matchers/ProfiledComponent.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAMjE,MAAM,CAAC,IAAM,UAAU,GACrB,UAAgB,MAAM,EAAE,OAAO;;;;;;oBACvB,SAAS,GAAG,MAEQ,CAAC;oBACrB,QAAQ,GACZ,mBAAmB,IAAI,SAAS,CAAC,CAAC;wBAChC,SAAS,CAAC,iBAAiB;wBAC7B,CAAC,CAAC,SAAS,CAAC;oBACR,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;oBAC9C,IAAI,GAAG,IAAI,CAAC;;;;oBAEd,qBAAM,QAAQ,CAAC,UAAU,YAAG,OAAO,EAAE,GAAG,IAAK,OAAO,EAAG,EAAA;;oBAAvD,SAAuD,CAAC;;;;oBAExD,IAAI,GAAC,YAAY,yBAAyB,EAAE,CAAC;wBAC3C,IAAI,GAAG,KAAK,CAAC;oBACf,CAAC;yB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C,yEAAyE;oBACzE,IAAI,CAAC,CAAC,GAAC,YAAY,yBAAyB,CAAC,EAAE,CAAC;wBAC9C,MAAM,GAAC,CAAC;oBACV,CAAC;;;;;oBAGH,IAAI,GAAC,KAAK,MAAM,EAAE,CAAC;wBACjB,IAAI,GAAG,KAAK,CAAC;oBACf,CAAC;yBAAM,CAAC;wBACN,MAAM,GAAC,CAAC;oBACV,CAAC;;yBAEH,sBAAO;wBACL,IAAI,MAAA;wBACJ,OAAO;4BACL,OAAO,CACL,IAAI;gCACJ,gCAAyB,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,6BAAmB,KAAK,MAAG;gCACtE,uBAAgB,QAAQ,CAAC,gBAAgB,EAAE,YAAS,CACrD,CAAC;wBACJ,CAAC;qBACF,EAAC;;;;CACH,CAAC","sourcesContent":["import type { MatcherFunction } from \"expect\";\nimport { WaitForRenderTimeoutError } from \"../internal/index.js\";\nimport type {\n NextRenderOptions,\n ProfiledComponent,\n ProfiledHook,\n} from \"../internal/index.js\";\nexport const toRerender: MatcherFunction<[options?: NextRenderOptions]> =\n async function (actual, options) {\n const _profiled = actual as\n | ProfiledComponent<any, any>\n | ProfiledHook<any, any>;\n const profiled =\n \"ProfiledComponent\" in _profiled ?\n _profiled.ProfiledComponent\n : _profiled;\n const hint = this.utils.matcherHint(\"toRerender\");\n let pass = true;\n try {\n await profiled.peekRender({ timeout: 100, ...options });\n } catch (e) {\n if (e instanceof WaitForRenderTimeoutError) {\n pass = false;\n } else {\n throw e;\n }\n }\n return {\n pass,\n message() {\n return (\n hint +\n ` Expected component to${pass ? \" not\" : \"\"} rerender, ` +\n `but it did${pass ? \"\" : \" not\"}.`\n );\n },\n };\n };\n\n/** to be thrown to \"break\" test execution and fail it */\nconst failed = {};\n\nexport const toRenderExactlyTimes: MatcherFunction<\n [times: number, options?: NextRenderOptions]\n> = async function (actual, times, optionsPerRender) {\n const _profiled = actual as\n | ProfiledComponent<any, any>\n | ProfiledHook<any, any>;\n const profiled =\n \"ProfiledComponent\" in _profiled ? _profiled.ProfiledComponent : _profiled;\n const options = { timeout: 100, ...optionsPerRender };\n const hint = this.utils.matcherHint(\"toRenderExactlyTimes\");\n let pass = true;\n try {\n if (profiled.totalRenderCount() > times) {\n throw failed;\n }\n try {\n while (profiled.totalRenderCount() < times) {\n await profiled.waitForNextRender(options);\n }\n } catch (e) {\n // timeouts here should just fail the test, rethrow other errors\n throw e instanceof WaitForRenderTimeoutError ? failed : e;\n }\n try {\n await profiled.waitForNextRender(options);\n } catch (e) {\n // we are expecting a timeout here, so swallow that error, rethrow others\n if (!(e instanceof WaitForRenderTimeoutError)) {\n throw e;\n }\n }\n } catch (e) {\n if (e === failed) {\n pass = false;\n } else {\n throw e;\n }\n }\n return {\n pass,\n message() {\n return (\n hint +\n ` Expected component to${pass ? \" not\" : \"\"} render exactly ${times}.` +\n ` It rendered ${profiled.totalRenderCount()} times.`\n );\n },\n };\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"toHaveSuspenseCacheEntryUsing.js","sourceRoot":"","sources":["../../../src/testing/matchers/toHaveSuspenseCacheEntryUsing.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG9D,MAAM,CAAC,IAAM,6BAA6B,GAQtC,UACF,MAAM,EACN,KAAK,EACL,EAAkD;;QAAlD,qBAA+B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAA,EAAhD,SAAS,eAAA,EAAE,gBAAa,EAAb,QAAQ,mBAAG,EAAE,KAAA;IAE1B,IAAI,CAAC,CAAC,MAAM,YAAY,YAAY,CAAC,EAAE;QACrC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;KACjE;IAED,IAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAE/C,IAAM,QAAQ;QACZ,KAAK;QACL,kBAAkB,CAAC,SAAS,CAAC;OACzB,EAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,OAClC,CAAC;IACF,IAAM,QAAQ,GAAG,MAAA,aAAa,CAAC,WAAW,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,0CAAE,OAAO,CAAC;IAE3E,OAAO;QACL,IAAI,EAAE,CAAC,CAAC,QAAQ;QAChB,OAAO,EAAE;YACP,OAAO,kCACL,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,kCACO,CAAC;QAClC,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { MatcherFunction } from \"expect\";\nimport type { DocumentNode } from \"graphql\";\nimport type { OperationVariables } from \"../../core/index.js\";\nimport { ApolloClient } from \"../../core/index.js\";\nimport { canonicalStringify } from \"../../cache/index.js\";\nimport { getSuspenseCache } from \"../../react/cache/index.js\";\nimport type { CacheKey } from \"../../react/cache/types.js\";\n\nexport const toHaveSuspenseCacheEntryUsing: MatcherFunction<\n [\n query: DocumentNode,\n options: {\n variables?: OperationVariables;\n queryKey?: string | number | any[];\n },\n ]\n> = function (\n client,\n query,\n { variables, queryKey = [] } = Object.create(null)\n) {\n if (!(client instanceof ApolloClient)) {\n throw new Error(\"Actual must be an instance of `ApolloClient`\");\n }\n\n const suspenseCache = getSuspenseCache(client);\n\n const cacheKey: CacheKey = [\n query,\n canonicalStringify(variables),\n ...([] as any[]).concat(queryKey),\n ];\n const queryRef = suspenseCache[\"queryRefs\"].lookupArray(cacheKey)?.current;\n\n return {\n pass: !!queryRef,\n message: () => {\n return `Expected suspense cache ${\n queryRef ? \"not \" : \"\"\n }to have cache entry using key`;\n },\n };\n};\n"]}
1
+ {"version":3,"file":"toHaveSuspenseCacheEntryUsing.js","sourceRoot":"","sources":["../../../src/testing/matchers/toHaveSuspenseCacheEntryUsing.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG9D,MAAM,CAAC,IAAM,6BAA6B,GAQtC,UACF,MAAM,EACN,KAAK,EACL,EAAkD;;QAAlD,qBAA+B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAA,EAAhD,SAAS,eAAA,EAAE,gBAAa,EAAb,QAAQ,mBAAG,EAAE,KAAA;IAE1B,IAAI,CAAC,CAAC,MAAM,YAAY,YAAY,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,IAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAE/C,IAAM,QAAQ;QACZ,KAAK;QACL,kBAAkB,CAAC,SAAS,CAAC;OACzB,EAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,OAClC,CAAC;IACF,IAAM,QAAQ,GAAG,MAAA,aAAa,CAAC,WAAW,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,0CAAE,OAAO,CAAC;IAE3E,OAAO;QACL,IAAI,EAAE,CAAC,CAAC,QAAQ;QAChB,OAAO,EAAE;YACP,OAAO,kCACL,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,kCACO,CAAC;QAClC,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { MatcherFunction } from \"expect\";\nimport type { DocumentNode } from \"graphql\";\nimport type { OperationVariables } from \"../../core/index.js\";\nimport { ApolloClient } from \"../../core/index.js\";\nimport { canonicalStringify } from \"../../cache/index.js\";\nimport { getSuspenseCache } from \"../../react/cache/index.js\";\nimport type { CacheKey } from \"../../react/cache/types.js\";\n\nexport const toHaveSuspenseCacheEntryUsing: MatcherFunction<\n [\n query: DocumentNode,\n options: {\n variables?: OperationVariables;\n queryKey?: string | number | any[];\n },\n ]\n> = function (\n client,\n query,\n { variables, queryKey = [] } = Object.create(null)\n) {\n if (!(client instanceof ApolloClient)) {\n throw new Error(\"Actual must be an instance of `ApolloClient`\");\n }\n\n const suspenseCache = getSuspenseCache(client);\n\n const cacheKey: CacheKey = [\n query,\n canonicalStringify(variables),\n ...([] as any[]).concat(queryKey),\n ];\n const queryRef = suspenseCache[\"queryRefs\"].lookupArray(cacheKey)?.current;\n\n return {\n pass: !!queryRef,\n message: () => {\n return `Expected suspense cache ${\n queryRef ? \"not \" : \"\"\n }to have cache entry using key`;\n },\n };\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"toMatchDocument.js","sourceRoot":"","sources":["../../../src/testing/matchers/toMatchDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAIhE,MAAM,CAAC,IAAM,eAAe,GAC1B,UAAU,MAAM,EAAE,QAAQ;IAA1B,iBA+CC;IA9CC,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;IACvD,IAAM,cAAc,GAAG,KAAK,CAC1B,gBAAgB,CACd,MAAM,EACN,IAAI;QACF,cAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAC9B,UAAU,CACX,yCAAsC,CAC1C,CACF,CAAC;IACF,IAAM,gBAAgB,GAAG,KAAK,CAC5B,gBAAgB,CACd,QAAQ,EACR,IAAI;QACF,cAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAC9B,UAAU,CACX,yCAAsC,CAC1C,CACF,CAAC;IAEF,IAAM,IAAI,GAAG,cAAc,KAAK,gBAAgB,CAAC;IAEjD,OAAO;QACL,IAAI,MAAA;QACJ,OAAO,EAAE;YACP,IAAM,IAAI,GAAG,KAAI,CAAC,KAAK,CAAC,WAAW,CACjC,iBAAiB,EACjB,SAAS,EACT,SAAS,EACT,EAAE,KAAK,EAAE,KAAI,CAAC,KAAK,EAAE,CACtB,CAAC;YAEF,IAAI,IAAI,EAAE;gBACR,OAAO,CACL,IAAI;oBACJ,MAAM;oBACN,eAAe;oBACf,KAAI,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAC1C,CAAC;aACH;YAED,OAAO,CACL,IAAI,GAAG,MAAM,GAAG,KAAI,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAClE,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEJ,SAAS,gBAAgB,CAAC,QAAiB,EAAE,OAAe;IAC1D,IAAI;QACF,aAAa,CAAC,QAAwB,CAAC,CAAC;KACzC;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;KAC1B;IAED,OAAO,QAAwB,CAAC;AAClC,CAAC","sourcesContent":["import { checkDocument, print } from \"../../utilities/index.js\";\nimport type { DocumentNode } from \"../../core/index.js\";\nimport type { MatcherFunction } from \"expect\";\n\nexport const toMatchDocument: MatcherFunction<[document: DocumentNode]> =\n function (actual, document) {\n const hint = this.utils.matcherHint(\"toMatchDocument\");\n const actualDocument = print(\n validateDocument(\n actual,\n hint +\n `\\n\\n${this.utils.RECEIVED_COLOR(\n \"received\"\n )} document must be a parsed document.`\n )\n );\n const expectedDocument = print(\n validateDocument(\n document,\n hint +\n `\\n\\n${this.utils.EXPECTED_COLOR(\n \"expected\"\n )} document must be a parsed document.`\n )\n );\n\n const pass = actualDocument === expectedDocument;\n\n return {\n pass,\n message: () => {\n const hint = this.utils.matcherHint(\n \"toMatchDocument\",\n undefined,\n undefined,\n { isNot: this.isNot }\n );\n\n if (pass) {\n return (\n hint +\n \"\\n\\n\" +\n \"Received:\\n\\n\" +\n this.utils.RECEIVED_COLOR(actualDocument)\n );\n }\n\n return (\n hint + \"\\n\\n\" + this.utils.diff(expectedDocument, actualDocument)\n );\n },\n };\n };\n\nfunction validateDocument(document: unknown, message: string) {\n try {\n checkDocument(document as DocumentNode);\n } catch (e) {\n throw new Error(message);\n }\n\n return document as DocumentNode;\n}\n"]}
1
+ {"version":3,"file":"toMatchDocument.js","sourceRoot":"","sources":["../../../src/testing/matchers/toMatchDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAIhE,MAAM,CAAC,IAAM,eAAe,GAC1B,UAAU,MAAM,EAAE,QAAQ;IAA1B,iBA+CC;IA9CC,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;IACvD,IAAM,cAAc,GAAG,KAAK,CAC1B,gBAAgB,CACd,MAAM,EACN,IAAI;QACF,cAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAC9B,UAAU,CACX,yCAAsC,CAC1C,CACF,CAAC;IACF,IAAM,gBAAgB,GAAG,KAAK,CAC5B,gBAAgB,CACd,QAAQ,EACR,IAAI;QACF,cAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAC9B,UAAU,CACX,yCAAsC,CAC1C,CACF,CAAC;IAEF,IAAM,IAAI,GAAG,cAAc,KAAK,gBAAgB,CAAC;IAEjD,OAAO;QACL,IAAI,MAAA;QACJ,OAAO,EAAE;YACP,IAAM,IAAI,GAAG,KAAI,CAAC,KAAK,CAAC,WAAW,CACjC,iBAAiB,EACjB,SAAS,EACT,SAAS,EACT,EAAE,KAAK,EAAE,KAAI,CAAC,KAAK,EAAE,CACtB,CAAC;YAEF,IAAI,IAAI,EAAE,CAAC;gBACT,OAAO,CACL,IAAI;oBACJ,MAAM;oBACN,eAAe;oBACf,KAAI,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAC1C,CAAC;YACJ,CAAC;YAED,OAAO,CACL,IAAI,GAAG,MAAM,GAAG,KAAI,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAClE,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEJ,SAAS,gBAAgB,CAAC,QAAiB,EAAE,OAAe;IAC1D,IAAI,CAAC;QACH,aAAa,CAAC,QAAwB,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,QAAwB,CAAC;AAClC,CAAC","sourcesContent":["import { checkDocument, print } from \"../../utilities/index.js\";\nimport type { DocumentNode } from \"../../core/index.js\";\nimport type { MatcherFunction } from \"expect\";\n\nexport const toMatchDocument: MatcherFunction<[document: DocumentNode]> =\n function (actual, document) {\n const hint = this.utils.matcherHint(\"toMatchDocument\");\n const actualDocument = print(\n validateDocument(\n actual,\n hint +\n `\\n\\n${this.utils.RECEIVED_COLOR(\n \"received\"\n )} document must be a parsed document.`\n )\n );\n const expectedDocument = print(\n validateDocument(\n document,\n hint +\n `\\n\\n${this.utils.EXPECTED_COLOR(\n \"expected\"\n )} document must be a parsed document.`\n )\n );\n\n const pass = actualDocument === expectedDocument;\n\n return {\n pass,\n message: () => {\n const hint = this.utils.matcherHint(\n \"toMatchDocument\",\n undefined,\n undefined,\n { isNot: this.isNot }\n );\n\n if (pass) {\n return (\n hint +\n \"\\n\\n\" +\n \"Received:\\n\\n\" +\n this.utils.RECEIVED_COLOR(actualDocument)\n );\n }\n\n return (\n hint + \"\\n\\n\" + this.utils.diff(expectedDocument, actualDocument)\n );\n },\n };\n };\n\nfunction validateDocument(document: unknown, message: string) {\n try {\n checkDocument(document as DocumentNode);\n } catch (e) {\n throw new Error(message);\n }\n\n return document as DocumentNode;\n}\n"]}
@@ -15,6 +15,10 @@ export interface MockedProviderProps<TSerializedCache = {}> {
15
15
  children?: any;
16
16
  link?: ApolloLink;
17
17
  showWarnings?: boolean;
18
+ /**
19
+ * If set to true, the MockedProvider will try to connect to the Apollo DevTools.
20
+ * Defaults to false.
21
+ */
18
22
  connectToDevTools?: boolean;
19
23
  }
20
24
  export interface MockedProviderState {
@@ -4,7 +4,7 @@ import { ApolloClient } from "../../core/index.js";
4
4
  import { InMemoryCache as Cache } from "../../cache/index.js";
5
5
  import { ApolloProvider } from "../../react/context/index.js";
6
6
  import { MockLink } from "../core/index.js";
7
- var MockedProvider = (function (_super) {
7
+ var MockedProvider = /** @class */ (function (_super) {
8
8
  __extends(MockedProvider, _super);
9
9
  function MockedProvider(props) {
10
10
  var _this = _super.call(this, props) || this;
@@ -24,9 +24,13 @@ var MockedProvider = (function (_super) {
24
24
  MockedProvider.prototype.render = function () {
25
25
  var _a = this.props, children = _a.children, childProps = _a.childProps;
26
26
  var client = this.state.client;
27
- return React.isValidElement(children) ? (React.createElement(ApolloProvider, { client: client }, React.cloneElement(React.Children.only(children), __assign({}, childProps)))) : null;
27
+ return React.isValidElement(children) ?
28
+ React.createElement(ApolloProvider, { client: client }, React.cloneElement(React.Children.only(children), __assign({}, childProps)))
29
+ : null;
28
30
  };
29
31
  MockedProvider.prototype.componentWillUnmount = function () {
32
+ // Since this.state.client was created in the constructor, it's this
33
+ // MockedProvider's responsibility to terminate it.
30
34
  this.state.client.stop();
31
35
  };
32
36
  MockedProvider.defaultProps = {
@@ -1 +1 @@
1
- {"version":3,"file":"MockedProvider.js","sourceRoot":"","sources":["../../../src/testing/react/MockedProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AA0B5C;IAAoC,kCAGnC;IAKC,wBAAY,KAA0B;QAAtC,YACE,kBAAM,KAAK,CAAC,SAuBb;QArBO,IAAA,KASF,KAAI,CAAC,K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from \"react\";\n\nimport type { DefaultOptions } from \"../../core/index.js\";\nimport { ApolloClient } from \"../../core/index.js\";\nimport { InMemoryCache as Cache } from \"../../cache/index.js\";\nimport { ApolloProvider } from \"../../react/context/index.js\";\nimport type { MockedResponse } from \"../core/index.js\";\nimport { MockLink } from \"../core/index.js\";\nimport type { ApolloLink } from \"../../link/core/index.js\";\nimport type { Resolvers } from \"../../core/index.js\";\nimport type { ApolloCache } from \"../../cache/index.js\";\n\nexport interface MockedProviderProps<TSerializedCache = {}> {\n mocks?: ReadonlyArray<MockedResponse>;\n addTypename?: boolean;\n defaultOptions?: DefaultOptions;\n cache?: ApolloCache<TSerializedCache>;\n resolvers?: Resolvers;\n childProps?: object;\n children?: any;\n link?: ApolloLink;\n showWarnings?: boolean;\n /**\n * If set to true, the MockedProvider will try to connect to the Apollo DevTools.\n * Defaults to false.\n */\n connectToDevTools?: boolean;\n}\n\nexport interface MockedProviderState {\n client: ApolloClient<any>;\n}\n\nexport class MockedProvider extends React.Component<\n MockedProviderProps,\n MockedProviderState\n> {\n public static defaultProps: MockedProviderProps = {\n addTypename: true,\n };\n\n constructor(props: MockedProviderProps) {\n super(props);\n\n const {\n mocks,\n addTypename,\n defaultOptions,\n cache,\n resolvers,\n link,\n showWarnings,\n connectToDevTools = false,\n } = this.props;\n const client = new ApolloClient({\n cache: cache || new Cache({ addTypename }),\n defaultOptions,\n connectToDevTools,\n link: link || new MockLink(mocks || [], addTypename, { showWarnings }),\n resolvers,\n });\n\n this.state = {\n client,\n };\n }\n\n public render() {\n const { children, childProps } = this.props;\n const { client } = this.state;\n\n return React.isValidElement(children) ? (\n <ApolloProvider client={client}>\n {React.cloneElement(React.Children.only(children), { ...childProps })}\n </ApolloProvider>\n ) : null;\n }\n\n public componentWillUnmount() {\n // Since this.state.client was created in the constructor, it's this\n // MockedProvider's responsibility to terminate it.\n this.state.client.stop();\n }\n}\n"]}
1
+ {"version":3,"file":"MockedProvider.js","sourceRoot":"","sources":["../../../src/testing/react/M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,IAC3B,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAO,UAAU,EAAG,CACtD;YACnB,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;IAEM,6CAAoB,GAA3B;QACE,oEAAoE;QACpE,mDAAmD;QACnD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;IA7Ca,2BAAY,GAAwB;QAChD,WAAW,EAAE,IAAI;KAClB,CAAC;IA4CJ,qBAAC;CAAA,AAlDD,CAAoC,KAAK,CAAC,SAAS,GAkDlD;SAlDY,cAAc","sourcesContent":["import * as React from \"react\";\n\nimport type { DefaultOptions } from \"../../core/index.js\";\nimport { ApolloClient } from \"../../core/index.js\";\nimport { InMemoryCache as Cache } from \"../../cache/index.js\";\nimport { ApolloProvider } from \"../../react/context/index.js\";\nimport type { MockedResponse } from \"../core/index.js\";\nimport { MockLink } from \"../core/index.js\";\nimport type { ApolloLink } from \"../../link/core/index.js\";\nimport type { Resolvers } from \"../../core/index.js\";\nimport type { ApolloCache } from \"../../cache/index.js\";\n\nexport interface MockedProviderProps<TSerializedCache = {}> {\n mocks?: ReadonlyArray<MockedResponse>;\n addTypename?: boolean;\n defaultOptions?: DefaultOptions;\n cache?: ApolloCache<TSerializedCache>;\n resolvers?: Resolvers;\n childProps?: object;\n children?: any;\n link?: ApolloLink;\n showWarnings?: boolean;\n /**\n * If set to true, the MockedProvider will try to connect to the Apollo DevTools.\n * Defaults to false.\n */\n connectToDevTools?: boolean;\n}\n\nexport interface MockedProviderState {\n client: ApolloClient<any>;\n}\n\nexport class MockedProvider extends React.Component<\n MockedProviderProps,\n MockedProviderState\n> {\n public static defaultProps: MockedProviderProps = {\n addTypename: true,\n };\n\n constructor(props: MockedProviderProps) {\n super(props);\n\n const {\n mocks,\n addTypename,\n defaultOptions,\n cache,\n resolvers,\n link,\n showWarnings,\n connectToDevTools = false,\n } = this.props;\n const client = new ApolloClient({\n cache: cache || new Cache({ addTypename }),\n defaultOptions,\n connectToDevTools,\n link: link || new MockLink(mocks || [], addTypename, { showWarnings }),\n resolvers,\n });\n\n this.state = {\n client,\n };\n }\n\n public render() {\n const { children, childProps } = this.props;\n const { client } = this.state;\n\n return React.isValidElement(children) ?\n <ApolloProvider client={client}>\n {React.cloneElement(React.Children.only(children), { ...childProps })}\n </ApolloProvider>\n : null;\n }\n\n public componentWillUnmount() {\n // Since this.state.client was created in the constructor, it's this\n // MockedProvider's responsibility to terminate it.\n this.state.client.stop();\n }\n}\n"]}