Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove itAsync from remaining relevant tests #12210

Open
wants to merge 44 commits into
base: jerel/remove-itasync-part-2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
25617fe
Remove itAsync from useMutation tests
jerelmiller Nov 30, 2024
c9d5467
Remove itAsync from useReactiveVar tests
jerelmiller Nov 30, 2024
1e08c42
Remove itAsync from HttpLink tests
jerelmiller Nov 30, 2024
ea73797
Remove itAsync from ApolloConsumer tests
jerelmiller Nov 30, 2024
4802fd0
Remove itAsync from webSocketLink tests
jerelmiller Nov 30, 2024
e66e7a1
Add ability to unsubscribe from observable in ObservableStream
jerelmiller Dec 2, 2024
091c7fd
Remove itAsync from persisted-queries tests
jerelmiller Dec 2, 2024
a4127bf
Remove itAsync from fragmentMatcher tests
jerelmiller Dec 2, 2024
2a16313
Remove itAsync from link/error tests
jerelmiller Dec 2, 2024
cdadb6f
Remove itAsync from client tests
jerelmiller Dec 5, 2024
b8242b4
Remove itAsync from writeToStore tests
jerelmiller Dec 5, 2024
fa83b8e
Allow toEmitError to compare error string
jerelmiller Dec 5, 2024
6eb840b
Remove itAsync from link/context tests
jerelmiller Dec 5, 2024
45792a2
Remove itAsync from ApolloClient tests
jerelmiller Dec 6, 2024
243d775
Remove itAsync from getDataFromTree tests
jerelmiller Dec 6, 2024
8fdd503
Remove itAsync from batchHttpLink tests
jerelmiller Dec 6, 2024
5b1f7a5
Remove itAsync from batchLink tests
jerelmiller Dec 7, 2024
4e642d6
Remove itAsync from fetchPolicies tests
jerelmiller Dec 7, 2024
3f66241
Remove itAsync from asyncMap tests
jerelmiller Dec 7, 2024
305a7e0
Remove itAsync from QueryManager/links tests
jerelmiller Dec 7, 2024
41b0905
Remove itAsync from local-state/resolvers tests
jerelmiller Dec 7, 2024
9e6efd1
Rename assertWithObserver to setupTestWithResolvers
jerelmiller Dec 7, 2024
5feb605
Remove itAsync from local-state/general tests
jerelmiller Dec 7, 2024
701d1a0
Use expect(...).rejects to check for errors
jerelmiller Dec 9, 2024
5019939
Ensure promise is awaited on assertion
jerelmiller Dec 9, 2024
e9d84ba
Default to false for boolean
jerelmiller Dec 9, 2024
81614e5
Remove itAsync from QueryManager/recycler tests
jerelmiller Dec 9, 2024
c40d468
Remove itAsync from local-state/export tests
jerelmiller Dec 9, 2024
8c83909
Silence cache write warnings in local-state/export tests
jerelmiller Dec 9, 2024
1102701
Remove itAsync from MockedProvider tests
jerelmiller Dec 9, 2024
1ac25c7
Remove itAsync from subscribeToMore tests
jerelmiller Dec 10, 2024
615ccfb
Remove itAsync from QueryManager/multiple-results tests
jerelmiller Dec 10, 2024
3035297
Remove itAsync from ApolloLink tests
jerelmiller Dec 10, 2024
9e36b6f
Remove itAsync from QueryManager/index tests
jerelmiller Dec 10, 2024
e0827a6
Stop using observableToPromise in QueryManager/index tests
jerelmiller Dec 11, 2024
fc7ca7f
Remove unused observableToPromise testing utility
jerelmiller Dec 11, 2024
b30bbbd
Remove itAsync from local-state/subscriptions tests
jerelmiller Dec 11, 2024
1775e15
Remove itAsync from parseAndCheckHttpResponse tests
jerelmiller Dec 11, 2024
c976713
Remove itAsync from optimistic tests
jerelmiller Dec 11, 2024
1a3bab7
Remove itAsync from refetchQueries tests
jerelmiller Dec 12, 2024
bf90069
Remove itAsync from Concast tests
jerelmiller Dec 12, 2024
67b57f0
Remove itAsync from toPromise tests
jerelmiller Dec 12, 2024
18ff5c0
Remove itAsync from graphqlSubscriptions tests
jerelmiller Dec 12, 2024
1e7d108
Remove itAsync from schemaLink tests
jerelmiller Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
475 changes: 207 additions & 268 deletions src/__tests__/ApolloClient.ts

