@apollo/client 3.8.7 → 3.8.8

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 (609) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/config.json +14 -0
  3. package/CHANGELOG.md +3357 -0
  4. package/apollo-client.cjs +314 -316
  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.js.map +1 -1
  120. package/link/http/createHttpLink.js +23 -1
  121. package/link/http/createHttpLink.js.map +1 -1
  122. package/link/http/createSignalIfSupported.d.ts +5 -0
  123. package/link/http/createSignalIfSupported.js +5 -0
  124. package/link/http/createSignalIfSupported.js.map +1 -1
  125. package/link/http/http.cjs +14 -12
  126. package/link/http/http.cjs.map +1 -1
  127. package/link/http/http.cjs.native.js +14 -12
  128. package/link/http/index.js +2 -1
  129. package/link/http/index.js.map +1 -1
  130. package/link/http/iterators/async.d.ts +4 -0
  131. package/link/http/iterators/async.js +4 -0
  132. package/link/http/iterators/async.js.map +1 -1
  133. package/link/http/iterators/nodeStream.d.ts +4 -0
  134. package/link/http/iterators/nodeStream.js +4 -0
  135. package/link/http/iterators/nodeStream.js.map +1 -1
  136. package/link/http/iterators/promise.d.ts +4 -0
  137. package/link/http/iterators/promise.js +4 -0
  138. package/link/http/iterators/promise.js.map +1 -1
  139. package/link/http/iterators/reader.d.ts +4 -0
  140. package/link/http/iterators/reader.js +4 -0
  141. package/link/http/iterators/reader.js.map +1 -1
  142. package/link/http/parseAndCheckHttpResponse.js +51 -10
  143. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  144. package/link/http/responseIterator.d.ts +4 -0
  145. package/link/http/responseIterator.js +6 -0
  146. package/link/http/responseIterator.js.map +1 -1
  147. package/link/http/rewriteURIForGET.d.ts +1 -1
  148. package/link/http/rewriteURIForGET.js +10 -0
  149. package/link/http/rewriteURIForGET.js.map +1 -1
  150. package/link/http/selectHttpOptionsAndBody.d.ts +45 -0
  151. package/link/http/selectHttpOptionsAndBody.js +23 -0
  152. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  153. package/link/http/selectURI.js.map +1 -1
  154. package/link/http/serializeFetchParameter.js.map +1 -1
  155. package/link/persisted-queries/index.js +34 -4
  156. package/link/persisted-queries/index.js.map +1 -1
  157. package/link/persisted-queries/persisted-queries.cjs +4 -4
  158. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  159. package/link/persisted-queries/persisted-queries.cjs.native.js +4 -4
  160. package/link/remove-typename/remove-typename.cjs +12 -9
  161. package/link/remove-typename/remove-typename.cjs.map +1 -1
  162. package/link/remove-typename/remove-typename.cjs.native.js +12 -9
  163. package/link/remove-typename/removeTypenameFromVariables.js +12 -9
  164. package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
  165. package/link/retry/delayFunction.d.ts +29 -0
  166. package/link/retry/delayFunction.js +6 -0
  167. package/link/retry/delayFunction.js.map +1 -1
  168. package/link/retry/retry.cjs +5 -5
  169. package/link/retry/retry.cjs.map +1 -1
  170. package/link/retry/retry.cjs.native.js +5 -5
  171. package/link/retry/retryFunction.d.ts +20 -0
  172. package/link/retry/retryLink.d.ts +6 -0
  173. package/link/retry/retryLink.js +31 -6
  174. package/link/retry/retryLink.js.map +1 -1
  175. package/link/schema/index.d.ts +13 -0
  176. package/link/schema/index.js +3 -3
  177. package/link/schema/index.js.map +1 -1
  178. package/link/schema/schema.cjs +3 -3
  179. package/link/schema/schema.cjs.map +1 -1
  180. package/link/schema/schema.cjs.native.js +3 -3
  181. package/link/subscriptions/index.js +35 -2
  182. package/link/subscriptions/index.js.map +1 -1
  183. package/link/subscriptions/subscriptions.cjs +3 -2
  184. package/link/subscriptions/subscriptions.cjs.map +1 -1
  185. package/link/subscriptions/subscriptions.cjs.native.js +3 -2
  186. package/link/utils/createOperation.js.map +1 -1
  187. package/link/utils/filterOperationVariables.js +4 -0
  188. package/link/utils/filterOperationVariables.js.map +1 -1
  189. package/link/utils/toPromise.js.map +1 -1
  190. package/link/utils/transformOperation.js +3 -2
  191. package/link/utils/transformOperation.js.map +1 -1
  192. package/link/utils/utils.cjs +2 -2
  193. package/link/utils/utils.cjs.map +1 -1
  194. package/link/utils/utils.cjs.native.js +2 -2
  195. package/link/utils/validateOperation.js.map +1 -1
  196. package/link/ws/index.d.ts +12 -0
  197. package/link/ws/index.js +1 -1
  198. package/link/ws/index.js.map +1 -1
  199. package/link/ws/ws.cjs +1 -1
  200. package/link/ws/ws.cjs.map +1 -1
  201. package/link/ws/ws.cjs.native.js +1 -1
  202. package/package.json +49 -38
  203. package/react/cache/QueryReference.d.ts +6 -1
  204. package/react/cache/QueryReference.js +26 -1
  205. package/react/cache/QueryReference.js.map +1 -1
  206. package/react/cache/SuspenseCache.d.ts +10 -0
  207. package/react/cache/SuspenseCache.js +1 -1
  208. package/react/cache/SuspenseCache.js.map +1 -1
  209. package/react/cache/getSuspenseCache.js.map +1 -1
  210. package/react/context/ApolloContext.d.ts +5 -0
  211. package/react/context/ApolloContext.js +10 -3
  212. package/react/context/ApolloContext.js.map +1 -1
  213. package/react/context/context.cjs +1 -3
  214. package/react/context/context.cjs.map +1 -1
  215. package/react/context/context.cjs.native.js +1 -3
  216. package/react/hoc/graphql.js.map +1 -1
  217. package/react/hoc/hoc-utils.js +3 -1
  218. package/react/hoc/hoc-utils.js.map +1 -1
  219. package/react/hoc/hoc.cjs +9 -17
  220. package/react/hoc/hoc.cjs.map +1 -1
  221. package/react/hoc/hoc.cjs.native.js +9 -17
  222. package/react/hoc/mutation-hoc.js +9 -4
  223. package/react/hoc/mutation-hoc.js.map +1 -1
  224. package/react/hoc/query-hoc.js +10 -4
  225. package/react/hoc/query-hoc.js.map +1 -1
  226. package/react/hoc/subscription-hoc.js +10 -4
  227. package/react/hoc/subscription-hoc.js.map +1 -1
  228. package/react/hoc/withApollo.js +3 -4
  229. package/react/hoc/withApollo.js.map +1 -1
  230. package/react/hooks/hooks.cjs +30 -22
  231. package/react/hooks/hooks.cjs.map +1 -1
  232. package/react/hooks/hooks.cjs.native.js +30 -22
  233. package/react/hooks/internal/__use.js +5 -0
  234. package/react/hooks/internal/__use.js.map +1 -1
  235. package/react/hooks/internal/index.js +1 -0
  236. package/react/hooks/internal/index.js.map +1 -1
  237. package/react/hooks/internal/useDeepMemo.js.map +1 -1
  238. package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -3
  239. package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
  240. package/react/hooks/useBackgroundQuery.js +6 -0
  241. package/react/hooks/useBackgroundQuery.js.map +1 -1
  242. package/react/hooks/useFragment.js +4 -3
  243. package/react/hooks/useFragment.js.map +1 -1
  244. package/react/hooks/useLazyQuery.js +13 -4
  245. package/react/hooks/useLazyQuery.js.map +1 -1
  246. package/react/hooks/useMutation.js +8 -3
  247. package/react/hooks/useMutation.js.map +1 -1
  248. package/react/hooks/useQuery.d.ts +11 -0
  249. package/react/hooks/useQuery.js +137 -5
  250. package/react/hooks/useQuery.js.map +1 -1
  251. package/react/hooks/useReactiveVar.js +5 -0
  252. package/react/hooks/useReactiveVar.js.map +1 -1
  253. package/react/hooks/useReadQuery.d.ts +19 -0
  254. package/react/hooks/useReadQuery.js.map +1 -1
  255. package/react/hooks/useSubscription.js +5 -0
  256. package/react/hooks/useSubscription.js.map +1 -1
  257. package/react/hooks/useSuspenseQuery.js +11 -5
  258. package/react/hooks/useSuspenseQuery.js.map +1 -1
  259. package/react/hooks/useSyncExternalStore.js +53 -1
  260. package/react/hooks/useSyncExternalStore.js.map +1 -1
  261. package/react/parser/index.js +4 -5
  262. package/react/parser/index.js.map +1 -1
  263. package/react/parser/parser.cjs +2 -4
  264. package/react/parser/parser.cjs.map +1 -1
  265. package/react/parser/parser.cjs.native.js +2 -4
  266. package/react/ssr/RenderPromises.js +21 -1
  267. package/react/ssr/RenderPromises.js.map +1 -1
  268. package/react/ssr/getDataFromTree.js +18 -3
  269. package/react/ssr/getDataFromTree.js.map +1 -1
  270. package/react/ssr/ssr.cjs +6 -4
  271. package/react/ssr/ssr.cjs.map +1 -1
  272. package/react/ssr/ssr.cjs.native.js +6 -4
  273. package/react/types/types.d.ts +66 -0
  274. package/testing/core/core.cjs +14 -11
  275. package/testing/core/core.cjs.map +1 -1
  276. package/testing/core/core.cjs.native.js +14 -11
  277. package/testing/core/itAsync.d.ts +1 -1
  278. package/testing/core/itAsync.js.map +1 -1
  279. package/testing/core/mocking/mockFetch.d.ts +2 -2
  280. package/testing/core/mocking/mockFetch.js +8 -4
  281. package/testing/core/mocking/mockFetch.js.map +1 -1
  282. package/testing/core/mocking/mockLink.js +17 -7
  283. package/testing/core/mocking/mockLink.js.map +1 -1
  284. package/testing/core/mocking/mockQueryManager.js +2 -0
  285. package/testing/core/mocking/mockQueryManager.js.map +1 -1
  286. package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
  287. package/testing/core/mocking/mockSubscriptionLink.js +1 -1
  288. package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
  289. package/testing/core/mocking/mockWatchQuery.js +1 -1
  290. package/testing/core/mocking/mockWatchQuery.js.map +1 -1
  291. package/testing/core/observableToPromise.d.ts +17 -3
  292. package/testing/core/observableToPromise.js +5 -0
  293. package/testing/core/observableToPromise.js.map +1 -1
  294. package/testing/core/subscribeAndCount.js +3 -0
  295. package/testing/core/subscribeAndCount.js.map +1 -1
  296. package/testing/core/wait.js +2 -2
  297. package/testing/core/wait.js.map +1 -1
  298. package/testing/core/withConsoleSpy.d.ts +3 -0
  299. package/testing/core/withConsoleSpy.js +7 -1
  300. package/testing/core/withConsoleSpy.js.map +1 -1
  301. package/testing/core/wrap.js +2 -0
  302. package/testing/core/wrap.js.map +1 -1
  303. package/testing/internal/ObservableStream.js +14 -14
  304. package/testing/internal/ObservableStream.js.map +1 -1
  305. package/testing/internal/disposables/spyOnConsole.d.ts +1 -0
  306. package/testing/internal/disposables/spyOnConsole.js +2 -0
  307. package/testing/internal/disposables/spyOnConsole.js.map +1 -1
  308. package/testing/internal/disposables/withCleanup.d.ts +1 -0
  309. package/testing/internal/disposables/withCleanup.js +3 -0
  310. package/testing/internal/disposables/withCleanup.js.map +1 -1
  311. package/testing/internal/profile/Render.d.ts +28 -0
  312. package/testing/internal/profile/Render.js +12 -1
  313. package/testing/internal/profile/Render.js.map +1 -1
  314. package/testing/internal/profile/profile.d.ts +44 -7
  315. package/testing/internal/profile/profile.js +63 -51
  316. package/testing/internal/profile/profile.js.map +1 -1
  317. package/testing/internal/profile/traces.d.ts +4 -0
  318. package/testing/internal/profile/traces.js +9 -5
  319. package/testing/internal/profile/traces.js.map +1 -1
  320. package/testing/matchers/ProfiledComponent.js +27 -22
  321. package/testing/matchers/ProfiledComponent.js.map +1 -1
  322. package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
  323. package/testing/matchers/toMatchDocument.js.map +1 -1
  324. package/testing/react/MockedProvider.d.ts +4 -0
  325. package/testing/react/MockedProvider.js +6 -2
  326. package/testing/react/MockedProvider.js.map +1 -1
  327. package/testing/testing.cjs +4 -2
  328. package/testing/testing.cjs.map +1 -1
  329. package/testing/testing.cjs.native.js +4 -2
  330. package/utilities/common/arrays.js +1 -0
  331. package/utilities/common/arrays.js.map +1 -1
  332. package/utilities/common/canUse.js +16 -1
  333. package/utilities/common/canUse.js.map +1 -1
  334. package/utilities/common/cloneDeep.d.ts +3 -0
  335. package/utilities/common/cloneDeep.js +5 -0
  336. package/utilities/common/cloneDeep.js.map +1 -1
  337. package/utilities/common/compact.d.ts +4 -0
  338. package/utilities/common/compact.js +4 -0
  339. package/utilities/common/compact.js.map +1 -1
  340. package/utilities/common/errorHandling.js +1 -3
  341. package/utilities/common/errorHandling.js.map +1 -1
  342. package/utilities/common/incrementalResult.js +3 -0
  343. package/utilities/common/incrementalResult.js.map +1 -1
  344. package/utilities/common/makeUniqueId.js +2 -0
  345. package/utilities/common/makeUniqueId.js.map +1 -1
  346. package/utilities/common/maybeDeepFreeze.js +3 -0
  347. package/utilities/common/maybeDeepFreeze.js.map +1 -1
  348. package/utilities/common/mergeDeep.js +12 -1
  349. package/utilities/common/mergeDeep.js.map +1 -1
  350. package/utilities/common/mergeOptions.d.ts +1 -1
  351. package/utilities/common/mergeOptions.js.map +1 -1
  352. package/utilities/common/omitDeep.js.map +1 -1
  353. package/utilities/globals/global.js +7 -1
  354. package/utilities/globals/global.js.map +1 -1
  355. package/utilities/globals/globals.cjs +4 -5
  356. package/utilities/globals/globals.cjs.map +1 -1
  357. package/utilities/globals/globals.cjs.native.js +4 -5
  358. package/utilities/globals/index.d.ts +4 -0
  359. package/utilities/globals/index.js +7 -0
  360. package/utilities/globals/index.js.map +1 -1
  361. package/utilities/globals/invariantWrappers.d.ts +40 -0
  362. package/utilities/globals/invariantWrappers.js +11 -3
  363. package/utilities/globals/invariantWrappers.js.map +1 -1
  364. package/utilities/globals/maybe.js.map +1 -1
  365. package/utilities/graphql/DocumentTransform.js +19 -6
  366. package/utilities/graphql/DocumentTransform.js.map +1 -1
  367. package/utilities/graphql/directives.js +3 -0
  368. package/utilities/graphql/directives.js.map +1 -1
  369. package/utilities/graphql/fragments.d.ts +25 -0
  370. package/utilities/graphql/fragments.js +36 -0
  371. package/utilities/graphql/fragments.js.map +1 -1
  372. package/utilities/graphql/getFromAST.d.ts +5 -0
  373. package/utilities/graphql/getFromAST.js +9 -0
  374. package/utilities/graphql/getFromAST.js.map +1 -1
  375. package/utilities/graphql/print.js.map +1 -1
  376. package/utilities/graphql/storeUtils.d.ts +14 -0
  377. package/utilities/graphql/storeUtils.js +7 -2
  378. package/utilities/graphql/storeUtils.js.map +1 -1
  379. package/utilities/graphql/transform.js +106 -7
  380. package/utilities/graphql/transform.js.map +1 -1
  381. package/utilities/observables/Concast.d.ts +1 -1
  382. package/utilities/observables/Concast.js +84 -1
  383. package/utilities/observables/Concast.js.map +1 -1
  384. package/utilities/observables/Observable.js +6 -0
  385. package/utilities/observables/Observable.js.map +1 -1
  386. package/utilities/observables/asyncMap.js +12 -3
  387. package/utilities/observables/asyncMap.js.map +1 -1
  388. package/utilities/observables/iteration.js +3 -0
  389. package/utilities/observables/iteration.js.map +1 -1
  390. package/utilities/observables/subclassing.js +14 -0
  391. package/utilities/observables/subclassing.js.map +1 -1
  392. package/utilities/policies/pagination.js +47 -3
  393. package/utilities/policies/pagination.js.map +1 -1
  394. package/utilities/promises/decoration.js +1 -0
  395. package/utilities/promises/decoration.js.map +1 -1
  396. package/utilities/types/DeepOmit.js.map +1 -1
  397. package/utilities/types/DeepPartial.d.ts +1 -1
  398. package/utilities/types/DeepPartial.js +4 -0
  399. package/utilities/types/DeepPartial.js.map +1 -1
  400. package/utilities/types/IsStrictlyAny.js.map +1 -1
  401. package/utilities/types/TODO.d.ts +3 -0
  402. package/utilities/types/TODO.js +2 -0
  403. package/utilities/types/TODO.js.map +1 -0
  404. package/utilities/utilities.cjs +31 -27
  405. package/utilities/utilities.cjs.map +1 -1
  406. package/utilities/utilities.cjs.native.js +31 -27
  407. package/version.js +1 -1
  408. package/cache/core/cache.d.ts.map +0 -1
  409. package/cache/core/types/Cache.d.ts.map +0 -1
  410. package/cache/core/types/DataProxy.d.ts.map +0 -1
  411. package/cache/core/types/common.d.ts.map +0 -1
  412. package/cache/index.d.ts.map +0 -1
  413. package/cache/inmemory/entityStore.d.ts.map +0 -1
  414. package/cache/inmemory/fixPolyfills.d.ts.map +0 -1
  415. package/cache/inmemory/fixPolyfills.native.d.ts.map +0 -1
  416. package/cache/inmemory/fragmentRegistry.d.ts.map +0 -1
  417. package/cache/inmemory/helpers.d.ts.map +0 -1
  418. package/cache/inmemory/inMemoryCache.d.ts.map +0 -1
  419. package/cache/inmemory/key-extractor.d.ts.map +0 -1
  420. package/cache/inmemory/object-canon.d.ts.map +0 -1
  421. package/cache/inmemory/policies.d.ts.map +0 -1
  422. package/cache/inmemory/reactiveVars.d.ts.map +0 -1
  423. package/cache/inmemory/readFromStore.d.ts.map +0 -1
  424. package/cache/inmemory/types.d.ts.map +0 -1
  425. package/cache/inmemory/writeToStore.d.ts.map +0 -1
  426. package/config/jest/setup.d.ts.map +0 -1
  427. package/core/ApolloClient.d.ts.map +0 -1
  428. package/core/LocalState.d.ts.map +0 -1
  429. package/core/ObservableQuery.d.ts.map +0 -1
  430. package/core/QueryInfo.d.ts.map +0 -1
  431. package/core/QueryManager.d.ts.map +0 -1
  432. package/core/equalByQuery.d.ts.map +0 -1
  433. package/core/index.d.ts.map +0 -1
  434. package/core/networkStatus.d.ts.map +0 -1
  435. package/core/types.d.ts.map +0 -1
  436. package/core/watchQueryOptions.d.ts.map +0 -1
  437. package/dev/index.d.ts.map +0 -1
  438. package/dev/loadDevMessages.d.ts.map +0 -1
  439. package/dev/loadErrorMessageHandler.d.ts.map +0 -1
  440. package/dev/loadErrorMessages.d.ts.map +0 -1
  441. package/errors/index.d.ts.map +0 -1
  442. package/index.d.ts.map +0 -1
  443. package/invariantErrorCodes.d.ts.map +0 -1
  444. package/link/batch/batchLink.d.ts.map +0 -1
  445. package/link/batch/batching.d.ts.map +0 -1
  446. package/link/batch/index.d.ts.map +0 -1
  447. package/link/batch-http/batchHttpLink.d.ts.map +0 -1
  448. package/link/batch-http/index.d.ts.map +0 -1
  449. package/link/context/index.d.ts.map +0 -1
  450. package/link/core/ApolloLink.d.ts.map +0 -1
  451. package/link/core/concat.d.ts.map +0 -1
  452. package/link/core/empty.d.ts.map +0 -1
  453. package/link/core/execute.d.ts.map +0 -1
  454. package/link/core/from.d.ts.map +0 -1
  455. package/link/core/index.d.ts.map +0 -1
  456. package/link/core/split.d.ts.map +0 -1
  457. package/link/core/types.d.ts.map +0 -1
  458. package/link/error/index.d.ts.map +0 -1
  459. package/link/http/HttpLink.d.ts.map +0 -1
  460. package/link/http/checkFetcher.d.ts.map +0 -1
  461. package/link/http/createHttpLink.d.ts.map +0 -1
  462. package/link/http/createSignalIfSupported.d.ts.map +0 -1
  463. package/link/http/index.d.ts.map +0 -1
  464. package/link/http/iterators/async.d.ts.map +0 -1
  465. package/link/http/iterators/nodeStream.d.ts.map +0 -1
  466. package/link/http/iterators/promise.d.ts.map +0 -1
  467. package/link/http/iterators/reader.d.ts.map +0 -1
  468. package/link/http/parseAndCheckHttpResponse.d.ts.map +0 -1
  469. package/link/http/responseIterator.d.ts.map +0 -1
  470. package/link/http/rewriteURIForGET.d.ts.map +0 -1
  471. package/link/http/selectHttpOptionsAndBody.d.ts.map +0 -1
  472. package/link/http/selectURI.d.ts.map +0 -1
  473. package/link/http/serializeFetchParameter.d.ts.map +0 -1
  474. package/link/persisted-queries/index.d.ts.map +0 -1
  475. package/link/remove-typename/index.d.ts.map +0 -1
  476. package/link/remove-typename/removeTypenameFromVariables.d.ts.map +0 -1
  477. package/link/retry/delayFunction.d.ts.map +0 -1
  478. package/link/retry/index.d.ts.map +0 -1
  479. package/link/retry/retryFunction.d.ts.map +0 -1
  480. package/link/retry/retryLink.d.ts.map +0 -1
  481. package/link/schema/index.d.ts.map +0 -1
  482. package/link/subscriptions/index.d.ts.map +0 -1
  483. package/link/utils/createOperation.d.ts.map +0 -1
  484. package/link/utils/filterOperationVariables.d.ts.map +0 -1
  485. package/link/utils/fromError.d.ts.map +0 -1
  486. package/link/utils/fromPromise.d.ts.map +0 -1
  487. package/link/utils/index.d.ts.map +0 -1
  488. package/link/utils/throwServerError.d.ts.map +0 -1
  489. package/link/utils/toPromise.d.ts.map +0 -1
  490. package/link/utils/transformOperation.d.ts.map +0 -1
  491. package/link/utils/validateOperation.d.ts.map +0 -1
  492. package/link/ws/index.d.ts.map +0 -1
  493. package/react/cache/QueryReference.d.ts.map +0 -1
  494. package/react/cache/SuspenseCache.d.ts.map +0 -1
  495. package/react/cache/getSuspenseCache.d.ts.map +0 -1
  496. package/react/cache/index.d.ts.map +0 -1
  497. package/react/cache/types.d.ts.map +0 -1
  498. package/react/components/Mutation.d.ts.map +0 -1
  499. package/react/components/Query.d.ts.map +0 -1
  500. package/react/components/Subscription.d.ts.map +0 -1
  501. package/react/components/index.d.ts.map +0 -1
  502. package/react/components/types.d.ts.map +0 -1
  503. package/react/context/ApolloConsumer.d.ts.map +0 -1
  504. package/react/context/ApolloContext.d.ts.map +0 -1
  505. package/react/context/ApolloProvider.d.ts.map +0 -1
  506. package/react/context/index.d.ts.map +0 -1
  507. package/react/hoc/graphql.d.ts.map +0 -1
  508. package/react/hoc/hoc-utils.d.ts.map +0 -1
  509. package/react/hoc/index.d.ts.map +0 -1
  510. package/react/hoc/mutation-hoc.d.ts.map +0 -1
  511. package/react/hoc/query-hoc.d.ts.map +0 -1
  512. package/react/hoc/subscription-hoc.d.ts.map +0 -1
  513. package/react/hoc/types.d.ts.map +0 -1
  514. package/react/hoc/withApollo.d.ts.map +0 -1
  515. package/react/hooks/constants.d.ts.map +0 -1
  516. package/react/hooks/index.d.ts.map +0 -1
  517. package/react/hooks/internal/__use.d.ts.map +0 -1
  518. package/react/hooks/internal/index.d.ts.map +0 -1
  519. package/react/hooks/internal/useDeepMemo.d.ts.map +0 -1
  520. package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +0 -1
  521. package/react/hooks/useApolloClient.d.ts.map +0 -1
  522. package/react/hooks/useBackgroundQuery.d.ts.map +0 -1
  523. package/react/hooks/useFragment.d.ts.map +0 -1
  524. package/react/hooks/useLazyQuery.d.ts.map +0 -1
  525. package/react/hooks/useMutation.d.ts.map +0 -1
  526. package/react/hooks/useQuery.d.ts.map +0 -1
  527. package/react/hooks/useReactiveVar.d.ts.map +0 -1
  528. package/react/hooks/useReadQuery.d.ts.map +0 -1
  529. package/react/hooks/useSubscription.d.ts.map +0 -1
  530. package/react/hooks/useSuspenseQuery.d.ts.map +0 -1
  531. package/react/hooks/useSyncExternalStore.d.ts.map +0 -1
  532. package/react/index.d.ts.map +0 -1
  533. package/react/parser/index.d.ts.map +0 -1
  534. package/react/ssr/RenderPromises.d.ts.map +0 -1
  535. package/react/ssr/getDataFromTree.d.ts.map +0 -1
  536. package/react/ssr/index.d.ts.map +0 -1
  537. package/react/ssr/renderToStringWithData.d.ts.map +0 -1
  538. package/react/types/types.d.ts.map +0 -1
  539. package/testing/core/index.d.ts.map +0 -1
  540. package/testing/core/itAsync.d.ts.map +0 -1
  541. package/testing/core/mocking/mockClient.d.ts.map +0 -1
  542. package/testing/core/mocking/mockFetch.d.ts.map +0 -1
  543. package/testing/core/mocking/mockLink.d.ts.map +0 -1
  544. package/testing/core/mocking/mockQueryManager.d.ts.map +0 -1
  545. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +0 -1
  546. package/testing/core/mocking/mockWatchQuery.d.ts.map +0 -1
  547. package/testing/core/observableToPromise.d.ts.map +0 -1
  548. package/testing/core/subscribeAndCount.d.ts.map +0 -1
  549. package/testing/core/wait.d.ts.map +0 -1
  550. package/testing/core/withConsoleSpy.d.ts.map +0 -1
  551. package/testing/core/wrap.d.ts.map +0 -1
  552. package/testing/index.d.ts.map +0 -1
  553. package/testing/internal/ObservableStream.d.ts.map +0 -1
  554. package/testing/internal/disposables/index.d.ts.map +0 -1
  555. package/testing/internal/disposables/spyOnConsole.d.ts.map +0 -1
  556. package/testing/internal/disposables/withCleanup.d.ts.map +0 -1
  557. package/testing/internal/index.d.ts.map +0 -1
  558. package/testing/internal/profile/Render.d.ts.map +0 -1
  559. package/testing/internal/profile/index.d.ts.map +0 -1
  560. package/testing/internal/profile/profile.d.ts.map +0 -1
  561. package/testing/internal/profile/traces.d.ts.map +0 -1
  562. package/testing/matchers/ProfiledComponent.d.ts.map +0 -1
  563. package/testing/matchers/index.d.ts.map +0 -1
  564. package/testing/matchers/toHaveSuspenseCacheEntryUsing.d.ts.map +0 -1
  565. package/testing/matchers/toMatchDocument.d.ts.map +0 -1
  566. package/testing/react/MockedProvider.d.ts.map +0 -1
  567. package/utilities/common/arrays.d.ts.map +0 -1
  568. package/utilities/common/canUse.d.ts.map +0 -1
  569. package/utilities/common/cloneDeep.d.ts.map +0 -1
  570. package/utilities/common/compact.d.ts.map +0 -1
  571. package/utilities/common/errorHandling.d.ts.map +0 -1
  572. package/utilities/common/filterInPlace.d.ts +0 -2
  573. package/utilities/common/filterInPlace.d.ts.map +0 -1
  574. package/utilities/common/filterInPlace.js +0 -11
  575. package/utilities/common/filterInPlace.js.map +0 -1
  576. package/utilities/common/incrementalResult.d.ts.map +0 -1
  577. package/utilities/common/makeUniqueId.d.ts.map +0 -1
  578. package/utilities/common/maybeDeepFreeze.d.ts.map +0 -1
  579. package/utilities/common/mergeDeep.d.ts.map +0 -1
  580. package/utilities/common/mergeOptions.d.ts.map +0 -1
  581. package/utilities/common/objects.d.ts.map +0 -1
  582. package/utilities/common/omitDeep.d.ts.map +0 -1
  583. package/utilities/common/stringifyForDisplay.d.ts.map +0 -1
  584. package/utilities/common/stripTypename.d.ts.map +0 -1
  585. package/utilities/globals/global.d.ts.map +0 -1
  586. package/utilities/globals/index.d.ts.map +0 -1
  587. package/utilities/globals/invariantWrappers.d.ts.map +0 -1
  588. package/utilities/globals/maybe.d.ts.map +0 -1
  589. package/utilities/graphql/DocumentTransform.d.ts.map +0 -1
  590. package/utilities/graphql/directives.d.ts.map +0 -1
  591. package/utilities/graphql/fragments.d.ts.map +0 -1
  592. package/utilities/graphql/getFromAST.d.ts.map +0 -1
  593. package/utilities/graphql/operations.d.ts.map +0 -1
  594. package/utilities/graphql/print.d.ts.map +0 -1
  595. package/utilities/graphql/storeUtils.d.ts.map +0 -1
  596. package/utilities/graphql/transform.d.ts.map +0 -1
  597. package/utilities/index.d.ts.map +0 -1
  598. package/utilities/observables/Concast.d.ts.map +0 -1
  599. package/utilities/observables/Observable.d.ts.map +0 -1
  600. package/utilities/observables/asyncMap.d.ts.map +0 -1
  601. package/utilities/observables/iteration.d.ts.map +0 -1
  602. package/utilities/observables/subclassing.d.ts.map +0 -1
  603. package/utilities/policies/pagination.d.ts.map +0 -1
  604. package/utilities/promises/decoration.d.ts.map +0 -1
  605. package/utilities/types/DeepOmit.d.ts.map +0 -1
  606. package/utilities/types/DeepPartial.d.ts.map +0 -1
  607. package/utilities/types/IsStrictlyAny.d.ts.map +0 -1
  608. package/utilities/types/Primitive.d.ts.map +0 -1
  609. package/version.d.ts.map +0 -1
