Skip to content
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
278 changes: 278 additions & 0 deletions .api-reports/api-report-testing_internal.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
## API Report File for "@apollo/client"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts

import type { ApolloClient } from '@apollo/client/core';
import { ApolloLink } from '@apollo/client/core';
import type { ApolloPayloadResult } from '@apollo/client/core';
import { FetchResult } from '@apollo/client/core';
import type { GraphQLFormattedError } from 'graphql-17-alpha2';
import { GraphQLRequest } from '@apollo/client/core';
import { HttpLink } from '@apollo/client/link/http';
import type { InitialIncrementalExecutionResult } from 'graphql-17-alpha2';
import type { MaskedDocumentNode } from '@apollo/client/masking';
import type { MockedProviderProps } from '@apollo/client/testing/react';
import type { MockedResponse } from '@apollo/client/testing/core';
import type { Observable } from 'rxjs';
import type { Queries } from '@testing-library/dom';
import type { queries } from '@testing-library/dom';
import * as React_2 from 'react';
import type * as ReactDOMClient from 'react-dom/client';
import type { RenderHookOptions } from '@testing-library/react';
import type { RenderHookResult } from '@testing-library/react';
import type { RenderOptions } from '@testing-library/react';
import type { RenderResult } from '@testing-library/react';
import { ResultFunction } from '@apollo/client/testing/core';
import type { Subscribable } from 'rxjs';
import type { SubsequentIncrementalExecutionResult } from 'graphql-17-alpha2';
import type { TypedDocumentNode } from '@apollo/client/core';

// @public (undocumented)
export function actAsync<T>(scope: () => T | Promise<T>): Promise<T>;

// @public (undocumented)
export function addDelayToMocks<T extends MockedResponse<unknown>[]>(mocks: T, delay?: number, override?: boolean): {
delay: number;
request: GraphQLRequest<Record<string, any>>;
maxUsageCount?: number;
result?: FetchResult<unknown> | ResultFunction<FetchResult<unknown>, Record<string, any>> | undefined;
error?: Error;
variableMatcher?: ((arg: Record<string, any>) => boolean) | undefined;
newData?: ResultFunction<FetchResult<unknown>, Record<string, any>> | undefined;
}[];

// @public (undocumented)
type ConsoleMethod = "log" | "info" | "warn" | "error" | "debug";

// @public (undocumented)
export function createClientWrapper(client: ApolloClient, Wrapper?: React_2.JSXElementConstructor<{
children: React_2.ReactNode;
}>): React_2.JSXElementConstructor<{
children: React_2.ReactNode;
}>;

// @public (undocumented)
export function createMockWrapper(renderOptions: MockedProviderProps, Wrapper?: React_2.JSXElementConstructor<{
children: React_2.ReactNode;
}>): React_2.JSXElementConstructor<{
children: React_2.ReactNode;
}>;

// @public (undocumented)
export function enableFakeTimers(config?: FakeTimersConfig | LegacyFakeTimersConfig): Disposable;

// @public (undocumented)
type HydrateableContainer = Parameters<(typeof ReactDOMClient)["hydrateRoot"]>[0];

// @public (undocumented)
type HydrateableContainer_2 = Parameters<(typeof ReactDOMClient)["hydrateRoot"]>[0];

// @public (undocumented)
interface Letter {
// (undocumented)
__typename: "Letter";
// (undocumented)
letter: string;
// (undocumented)
position: number;
}

// @public (undocumented)
export interface MaskedVariablesCaseData {
// (undocumented)
character: {
__typename: "Character";
id: string;
} & {
" $fragmentRefs"?: {
MaskedVariablesCaseFragment: MaskedVariablesCaseFragment;
};
};
}

// @public (undocumented)
type MaskedVariablesCaseFragment = {
__typename: "Character";
name: string;
} & {
" $fragmentName"?: "MaskedVariablesCaseFragment";
};