Large diffs are not rendered by default.

3,958 changes: 1,832 additions & 2,126 deletions src/__tests__/client.ts

Large diffs are not rendered by default.

214 changes: 80 additions & 134 deletions src/__tests__/graphqlSubscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { ApolloClient, FetchResult } from "../core";
import { InMemoryCache } from "../cache";
import { ApolloError, PROTOCOL_ERRORS_SYMBOL } from "../errors";
import { QueryManager } from "../core/QueryManager";
import { itAsync, mockObservableLink } from "../testing";
import { mockObservableLink } from "../testing";
import { GraphQLError } from "graphql";
import { spyOnConsole } from "../testing/internal";
import { ObservableStream, spyOnConsole } from "../testing/internal";
import { getDefaultOptionsForQueryManagerTests } from "../testing/core/mocking/mockQueryManager";

describe("GraphQL Subscriptions", () => {
Expand Down Expand Up @@ -47,62 +47,44 @@ describe("GraphQL Subscriptions", () => {
};
});

itAsync(
"should start a subscription on network interface and unsubscribe",
(resolve, reject) => {
const link = mockObservableLink();
// This test calls directly through Apollo Client
const client = new ApolloClient({
link,
cache: new InMemoryCache({ addTypename: false }),
});
it("should start a subscription on network interface and unsubscribe", async () => {
const link = mockObservableLink();
// This test calls directly through Apollo Client
const client = new ApolloClient({
link,
cache: new InMemoryCache({ addTypename: false }),
});

let count = 0;
const sub = client.subscribe(defaultOptions).subscribe({
next(result) {
count++;
expect(result).toEqual(results[0].result);
const stream = new ObservableStream(client.subscribe(defaultOptions));
link.simulateResult(results[0]);

// Test unsubscribing
if (count > 1) {
throw new Error("next fired after unsubscribing");
}
sub.unsubscribe();
resolve();
},
});
await expect(stream).toEmitValue(results[0].result);

link.simulateResult(results[0]);
}
);
stream.unsubscribe();

await expect(stream).not.toEmitAnything();
});

itAsync("should subscribe with default values", (resolve, reject) => {
it("should subscribe with default values", async () => {
const link = mockObservableLink();
// This test calls directly through Apollo Client
const client = new ApolloClient({
link,
cache: new InMemoryCache({ addTypename: false }),
});

let count = 0;
const sub = client.subscribe(options).subscribe({
next(result) {
expect(result).toEqual(results[0].result);
const stream = new ObservableStream(client.subscribe(options));

// Test unsubscribing
if (count > 1) {
throw new Error("next fired after unsubscribing");
}
sub.unsubscribe();
link.simulateResult(results[0]);

resolve();
},
});
await expect(stream).toEmitValue(results[0].result);

link.simulateResult(results[0]);
stream.unsubscribe();

await expect(stream).not.toEmitAnything();
});

itAsync("should multiplex subscriptions", (resolve, reject) => {
it("should multiplex subscriptions", async () => {
const link = mockObservableLink();
const queryManager = new QueryManager(
getDefaultOptionsForQueryManagerTests({
Expand All @@ -112,88 +94,57 @@ describe("GraphQL Subscriptions", () => {
);

const obs = queryManager.startGraphQLSubscription(options);

let counter = 0;

// tslint:disable-next-line
obs.subscribe({
next(result) {
expect(result).toEqual(results[0].result);
counter++;
if (counter === 2) {
resolve();
}
},
}) as any;

// Subscribe again. Should also receive the same result.
// tslint:disable-next-line
obs.subscribe({
next(result) {
expect(result).toEqual(results[0].result);
counter++;
if (counter === 2) {
resolve();
}
},
}) as any;
const stream1 = new ObservableStream(obs);
const stream2 = new ObservableStream(obs);

link.simulateResult(results[0]);

await expect(stream1).toEmitValue(results[0].result);
await expect(stream2).toEmitValue(results[0].result);
});

itAsync(
"should receive multiple results for a subscription",
(resolve, reject) => {
const link = mockObservableLink();
let numResults = 0;
const queryManager = new QueryManager(
getDefaultOptionsForQueryManagerTests({
link,
cache: new InMemoryCache({ addTypename: false }),
})
);

// tslint:disable-next-line
queryManager.startGraphQLSubscription(options).subscribe({
next(result) {
expect(result).toEqual(results[numResults].result);
numResults++;
if (numResults === 4) {
resolve();
}
},
}) as any;
it("should receive multiple results for a subscription", async () => {
const link = mockObservableLink();
const queryManager = new QueryManager(
getDefaultOptionsForQueryManagerTests({
link,
cache: new InMemoryCache({ addTypename: false }),
})
);

for (let i = 0; i < 4; i++) {
link.simulateResult(results[i]);
}
const stream = new ObservableStream(
queryManager.startGraphQLSubscription(options)
);

for (let i = 0; i < 4; i++) {
link.simulateResult(results[i]);
}
);

itAsync(
"should not cache subscription data if a `no-cache` fetch policy is used",
(resolve, reject) => {
const link = mockObservableLink();
const cache = new InMemoryCache({ addTypename: false });
const client = new ApolloClient({
link,
cache,
});

expect(cache.extract()).toEqual({});
await expect(stream).toEmitValue(results[0].result);
await expect(stream).toEmitValue(results[1].result);
await expect(stream).toEmitValue(results[2].result);
await expect(stream).toEmitValue(results[3].result);
await expect(stream).not.toEmitAnything();
});

options.fetchPolicy = "no-cache";
const sub = client.subscribe(options).subscribe({
next() {
expect(cache.extract()).toEqual({});
sub.unsubscribe();
resolve();
},
});
it("should not cache subscription data if a `no-cache` fetch policy is used", async () => {
const link = mockObservableLink();
const cache = new InMemoryCache({ addTypename: false });
const client = new ApolloClient({
link,
cache,
});

link.simulateResult(results[0]);
}
);
expect(cache.extract()).toEqual({});

options.fetchPolicy = "no-cache";
const stream = new ObservableStream(client.subscribe(options));

link.simulateResult(results[0]);

await expect(stream).toEmitNext();
expect(cache.extract()).toEqual({});
});

it("should throw an error if the result has errors on it", () => {
const link = mockObservableLink();
Expand Down Expand Up @@ -492,27 +443,22 @@ describe("GraphQL Subscriptions", () => {
});
});

itAsync(
"should pass a context object through the link execution chain",
(resolve, reject) => {
const link = mockObservableLink();
const client = new ApolloClient({
cache: new InMemoryCache(),
link,
});
it("should pass a context object through the link execution chain", async () => {
const link = mockObservableLink();
const client = new ApolloClient({
cache: new InMemoryCache(),
link,
});

client.subscribe(options).subscribe({
next() {
expect(link.operation?.getContext().someVar).toEqual(
options.context.someVar
);
resolve();
},
});
const stream = new ObservableStream(client.subscribe(options));

link.simulateResult(results[0]);
}
);
link.simulateResult(results[0]);

await expect(stream).toEmitNext();
expect(link.operation?.getContext().someVar).toEqual(
options.context.someVar
);
});

it("should throw an error if the result has protocolErrors on it", async () => {
const link = mockObservableLink();
Expand Down
Loading
Loading