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

Update Jest-related dependencies to latest version (v27) to address npm audit problems #9004

Merged
merged 3 commits into from
Nov 4, 2021
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
1 change: 1 addition & 0 deletions config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ module.exports = {
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
testURL: 'http://localhost',
setupFiles: ['<rootDir>/config/jest/setup.ts'],
testEnvironment: 'jsdom',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the change that reenables jsdom for all tests. Should we restrict it to the ones that actually need it?

};
12,264 changes: 4,087 additions & 8,177 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"@types/fetch-mock": "7.3.5",
"@types/glob": "7.2.0",
"@types/hoist-non-react-statics": "3.3.1",
"@types/jest": "26.0.24",
"@types/jest": "27.0.2",
"@types/lodash": "4.14.176",
"@types/node": "16.11.6",
"@types/react": "17.0.33",
Expand All @@ -109,9 +109,9 @@
"fetch-mock": "9.11.0",
"glob": "7.2.0",
"graphql": "15.7.2",
"jest": "26.6.3",
"jest": "27.3.1",
"jest-fetch-mock": "3.0.3",
"jest-junit": "12.3.0",
"jest-junit": "13.0.0",
"lodash": "4.17.21",
"react": "17.0.2",
"react-dom": "17.0.2",
Expand All @@ -123,7 +123,7 @@
"rxjs": "6.6.7",
"subscriptions-transport-ws": "0.9.19",
"terser": "5.9.0",
"ts-jest": "26.5.6",
"ts-jest": "27.0.7",
"ts-node": "10.4.0",
"typescript": "4.4.4",
"wait-for-observables": "1.0.3",
Expand Down
24 changes: 12 additions & 12 deletions src/__tests__/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Observable } from '../utilities';
import { ApolloLink } from '../link/core';
import { HttpLink } from '../link/http';
import { InMemoryCache } from '../cache';
import { withErrorSpy } from '../testing';
import { itAsync, withErrorSpy } from '../testing';
import { TypedDocumentNode } from '@graphql-typed-document-node/core';