// @public (undocumented)
export function mockDeferStream<TData = Record<string, unknown>, TExtensions = Record<string, unknown>>(): {
httpLink: HttpLink;
enqueueInitialChunk(chunk: InitialIncrementalExecutionResult<TData, TExtensions>): void;
enqueueSubsequentChunk(chunk: SubsequentIncrementalExecutionResult<TData, TExtensions>): void;
enqueueErrorChunk(errors: GraphQLFormattedError[]): void;
};

// @public (undocumented)
export function mockMultipartSubscriptionStream<TData = Record<string, unknown>, TExtensions = Record<string, unknown>>(): {
httpLink: HttpLink;
enqueueHeartbeat: () => void;
enqueuePayloadResult(payload: ApolloPayloadResult<TData, TExtensions>["payload"], hasNext?: boolean): void;
enqueueProtocolErrors(errors: ApolloPayloadResult["errors"]): void;
};

// @public (undocumented)
type ObservableEvent<T> = {
type: "next";
value: T;
} | {
type: "error";
error: any;
} | {
type: "complete";
};

// @public (undocumented)
export class ObservableStream<T> {
constructor(observable: Observable<T> | Subscribable<T>);
// Warning: (ae-forgotten-export) The symbol "TakeOptions" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ObservableEvent" needs to be exported by the entry point index.d.ts
//
// (undocumented)
peek({ timeout }?: TakeOptions): Promise<ObservableEvent<T>>;
// (undocumented)
take({ timeout }?: TakeOptions): Promise<ObservableEvent<T>>;
// (undocumented)
takeComplete(options?: TakeOptions): Promise<void>;
// (undocumented)
takeError(options?: TakeOptions): Promise<any>;
// (undocumented)
takeNext(options?: TakeOptions): Promise<T>;
// (undocumented)
unsubscribe(): void;
}

// @public (undocumented)
export interface PaginatedCaseData {
// Warning: (ae-forgotten-export) The symbol "Letter" needs to be exported by the entry point index.d.ts
//
// (undocumented)
letters: Letter[];
}

// @public (undocumented)
export interface PaginatedCaseVariables {
// (undocumented)
limit?: number;
// (undocumented)
offset?: number;
}

// Warning: (ae-forgotten-export) The symbol "RendererableContainer" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "HydrateableContainer" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export function renderAsync<Q extends Queries = typeof queries, Container extends RendererableContainer | HydrateableContainer = HTMLElement, BaseElement extends RendererableContainer | HydrateableContainer = Container>(ui: React.ReactNode, options: RenderOptions<Q, Container, BaseElement>): Promise<RenderResult<Q, Container, BaseElement>>;

// @public (undocumented)
export function renderAsync(ui: React.ReactNode, options?: Omit<RenderOptions, "queries"> | undefined): Promise<RenderResult>;

// @public (undocumented)
type RendererableContainer = ReactDOMClient.Container;

// @public (undocumented)
type RendererableContainer_2 = ReactDOMClient.Container;

// Warning: (ae-forgotten-export) The symbol "RendererableContainer_2" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "HydrateableContainer_2" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export function renderHookAsync<Result, Props, Q extends Queries = typeof queries, Container extends RendererableContainer_2 | HydrateableContainer_2 = HTMLElement, BaseElement extends RendererableContainer_2 | HydrateableContainer_2 = Container>(renderCallback: (initialProps: Props) => Result, options?: RenderHookOptions<Props, Q, Container, BaseElement> | undefined): Promise<RenderHookResult<Result, Props>>;

// @public
export function resetApolloContext(): void;

// @public (undocumented)
export function setupMaskedVariablesCase(): {
mocks: MockedResponse<MaskedVariablesCaseData, Record<string, any>>[];
query: MaskedDocumentNode<MaskedVariablesCaseData, VariablesCaseVariables>;
unmaskedQuery: TypedDocumentNode<MaskedVariablesCaseData, VariablesCaseVariables>;
};

// @public (undocumented)
export function setupPaginatedCase(): {
query: TypedDocumentNode<PaginatedCaseData, PaginatedCaseVariables>;
link: ApolloLink;
data: {
__typename: string;
letter: string;
position: number;
}[];
};

