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

Testing utilities cleanup #5514

Merged
merged 13 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from 10 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
3 changes: 1 addition & 2 deletions config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ module.exports = {
testURL: 'http://localhost',
testPathIgnorePatterns: [
'/node_modules/',
'/dist/',
'src/__tests__/utils'
'/dist/'
],
modulePathIgnorePatterns: ['/dist/'],
setupFiles: ['<rootDir>/src/config/jest/setup.ts'],
Expand Down
10 changes: 5 additions & 5 deletions config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ function prepareCJSMinified() {
// context.
function prepareTesting() {
const bundleName = 'testing';
const apolloProviderPath = 'context/ApolloProvider';
const apolloProviderPath = 'react/context/ApolloProvider';

const testingGlobals = {
...globals,
[`../../${apolloProviderPath}`]: 'ApolloProvider'
[`../../../${apolloProviderPath}`]: 'ApolloProvider'
};

const output = {
Expand All @@ -140,11 +140,11 @@ function prepareTesting() {
// `react/testing` type definitions.
fs.writeFileSync(
`${distDir}/${bundleName}.d.ts`,
"export * from './react/testing';"
"export * from './utilities/testing';"
);

return {
input: `${distDir}/react/testing/index.js`,
input: `${distDir}/utilities/testing/index.js`,
external: (id) => hasOwn.call(testingGlobals, id),
output,
plugins: [
Expand All @@ -162,7 +162,7 @@ function prepareTesting() {
generateBundle(_option, bundle) {
bundle[bundleJs].code =
bundle[bundleJs].code.replace(
`../${apolloProviderPath}`,
`../../${apolloProviderPath}`,
packageJson.main.replace(distDir, '.')
);
}
Expand Down
167 changes: 0 additions & 167 deletions src/__mocks__/mockLinks.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/__tests__/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { makeReference } from '../utilities/graphql/storeUtils';
import { ApolloLink } from '../link/core/ApolloLink';
import { HttpLink } from '../link/http/HttpLink';
import { InMemoryCache } from '../cache/inmemory/inMemoryCache';
import { stripSymbols } from './utils/stripSymbols';
import { withWarning } from './utils/wrap';
import { stripSymbols } from '../utilities/testing/stripSymbols';
Copy link
Member Author

Choose a reason for hiding this comment

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

@benjamn Just calling this out; I consolidated the testing utilities under a new location of utilities/testing. The previous __tests__/utils location worked, but I didn’t like how our rollup config looked when creating a separate testing bundle from the __tests__ dir. Let me know if the new location works - thanks!

import { withWarning } from '../utilities/testing/wrap';
import { ApolloClient } from '../';
import { DefaultOptions } from '../ApolloClient';
import { FetchPolicy, QueryOptions } from '../core/watchQueryOptions';
Expand Down
12 changes: 7 additions & 5 deletions src/__tests__/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { Observable } from '../utilities/observables/Observable';
import { ApolloLink } from '../link/core/ApolloLink';
import { InMemoryCache } from '../cache/inmemory/inMemoryCache';
import { PossibleTypesMap } from '../cache/inmemory/types';
import { stripSymbols } from './utils/stripSymbols';
import { stripSymbols } from '../utilities/testing/stripSymbols';
import { WatchQueryOptions, FetchPolicy } from '../core/watchQueryOptions';
import { ApolloError } from '../errors/ApolloError';
import { ApolloClient } from '..';
import subscribeAndCount from './utils/subscribeAndCount';
import { withWarning } from './utils/wrap';
import { itAsync } from './utils/itAsync';
import { mockSingleLink } from '../__mocks__/mockLinks';
import subscribeAndCount from '../utilities/testing/subscribeAndCount';
import { withWarning } from '../utilities/testing/wrap';
import { itAsync } from '../utilities/testing/itAsync';
import { mockSingleLink } from '../utilities/testing/mocking/mockLink';

describe('client', () => {
it('can be loaded via require', () => {
Expand Down Expand Up @@ -917,6 +917,7 @@ describe('client', () => {
request: { query: transformedQuery },
result: { data: transformedResult },
},
false
);

const client = new ApolloClient({
Expand Down Expand Up @@ -970,6 +971,7 @@ describe('client', () => {
request: { query: transformedQuery },
result: { data: transformedResult },
},
false
);

const client = new ApolloClient({
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/fetchMore.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { assign, cloneDeep } from 'lodash';
import gql from 'graphql-tag';

import { mockSingleLink } from '../__mocks__/mockLinks';
import { mockSingleLink } from '../utilities/testing/mocking/mockLink';
import { InMemoryCache } from '../cache/inmemory/inMemoryCache';
import { ApolloClient, NetworkStatus, ObservableQuery } from '../';
import { itAsync } from './utils/itAsync';
import { itAsync } from '../utilities/testing/itAsync';

describe('updateQuery on a simple query', () => {
const query = gql`
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/graphqlSubscriptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import gql from 'graphql-tag';

import { mockObservableLink, MockedSubscription } from '../__mocks__/mockLinks';
import {
mockObservableLink,
MockedSubscription
} from '../utilities/testing/mocking/mockSubscriptionLink';
import { InMemoryCache } from '../cache/inmemory/inMemoryCache';
import { ApolloClient } from '../';
import { QueryManager } from '../core/QueryManager';
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/local-state/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ApolloClient } from '../..';
import { ApolloCache } from '../../cache/core/cache';
import { InMemoryCache } from '../../cache/inmemory/inMemoryCache';
import { hasDirectives } from '../../utilities/graphql/directives';
import { itAsync } from '../utils/itAsync';
import { itAsync } from '../../utilities/testing/itAsync';

describe('General functionality', () => {
it('should not impact normal non-@client use', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/local-state/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { assign } from 'lodash';
import { Observable, Observer } from '../../utilities/observables/Observable';
import { ApolloLink } from '../../link/core/ApolloLink';
import { ApolloClient } from '../..';
import mockQueryManager from '../../__mocks__/mockQueryManager';
import wrap from '../../__tests__/utils/wrap';
import { itAsync } from '../utils/itAsync';
import mockQueryManager from '../../utilities/testing/mocking/mockQueryManager';
import wrap from '../../utilities/testing/wrap';
import { itAsync } from '../../utilities/testing/itAsync';
import { ApolloQueryResult, Resolvers } from '../../core/types';
import { WatchQueryOptions } from '../../core/watchQueryOptions';
import { LocalState } from '../../core/LocalState';
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/mutationResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import gql from 'graphql-tag';

import { Observable, Subscription } from '../utilities/observables/Observable';
import { ApolloLink } from '../link/core/ApolloLink';
import { mockSingleLink } from '../__mocks__/mockLinks';
import { mockSingleLink } from '../utilities/testing/mocking/mockLink';
import { ApolloClient } from '..';
import { InMemoryCache } from '../cache/inmemory/inMemoryCache';
import { withWarning } from './utils/wrap';
import { itAsync } from './utils/itAsync';
import { withWarning } from '../utilities/testing/wrap';
import { itAsync } from '../utilities/testing/itAsync';

describe('mutation results', () => {
const query = gql`
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/optimistic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { take, toArray, map } from 'rxjs/operators';
import { assign, cloneDeep } from 'lodash';
import gql from 'graphql-tag';

import { mockSingleLink } from '../__mocks__/mockLinks';
import { mockSingleLink } from '../utilities/testing/mocking/mockLink';
import { MutationQueryReducersMap } from '../core/types';
import { Subscription } from '../utilities/observables/Observable';
import { ApolloClient } from '../';
import { addTypenameToDocument } from '../utilities/graphql/transform';
import { makeReference } from '../utilities/graphql/storeUtils';
import { stripSymbols } from './utils/stripSymbols';
import { itAsync } from './utils/itAsync';
import { stripSymbols } from '../utilities/testing/stripSymbols';
import { itAsync } from '../utilities/testing/itAsync';
import { InMemoryCache } from '../cache/inmemory/inMemoryCache';

describe('optimistic mutation results', () => {
Expand Down
7 changes: 4 additions & 3 deletions src/__tests__/subscribeToMore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { DocumentNode, OperationDefinitionNode } from 'graphql';

import { ApolloLink } from '../link/core/ApolloLink';
import { Operation } from '../link/core/types';
import { mockSingleLink, mockObservableLink } from '../__mocks__/mockLinks';
import { mockSingleLink } from '../utilities/testing/mocking/mockLink';
import { mockObservableLink } from '../utilities/testing/mocking/mockSubscriptionLink';
import { ApolloClient } from '../';
import { InMemoryCache } from '../cache/inmemory/inMemoryCache';
import { stripSymbols } from './utils/stripSymbols';
import { itAsync } from './utils/itAsync';
import { stripSymbols } from '../utilities/testing/stripSymbols';
import { itAsync } from '../utilities/testing/itAsync';

const isSub = (operation: Operation) =>
(operation.query as DocumentNode).definitions
Expand Down
2 changes: 1 addition & 1 deletion src/cache/inmemory/__tests__/cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gql, { disableFragmentWarnings } from 'graphql-tag';

import { stripSymbols } from '../../../__tests__/utils/stripSymbols';
import { stripSymbols } from '../../../utilities/testing/stripSymbols';
import { cloneDeep } from '../../../utilities/common/cloneDeep';
import { makeReference } from '../../../utilities/graphql/storeUtils';
import { InMemoryCache, InMemoryCacheConfig } from '../inMemoryCache';
Expand Down
2 changes: 1 addition & 1 deletion src/cache/inmemory/__tests__/readFromStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assign, omit } from 'lodash';
import gql from 'graphql-tag';

import { stripSymbols } from '../../../__tests__/utils/stripSymbols';
import { stripSymbols } from '../../../utilities/testing/stripSymbols';
import { StoreObject } from '../types';
import { StoreReader } from '../readFromStore';
import { makeReference } from '../../../utilities/graphql/storeUtils';
Expand Down
Loading