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

cleanup optimistic updates tests #3713

Merged
merged 14 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 7 additions & 9 deletions packages/apollo-cache-inmemory/src/__tests__/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import { InMemoryCache, ApolloReducerConfig, NormalizedCache } from '..';
disableFragmentWarnings();

describe('Cache', () => {
function createCache(
{
initialState,
config,
}: {
initialState?: any;
config?: ApolloReducerConfig;
} = {},
): ApolloCache<NormalizedCache> {
function createCache({
initialState,
config,
}: {
initialState?: any;
config?: ApolloReducerConfig;
} = {}): ApolloCache<NormalizedCache> {
return new InMemoryCache(
config || { addTypename: false },
// XXX this is the old format. The tests need to be updated but since it is mapped down
Expand Down
8 changes: 6 additions & 2 deletions packages/apollo-cache-inmemory/src/writeToStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ function writeFieldToStore({
if (generated && !escapedId.generated && !typenameChanged) {
throw new Error(
`Store error: the application attempted to write an object with no provided id` +
` but the store already contains an id of ${escapedId.id} for this object. The selectionSet` +
` but the store already contains an id of ${
escapedId.id
} for this object. The selectionSet` +
` that was trying to be written is:\n` +
print(field),
);
Expand All @@ -438,7 +440,9 @@ function writeFieldToStore({
if (hadTypename && !hasTypename) {
throw new Error(
`Store error: the application attempted to write an object with no provided typename` +
` but the store already contains an object with typename of ${escapedId.typename} for the object of id ${escapedId.id}. The selectionSet` +
` but the store already contains an object with typename of ${
escapedId.typename
} for the object of id ${escapedId.id}. The selectionSet` +
` that was trying to be written is:\n` +
print(field),
);
Expand Down
18 changes: 10 additions & 8 deletions packages/apollo-client/benchmark/github-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,23 @@ export function collectAndReportBenchmarks(uploadToGithub: Boolean) {
} else {
const normalizedMean = res[element].mean / res['baseline'].mean;
if (normalizedMean > thresholds[element]) {
const perfDropMessage = `Performance drop detected for benchmark: "${element}", ${res[
element
].mean} / ${res['baseline']
.mean} = ${normalizedMean} > ${thresholds[element]}`;
const perfDropMessage = `Performance drop detected for benchmark: "${element}", ${
res[element].mean
} / ${res['baseline'].mean} = ${normalizedMean} > ${
thresholds[element]
}`;
console.error(perfDropMessage);
if (message === '') {
message = `Performance drop detected for benchmark: "${element}"`;
pass = false;
}
} else {
console.log(
`No performance drop detected for benchmark: "${element}", ${res[
element
].mean} / ${res['baseline']
.mean} = ${normalizedMean} <= ${thresholds[element]}`,
`No performance drop detected for benchmark: "${element}", ${
res[element].mean
} / ${res['baseline'].mean} = ${normalizedMean} <= ${
thresholds[element]
}`,
);
}
}
Expand Down
19 changes: 9 additions & 10 deletions packages/apollo-client/src/__tests__/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2073,16 +2073,15 @@ describe('ApolloClient', () => {
}
`;

[
'network-only',
'cache-and-network',
].forEach((fetchPolicy: FetchPolicy) => {
const observable = client.watchQuery({
query,
fetchPolicy,
});
expect(observable.options.fetchPolicy).toEqual('cache-first');
});
['network-only', 'cache-and-network'].forEach(
(fetchPolicy: FetchPolicy) => {
const observable = client.watchQuery({
query,
fetchPolicy,
});
expect(observable.options.fetchPolicy).toEqual('cache-first');
},
);
},
);

Expand Down
65 changes: 32 additions & 33 deletions packages/apollo-client/src/__tests__/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ describe('client', () => {
});

expect(() => {
client.query(gql`{
client.query(gql`
{
a
}` as any);
}
` as any);
}).toThrowError(
'query option is required. You must specify your GraphQL document in the query option.',
);
Expand Down Expand Up @@ -621,43 +623,40 @@ describe('client', () => {
});
});

xit(
'should pass a network error correctly on a query using an observable network interface with a warning',
done => {
withWarning(() => {
const query = gql`
query people {
allPeople(first: 1) {
people {
name
}
xit('should pass a network error correctly on a query using an observable network interface with a warning', done => {
withWarning(() => {
const query = gql`
query people {
allPeople(first: 1) {
people {
name
}
}
`;
}
`;

const networkError = new Error('Some kind of network error.');
const networkError = new Error('Some kind of network error.');

const link = ApolloLink.from([
() => {
return new Observable(_ => {
throw networkError;
});
},
]);
const link = ApolloLink.from([
() => {
return new Observable(_ => {
throw networkError;
});
},
]);

const client = new ApolloClient({
link,
cache: new InMemoryCache({ addTypename: false }),
});
const client = new ApolloClient({
link,
cache: new InMemoryCache({ addTypename: false }),
});

client.query({ query }).catch((error: ApolloError) => {
expect(error.networkError).toBeDefined();
expect(error.networkError!.message).toEqual(networkError.message);
done();
});
}, /deprecated/);
},
);
client.query({ query }).catch((error: ApolloError) => {
expect(error.networkError).toBeDefined();
expect(error.networkError!.message).toEqual(networkError.message);
done();
});
}, /deprecated/);
});

it('should pass a network error correctly on a query with apollo-link network interface', done => {
const query = gql`
Expand Down
Loading