From 69c1cb6f831941598987185238a299b050a364bd Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Mon, 16 Dec 2024 02:32:24 -0700 Subject: [PATCH] Remove `subscribeAndCount` testing utility (#12223) Co-authored-by: Lenz Weber-Tronic Co-authored-by: phryneas --- .api-reports/api-report-testing.api.md | 3 -- .api-reports/api-report-testing_core.api.md | 3 -- .changeset/shiny-carrots-invent.md | 5 ++++ src/__tests__/__snapshots__/exports.ts.snap | 2 -- src/testing/core/index.ts | 1 - src/testing/core/subscribeAndCount.ts | 32 --------------------- 6 files changed, 5 insertions(+), 41 deletions(-) create mode 100644 .changeset/shiny-carrots-invent.md delete mode 100644 src/testing/core/subscribeAndCount.ts diff --git a/.api-reports/api-report-testing.api.md b/.api-reports/api-report-testing.api.md index 00f01de37dd..2b2bd0e0529 100644 --- a/.api-reports/api-report-testing.api.md +++ b/.api-reports/api-report-testing.api.md @@ -1814,9 +1814,6 @@ Item // @public (undocumented) type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object; -// @public (undocumented) -export function subscribeAndCount(reject: (reason: any) => any, observable: Observable, cb: (handleCount: number, result: TResult) => any): Subscription; - // @public (undocumented) type SubscribeToMoreOptions = { document: DocumentNode | TypedDocumentNode; diff --git a/.api-reports/api-report-testing_core.api.md b/.api-reports/api-report-testing_core.api.md index 1606498c68a..473326a16a8 100644 --- a/.api-reports/api-report-testing_core.api.md +++ b/.api-reports/api-report-testing_core.api.md @@ -1771,9 +1771,6 @@ Item // @public (undocumented) type StoreValue = number | string | string[] | Reference | Reference[] | null | undefined | void | Object; -// @public (undocumented) -export function subscribeAndCount(reject: (reason: any) => any, observable: Observable, cb: (handleCount: number, result: TResult) => any): Subscription; - // @public (undocumented) type SubscribeToMoreOptions = { document: DocumentNode | TypedDocumentNode; diff --git a/.changeset/shiny-carrots-invent.md b/.changeset/shiny-carrots-invent.md new file mode 100644 index 00000000000..0ba9824650d --- /dev/null +++ b/.changeset/shiny-carrots-invent.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": major +--- + +Remove `subscribeAndCount` testing utility from `@apollo/client/testing`. diff --git a/src/__tests__/__snapshots__/exports.ts.snap b/src/__tests__/__snapshots__/exports.ts.snap index 77654247852..1019413b6bd 100644 --- a/src/__tests__/__snapshots__/exports.ts.snap +++ b/src/__tests__/__snapshots__/exports.ts.snap @@ -363,7 +363,6 @@ Array [ "itAsync", "mockObservableLink", "mockSingleLink", - "subscribeAndCount", "tick", "wait", "withErrorSpy", @@ -380,7 +379,6 @@ Array [ "itAsync", "mockObservableLink", "mockSingleLink", - "subscribeAndCount", "tick", "wait", "withErrorSpy", diff --git a/src/testing/core/index.ts b/src/testing/core/index.ts index e999590509a..94af1dbe3ea 100644 --- a/src/testing/core/index.ts +++ b/src/testing/core/index.ts @@ -9,7 +9,6 @@ export { mockObservableLink, } from "./mocking/mockSubscriptionLink.js"; export { createMockClient } from "./mocking/mockClient.js"; -export { default as subscribeAndCount } from "./subscribeAndCount.js"; export { itAsync } from "./itAsync.js"; export { wait, tick } from "./wait.js"; export * from "./withConsoleSpy.js"; diff --git a/src/testing/core/subscribeAndCount.ts b/src/testing/core/subscribeAndCount.ts deleted file mode 100644 index 4b366193b53..00000000000 --- a/src/testing/core/subscribeAndCount.ts +++ /dev/null @@ -1,32 +0,0 @@ -import type { - ObservableSubscription, - Observable, -} from "../../utilities/index.js"; -import { asyncMap } from "../../utilities/index.js"; - -export default function subscribeAndCount( - reject: (reason: any) => any, - observable: Observable, - cb: (handleCount: number, result: TResult) => any -): ObservableSubscription { - // Use a Promise queue to prevent callbacks from being run out of order. - let queue = Promise.resolve(); - let handleCount = 0; - - const subscription = asyncMap(observable, (result) => { - // All previous asynchronous callbacks must complete before cb can - // be invoked with this result. - return (queue = queue - .then(() => { - return cb(++handleCount, result); - }) - .catch(error)); - }).subscribe({ error }); - - function error(e: any) { - subscription.unsubscribe(); - reject(e); - } - - return subscription; -}