Skip to content

Commit

Permalink
Make @apollo/client/testing a full-fledged entry point.
Browse files Browse the repository at this point in the history
#8687 (comment)

Until now, the `@apollo/client/testing` entry point has merely
re-exported the contents of `@apollo/client/utilities/testing`, even
though the latter is not an official entry point, leading to "Risky
cross-entry-point nested import..." warnings during build.

This commit moves the contents of `@apollo/client/utilities/testing` to
actually reside within `@apollo/client/testing`, which should be safe
because `@apollo/client/testing` was the only safe way to access these
modules before now.
  • Loading branch information
benjamn committed Sep 10, 2021
1 parent b208f74 commit 990e436
Show file tree
Hide file tree
Showing 28 changed files with 57 additions and 61 deletions.
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 '../../utilities/testing/mocking/mockQueryManager';
import wrap from '../../utilities/testing/wrap';
import mockQueryManager from '../../testing/mocking/mockQueryManager';
import wrap from '../../testing/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 '../utilities/testing/itAsync';
import { itAsync } from '../testing/itAsync';
import {
ApolloClient,
ApolloLink,
Expand Down
6 changes: 3 additions & 3 deletions src/cache/inmemory/__tests__/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { ReactiveVar, makeVar } from "../reactiveVars";
import { Reference, StoreObject, ApolloClient, NetworkStatus, TypedDocumentNode, DocumentNode } from "../../../core";
import { MissingFieldError } from "../..";
import { relayStylePagination } from "../../../utilities";
import { MockLink } from '../../../utilities/testing/mocking/mockLink';
import subscribeAndCount from '../../../utilities/testing/subscribeAndCount';
import { itAsync } from '../../../utilities/testing/itAsync';
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";

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 '../../../utilities/testing/itAsync';
import { itAsync } from '../../../testing/itAsync';
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 '../../utilities/testing/mocking/mockQueryManager';
import mockWatchQuery from '../../utilities/testing/mocking/mockWatchQuery';
import wrap from '../../utilities/testing/wrap';
import mockQueryManager from '../../testing/mocking/mockQueryManager';
import mockWatchQuery from '../../testing/mocking/mockWatchQuery';
import wrap from '../../testing/wrap';

export const mockFetchQuery = (queryManager: QueryManager<any>) => {
const fetchQueryObservable = queryManager.fetchQueryObservable;
Expand Down
14 changes: 7 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 '../../../utilities/testing/mocking/mockQueryManager';
import mockWatchQuery from '../../../utilities/testing/mocking/mockWatchQuery';
import { MockApolloLink, mockSingleLink } from '../../../utilities/testing/mocking/mockLink';
import mockQueryManager from '../../../testing/mocking/mockQueryManager';
import mockWatchQuery from '../../../testing/mocking/mockWatchQuery';
import { MockApolloLink, mockSingleLink } from '../../../testing/mocking/mockLink';

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

// testing utils
import wrap from '../../../utilities/testing/wrap';
import wrap from '../../../testing/wrap';
import observableToPromise, {
observableToPromiseAndSubscription,
} from '../../../utilities/testing/observableToPromise';
import subscribeAndCount from '../../../utilities/testing/subscribeAndCount';
import { itAsync } from '../../../utilities/testing/itAsync';
} from '../../../testing/observableToPromise';
import subscribeAndCount from '../../../testing/subscribeAndCount';
import { itAsync } from '../../../testing/itAsync';
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 '../../../utilities/testing/mocking/mockSubscriptionLink';
import { MockSubscriptionLink } from '../../../testing/mocking/mockSubscriptionLink';

// core
import { QueryManager } from '../../QueryManager';
Expand Down
2 changes: 1 addition & 1 deletion src/core/__tests__/QueryManager/multiple-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { InMemoryCache } from '../../../cache/inmemory/inMemoryCache';
// mocks
import {
MockSubscriptionLink
} from '../../../utilities/testing/mocking/mockSubscriptionLink';
} from '../../../testing/mocking/mockSubscriptionLink';

// core
import { QueryManager } from '../../QueryManager';
Expand Down
2 changes: 1 addition & 1 deletion src/core/__tests__/QueryManager/recycler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import gql from 'graphql-tag';
import { InMemoryCache } from '../../../cache/inmemory/inMemoryCache';
import {
MockSubscriptionLink
} from '../../../utilities/testing/mocking/mockSubscriptionLink';
} from '../../../testing/mocking/mockSubscriptionLink';

// core
import { QueryManager } from '../../QueryManager';
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 '../../../../utilities/testing/mocking/mockClient';
import { createMockClient } from '../../../../testing/mocking/mockClient';
import { graphql } from '../../graphql';
import { ChildProps } from '../../types';

Expand Down
16 changes: 15 additions & 1 deletion src/testing/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
import '../utilities/globals';
export * from '../utilities/testing';
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';
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from 'react';

import { ApolloClient, DefaultOptions } from '../../../core';
import { InMemoryCache as Cache } from '../../../cache';
import { ApolloProvider } from '../../../react/context';
import { ApolloClient, DefaultOptions } from '../../core';
import { InMemoryCache as Cache } from '../../cache';
import { ApolloProvider } from '../../react/context';
import { MockLink, MockedResponse } from './mockLink';
import { ApolloLink } from '../../../link/core';
import { Resolvers } from '../../../core';
import { ApolloCache } from '../../../cache';
import { ApolloLink } from '../../link/core';
import { Resolvers } from '../../core';
import { ApolloCache } from '../../cache';

export interface MockedProviderProps<TSerializedCache = {}> {
mocks?: ReadonlyArray<MockedResponse>;
Expand Down
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 '../../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/inmemory/inMemoryCache';
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/ObservableQuery';
import { ObservableQuery } from '../../core';

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

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { ObservableQuery } from '../../core/ObservableQuery';
import { ApolloQueryResult, OperationVariables } from '../../core/types';
import { ObservableSubscription } from '../../utilities/observables/Observable';
import { asyncMap } from '../../utilities/observables/asyncMap';
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.
2 changes: 1 addition & 1 deletion src/utilities/observables/__tests__/asyncMap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { itAsync } from "../../testing";
import { Observable } from "../Observable";
import { asyncMap } from "../asyncMap";
import { itAsync } from "../../../testing";

const wait = (delayMs: number) =>
new Promise<void>(resolve => setTimeout(resolve, delayMs));
Expand Down
15 changes: 0 additions & 15 deletions src/utilities/testing/index.ts

This file was deleted.

0 comments on commit 990e436

Please sign in to comment.