// @public (undocumented)
export function setupSimpleCase(): {
query: TypedDocumentNode<SimpleCaseData, Record<string, never>>;
mocks: MockedResponse<SimpleCaseData, Record<string, any>>[];
};

// @public (undocumented)
export function setupVariablesCase(): {
mocks: MockedResponse<VariablesCaseData, Record<string, any>>[];
query: TypedDocumentNode<VariablesCaseData, VariablesCaseVariables>;
};

// @public (undocumented)
export interface SimpleCaseData {
// (undocumented)
greeting: string;
}

// Warning: (ae-forgotten-export) The symbol "ConsoleMethod" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type Spies<Keys extends ConsoleMethod[]> = Record<Keys[number], jest.SpyInstance<void, any[], any>>;

// Warning: (ae-forgotten-export) The symbol "Spies" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export function spyOnConsole<Keys extends ConsoleMethod[]>(...spyOn: Keys): Spies<Keys> & Disposable;

// @public (undocumented)
export namespace spyOnConsole {
var // (undocumented)
takeSnapshots: <Keys extends ConsoleMethod[]>(...spyOn: Keys) => Spies<Keys> & Disposable;
}

// @public (undocumented)
interface TakeOptions {
// (undocumented)
timeout?: number;
}

// @public (undocumented)
export interface VariablesCaseData {
// (undocumented)
character: {
__typename: "Character";
id: string;
name: string;
};
}

// @public (undocumented)
export interface VariablesCaseVariables {
// (undocumented)
id: string;
}

// @internal (undocumented)
export function withCleanup<T extends object>(item: T, cleanup: (item: T) => void): T & Disposable;

// @public (undocumented)
export function withProdMode(): {
prevDEV: boolean;
} & Disposable;

// Warnings were encountered during analysis:
//
// src/testing/internal/scenarios/index.ts:80:7 - (ae-forgotten-export) The symbol "MaskedVariablesCaseFragment" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

```
57 changes: 57 additions & 0 deletions eslint-local-rules/import-from-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,60 @@ export const noInternalImportOfficialExport =
},
defaultOptions: [],
});

/**
* to be used in tests, so the test imports from the library instead of testing internals
* (where possible)
*/
export const noRelativeImports = ESLintUtils.RuleCreator.withoutDocs({
create(context, options) {
return {
ImportDeclaration(node) {
if (!node.source.value.startsWith("..")) {
// we're only interested in imports from parent folders outside of the test folder
return;
}
if (node.importKind === "type") {
// we're okay with internal types for now, although in most cases
// they should probably be exports if they are important enough
// that we need them for a test
return;
}
const resolvedTarget = resolve(
dirname(context.physicalFilename),
node.source.value
);
if (options[0].ignoreFrom.includes(resolvedTarget)) {
return;
}
context.report({
node: node.source,
messageId: "noRelativeImports",
});
},
};
},
meta: {
messages: {
noRelativeImports:
"Don't use relative imports in tests, import from official entry points instead.",
},
type: "problem",
schema: [
{
type: "object",
properties: {
ignoreFrom: {
type: "array",
items: { type: "string" },
},
},
},
],
},
defaultOptions: [
{
ignoreFrom: [],
},
],
});
2 changes: 2 additions & 0 deletions eslint-local-rules/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
importFromInsideOtherExport,
noDuplicateExports,
noInternalImportOfficialExport,
noRelativeImports,
} from "./import-from-export.ts";
import { rule as requireDisableActEnvironment } from "./require-disable-act-environment.ts";
import { rule as requireUsingDisposable } from "./require-using-disposable.ts";
Expand All @@ -16,4 +17,5 @@ export default {
"import-from-inside-other-export": importFromInsideOtherExport,
"no-internal-import-official-export": noInternalImportOfficialExport,
"no-duplicate-exports": noDuplicateExports,
"no-relative-imports": noRelativeImports,
};
Loading