@@ -1,8 +1,11 @@
1
1
  import { __assign } from "tslib";
2
+ /** @internal */
2
3
  export function withCleanup(item, cleanup) {
3
4
  var _a;
4
5
  return __assign(__assign({}, item), (_a = {}, _a[Symbol.dispose] = function () {
5
6
  cleanup(item);
7
+ // if `item` already has a cleanup function, we also need to call the original cleanup function
8
+ // (e.g. if something is wrapped in `withCleanup` twice)
6
9
  if (Symbol.dispose in item) {
7
10
  item[Symbol.dispose]();
8
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"withCleanup.js","sourceRoot":"","sources":["../../../../src/testing/internal/disposables/withCleanup.ts"],"names":[],"mappings":";AACA,MAAM,UAAU,WAAW,CACzB,IAAO,EACP,OAA0B;;IAE1B,6BACK,IAAI,aACP,GAAC,MAAM,CAAC,OAAO,IAAf;QACE,OAAO,CAAC,IAAI,CAAC,CAAC;QAGd,IAAI,MAAM,CAAC,OAAO,IAAI,IAAI,EAAE;YACzB,IAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;SACxC;IACH,CAAC,OACD;AACJ,CAAC","sourcesContent":["/** @internal */\nexport function withCleanup<T extends object>(\n item: T,\n cleanup: (item: T) => void\n): T & Disposable {\n return {\n ...item,\n [Symbol.dispose]() {\n cleanup(item);\n // if `item` already has a cleanup function, we also need to call the original cleanup function\n // (e.g. if something is wrapped in `withCleanup` twice)\n if (Symbol.dispose in item) {\n (item as Disposable)[Symbol.dispose]();\n }\n },\n };\n}\n"]}
1
+ {"version":3,"file":"withCleanup.js","sourceRoot":"","sources":["../../../../src/testing/internal/disposables/withCleanup.ts"],"names":[],"mappings":";AAAA,gBAAgB;AAChB,MAAM,UAAU,WAAW,CACzB,IAAO,EACP,OAA0B;;IAE1B,6BACK,IAAI,aACP,GAAC,MAAM,CAAC,OAAO,IAAf;QACE,OAAO,CAAC,IAAI,CAAC,CAAC;QACd,+FAA+F;QAC/F,wDAAwD;QACxD,IAAI,MAAM,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;YAC1B,IAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACzC,CAAC;IACH,CAAC,OACD;AACJ,CAAC","sourcesContent":["/** @internal */\nexport function withCleanup<T extends object>(\n item: T,\n cleanup: (item: T) => void\n): T & Disposable {\n return {\n ...item,\n [Symbol.dispose]() {\n cleanup(item);\n // if `item` already has a cleanup function, we also need to call the original cleanup function\n // (e.g. if something is wrapped in `withCleanup` twice)\n if (Symbol.dispose in item) {\n (item as Disposable)[Symbol.dispose]();\n }\n },\n };\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { screen } from "@testing-library/dom";
2
+ /** @internal */
2
3
  export interface BaseRender {
3
4
  id: string;
4
5
  phase: "mount" | "update" | "nested-update";
@@ -6,19 +7,45 @@ export interface BaseRender {
6
7
  baseDuration: number;
7
8
  startTime: number;
8
9
  commitTime: number;
10
+ /**
11
+ * The number of renders that have happened so far (including this render).
12
+ */
9
13
  count: number;
10
14
  }
11
15
  type Screen = typeof screen;
16
+ /** @internal */
12
17
  export type SyncScreen = {
13
18
  [K in keyof Screen]: K extends `find${string}` ? {
19
+ /** @deprecated A snapshot is static, so avoid async queries! */
14
20
  (...args: Parameters<Screen[K]>): ReturnType<Screen[K]>;
15
21
  } : Screen[K];
16
22
  };
23
+ /** @internal */
17
24
  export interface Render<Snapshot> extends BaseRender {
25
+ /**
26
+ * The snapshot, as returned by the `takeSnapshot` option of `profile`.
27
+ * (If using `profileHook`, this is the return value of the hook.)
28
+ */
18
29
  snapshot: Snapshot;
30
+ /**
31
+ * A DOM snapshot of the rendered component, if the `snapshotDOM`
32
+ * option of `profile` was enabled.
33
+ */
19
34
  readonly domSnapshot: HTMLElement;
35
+ /**
36
+ * Returns a callback to receive a `screen` instance that is scoped to the
37
+ * DOM snapshot of this `Render` instance.
38
+ * Note: this is used as a callback to prevent linter errors.
39
+ * @example
40
+ * ```diff
41
+ * const { withinDOM } = RenderedComponent.takeRender();
42
+ * -expect(screen.getByText("foo")).toBeInTheDocument();
43
+ * +expect(withinDOM().getByText("foo")).toBeInTheDocument();
44
+ * ```
45
+ */
20
46
  withinDOM: () => SyncScreen;
21
47
  }
48
+ /** @internal */
22
49
  export declare class RenderInstance<Snapshot> implements Render<Snapshot> {
23
50
  snapshot: Snapshot;
24
51
  private stringifiedDOM;
@@ -135,6 +162,7 @@ export declare class RenderInstance<Snapshot> implements Render<Snapshot> {
135
162
  logTestingPlaygroundURL: (element?: Element | HTMLDocument | undefined) => void;
136
163
  };
137
164
  }
165
+ /** @internal */
138
166
  export declare function errorOnDomInteraction(): void;
139
167
  export {};
140
168
  //# sourceMappingURL=Render.d.ts.map
@@ -1,8 +1,18 @@
1
+ /* istanbul ignore file */
1
2
  import { __spreadArray } from "tslib";
3
+ /*
4
+ Something in this file does not compile correctly while measuring code coverage
5
+ and will lead to a
6
+ Uncaught [ReferenceError: cov_1zb8w312au is not defined]
7
+ if we do not ignore this file in code coverage.
8
+
9
+ As we only use this file in our internal tests, we can safely ignore it.
10
+ */
2
11
  import { within, screen } from "@testing-library/dom";
3
12
  import { JSDOM, VirtualConsole } from "jsdom";
4
13
  import { applyStackTrace, captureStackTrace } from "./traces.js";
5
- var RenderInstance = (function () {
14
+ /** @internal */
15
+ var RenderInstance = /** @class */ (function () {
6
16
  function RenderInstance(baseRender, snapshot, stringifiedDOM) {
7
17
  this.snapshot = snapshot;
8
18
  this.stringifiedDOM = stringifiedDOM;
@@ -71,6 +81,7 @@ var RenderInstance = (function () {
71
81
  return RenderInstance;
72
82
  }());
73
83
  export { RenderInstance };
84
+ /** @internal */
74
85
  export function errorOnDomInteraction() {
75
86
  var events = [
76
87
  "auxclick",
@@ -1 +1 @@
1
- {"version":3,"file":"Render.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/Render.tsx"],"names":[],"mappings":";AAWA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAsDjE;IASE,wBACE,UAAsB,EACf,QAAkB,EACjB,cAAkC;QADnC,aAAQ,GAAR,QAAQ,CAAU;QACjB,mBAAc,GAAd,cAAc,CAAoB;QAE1C,IAAI,CAAC,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;QAC9B,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;QAChD,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,SAAS,GAAG,UAAU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;QACR,QAAQ;QACR,iBAAiB;QACjB,aAAa;QACb,QAAQ;QACR,QAAQ;QACR,aAAa;QACb,UAAU;QACV,WAAW;QACX,YAAY;QACZ,OAAO;KACR,CAAC;IACF,SAAS,oBAAoB;QAC3B,MAAM,IAAI,KAAK,CAAC,8MAIf,CAAC,CAAC;IACL,CAAC;IACD,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK;QACnB,QAAQ,CAAC,gBAAgB,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/* istanbul ignore file */\n\n/*\nSomething in this file does not compile correctly while measuring code coverage\nand will lead to a\n Uncaught [ReferenceError: cov_1zb8w312au is not defined]\nif we do not ignore this file in code coverage.\n\nAs we only use this file in our internal tests, we can safely ignore it.\n*/\n\nimport { within, screen } from \"@testing-library/dom\";\nimport { JSDOM, VirtualConsole } from \"jsdom\";\nimport { applyStackTrace, captureStackTrace } from \"./traces.js\";\n\n/** @internal */\nexport interface BaseRender {\n id: string;\n phase: \"mount\" | \"update\" | \"nested-update\";\n actualDuration: number;\n baseDuration: number;\n startTime: number;\n commitTime: number;\n /**\n * The number of renders that have happened so far (including this render).\n */\n count: number;\n}\n\ntype Screen = typeof screen;\n/** @internal */\nexport type SyncScreen = {\n [K in keyof Screen]: K extends `find${string}`\n ? {\n /** @deprecated A snapshot is static, so avoid async queries! */\n (...args: Parameters<Screen[K]>): ReturnType<Screen[K]>;\n }\n : Screen[K];\n};\n\n/** @internal */\nexport interface Render<Snapshot> extends BaseRender {\n /**\n * The snapshot, as returned by the `takeSnapshot` option of `profile`.\n * (If using `profileHook`, this is the return value of the hook.)\n */\n snapshot: Snapshot;\n /**\n * A DOM snapshot of the rendered component, if the `snapshotDOM`\n * option of `profile` was enabled.\n */\n readonly domSnapshot: HTMLElement;\n /**\n * Returns a callback to receive a `screen` instance that is scoped to the\n * DOM snapshot of this `Render` instance.\n * Note: this is used as a callback to prevent linter errors.\n * @example\n * ```diff\n * const { withinDOM } = RenderedComponent.takeRender();\n * -expect(screen.getByText(\"foo\")).toBeInTheDocument();\n * +expect(withinDOM().getByText(\"foo\")).toBeInTheDocument();\n * ```\n */\n withinDOM: () => SyncScreen;\n}\n\n/** @internal */\nexport class RenderInstance<Snapshot> implements Render<Snapshot> {\n id: string;\n phase: \"mount\" | \"update\" | \"nested-update\";\n actualDuration: number;\n baseDuration: number;\n startTime: number;\n commitTime: number;\n count: number;\n\n constructor(\n baseRender: BaseRender,\n public snapshot: Snapshot,\n private stringifiedDOM: string | undefined\n ) {\n this.id = baseRender.id;\n this.phase = baseRender.phase;\n this.actualDuration = baseRender.actualDuration;\n this.baseDuration = baseRender.baseDuration;\n this.startTime = baseRender.startTime;\n this.commitTime = baseRender.commitTime;\n this.count = baseRender.count;\n }\n\n private _domSnapshot: HTMLElement | undefined;\n get domSnapshot() {\n if (this._domSnapshot) return this._domSnapshot;\n if (!this.stringifiedDOM) {\n throw new Error(\n \"DOM snapshot is not available - please set the `snapshotDOM` option\"\n );\n }\n\n const virtualConsole = new VirtualConsole();\n const stackTrace = captureStackTrace(\"RenderInstance.get\");\n virtualConsole.on(\"jsdomError\", (error) => {\n throw applyStackTrace(error, stackTrace);\n });\n\n const snapDOM = new JSDOM(this.stringifiedDOM, {\n runScripts: \"dangerously\",\n virtualConsole,\n });\n const document = snapDOM.window.document;\n const body = document.body;\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.text = `\n ${errorOnDomInteraction.toString()};\n ${errorOnDomInteraction.name}();\n `;\n body.appendChild(script);\n body.removeChild(script);\n\n return (this._domSnapshot = body);\n }\n\n get withinDOM() {\n const snapScreen = Object.assign(within(this.domSnapshot), {\n debug: (\n ...[dom = this.domSnapshot, ...rest]: Parameters<typeof screen.debug>\n ) => {\n screen.debug(dom, ...rest);\n },\n logTestingPlaygroundURL: (\n ...[dom = this.domSnapshot, ...rest]: Parameters<\n typeof screen.logTestingPlaygroundURL\n >\n ) => {\n screen.logTestingPlaygroundURL(dom, ...rest);\n },\n });\n return () => snapScreen;\n }\n}\n/** @internal */\nexport function errorOnDomInteraction() {\n const events: Array<keyof DocumentEventMap> = [\n \"auxclick\",\n \"blur\",\n \"change\",\n \"click\",\n \"copy\",\n \"cut\",\n \"dblclick\",\n \"drag\",\n \"dragend\",\n \"dragenter\",\n \"dragleave\",\n \"dragover\",\n \"dragstart\",\n \"drop\",\n \"focus\",\n \"focusin\",\n \"focusout\",\n \"input\",\n \"keydown\",\n \"keypress\",\n \"keyup\",\n \"mousedown\",\n \"mouseenter\",\n \"mouseleave\",\n \"mousemove\",\n \"mouseout\",\n \"mouseover\",\n \"mouseup\",\n \"paste\",\n \"pointercancel\",\n \"pointerdown\",\n \"pointerenter\",\n \"pointerleave\",\n \"pointermove\",\n \"pointerout\",\n \"pointerover\",\n \"pointerup\",\n \"scroll\",\n \"select\",\n \"selectionchange\",\n \"selectstart\",\n \"submit\",\n \"toggle\",\n \"touchcancel\",\n \"touchend\",\n \"touchmove\",\n \"touchstart\",\n \"wheel\",\n ];\n function warnOnDomInteraction() {\n throw new Error(`\n DOM interaction with a snapshot detected in test.\n Please don't interact with the DOM you get from \\`withinDOM\\`,\n but still use \\`screen\\' to get elements for simulating user interaction.\n `);\n }\n events.forEach((event) => {\n document.addEventListener(event, warnOnDomInteraction);\n });\n}\n"]}
1
+ {"version":3,"file":"Render.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/Render.tsx"],"names":[],"mappings":"AAAA,0BAA0B;;AAE1B;;;;;;;EAOE;AAEF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAqDjE,gBAAgB;AAChB;IASE,wBACE,UAAsB,EACf,QAAkB,EACjB,cAAkC;QADnC,aAAQ,GAAR,QAAQ,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AS;QACT,WAAW;QACX,WAAW;QACX,UAAU;QACV,WAAW;QACX,MAAM;QACN,OAAO;QACP,SAAS;QACT,UAAU;QACV,OAAO;QACP,SAAS;QACT,UAAU;QACV,OAAO;QACP,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,WAAW;QACX,UAAU;QACV,WAAW;QACX,SAAS;QACT,OAAO;QACP,eAAe;QACf,aAAa;QACb,cAAc;QACd,cAAc;QACd,aAAa;QACb,YAAY;QACZ,aAAa;QACb,WAAW;QACX,QAAQ;QACR,QAAQ;QACR,iBAAiB;QACjB,aAAa;QACb,QAAQ;QACR,QAAQ;QACR,aAAa;QACb,UAAU;QACV,WAAW;QACX,YAAY;QACZ,OAAO;KACR,CAAC;IACF,SAAS,oBAAoB;QAC3B,MAAM,IAAI,KAAK,CAAC,8MAIf,CAAC,CAAC;IACL,CAAC;IACD,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK;QACnB,QAAQ,CAAC,gBAAgB,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/* istanbul ignore file */\n\n/*\nSomething in this file does not compile correctly while measuring code coverage\nand will lead to a\n Uncaught [ReferenceError: cov_1zb8w312au is not defined]\nif we do not ignore this file in code coverage.\n\nAs we only use this file in our internal tests, we can safely ignore it.\n*/\n\nimport { within, screen } from \"@testing-library/dom\";\nimport { JSDOM, VirtualConsole } from \"jsdom\";\nimport { applyStackTrace, captureStackTrace } from \"./traces.js\";\n\n/** @internal */\nexport interface BaseRender {\n id: string;\n phase: \"mount\" | \"update\" | \"nested-update\";\n actualDuration: number;\n baseDuration: number;\n startTime: number;\n commitTime: number;\n /**\n * The number of renders that have happened so far (including this render).\n */\n count: number;\n}\n\ntype Screen = typeof screen;\n/** @internal */\nexport type SyncScreen = {\n [K in keyof Screen]: K extends `find${string}` ?\n {\n /** @deprecated A snapshot is static, so avoid async queries! */\n (...args: Parameters<Screen[K]>): ReturnType<Screen[K]>;\n }\n : Screen[K];\n};\n\n/** @internal */\nexport interface Render<Snapshot> extends BaseRender {\n /**\n * The snapshot, as returned by the `takeSnapshot` option of `profile`.\n * (If using `profileHook`, this is the return value of the hook.)\n */\n snapshot: Snapshot;\n /**\n * A DOM snapshot of the rendered component, if the `snapshotDOM`\n * option of `profile` was enabled.\n */\n readonly domSnapshot: HTMLElement;\n /**\n * Returns a callback to receive a `screen` instance that is scoped to the\n * DOM snapshot of this `Render` instance.\n * Note: this is used as a callback to prevent linter errors.\n * @example\n * ```diff\n * const { withinDOM } = RenderedComponent.takeRender();\n * -expect(screen.getByText(\"foo\")).toBeInTheDocument();\n * +expect(withinDOM().getByText(\"foo\")).toBeInTheDocument();\n * ```\n */\n withinDOM: () => SyncScreen;\n}\n\n/** @internal */\nexport class RenderInstance<Snapshot> implements Render<Snapshot> {\n id: string;\n phase: \"mount\" | \"update\" | \"nested-update\";\n actualDuration: number;\n baseDuration: number;\n startTime: number;\n commitTime: number;\n count: number;\n\n constructor(\n baseRender: BaseRender,\n public snapshot: Snapshot,\n private stringifiedDOM: string | undefined\n ) {\n this.id = baseRender.id;\n this.phase = baseRender.phase;\n this.actualDuration = baseRender.actualDuration;\n this.baseDuration = baseRender.baseDuration;\n this.startTime = baseRender.startTime;\n this.commitTime = baseRender.commitTime;\n this.count = baseRender.count;\n }\n\n private _domSnapshot: HTMLElement | undefined;\n get domSnapshot() {\n if (this._domSnapshot) return this._domSnapshot;\n if (!this.stringifiedDOM) {\n throw new Error(\n \"DOM snapshot is not available - please set the `snapshotDOM` option\"\n );\n }\n\n const virtualConsole = new VirtualConsole();\n const stackTrace = captureStackTrace(\"RenderInstance.get\");\n virtualConsole.on(\"jsdomError\", (error) => {\n throw applyStackTrace(error, stackTrace);\n });\n\n const snapDOM = new JSDOM(this.stringifiedDOM, {\n runScripts: \"dangerously\",\n virtualConsole,\n });\n const document = snapDOM.window.document;\n const body = document.body;\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.text = `\n ${errorOnDomInteraction.toString()};\n ${errorOnDomInteraction.name}();\n `;\n body.appendChild(script);\n body.removeChild(script);\n\n return (this._domSnapshot = body);\n }\n\n get withinDOM() {\n const snapScreen = Object.assign(within(this.domSnapshot), {\n debug: (\n ...[dom = this.domSnapshot, ...rest]: Parameters<typeof screen.debug>\n ) => {\n screen.debug(dom, ...rest);\n },\n logTestingPlaygroundURL: (\n ...[dom = this.domSnapshot, ...rest]: Parameters<\n typeof screen.logTestingPlaygroundURL\n >\n ) => {\n screen.logTestingPlaygroundURL(dom, ...rest);\n },\n });\n return () => snapScreen;\n }\n}\n/** @internal */\nexport function errorOnDomInteraction() {\n const events: Array<keyof DocumentEventMap> = [\n \"auxclick\",\n \"blur\",\n \"change\",\n \"click\",\n \"copy\",\n \"cut\",\n \"dblclick\",\n \"drag\",\n \"dragend\",\n \"dragenter\",\n \"dragleave\",\n \"dragover\",\n \"dragstart\",\n \"drop\",\n \"focus\",\n \"focusin\",\n \"focusout\",\n \"input\",\n \"keydown\",\n \"keypress\",\n \"keyup\",\n \"mousedown\",\n \"mouseenter\",\n \"mouseleave\",\n \"mousemove\",\n \"mouseout\",\n \"mouseover\",\n \"mouseup\",\n \"paste\",\n \"pointercancel\",\n \"pointerdown\",\n \"pointerenter\",\n \"pointerleave\",\n \"pointermove\",\n \"pointerout\",\n \"pointerover\",\n \"pointerup\",\n \"scroll\",\n \"select\",\n \"selectionchange\",\n \"selectstart\",\n \"submit\",\n \"toggle\",\n \"touchcancel\",\n \"touchend\",\n \"touchmove\",\n \"touchstart\",\n \"wheel\",\n ];\n function warnOnDomInteraction() {\n throw new Error(`\n DOM interaction with a snapshot detected in test.\n Please don't interact with the DOM you get from \\`withinDOM\\`,\n but still use \\`screen\\' to get elements for simulating user interaction.\n `);\n }\n events.forEach((event) => {\n document.addEventListener(event, warnOnDomInteraction);\n });\n}\n"]}
@@ -3,42 +3,77 @@ import type { Render, BaseRender } from "./Render.js";
3
3
  type ValidSnapshot = void | (object & {
4
4
  call?: never;
5
5
  });
6
+ /** only used for passing around data internally */
6
7
  declare const _stackTrace: unique symbol;
8
+ /** @internal */
7
9
  export interface NextRenderOptions {
8
10
  timeout?: number;
9
11
  [_stackTrace]?: string;
10
12
  }
11
- export interface ProfiledComponent<Props, Snapshot> extends React.FC<Props>, ProfiledComponentFields<Props, Snapshot>, ProfiledComponenOnlyFields<Props, Snapshot> {
13
+ /** @internal */
14
+ export interface ProfiledComponent<Props, Snapshot> extends React.FC<Props>, ProfiledComponentFields<Props, Snapshot>, ProfiledComponentOnlyFields<Props, Snapshot> {
12
15
  }
13
- interface UpdateSnapshot<Snapshot> {
16
+ interface ReplaceSnapshot<Snapshot> {
14
17
  (newSnapshot: Snapshot): void;
15
18
  (updateSnapshot: (lastSnapshot: Readonly<Snapshot>) => Snapshot): void;
16
19
  }
17
- interface ProfiledComponenOnlyFields<Props, Snapshot> {
18
- updateSnapshot: UpdateSnapshot<Snapshot>;
20
+ interface MergeSnapshot<Snapshot> {
21
+ (partialSnapshot: Partial<Snapshot>): void;
22
+ (updatePartialSnapshot: (lastSnapshot: Readonly<Snapshot>) => Partial<Snapshot>): void;
23
+ }
24
+ interface ProfiledComponentOnlyFields<Props, Snapshot> {
25
+ mergeSnapshot: MergeSnapshot<Snapshot>;
26
+ replaceSnapshot: ReplaceSnapshot<Snapshot>;
19
27
  }
20
28
  interface ProfiledComponentFields<Props, Snapshot> {
29
+ /**
30
+ * An array of all renders that have happened so far.
31
+ * Errors thrown during component render will be captured here, too.
32
+ */
21
33
  renders: Array<Render<Snapshot> | {
22
34
  phase: "snapshotError";
23
35
  count: number;
24
36
  error: unknown;
25
37
  }>;
38
+ /**
39
+ * Peeks the next render from the current iterator position, without advancing the iterator.
40
+ * If no render has happened yet, it will wait for the next render to happen.
41
+ * @throws {WaitForRenderTimeoutError} if no render happens within the timeout
42
+ */
26
43
  peekRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;
44
+ /**
45
+ * Iterates to the next render and returns it.
46
+ * If no render has happened yet, it will wait for the next render to happen.
47
+ * @throws {WaitForRenderTimeoutError} if no render happens within the timeout
48
+ */
27
49
  takeRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;
28
- currentRenderCount(): number;
50
+ /**
51
+ * Returns the total number of renders.
52
+ */
53
+ totalRenderCount(): number;
54
+ /**
55
+ * Returns the current render.
56
+ * @throws {Error} if no render has happened yet
57
+ */
29
58
  getCurrentRender(): Render<Snapshot>;
30
- takeUntilRenderCount(count: number, optionsPerRender?: NextRenderOptions): Promise<void>;
59
+ /**
60
+ * Waits for the next render to happen.
61
+ * Does not advance the render iterator.
62
+ */
31
63
  waitForNextRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;
32
64
  }
65
+ /** @internal */
33
66
  export declare function profile<Snapshot extends ValidSnapshot = void, Props = Record<string, never>>({ Component, onRender, snapshotDOM, initialSnapshot, }: {
34
67
  Component: React.ComponentType<Props>;
35
68
  onRender?: (info: BaseRender & {
36
69
  snapshot: Snapshot;
37
- updateSnapshot: UpdateSnapshot<Snapshot>;
70
+ replaceSnapshot: ReplaceSnapshot<Snapshot>;
71
+ mergeSnapshot: MergeSnapshot<Snapshot>;
38
72
  }) => void;
39
73
  snapshotDOM?: boolean;
40
74
  initialSnapshot?: Snapshot;
41
75
  }): ProfiledComponent<Props, Snapshot>;
76
+ /** @internal */
42
77
  export declare class WaitForRenderTimeoutError extends Error {
43
78
  constructor();
44
79
  }
@@ -47,9 +82,11 @@ type ResultReplaceRenderWithSnapshot<T> = T extends (...args: infer Args) => Ren
47
82
  type ProfiledHookFields<Props, ReturnValue> = ProfiledComponentFields<Props, ReturnValue> extends infer PC ? {
48
83
  [K in keyof PC as StringReplaceRenderWithSnapshot<K & string>]: ResultReplaceRenderWithSnapshot<PC[K]>;
49
84
  } : never;
85
+ /** @internal */
50
86
  export interface ProfiledHook<Props, ReturnValue> extends React.FC<Props>, ProfiledHookFields<Props, ReturnValue> {
51
87
  ProfiledComponent: ProfiledComponent<Props, ReturnValue>;
52
88
  }
89
+ /** @internal */
53
90
  export declare function profileHook<ReturnValue extends ValidSnapshot, Props>(renderCallback: (props: Props) => ReturnValue): ProfiledHook<Props, ReturnValue>;
54
91
  export {};
55
92
  //# sourceMappingURL=profile.d.ts.map
@@ -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,CAAC,WAAW,GAAK,WAAW,EAAC;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAKjE,IAAM,WAAW,GAAG,MAAM,EAAE,CAAC;AAiE7B,MAAM,UAAU,OAAO,CAGrB,EAeD;QAdC,SAAS,eAAA,EACT,QAAQ,cAAA,EACR,mBAAmB,EAAnB,WAAW,mBAAG,KAAK,KAAA,EACnB,eAAe,qBAAA;IAYf,IAAI,aAA2C,CAAC;IAChD,IAAI,UAAiD,CAAC;IACtD,IAAI,iBAAmE,CAAC;IACxE,IAAI,gBAAwD,CAAC;IAC7D,IAAM,WAAW,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;IACjD,IAAM,cAAc,GAA6B,UAAC,IAAI;QACpD,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;YAC9B,IAAI,CAAC,eAAe,EAAE;gBACpB,MAAM,IAAI,KAAK,CACb,mFAAmF,CACpF,CAAC;aACH;YACD,WAAW,CAAC,OAAO,GAAG,IAAI,CACxB,OAAO,WAAW,CAAC,OAAO,KAAK,QAAQ;gBACrC,CAAC,cACM,WAAW,CAAC,OAAQ,EAC3B,CAAC,CAAC,WAAW,CAAC,OAA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,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,i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CAAC,eAAe,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;QACzD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IACF,IAAM,iBAAiB,GAAG,OAAO,CAAqB;QACpD,SAAS,WAAA;QACT,QAAQ,EAAE,cAAM,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,kBAAkB,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"]}