describe('ApolloClient', () => {
Expand Down Expand Up @@ -1192,7 +1192,7 @@ describe('ApolloClient', () => {
result.data?.people.friends[0].id;
});

it('with a replacement of nested array (wq)', done => {
itAsync('with a replacement of nested array (wq)', (resolve, reject) => {
let count = 0;
const client = newClient();
const observable = client.watchQuery<Data>({ query });
Expand Down Expand Up @@ -1236,13 +1236,13 @@ describe('ApolloClient', () => {
expectation,
);
subscription.unsubscribe();
done();
resolve();
}
},
});
});

it('with a value change inside a nested array (wq)', done => {
itAsync('with a value change inside a nested array (wq)', (resolve, reject) => {
let count = 0;
const client = newClient();
const observable = client.watchQuery<Data>({ query });
Expand Down Expand Up @@ -1277,7 +1277,7 @@ describe('ApolloClient', () => {

setTimeout(() => {
if (count === 1)
done.fail(
reject(
new Error(
'writeFragment did not re-call observable with next value',
),
Expand All @@ -1301,14 +1301,14 @@ describe('ApolloClient', () => {
const readFriends = client.readQuery<Data>({ query })!.people.friends;
expect(readFriends[0]).toEqual(expectation0);
expect(readFriends[1]).toEqual(expectation1);
done();
resolve();
}
},
});
});
});
describe('using writeFragment', () => {
it('with a replacement of nested array (wf)', done => {
itAsync('with a replacement of nested array (wf)', (resolve, reject) => {
let count = 0;
const client = newClient();
const observable = client.watchQuery<Data>({ query });
Expand Down Expand Up @@ -1341,7 +1341,7 @@ describe('ApolloClient', () => {

setTimeout(() => {
if (count === 1)
done.fail(
reject(
new Error(
'writeFragment did not re-call observable with next value',
),
Expand All @@ -1353,13 +1353,13 @@ describe('ApolloClient', () => {
expect(result.data!.people.friends).toEqual([
bestFriend,
]);
done();
resolve();
}
},
});
});

it('with a value change inside a nested array (wf)', done => {
itAsync('with a value change inside a nested array (wf)', (resolve, reject) => {
let count = 0;
const client = newClient();
const observable = client.watchQuery<Data>({ query });
Expand Down Expand Up @@ -1395,7 +1395,7 @@ describe('ApolloClient', () => {

setTimeout(() => {
if (count === 1)
done.fail(
reject(
new Error(
'writeFragment did not re-call observable with next value',
),
Expand All @@ -1413,7 +1413,7 @@ describe('ApolloClient', () => {
...badFriend,
type: 'okayest',
});
done();
resolve();
}
},
});
Expand Down
8 changes: 5 additions & 3 deletions src/__tests__/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2335,7 +2335,7 @@ describe('client', () => {
expect(count).toEqual(2);
});

it('invokes onResetStore callbacks before notifying queries during resetStore call', async () => {
itAsync('invokes onResetStore callbacks before notifying queries during resetStore call', async (resolve, reject) => {
const delay = (time: number) => new Promise(r => setTimeout(r, time));

const query = gql`
Expand Down Expand Up @@ -2414,15 +2414,17 @@ describe('client', () => {
})
.subscribe({
next,
error: fail,
complete: fail,
error: reject,
complete: reject,
});

expect(count).toEqual(0);
await client.resetStore();
expect(count).toEqual(2);
//watchQuery should only receive data twice
expect(next).toHaveBeenCalledTimes(2);

resolve();
});

it('has a reFetchObservableQueries method which calls QueryManager', async () => {
Expand Down
31 changes: 15 additions & 16 deletions src/__tests__/graphqlSubscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import gql from 'graphql-tag';
import { ApolloClient } from '../core';
import { InMemoryCache } from '../cache';
import { QueryManager } from '../core/QueryManager';
import { mockObservableLink } from '../testing';
import { itAsync, mockObservableLink } from '../testing';

describe('GraphQL Subscriptions', () => {
const results = [
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('GraphQL Subscriptions', () => {
};
});

it('should start a subscription on network interface and unsubscribe', done => {
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({
Expand All @@ -62,14 +62,14 @@ describe('GraphQL Subscriptions', () => {
throw new Error('next fired after unsubscribing');
}
sub.unsubscribe();
done();
resolve();
},
});

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

it('should subscribe with default values', done => {
itAsync('should subscribe with default values', (resolve, reject) => {
const link = mockObservableLink();
// This test calls directly through Apollo Client
const client = new ApolloClient({
Expand All @@ -88,14 +88,14 @@ describe('GraphQL Subscriptions', () => {
}
sub.unsubscribe();

done();
resolve();
},
});

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

it('should multiplex subscriptions', done => {
itAsync('should multiplex subscriptions', (resolve, reject) => {
const link = mockObservableLink();
const queryManager = new QueryManager({
link,
Expand All @@ -112,7 +112,7 @@ describe('GraphQL Subscriptions', () => {
expect(result).toEqual(results[0].result);
counter++;
if (counter === 2) {
done();
resolve();
}
},
}) as any;
Expand All @@ -124,15 +124,15 @@ describe('GraphQL Subscriptions', () => {
expect(result).toEqual(results[0].result);
counter++;
if (counter === 2) {
done();
resolve();
}
},
}) as any;

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

it('should receive multiple results for a subscription', done => {
itAsync('should receive multiple results for a subscription', (resolve, reject) => {
const link = mockObservableLink();
let numResults = 0;
const queryManager = new QueryManager({
Expand All @@ -146,7 +146,7 @@ describe('GraphQL Subscriptions', () => {
expect(result).toEqual(results[numResults].result);
numResults++;
if (numResults === 4) {
done();
resolve();
}
},
}) as any;
Expand All @@ -156,7 +156,7 @@ describe('GraphQL Subscriptions', () => {
}
});

it('should not cache subscription data if a `no-cache` fetch policy is used', done => {
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({
Expand All @@ -171,7 +171,7 @@ describe('GraphQL Subscriptions', () => {
next() {
expect(cache.extract()).toEqual({});
sub.unsubscribe();
done();
resolve();
},
});

Expand All @@ -193,8 +193,7 @@ describe('GraphQL Subscriptions', () => {
new Promise<void>((resolve, reject) => {
obs.subscribe({
next(result) {
fail('Should have hit the error block');
reject();
reject('Should have hit the error block');
},
error(error) {
expect(error).toMatchSnapshot();
Expand Down Expand Up @@ -244,7 +243,7 @@ describe('GraphQL Subscriptions', () => {
});
});

it('should pass a context object through the link execution chain', done => {
itAsync('should pass a context object through the link execution chain', (resolve, reject) => {
const link = mockObservableLink();
const client = new ApolloClient({
cache: new InMemoryCache(),
Expand All @@ -256,7 +255,7 @@ describe('GraphQL Subscriptions', () => {
expect(link.operation.getContext().someVar).toEqual(
options.context.someVar
);
done();
resolve();
},
});

Expand Down
9 changes: 9 additions & 0 deletions src/__tests__/local-state/__snapshots__/export.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ exports[`@client @export tests should NOT refetch if an @export variable has not
"calls": Array [
Array [
"Missing field 'postCount' while writing result {
\\"currentAuthorId\\": 101
}",
],
Array [
"Missing field 'postCount' while writing result {
\\"currentAuthorId\\": 100
}",
],
Expand All @@ -14,6 +19,10 @@ exports[`@client @export tests should NOT refetch if an @export variable has not
"type": "return",
"value": undefined,
},
Object {
"type": "return",
"value": undefined,
},
],
}
`;
Expand Down
Loading