@gitlab/frontend-tests 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -1
- package/dist/index.cjs +38 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/integration/constants.d.cts +3 -0
- package/dist/integration/constants.d.ts +3 -0
- package/dist/integration/fixture_utils.d.cts +107 -0
- package/dist/integration/fixture_utils.d.ts +107 -0
- package/dist/integration/fixture_variant_schema.d.cts +74 -0
- package/dist/integration/fixture_variant_schema.d.ts +74 -0
- package/dist/integration/handlers.d.cts +10 -0
- package/dist/integration/handlers.d.ts +10 -0
- package/dist/integration/index.d.cts +7 -0
- package/dist/integration/index.d.ts +7 -0
- package/dist/integration/jest_config.cjs +31 -0
- package/dist/integration/jest_config.d.cts +11 -0
- package/dist/integration/jest_config.d.ts +11 -0
- package/dist/integration/jest_config.js +27 -0
- package/dist/integration/operation_helpers.d.cts +70 -0
- package/dist/integration/operation_helpers.d.ts +70 -0
- package/dist/integration/polyfills.cjs +21 -0
- package/dist/integration/polyfills.d.cts +1 -0
- package/dist/integration/polyfills.d.ts +1 -0
- package/dist/integration/polyfills.js +19 -0
- package/dist/integration/polyfills_text_encoding.cjs +8 -0
- package/dist/integration/polyfills_text_encoding.d.cts +1 -0
- package/dist/integration/polyfills_text_encoding.d.ts +1 -0
- package/dist/integration/polyfills_text_encoding.js +6 -0
- package/dist/integration/server.d.cts +3 -0
- package/dist/integration/server.d.ts +3 -0
- package/dist/integration/types.d.cts +82 -0
- package/dist/integration/types.d.ts +82 -0
- package/dist/integration.cjs +38 -0
- package/dist/integration.js +5 -0
- package/dist/server-Ds9SYBSn.js +3963 -0
- package/dist/server-otsK-xxA.cjs +3992 -0
- package/integration/jest-config.js +2 -0
- package/integration/polyfills/text-encoding.js +2 -0
- package/integration/polyfills.js +2 -0
- package/integration.js +2 -0
- package/package.json +138 -5
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// `msw` dependencies that ship ESM only, so Jest has to transform them.
|
|
2
|
+
const MSW_ESM_DEPENDENCIES = ['rettime', 'until-async', '@open-draft/.*'];
|
|
3
|
+
// Order matters: `@whatwg-node/fetch` needs TextEncoder/TextDecoder at load time.
|
|
4
|
+
const POLYFILLS_SETUP_FILES = [
|
|
5
|
+
'@gitlab/frontend-tests/integration/polyfills/text-encoding',
|
|
6
|
+
'@gitlab/frontend-tests/integration/polyfills',
|
|
7
|
+
];
|
|
8
|
+
/**
|
|
9
|
+
* Turns a consumer's Jest config into one that can run MSW integration specs. It
|
|
10
|
+
* lets Jest transform the ESM-only MSW dependencies, loads the polyfills MSW needs
|
|
11
|
+
* before anything else, keeps real timers and gives the specs a longer timeout.
|
|
12
|
+
* Module aliases, the test environment and `setupFilesAfterEnv` stay the
|
|
13
|
+
* consumer's responsibility.
|
|
14
|
+
*/
|
|
15
|
+
function createFrontendIntegrationConfig(config = {}) {
|
|
16
|
+
const { transformIgnorePatterns = [], setupFiles = [] } = config;
|
|
17
|
+
return {
|
|
18
|
+
...config,
|
|
19
|
+
transformIgnorePatterns: transformIgnorePatterns.map((pattern) => pattern.replace('node_modules/(?!(', `node_modules/(?!(${MSW_ESM_DEPENDENCIES.join('|')}|`)),
|
|
20
|
+
testPathIgnorePatterns: [],
|
|
21
|
+
setupFiles: [...setupFiles, ...POLYFILLS_SETUP_FILES],
|
|
22
|
+
fakeTimers: { enableGlobally: false },
|
|
23
|
+
testTimeout: process.env.CI ? 20000 : 7000,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { MSW_ESM_DEPENDENCIES, POLYFILLS_SETUP_FILES, createFrontendIntegrationConfig };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { CapturedRequest, GraphqlVariables, RequestCounts } from './types.cjs';
|
|
2
|
+
/**
|
|
3
|
+
* Every GraphQL operation a test triggered that no handler answered, collected across
|
|
4
|
+
* the run so a new suite shows all the handlers it still needs in one go.
|
|
5
|
+
*/
|
|
6
|
+
export declare const missingOperations: Set<string>;
|
|
7
|
+
/** Records an operation no handler answered, so it shows up in the run's summary of missing handlers. */
|
|
8
|
+
export declare function captureMissingOperation(name: string): void;
|
|
9
|
+
/** Forgets the recorded missing operations, so one spec's gaps do not bleed into the next. */
|
|
10
|
+
export declare function clearMissingOperations(): void;
|
|
11
|
+
/**
|
|
12
|
+
* Request tracking utilities for frontend integration tests.
|
|
13
|
+
* Allows tests to verify which endpoints were called and with what parameters.
|
|
14
|
+
*/
|
|
15
|
+
export declare const capturedRequests: Record<string, CapturedRequest[]>;
|
|
16
|
+
/** Drops every captured request so the next spec's assertions start from zero. Belongs in the global `afterEach`. */
|
|
17
|
+
export declare function resetCapturedRequests(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Records that a request reached the mock server, with its URL, params and GraphQL
|
|
20
|
+
* variables, so a spec can later assert what the app asked for and how often. The
|
|
21
|
+
* handlers call this. Specs read the results through `snapshotRequests`,
|
|
22
|
+
* `expectGraphQLCalls` and `lastRequestVariables`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function captureRequest(name: string, request: Request, variables?: GraphqlVariables): void;
|
|
25
|
+
/**
|
|
26
|
+
* Returns what the app sent in its latest call to an operation, for asserting on
|
|
27
|
+
* the request rather than the response. Two filters can return the same rows, so
|
|
28
|
+
* checking the rendered result cannot prove which one the app applied. The
|
|
29
|
+
* variables can.
|
|
30
|
+
*
|
|
31
|
+
* @throws {Error} When the operation was never called, or was not a GraphQL
|
|
32
|
+
* operation and so has no variables.
|
|
33
|
+
*/
|
|
34
|
+
export declare function lastRequestVariables(operationName: string): GraphqlVariables;
|
|
35
|
+
/**
|
|
36
|
+
* Captures how many times each operation has been called so far. Take one before
|
|
37
|
+
* an action and hand it to `expectGraphQLCalls` afterwards to assert on only the
|
|
38
|
+
* calls that action caused.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* const baselineRequests = snapshotRequests();
|
|
42
|
+
* // baselineRequests = { getWorkItemsFullEE: 1, projectLabels: 1 }
|
|
43
|
+
*/
|
|
44
|
+
export declare function snapshotRequests(): RequestCounts;
|
|
45
|
+
export interface GraphQLCallAssertions {
|
|
46
|
+
/** Operations that MUST fire (e.g., the mutation) */
|
|
47
|
+
expect: string[];
|
|
48
|
+
/** Operations that must NOT fire (e.g., list refetches) */
|
|
49
|
+
forbid: Array<string | RegExp>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Asserts which operations an action triggered since a snapshot: everything in
|
|
53
|
+
* `expect` must have fired and nothing matching `forbid` may have. Its main use is
|
|
54
|
+
* proving a mutation updated the Apollo cache in place instead of refetching the
|
|
55
|
+
* lists around it.
|
|
56
|
+
*
|
|
57
|
+
* @throws {Error} Listing everything that fired, when an expected operation is
|
|
58
|
+
* missing or a forbidden one ran.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* const baselineRequests = snapshotRequests();
|
|
62
|
+
* clickUpdateButton();
|
|
63
|
+
* await waitFor(() => {
|
|
64
|
+
* expectGraphQLCalls(baselineRequests, {
|
|
65
|
+
* expect: ['workItemUpdate'],
|
|
66
|
+
* forbid: ['getWorkItemsFullEE', 'projectLabels'],
|
|
67
|
+
* });
|
|
68
|
+
* });
|
|
69
|
+
*/
|
|
70
|
+
export declare function expectGraphQLCalls(baselineRequests: RequestCounts, { expect: expectedOperations, forbid: forbiddenOperations }: GraphQLCallAssertions): void;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { CapturedRequest, GraphqlVariables, RequestCounts } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Every GraphQL operation a test triggered that no handler answered, collected across
|
|
4
|
+
* the run so a new suite shows all the handlers it still needs in one go.
|
|
5
|
+
*/
|
|
6
|
+
export declare const missingOperations: Set<string>;
|
|
7
|
+
/** Records an operation no handler answered, so it shows up in the run's summary of missing handlers. */
|
|
8
|
+
export declare function captureMissingOperation(name: string): void;
|
|
9
|
+
/** Forgets the recorded missing operations, so one spec's gaps do not bleed into the next. */
|
|
10
|
+
export declare function clearMissingOperations(): void;
|
|
11
|
+
/**
|
|
12
|
+
* Request tracking utilities for frontend integration tests.
|
|
13
|
+
* Allows tests to verify which endpoints were called and with what parameters.
|
|
14
|
+
*/
|
|
15
|
+
export declare const capturedRequests: Record<string, CapturedRequest[]>;
|
|
16
|
+
/** Drops every captured request so the next spec's assertions start from zero. Belongs in the global `afterEach`. */
|
|
17
|
+
export declare function resetCapturedRequests(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Records that a request reached the mock server, with its URL, params and GraphQL
|
|
20
|
+
* variables, so a spec can later assert what the app asked for and how often. The
|
|
21
|
+
* handlers call this. Specs read the results through `snapshotRequests`,
|
|
22
|
+
* `expectGraphQLCalls` and `lastRequestVariables`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function captureRequest(name: string, request: Request, variables?: GraphqlVariables): void;
|
|
25
|
+
/**
|
|
26
|
+
* Returns what the app sent in its latest call to an operation, for asserting on
|
|
27
|
+
* the request rather than the response. Two filters can return the same rows, so
|
|
28
|
+
* checking the rendered result cannot prove which one the app applied. The
|
|
29
|
+
* variables can.
|
|
30
|
+
*
|
|
31
|
+
* @throws {Error} When the operation was never called, or was not a GraphQL
|
|
32
|
+
* operation and so has no variables.
|
|
33
|
+
*/
|
|
34
|
+
export declare function lastRequestVariables(operationName: string): GraphqlVariables;
|
|
35
|
+
/**
|
|
36
|
+
* Captures how many times each operation has been called so far. Take one before
|
|
37
|
+
* an action and hand it to `expectGraphQLCalls` afterwards to assert on only the
|
|
38
|
+
* calls that action caused.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* const baselineRequests = snapshotRequests();
|
|
42
|
+
* // baselineRequests = { getWorkItemsFullEE: 1, projectLabels: 1 }
|
|
43
|
+
*/
|
|
44
|
+
export declare function snapshotRequests(): RequestCounts;
|
|
45
|
+
export interface GraphQLCallAssertions {
|
|
46
|
+
/** Operations that MUST fire (e.g., the mutation) */
|
|
47
|
+
expect: string[];
|
|
48
|
+
/** Operations that must NOT fire (e.g., list refetches) */
|
|
49
|
+
forbid: Array<string | RegExp>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Asserts which operations an action triggered since a snapshot: everything in
|
|
53
|
+
* `expect` must have fired and nothing matching `forbid` may have. Its main use is
|
|
54
|
+
* proving a mutation updated the Apollo cache in place instead of refetching the
|
|
55
|
+
* lists around it.
|
|
56
|
+
*
|
|
57
|
+
* @throws {Error} Listing everything that fired, when an expected operation is
|
|
58
|
+
* missing or a forbidden one ran.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* const baselineRequests = snapshotRequests();
|
|
62
|
+
* clickUpdateButton();
|
|
63
|
+
* await waitFor(() => {
|
|
64
|
+
* expectGraphQLCalls(baselineRequests, {
|
|
65
|
+
* expect: ['workItemUpdate'],
|
|
66
|
+
* forbid: ['getWorkItemsFullEE', 'projectLabels'],
|
|
67
|
+
* });
|
|
68
|
+
* });
|
|
69
|
+
*/
|
|
70
|
+
export declare function expectGraphQLCalls(baselineRequests: RequestCounts, { expect: expectedOperations, forbid: forbiddenOperations }: GraphQLCallAssertions): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var web = require('node:stream/web');
|
|
4
|
+
var node_worker_threads = require('node:worker_threads');
|
|
5
|
+
var fetch = require('@whatwg-node/fetch');
|
|
6
|
+
|
|
7
|
+
// `msw/node` reads these globals while its module body evaluates, which is before any
|
|
8
|
+
// `setupFilesAfterEnv` file runs, so this file belongs in Jest's `setupFiles`, after
|
|
9
|
+
// `./polyfills_text_encoding`.
|
|
10
|
+
// The ponyfill types differ from the DOM lib's, so assign through `Object.assign`
|
|
11
|
+
// rather than typed global properties.
|
|
12
|
+
Object.assign(globalThis, {
|
|
13
|
+
fetch: fetch.fetch,
|
|
14
|
+
Request: fetch.Request,
|
|
15
|
+
Response: fetch.Response,
|
|
16
|
+
Headers: fetch.Headers,
|
|
17
|
+
ReadableStream: web.ReadableStream,
|
|
18
|
+
TransformStream: web.TransformStream,
|
|
19
|
+
WritableStream: web.WritableStream,
|
|
20
|
+
BroadcastChannel: node_worker_threads.BroadcastChannel,
|
|
21
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { WritableStream, TransformStream, ReadableStream } from 'node:stream/web';
|
|
2
|
+
import { BroadcastChannel } from 'node:worker_threads';
|
|
3
|
+
import { Headers, Response, Request, fetch } from '@whatwg-node/fetch';
|
|
4
|
+
|
|
5
|
+
// `msw/node` reads these globals while its module body evaluates, which is before any
|
|
6
|
+
// `setupFilesAfterEnv` file runs, so this file belongs in Jest's `setupFiles`, after
|
|
7
|
+
// `./polyfills_text_encoding`.
|
|
8
|
+
// The ponyfill types differ from the DOM lib's, so assign through `Object.assign`
|
|
9
|
+
// rather than typed global properties.
|
|
10
|
+
Object.assign(globalThis, {
|
|
11
|
+
fetch,
|
|
12
|
+
Request,
|
|
13
|
+
Response,
|
|
14
|
+
Headers,
|
|
15
|
+
ReadableStream,
|
|
16
|
+
TransformStream,
|
|
17
|
+
WritableStream,
|
|
18
|
+
BroadcastChannel,
|
|
19
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_util = require('node:util');
|
|
4
|
+
|
|
5
|
+
// `@whatwg-node/fetch` needs these while its module body evaluates, so this file must be
|
|
6
|
+
// a separate Jest `setupFiles` entry listed before `./polyfills`: bundlers hoist external
|
|
7
|
+
// imports above a module's own statements, so ordering inside one file is not enough.
|
|
8
|
+
Object.assign(globalThis, { TextDecoder: node_util.TextDecoder, TextEncoder: node_util.TextEncoder });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TextEncoder, TextDecoder } from 'node:util';
|
|
2
|
+
|
|
3
|
+
// `@whatwg-node/fetch` needs these while its module body evaluates, so this file must be
|
|
4
|
+
// a separate Jest `setupFiles` entry listed before `./polyfills`: bundlers hoist external
|
|
5
|
+
// imports above a module's own statements, so ordering inside one file is not enough.
|
|
6
|
+
Object.assign(globalThis, { TextDecoder, TextEncoder });
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { FeatureHandler, RestEndpoint } from './types.cjs';
|
|
2
|
+
/** Builds the MSW node server for a test run from the consumer's feature handlers and REST endpoints. */
|
|
3
|
+
export declare const createServer: (featureHandlers: FeatureHandler[], restEndpoints: RestEndpoint[]) => import("msw/node").SetupServer;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { FeatureHandler, RestEndpoint } from './types.js';
|
|
2
|
+
/** Builds the MSW node server for a test run from the consumer's feature handlers and REST endpoints. */
|
|
3
|
+
export declare const createServer: (featureHandlers: FeatureHandler[], restEndpoints: RestEndpoint[]) => import("msw/node").SetupServer;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { JsonBodyType } from 'msw';
|
|
2
|
+
/** One entry of a GraphQL response's `errors` array. */
|
|
3
|
+
export interface GraphqlError {
|
|
4
|
+
message: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
/** A recorded GraphQL response, as served by a handler. */
|
|
8
|
+
export interface GraphqlFixture<ResponseData extends object = object> {
|
|
9
|
+
data: ResponseData;
|
|
10
|
+
errors: GraphqlError[];
|
|
11
|
+
}
|
|
12
|
+
/** A GraphQL fixture as written in a variant file; `errors` is filled in when omitted. */
|
|
13
|
+
export interface GraphqlFixtureInput {
|
|
14
|
+
data: object;
|
|
15
|
+
errors?: GraphqlError[];
|
|
16
|
+
}
|
|
17
|
+
/** Variables of an intercepted GraphQL operation. */
|
|
18
|
+
export type GraphqlVariables = Record<string, unknown>;
|
|
19
|
+
/** One row of a {@link FixtureTable}: the fixture to serve when `matches` accepts the variables. */
|
|
20
|
+
export interface FixtureTableEntry<OperationVariables = GraphqlVariables, Fixture = GraphqlFixture> {
|
|
21
|
+
matches: (variables: OperationVariables) => boolean;
|
|
22
|
+
fixture: () => Fixture;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The recorded fixtures for one operation, one row per variable shape it was recorded
|
|
26
|
+
* with (first page, next page, search, ...). `matchFixture` searches it in order and
|
|
27
|
+
* serves the first row whose `matches` accepts the request variables.
|
|
28
|
+
*
|
|
29
|
+
* Plain `FixtureTable` is a table of GraphQL fixtures keyed on untyped variables. Pass
|
|
30
|
+
* type parameters to type the variables `matches` receives and the fixture rows return.
|
|
31
|
+
*/
|
|
32
|
+
export type FixtureTable<OperationVariables = GraphqlVariables, Fixture = GraphqlFixture> = Array<FixtureTableEntry<OperationVariables, Fixture>>;
|
|
33
|
+
/** A raw REST response body, served as is. */
|
|
34
|
+
export type RestFixture = JsonBodyType;
|
|
35
|
+
export interface FeatureHandlerArgs {
|
|
36
|
+
operationName: string;
|
|
37
|
+
variables: GraphqlVariables;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Resolves one GraphQL operation to a response, or returns a falsy value to let the
|
|
41
|
+
* next feature handler try.
|
|
42
|
+
*/
|
|
43
|
+
export type FeatureHandler = (args: FeatureHandlerArgs) => Response | null | undefined;
|
|
44
|
+
export type RestMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head' | 'options' | 'all';
|
|
45
|
+
export interface RestEndpoint {
|
|
46
|
+
method: RestMethod;
|
|
47
|
+
path: string;
|
|
48
|
+
/** Request-capture key; defaults to `REST:<method>:<path>`. */
|
|
49
|
+
name?: string;
|
|
50
|
+
headers?: HeadersInit;
|
|
51
|
+
/** Static body, used when the endpoint has no `variants`. */
|
|
52
|
+
response?: RestFixture;
|
|
53
|
+
/** Variants from `defineRestFixtureVariants`; the active one wins over `response`. */
|
|
54
|
+
variants?: FixtureVariants<Record<string, RestFixture>>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A registered variants map, as returned by `defineFixtureVariants` and
|
|
58
|
+
* `defineRestFixtureVariants`. The `query` tag is non-enumerable at runtime.
|
|
59
|
+
*/
|
|
60
|
+
export type FixtureVariants<V extends Record<string, unknown>> = Readonly<V> & {
|
|
61
|
+
readonly query: string;
|
|
62
|
+
};
|
|
63
|
+
/** The variant key of a `FixtureVariants` map. */
|
|
64
|
+
export type VariantKey<V extends FixtureVariants<Record<string, unknown>>> = Exclude<Extract<keyof V, string>, 'query'>;
|
|
65
|
+
type CamelCaseTail<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Capitalize<Lowercase<Head>>}${CamelCaseTail<Tail>}` : Capitalize<Lowercase<S>>;
|
|
66
|
+
/** UPPER_SNAKE_CASE to camelCase, mirroring lodash `camelCase` for letter-only words. */
|
|
67
|
+
export type CamelCase<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Lowercase<Head>}${CamelCaseTail<Tail>}` : Lowercase<S>;
|
|
68
|
+
/** One activator per variant key, named after the key: `WITH_ERROR` becomes `withError()`. */
|
|
69
|
+
export type VariantActivators<V extends FixtureVariants<Record<string, unknown>>> = {
|
|
70
|
+
[K in VariantKey<V> as CamelCase<K>]: () => void;
|
|
71
|
+
};
|
|
72
|
+
/** One intercepted request, as stored in `capturedRequests`. */
|
|
73
|
+
export interface CapturedRequest {
|
|
74
|
+
url: string;
|
|
75
|
+
params: Record<string, string>;
|
|
76
|
+
method: string;
|
|
77
|
+
variables?: GraphqlVariables;
|
|
78
|
+
timestamp: number;
|
|
79
|
+
}
|
|
80
|
+
/** Operation name to call count, as returned by `snapshotRequests`. */
|
|
81
|
+
export type RequestCounts = Record<string, number>;
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { JsonBodyType } from 'msw';
|
|
2
|
+
/** One entry of a GraphQL response's `errors` array. */
|
|
3
|
+
export interface GraphqlError {
|
|
4
|
+
message: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
/** A recorded GraphQL response, as served by a handler. */
|
|
8
|
+
export interface GraphqlFixture<ResponseData extends object = object> {
|
|
9
|
+
data: ResponseData;
|
|
10
|
+
errors: GraphqlError[];
|
|
11
|
+
}
|
|
12
|
+
/** A GraphQL fixture as written in a variant file; `errors` is filled in when omitted. */
|
|
13
|
+
export interface GraphqlFixtureInput {
|
|
14
|
+
data: object;
|
|
15
|
+
errors?: GraphqlError[];
|
|
16
|
+
}
|
|
17
|
+
/** Variables of an intercepted GraphQL operation. */
|
|
18
|
+
export type GraphqlVariables = Record<string, unknown>;
|
|
19
|
+
/** One row of a {@link FixtureTable}: the fixture to serve when `matches` accepts the variables. */
|
|
20
|
+
export interface FixtureTableEntry<OperationVariables = GraphqlVariables, Fixture = GraphqlFixture> {
|
|
21
|
+
matches: (variables: OperationVariables) => boolean;
|
|
22
|
+
fixture: () => Fixture;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The recorded fixtures for one operation, one row per variable shape it was recorded
|
|
26
|
+
* with (first page, next page, search, ...). `matchFixture` searches it in order and
|
|
27
|
+
* serves the first row whose `matches` accepts the request variables.
|
|
28
|
+
*
|
|
29
|
+
* Plain `FixtureTable` is a table of GraphQL fixtures keyed on untyped variables. Pass
|
|
30
|
+
* type parameters to type the variables `matches` receives and the fixture rows return.
|
|
31
|
+
*/
|
|
32
|
+
export type FixtureTable<OperationVariables = GraphqlVariables, Fixture = GraphqlFixture> = Array<FixtureTableEntry<OperationVariables, Fixture>>;
|
|
33
|
+
/** A raw REST response body, served as is. */
|
|
34
|
+
export type RestFixture = JsonBodyType;
|
|
35
|
+
export interface FeatureHandlerArgs {
|
|
36
|
+
operationName: string;
|
|
37
|
+
variables: GraphqlVariables;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Resolves one GraphQL operation to a response, or returns a falsy value to let the
|
|
41
|
+
* next feature handler try.
|
|
42
|
+
*/
|
|
43
|
+
export type FeatureHandler = (args: FeatureHandlerArgs) => Response | null | undefined;
|
|
44
|
+
export type RestMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head' | 'options' | 'all';
|
|
45
|
+
export interface RestEndpoint {
|
|
46
|
+
method: RestMethod;
|
|
47
|
+
path: string;
|
|
48
|
+
/** Request-capture key; defaults to `REST:<method>:<path>`. */
|
|
49
|
+
name?: string;
|
|
50
|
+
headers?: HeadersInit;
|
|
51
|
+
/** Static body, used when the endpoint has no `variants`. */
|
|
52
|
+
response?: RestFixture;
|
|
53
|
+
/** Variants from `defineRestFixtureVariants`; the active one wins over `response`. */
|
|
54
|
+
variants?: FixtureVariants<Record<string, RestFixture>>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A registered variants map, as returned by `defineFixtureVariants` and
|
|
58
|
+
* `defineRestFixtureVariants`. The `query` tag is non-enumerable at runtime.
|
|
59
|
+
*/
|
|
60
|
+
export type FixtureVariants<V extends Record<string, unknown>> = Readonly<V> & {
|
|
61
|
+
readonly query: string;
|
|
62
|
+
};
|
|
63
|
+
/** The variant key of a `FixtureVariants` map. */
|
|
64
|
+
export type VariantKey<V extends FixtureVariants<Record<string, unknown>>> = Exclude<Extract<keyof V, string>, 'query'>;
|
|
65
|
+
type CamelCaseTail<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Capitalize<Lowercase<Head>>}${CamelCaseTail<Tail>}` : Capitalize<Lowercase<S>>;
|
|
66
|
+
/** UPPER_SNAKE_CASE to camelCase, mirroring lodash `camelCase` for letter-only words. */
|
|
67
|
+
export type CamelCase<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Lowercase<Head>}${CamelCaseTail<Tail>}` : Lowercase<S>;
|
|
68
|
+
/** One activator per variant key, named after the key: `WITH_ERROR` becomes `withError()`. */
|
|
69
|
+
export type VariantActivators<V extends FixtureVariants<Record<string, unknown>>> = {
|
|
70
|
+
[K in VariantKey<V> as CamelCase<K>]: () => void;
|
|
71
|
+
};
|
|
72
|
+
/** One intercepted request, as stored in `capturedRequests`. */
|
|
73
|
+
export interface CapturedRequest {
|
|
74
|
+
url: string;
|
|
75
|
+
params: Record<string, string>;
|
|
76
|
+
method: string;
|
|
77
|
+
variables?: GraphqlVariables;
|
|
78
|
+
timestamp: number;
|
|
79
|
+
}
|
|
80
|
+
/** Operation name to call count, as returned by `snapshotRequests`. */
|
|
81
|
+
export type RequestCounts = Record<string, number>;
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var server = require('./server-otsK-xxA.cjs');
|
|
4
|
+
require('msw/node');
|
|
5
|
+
require('msw');
|
|
6
|
+
require('node:fs');
|
|
7
|
+
require('node:path');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.activateVariant = server.activateVariant;
|
|
12
|
+
exports.baseMetadata = server.baseMetadata;
|
|
13
|
+
exports.buildHandlers = server.buildHandlers;
|
|
14
|
+
exports.captureMissingOperation = server.captureMissingOperation;
|
|
15
|
+
exports.captureRequest = server.captureRequest;
|
|
16
|
+
exports.capturedRequests = server.capturedRequests;
|
|
17
|
+
exports.clearMissingOperations = server.clearMissingOperations;
|
|
18
|
+
exports.createFixturePaginator = server.createFixturePaginator;
|
|
19
|
+
exports.createServer = server.createServer;
|
|
20
|
+
exports.defineFixtureVariants = server.defineFixtureVariants;
|
|
21
|
+
exports.defineRestFixtureVariants = server.defineRestFixtureVariants;
|
|
22
|
+
exports.dumpRegistry = server.dumpRegistry;
|
|
23
|
+
exports.expectGraphQLCalls = server.expectGraphQLCalls;
|
|
24
|
+
exports.getActiveVariant = server.getActiveVariant;
|
|
25
|
+
exports.getVariant = server.getVariant;
|
|
26
|
+
exports.isValidGraphqlFixture = server.isValidGraphqlFixture;
|
|
27
|
+
exports.lastRequestVariables = server.lastRequestVariables;
|
|
28
|
+
exports.loadFixturesMap = server.loadFixturesMap;
|
|
29
|
+
exports.matchFixture = server.matchFixture;
|
|
30
|
+
exports.missingOperations = server.missingOperations;
|
|
31
|
+
exports.normaliseGraphqlFixture = server.normaliseGraphqlFixture;
|
|
32
|
+
exports.resetAllVariants = server.resetAllVariants;
|
|
33
|
+
exports.resetCapturedRequests = server.resetCapturedRequests;
|
|
34
|
+
exports.setFixtureData = server.setFixtureData;
|
|
35
|
+
exports.setFixtureErrors = server.setFixtureErrors;
|
|
36
|
+
exports.setFixtureItemsCount = server.setFixtureItemsCount;
|
|
37
|
+
exports.setQueryVariant = server.setQueryVariant;
|
|
38
|
+
exports.snapshotRequests = server.snapshotRequests;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { a as activateVariant, b as baseMetadata, c as buildHandlers, d as captureMissingOperation, e as captureRequest, f as capturedRequests, g as clearMissingOperations, h as createFixturePaginator, i as createServer, j as defineFixtureVariants, k as defineRestFixtureVariants, l as dumpRegistry, m as expectGraphQLCalls, n as getActiveVariant, o as getVariant, p as isValidGraphqlFixture, q as lastRequestVariables, r as loadFixturesMap, s as matchFixture, t as missingOperations, u as normaliseGraphqlFixture, v as resetAllVariants, w as resetCapturedRequests, x as setFixtureData, y as setFixtureErrors, z as setFixtureItemsCount, A as setQueryVariant, B as snapshotRequests } from './server-Ds9SYBSn.js';
|
|
2
|
+
import 'msw/node';
|
|
3
|
+
import 'msw';
|
|
4
|
+
import 'node:fs';
|
|
5
|
+
import 'node:path';
|