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

Added @apollo/client/testing/core entry point #8687

Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
- The `HttpLink` constructor now accepts an optional `print` function that can be used to customize how GraphQL `DocumentNode` objects are transformed back into strings before they are sent over the network. <br/>
[@sarahgp](https://github.com/sarahgp) in [#8699](https://github.com/apollographql/apollo-client/pull/8699)

- A new nested entry point called `@apollo/client/testing/core` has been created. Importing from this entry point instead of `@apollo/client/testing` excludes any React-related dependencies. <br/>
[@wassim-k](https://github.com/wassim-k) in [#8687](https://github.com/apollographql/apollo-client/pull/8687)

### React Refactoring

#### Bug Fixes (due to [@brainkim](https://github.com/brainkim) in [#8596](https://github.com/apollographql/apollo-client/pull/8596)):
Expand Down
1 change: 1 addition & 0 deletions config/entryPoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const entryPoints = [
{ dirs: ['react', 'parser'] },
{ dirs: ['react', 'ssr'] },
{ dirs: ['testing'], extensions: [".js", ".jsx"] },
{ dirs: ['testing', 'core'] },
{ dirs: ['utilities'] },
{ dirs: ['utilities', 'globals'], sideEffects: true },
];
Expand Down
15 changes: 15 additions & 0 deletions src/__tests__/__snapshots__/exports.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,21 @@ Array [
]
`;

exports[`exports of public entry points @apollo/client/testing/core 1`] = `
Array [
"MockLink",
"MockSubscriptionLink",
"createMockClient",
"itAsync",
"mockObservableLink",
"mockSingleLink",
"subscribeAndCount",
"withErrorSpy",
"withLogSpy",
"withWarningSpy",
]
`;

exports[`exports of public entry points @apollo/client/utilities 1`] = `
Array [
"Concast",
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as reactHooks from "../react/hooks";
import * as reactParser from "../react/parser";
import * as reactSSR from "../react/ssr";
import * as testing from "../testing";
import * as testingCore from "../testing/core";
import * as utilities from "../utilities";
import * as utilitiesGlobals from "../utilities/globals";

Expand Down Expand Up @@ -61,6 +62,7 @@ describe('exports of public entry points', () => {
check("@apollo/client/react/parser", reactParser);
check("@apollo/client/react/ssr", reactSSR);
check("@apollo/client/testing", testing);
check("@apollo/client/testing/core", testingCore);
check("@apollo/client/utilities", utilities);
check("@apollo/client/utilities/globals", utilitiesGlobals);

Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/local-state/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { InMemoryCache } from '../../cache';
import { Observable, Observer } from '../../utilities';
import { ApolloLink } from '../../link/core';
import { itAsync } from '../../testing';
import mockQueryManager from '../../testing/mocking/mockQueryManager';
import wrap from '../../testing/wrap';
import mockQueryManager from '../../testing/core/mocking/mockQueryManager';
import wrap from '../../testing/core/wrap';

// Helper method that sets up a mockQueryManager and then passes on the
// results to an observer.
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/refetchQueries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Subscription } from "zen-observable-ts";

import { itAsync } from '../testing/itAsync';
import { itAsync } from '../testing';
import {
ApolloClient,
ApolloLink,
Expand Down
11 changes: 7 additions & 4 deletions src/cache/inmemory/__tests__/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import { ReactiveVar, makeVar } from "../reactiveVars";
import { Reference, StoreObject, ApolloClient, NetworkStatus, TypedDocumentNode, DocumentNode } from "../../../core";
import { MissingFieldError } from "../..";
import { relayStylePagination } from "../../../utilities";
import { MockLink } from '../../../testing/mocking/mockLink';
import subscribeAndCount from '../../../testing/subscribeAndCount';
import { itAsync } from '../../../testing/itAsync';
import { FieldPolicy, StorageType } from "../policies";
import { withErrorSpy, withWarningSpy } from "../../../testing";
import {
itAsync,
withErrorSpy,
withWarningSpy,
subscribeAndCount,
MockLink,
} from "../../../testing/core";

function reverse(s: string) {
return s.split("").reverse().join("");
Expand Down
2 changes: 1 addition & 1 deletion src/cache/inmemory/__tests__/writeToStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '../../../utilities/graphql/storeUtils';
import { addTypenameToDocument } from '../../../utilities/graphql/transform';
import { cloneDeep } from '../../../utilities/common/cloneDeep';
import { itAsync } from '../../../testing/itAsync';
import { itAsync } from '../../../testing/core';
import { StoreWriter } from '../writeToStore';
import { defaultNormalizedCacheFactory, writeQueryToStore } from './helpers';
import { InMemoryCache } from '../inMemoryCache';
Expand Down
6 changes: 3 additions & 3 deletions src/core/__tests__/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { InMemoryCache, NormalizedCacheObject } from '../../cache';
import { ApolloError } from '../../errors';

import { itAsync, mockSingleLink, subscribeAndCount } from '../../testing';
import mockQueryManager from '../../testing/mocking/mockQueryManager';
import mockWatchQuery from '../../testing/mocking/mockWatchQuery';
import wrap from '../../testing/wrap';
import mockQueryManager from '../../testing/core/mocking/mockQueryManager';
import mockWatchQuery from '../../testing/core/mocking/mockWatchQuery';
import wrap from '../../testing/core/wrap';

export const mockFetchQuery = (queryManager: QueryManager<any>) => {
const fetchQueryObservable = queryManager.fetchQueryObservable;
Expand Down
13 changes: 6 additions & 7 deletions src/core/__tests__/QueryManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
} from '../../../cache/inmemory/types';

// mocks
import mockQueryManager from '../../../testing/mocking/mockQueryManager';
import mockWatchQuery from '../../../testing/mocking/mockWatchQuery';
import { MockApolloLink, mockSingleLink } from '../../../testing/mocking/mockLink';
import mockQueryManager from '../../../testing/core/mocking/mockQueryManager';
import mockWatchQuery from '../../../testing/core/mocking/mockWatchQuery';
import { MockApolloLink, mockSingleLink } from '../../../testing/core/mocking/mockLink';

// core
import { ApolloQueryResult } from '../../types';
Expand All @@ -29,12 +29,11 @@ import { QueryManager } from '../../QueryManager';
import { ApolloError } from '../../../errors';

// testing utils
import wrap from '../../../testing/wrap';
import wrap from '../../../testing/core/wrap';
import observableToPromise, {
observableToPromiseAndSubscription,
} from '../../../testing/observableToPromise';
import subscribeAndCount from '../../../testing/subscribeAndCount';
import { itAsync } from '../../../testing/itAsync';
} from '../../../testing/core/observableToPromise';
import { itAsync, subscribeAndCount } from '../../../testing/core';
import { ApolloClient } from '../../../core'
import { mockFetchQuery } from '../ObservableQuery';

Expand Down
2 changes: 1 addition & 1 deletion src/core/__tests__/QueryManager/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ApolloLink } from '../../../link/core';
import { InMemoryCache } from '../../../cache/inmemory/inMemoryCache';

// mocks
import { MockSubscriptionLink } from '../../../testing/mocking/mockSubscriptionLink';
import { MockSubscriptionLink } from '../../../testing/core';

// core
import { QueryManager } from '../../QueryManager';
Expand Down
4 changes: 1 addition & 3 deletions src/core/__tests__/QueryManager/multiple-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import gql from 'graphql-tag';
import { InMemoryCache } from '../../../cache/inmemory/inMemoryCache';

// mocks
import {
MockSubscriptionLink
} from '../../../testing/mocking/mockSubscriptionLink';
import { MockSubscriptionLink } from '../../../testing/core';

// core
import { QueryManager } from '../../QueryManager';
Expand Down
8 changes: 4 additions & 4 deletions src/core/__tests__/QueryManager/recycler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

// externals
import gql from 'graphql-tag';
import { InMemoryCache } from '../../../cache/inmemory/inMemoryCache';
import {
MockSubscriptionLink
} from '../../../testing/mocking/mockSubscriptionLink';

// core
import { QueryManager } from '../../QueryManager';
import { ObservableQuery } from '../../ObservableQuery';
import { ObservableSubscription } from '../../../utilities';
import { InMemoryCache } from '../../../cache';

// mocks
import { MockSubscriptionLink } from '../../../testing/core';

describe('Subscription lifecycles', () => {
it('cleans up and reuses data like QueryRecycler wants', done => {
Expand Down
2 changes: 1 addition & 1 deletion src/react/hoc/__tests__/mutations/lifecycle.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render, cleanup } from '@testing-library/react';
import gql from 'graphql-tag';

import { ApolloProvider } from '../../../context/ApolloProvider';
import { createMockClient } from '../../../../testing/mocking/mockClient';
import { createMockClient } from '../../../../testing/core';
import { graphql } from '../../graphql';
import { ChildProps } from '../../types';

Expand Down
14 changes: 14 additions & 0 deletions src/testing/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export {
MockLink,
mockSingleLink,
MockedResponse,
ResultFunction
} from './mocking/mockLink';
export {
MockSubscriptionLink,
mockObservableLink
} from './mocking/mockSubscriptionLink';
export { createMockClient } from './mocking/mockClient';
export { default as subscribeAndCount } from './subscribeAndCount';
export { itAsync } from './itAsync';
export * from './withConsoleSpy';
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DocumentNode } from 'graphql';

import { ApolloClient } from '../../core';
import { InMemoryCache, NormalizedCacheObject } from '../../cache';
import { ApolloClient } from '../../../core';
import { InMemoryCache, NormalizedCacheObject } from '../../../cache';
import { mockSingleLink } from './mockLink';

export function createMockClient<TData>(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { invariant } from '../../utilities/globals';
import { invariant } from '../../../utilities/globals';

import { print } from 'graphql';
import { equal } from '@wry/equality';
Expand All @@ -8,7 +8,7 @@ import {
Operation,
GraphQLRequest,
FetchResult,
} from '../../link/core';
} from '../../../link/core';

import {
Observable,
Expand All @@ -17,7 +17,7 @@ import {
removeConnectionDirectiveFromDocument,
cloneDeep,
stringifyForDisplay,
} from '../../utilities';
} from '../../../utilities';

export type ResultFunction<T> = () => T;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QueryManager } from '../../core/QueryManager';
import { QueryManager } from '../../../core/QueryManager';
import { mockSingleLink, MockedResponse } from './mockLink';
import { InMemoryCache } from '../../cache';
import { InMemoryCache } from '../../../cache';

// Helper method for the tests that construct a query manager out of a
// a list of mocked responses for a mocked network interface.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Observable } from '../../utilities';
import { ApolloLink, FetchResult, Operation } from '../../link/core';
import { Observable } from '../../../utilities';
import { ApolloLink, FetchResult, Operation } from '../../../link/core';

export interface MockedSubscription {
request: Operation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MockedResponse } from './mockLink';
import mockQueryManager from './mockQueryManager';
import { ObservableQuery } from '../../core';
import { ObservableQuery } from '../../../core';

export default (
reject: (reason: any) => any,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ObservableQuery, ApolloQueryResult } from '../core';
import { ObservableSubscription } from '../utilities';
import { ObservableQuery, ApolloQueryResult } from '../../core';
import { ObservableSubscription } from '../../utilities';

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ObservableQuery, ApolloQueryResult, OperationVariables } from '../core';
import { ObservableSubscription, asyncMap } from '../utilities';
import { ObservableQuery, ApolloQueryResult, OperationVariables } from '../../core';
import { ObservableSubscription, asyncMap } from '../../utilities';

export default function subscribeAndCount<
TData,
Expand Down
File renamed without changes.
File renamed without changes.
17 changes: 2 additions & 15 deletions src/testing/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
import '../utilities/globals';
export { MockedProvider, MockedProviderProps } from './mocking/MockedProvider';
export {
MockLink,
mockSingleLink,
MockedResponse,
ResultFunction
} from './mocking/mockLink';
export {
MockSubscriptionLink,
mockObservableLink
} from './mocking/mockSubscriptionLink';
export { createMockClient } from './mocking/mockClient';
export { default as subscribeAndCount } from './subscribeAndCount';
export { itAsync } from './itAsync';
export * from './withConsoleSpy';
export { MockedProvider, MockedProviderProps } from './react/MockedProvider';
export * from './core';
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import { ApolloClient, DefaultOptions } from '../../core';
import { InMemoryCache as Cache } from '../../cache';
import { ApolloProvider } from '../../react/context';
import { MockLink, MockedResponse } from './mockLink';
import { MockLink, MockedResponse } from '../core';
import { ApolloLink } from '../../link/core';
import { Resolvers } from '../../core';
import { ApolloCache } from '../../cache';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React from 'react';
import { DocumentNode } from 'graphql';
import { render, wait } from '@testing-library/react';
import gql from 'graphql-tag';

import { itAsync } from '../../itAsync';
import { itAsync, MockedResponse, MockLink } from '../../core';
import { MockedProvider } from '../MockedProvider';
import { MockedResponse, MockLink } from '../mockLink';
import { DocumentNode } from 'graphql';
import { useQuery } from '../../../react/hooks';
import { InMemoryCache } from '../../../cache';
import { ApolloLink } from '../../../link/core';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { render, wait } from '@testing-library/react';
import gql from 'graphql-tag';

import { MockSubscriptionLink } from '../mockSubscriptionLink';
import { MockSubscriptionLink } from '../../core';
import { ApolloClient } from '../../../core';
import { InMemoryCache as Cache } from '../../../cache';
import { ApolloProvider } from '../../../react/context';
Expand Down