Skip to content

Commit 86f23a4

Browse files
authored
Remove wait-for-observables in favor of ObservableStream (apollographql#12317)
1 parent 68e29dd commit 86f23a4

File tree

3 files changed

+28
-36
lines changed

3 files changed

+28
-36
lines changed

package-lock.json

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@
198198
"tsx": "4.19.2",
199199
"typedoc": "0.25.0",
200200
"typescript": "5.7.3",
201-
"wait-for-observables": "1.0.3",
202201
"web-streams-polyfill": "4.0.0",
203202
"whatwg-fetch": "3.6.20"
204203
},

src/link/retry/__tests__/retryLink.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import gql from "graphql-tag";
2-
import waitFor from "wait-for-observables";
32

43
import { ApolloLink } from "../../core/ApolloLink";
54
import { execute } from "../../core/execute";
65
import { Observable } from "../../../utilities/observables/Observable";
76
import { fromError } from "../../utils/fromError";
87
import { RetryLink } from "../retryLink";
8+
import { ObservableStream } from "../../../testing/internal";
99

1010
const query = gql`
1111
{
@@ -23,9 +23,10 @@ describe("RetryLink", () => {
2323
const retry = new RetryLink({ delay: { initial: 1 }, attempts: { max } });
2424
const stub = jest.fn(() => fromError(standardError)) as any;
2525
const link = ApolloLink.from([retry, stub]);
26+
const stream = new ObservableStream(execute(link, { query }));
27+
28+
await expect(stream).toEmitError(standardError, { timeout: 1000 });
2629

27-
const [{ error }] = (await waitFor(execute(link, { query }))) as any;
28-
expect(error).toEqual(standardError);
2930
expect(stub).toHaveBeenCalledTimes(max);
3031
});
3132

@@ -34,9 +35,11 @@ describe("RetryLink", () => {
3435
const data = { data: { hello: "world" } };
3536
const stub = jest.fn(() => Observable.of(data));
3637
const link = ApolloLink.from([retry, stub]);
38+
const stream = new ObservableStream(execute(link, { query }));
39+
40+
await expect(stream).toEmitValue(data);
41+
await expect(stream).toComplete();
3742

38-
const [{ values }] = (await waitFor(execute(link, { query }))) as any;
39-
expect(values).toEqual([data]);
4043
expect(stub).toHaveBeenCalledTimes(1);
4144
});
4245

@@ -50,9 +53,11 @@ describe("RetryLink", () => {
5053
stub.mockReturnValueOnce(fromError(standardError));
5154
stub.mockReturnValueOnce(Observable.of(data));
5255
const link = ApolloLink.from([retry, stub]);
56+
const stream = new ObservableStream(execute(link, { query }));
57+
58+
await expect(stream).toEmitValue(data);
59+
await expect(stream).toComplete();
5360

54-
const [{ values }] = (await waitFor(execute(link, { query }))) as any;
55-
expect(values).toEqual([data]);
5661
expect(stub).toHaveBeenCalledTimes(2);
5762
});
5863

@@ -129,13 +134,14 @@ describe("RetryLink", () => {
129134
});
130135
const stub = jest.fn(() => fromError(standardError)) as any;
131136
const link = ApolloLink.from([retry, stub]);
137+
const stream1 = new ObservableStream(execute(link, { query }));
138+
const stream2 = new ObservableStream(execute(link, { query }));
139+
140+
await Promise.all([
141+
expect(stream1).toEmitError(standardError),
142+
expect(stream2).toEmitError(standardError),
143+
]);
132144

133-
const [result1, result2] = (await waitFor(
134-
execute(link, { query }),
135-
execute(link, { query })
136-
)) as any;
137-
expect(result1.error).toEqual(standardError);
138-
expect(result2.error).toEqual(standardError);
139145
expect(stub).toHaveBeenCalledTimes(10);
140146
});
141147

@@ -144,9 +150,10 @@ describe("RetryLink", () => {
144150
const retry = new RetryLink({ delay: delayStub, attempts: { max: 3 } });
145151
const linkStub = jest.fn(() => fromError(standardError)) as any;
146152
const link = ApolloLink.from([retry, linkStub]);
147-
const [{ error }] = (await waitFor(execute(link, { query }))) as any;
153+
const stream = new ObservableStream(execute(link, { query }));
154+
155+
await expect(stream).toEmitError(standardError);
148156

149-
expect(error).toEqual(standardError);
150157
const operation = (delayStub.mock.calls[0] as any)[1];
151158
expect(delayStub.mock.calls).toEqual([
152159
[1, operation, standardError],
@@ -166,9 +173,10 @@ describe("RetryLink", () => {
166173
});
167174
const linkStub = jest.fn(() => fromError(standardError)) as any;
168175
const link = ApolloLink.from([retry, linkStub]);
169-
const [{ error }] = (await waitFor(execute(link, { query }))) as any;
176+
const stream = new ObservableStream(execute(link, { query }));
177+
178+
await expect(stream).toEmitError(standardError);
170179

171-
expect(error).toEqual(standardError);
172180
const operation = attemptStub.mock.calls[0][1];
173181
expect(attemptStub.mock.calls).toEqual([
174182
[1, operation, standardError],
@@ -191,9 +199,10 @@ describe("RetryLink", () => {
191199
() => new Observable((o) => o.error(standardError))
192200
) as any;
193201
const link = ApolloLink.from([retry, linkStub]);
194-
const [{ error }] = (await waitFor(execute(link, { query }))) as any;
202+
const stream = new ObservableStream(execute(link, { query }));
203+
204+
await expect(stream).toEmitError(standardError);
195205

196-
expect(error).toEqual(standardError);
197206
const operation = attemptStub.mock.calls[0][1];
198207
expect(attemptStub.mock.calls).toEqual([
199208
[1, operation, standardError],

0 commit comments

Comments
 (0)