@frontmcp/testing 0.5.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/LICENSE +201 -0
- package/README.md +1358 -0
- package/jest-preset.js +61 -0
- package/package.json +94 -0
- package/src/assertions/index.d.ts +5 -0
- package/src/assertions/index.js +18 -0
- package/src/assertions/index.js.map +1 -0
- package/src/assertions/mcp-assertions.d.ts +81 -0
- package/src/assertions/mcp-assertions.js +220 -0
- package/src/assertions/mcp-assertions.js.map +1 -0
- package/src/auth/auth-headers.d.ts +29 -0
- package/src/auth/auth-headers.js +62 -0
- package/src/auth/auth-headers.js.map +1 -0
- package/src/auth/index.d.ts +9 -0
- package/src/auth/index.js +15 -0
- package/src/auth/index.js.map +1 -0
- package/src/auth/token-factory.d.ts +94 -0
- package/src/auth/token-factory.js +181 -0
- package/src/auth/token-factory.js.map +1 -0
- package/src/auth/user-fixtures.d.ts +26 -0
- package/src/auth/user-fixtures.js +92 -0
- package/src/auth/user-fixtures.js.map +1 -0
- package/src/client/index.d.ts +7 -0
- package/src/client/index.js +12 -0
- package/src/client/index.js.map +1 -0
- package/src/client/mcp-test-client.builder.d.ts +72 -0
- package/src/client/mcp-test-client.builder.js +111 -0
- package/src/client/mcp-test-client.builder.js.map +1 -0
- package/src/client/mcp-test-client.d.ts +360 -0
- package/src/client/mcp-test-client.js +929 -0
- package/src/client/mcp-test-client.js.map +1 -0
- package/src/client/mcp-test-client.types.d.ts +216 -0
- package/src/client/mcp-test-client.types.js +7 -0
- package/src/client/mcp-test-client.types.js.map +1 -0
- package/src/errors/index.d.ts +45 -0
- package/src/errors/index.js +85 -0
- package/src/errors/index.js.map +1 -0
- package/src/expect.d.ts +67 -0
- package/src/expect.js +31 -0
- package/src/expect.js.map +1 -0
- package/src/fixtures/fixture-types.d.ts +166 -0
- package/src/fixtures/fixture-types.js +7 -0
- package/src/fixtures/fixture-types.js.map +1 -0
- package/src/fixtures/index.d.ts +7 -0
- package/src/fixtures/index.js +16 -0
- package/src/fixtures/index.js.map +1 -0
- package/src/fixtures/test-fixture.d.ts +41 -0
- package/src/fixtures/test-fixture.js +280 -0
- package/src/fixtures/test-fixture.js.map +1 -0
- package/src/http-mock/http-mock.d.ts +84 -0
- package/src/http-mock/http-mock.js +544 -0
- package/src/http-mock/http-mock.js.map +1 -0
- package/src/http-mock/http-mock.types.d.ts +124 -0
- package/src/http-mock/http-mock.types.js +10 -0
- package/src/http-mock/http-mock.types.js.map +1 -0
- package/src/http-mock/index.d.ts +6 -0
- package/src/http-mock/index.js +11 -0
- package/src/http-mock/index.js.map +1 -0
- package/src/index.d.ts +65 -0
- package/src/index.js +128 -0
- package/src/index.js.map +1 -0
- package/src/interceptor/index.d.ts +7 -0
- package/src/interceptor/index.js +15 -0
- package/src/interceptor/index.js.map +1 -0
- package/src/interceptor/interceptor-chain.d.ts +77 -0
- package/src/interceptor/interceptor-chain.js +207 -0
- package/src/interceptor/interceptor-chain.js.map +1 -0
- package/src/interceptor/interceptor.types.d.ts +131 -0
- package/src/interceptor/interceptor.types.js +7 -0
- package/src/interceptor/interceptor.types.js.map +1 -0
- package/src/interceptor/mock-registry.d.ts +82 -0
- package/src/interceptor/mock-registry.js +189 -0
- package/src/interceptor/mock-registry.js.map +1 -0
- package/src/matchers/index.d.ts +7 -0
- package/src/matchers/index.js +12 -0
- package/src/matchers/index.js.map +1 -0
- package/src/matchers/matcher-types.d.ts +266 -0
- package/src/matchers/matcher-types.js +10 -0
- package/src/matchers/matcher-types.js.map +1 -0
- package/src/matchers/mcp-matchers.d.ts +47 -0
- package/src/matchers/mcp-matchers.js +391 -0
- package/src/matchers/mcp-matchers.js.map +1 -0
- package/src/playwright/index.d.ts +37 -0
- package/src/playwright/index.js +49 -0
- package/src/playwright/index.js.map +1 -0
- package/src/server/index.d.ts +6 -0
- package/src/server/index.js +10 -0
- package/src/server/index.js.map +1 -0
- package/src/server/test-server.d.ts +99 -0
- package/src/server/test-server.js +286 -0
- package/src/server/test-server.js.map +1 -0
- package/src/setup.d.ts +22 -0
- package/src/setup.js +30 -0
- package/src/setup.js.map +1 -0
- package/src/transport/index.d.ts +6 -0
- package/src/transport/index.js +10 -0
- package/src/transport/index.js.map +1 -0
- package/src/transport/streamable-http.transport.d.ts +65 -0
- package/src/transport/streamable-http.transport.js +432 -0
- package/src/transport/streamable-http.transport.js.map +1 -0
- package/src/transport/transport.interface.d.ts +124 -0
- package/src/transport/transport.interface.js +7 -0
- package/src/transport/transport.interface.js.map +1 -0
- package/src/ui/index.d.ts +17 -0
- package/src/ui/index.js +23 -0
- package/src/ui/index.js.map +1 -0
- package/src/ui/ui-assertions.d.ts +94 -0
- package/src/ui/ui-assertions.js +215 -0
- package/src/ui/ui-assertions.js.map +1 -0
- package/src/ui/ui-matchers.d.ts +39 -0
- package/src/ui/ui-matchers.js +275 -0
- package/src/ui/ui-matchers.js.map +1 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file http-mock.types.ts
|
|
3
|
+
* @description Types for HTTP request mocking (fetch/XHR interception)
|
|
4
|
+
*
|
|
5
|
+
* This module allows mocking HTTP requests made by tools during MCP server testing,
|
|
6
|
+
* enabling fully offline testing of MCP servers.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* HTTP method types
|
|
10
|
+
*/
|
|
11
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
12
|
+
/**
|
|
13
|
+
* Request matcher - defines which requests to intercept
|
|
14
|
+
*/
|
|
15
|
+
export interface HttpRequestMatcher {
|
|
16
|
+
/** URL pattern - string for exact match, RegExp for pattern, or function for custom */
|
|
17
|
+
url: string | RegExp | ((url: string) => boolean);
|
|
18
|
+
/** HTTP method(s) to match (default: all methods) */
|
|
19
|
+
method?: HttpMethod | HttpMethod[];
|
|
20
|
+
/** Headers that must be present (partial match) */
|
|
21
|
+
headers?: Record<string, string | RegExp>;
|
|
22
|
+
/** Body matcher for POST/PUT/PATCH */
|
|
23
|
+
body?: string | RegExp | Record<string, unknown> | ((body: unknown) => boolean);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Mocked HTTP response
|
|
27
|
+
*/
|
|
28
|
+
export interface HttpMockResponse {
|
|
29
|
+
/** HTTP status code (default: 200) */
|
|
30
|
+
status?: number;
|
|
31
|
+
/** Status text (default: 'OK') */
|
|
32
|
+
statusText?: string;
|
|
33
|
+
/** Response headers */
|
|
34
|
+
headers?: Record<string, string>;
|
|
35
|
+
/** Response body - string, object/array (will be JSON.stringify'd), or Buffer */
|
|
36
|
+
body?: string | Record<string, unknown> | unknown[] | Buffer | ArrayBuffer;
|
|
37
|
+
/** Delay before responding in ms */
|
|
38
|
+
delay?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* HTTP mock definition
|
|
42
|
+
*/
|
|
43
|
+
export interface HttpMockDefinition {
|
|
44
|
+
/** Request matcher */
|
|
45
|
+
match: HttpRequestMatcher;
|
|
46
|
+
/** Response to return */
|
|
47
|
+
response: HttpMockResponse | ((request: HttpRequestInfo) => HttpMockResponse | Promise<HttpMockResponse>);
|
|
48
|
+
/** Number of times to use this mock (default: Infinity) */
|
|
49
|
+
times?: number;
|
|
50
|
+
/** Name for debugging/tracking */
|
|
51
|
+
name?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Information about an intercepted HTTP request
|
|
55
|
+
*/
|
|
56
|
+
export interface HttpRequestInfo {
|
|
57
|
+
/** Full URL */
|
|
58
|
+
url: string;
|
|
59
|
+
/** HTTP method */
|
|
60
|
+
method: HttpMethod;
|
|
61
|
+
/** Request headers */
|
|
62
|
+
headers: Record<string, string>;
|
|
63
|
+
/** Request body (parsed if JSON) */
|
|
64
|
+
body?: unknown;
|
|
65
|
+
/** Raw body string */
|
|
66
|
+
rawBody?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Handle returned when adding an HTTP mock
|
|
70
|
+
*/
|
|
71
|
+
export interface HttpMockHandle {
|
|
72
|
+
/** Remove this mock */
|
|
73
|
+
remove(): void;
|
|
74
|
+
/** Get call count */
|
|
75
|
+
callCount(): number;
|
|
76
|
+
/** Get all intercepted requests */
|
|
77
|
+
calls(): HttpRequestInfo[];
|
|
78
|
+
/** Wait for a specific number of calls */
|
|
79
|
+
waitForCalls(count: number, timeoutMs?: number): Promise<HttpRequestInfo[]>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* HTTP interceptor - controls when mocks are active
|
|
83
|
+
*/
|
|
84
|
+
export interface HttpInterceptor {
|
|
85
|
+
/** Add an HTTP mock */
|
|
86
|
+
mock(definition: HttpMockDefinition): HttpMockHandle;
|
|
87
|
+
/** Convenience: mock a GET request */
|
|
88
|
+
get(url: string | RegExp, response: HttpMockResponse | Record<string, unknown>): HttpMockHandle;
|
|
89
|
+
/** Convenience: mock a POST request */
|
|
90
|
+
post(url: string | RegExp, response: HttpMockResponse | Record<string, unknown>): HttpMockHandle;
|
|
91
|
+
/** Convenience: mock a PUT request */
|
|
92
|
+
put(url: string | RegExp, response: HttpMockResponse | Record<string, unknown>): HttpMockHandle;
|
|
93
|
+
/** Convenience: mock a DELETE request */
|
|
94
|
+
delete(url: string | RegExp, response: HttpMockResponse | Record<string, unknown>): HttpMockHandle;
|
|
95
|
+
/** Convenience: mock any method */
|
|
96
|
+
any(url: string | RegExp, response: HttpMockResponse | Record<string, unknown>): HttpMockHandle;
|
|
97
|
+
/** Clear all mocks in this scope */
|
|
98
|
+
clear(): void;
|
|
99
|
+
/** Get all pending (unused) mocks */
|
|
100
|
+
pending(): HttpMockDefinition[];
|
|
101
|
+
/** Check if all mocks were used */
|
|
102
|
+
isDone(): boolean;
|
|
103
|
+
/** Assert all mocks were used (throws if not) */
|
|
104
|
+
assertDone(): void;
|
|
105
|
+
/** Enable passthrough for unmatched requests (default: false, throws error) */
|
|
106
|
+
allowPassthrough(allow: boolean): void;
|
|
107
|
+
/** Restore original fetch/XHR */
|
|
108
|
+
restore(): void;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Global HTTP mock manager
|
|
112
|
+
*/
|
|
113
|
+
export interface HttpMockManager {
|
|
114
|
+
/** Create a new HTTP interceptor */
|
|
115
|
+
interceptor(): HttpInterceptor;
|
|
116
|
+
/** Enable HTTP mocking globally */
|
|
117
|
+
enable(): void;
|
|
118
|
+
/** Disable HTTP mocking and restore originals */
|
|
119
|
+
disable(): void;
|
|
120
|
+
/** Check if mocking is enabled */
|
|
121
|
+
isEnabled(): boolean;
|
|
122
|
+
/** Clear all scopes and mocks */
|
|
123
|
+
clearAll(): void;
|
|
124
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file http-mock.types.ts
|
|
4
|
+
* @description Types for HTTP request mocking (fetch/XHR interception)
|
|
5
|
+
*
|
|
6
|
+
* This module allows mocking HTTP requests made by tools during MCP server testing,
|
|
7
|
+
* enabling fully offline testing of MCP servers.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
//# sourceMappingURL=http-mock.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-mock.types.js","sourceRoot":"","sources":["../../../src/http-mock/http-mock.types.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * @file http-mock.types.ts\n * @description Types for HTTP request mocking (fetch/XHR interception)\n *\n * This module allows mocking HTTP requests made by tools during MCP server testing,\n * enabling fully offline testing of MCP servers.\n */\n\n/**\n * HTTP method types\n */\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';\n\n/**\n * Request matcher - defines which requests to intercept\n */\nexport interface HttpRequestMatcher {\n /** URL pattern - string for exact match, RegExp for pattern, or function for custom */\n url: string | RegExp | ((url: string) => boolean);\n /** HTTP method(s) to match (default: all methods) */\n method?: HttpMethod | HttpMethod[];\n /** Headers that must be present (partial match) */\n headers?: Record<string, string | RegExp>;\n /** Body matcher for POST/PUT/PATCH */\n body?: string | RegExp | Record<string, unknown> | ((body: unknown) => boolean);\n}\n\n/**\n * Mocked HTTP response\n */\nexport interface HttpMockResponse {\n /** HTTP status code (default: 200) */\n status?: number;\n /** Status text (default: 'OK') */\n statusText?: string;\n /** Response headers */\n headers?: Record<string, string>;\n /** Response body - string, object/array (will be JSON.stringify'd), or Buffer */\n body?: string | Record<string, unknown> | unknown[] | Buffer | ArrayBuffer;\n /** Delay before responding in ms */\n delay?: number;\n}\n\n/**\n * HTTP mock definition\n */\nexport interface HttpMockDefinition {\n /** Request matcher */\n match: HttpRequestMatcher;\n /** Response to return */\n response: HttpMockResponse | ((request: HttpRequestInfo) => HttpMockResponse | Promise<HttpMockResponse>);\n /** Number of times to use this mock (default: Infinity) */\n times?: number;\n /** Name for debugging/tracking */\n name?: string;\n}\n\n/**\n * Information about an intercepted HTTP request\n */\nexport interface HttpRequestInfo {\n /** Full URL */\n url: string;\n /** HTTP method */\n method: HttpMethod;\n /** Request headers */\n headers: Record<string, string>;\n /** Request body (parsed if JSON) */\n body?: unknown;\n /** Raw body string */\n rawBody?: string;\n}\n\n/**\n * Handle returned when adding an HTTP mock\n */\nexport interface HttpMockHandle {\n /** Remove this mock */\n remove(): void;\n /** Get call count */\n callCount(): number;\n /** Get all intercepted requests */\n calls(): HttpRequestInfo[];\n /** Wait for a specific number of calls */\n waitForCalls(count: number, timeoutMs?: number): Promise<HttpRequestInfo[]>;\n}\n\n/**\n * HTTP interceptor - controls when mocks are active\n */\nexport interface HttpInterceptor {\n /** Add an HTTP mock */\n mock(definition: HttpMockDefinition): HttpMockHandle;\n\n /** Convenience: mock a GET request */\n get(url: string | RegExp, response: HttpMockResponse | Record<string, unknown>): HttpMockHandle;\n\n /** Convenience: mock a POST request */\n post(url: string | RegExp, response: HttpMockResponse | Record<string, unknown>): HttpMockHandle;\n\n /** Convenience: mock a PUT request */\n put(url: string | RegExp, response: HttpMockResponse | Record<string, unknown>): HttpMockHandle;\n\n /** Convenience: mock a DELETE request */\n delete(url: string | RegExp, response: HttpMockResponse | Record<string, unknown>): HttpMockHandle;\n\n /** Convenience: mock any method */\n any(url: string | RegExp, response: HttpMockResponse | Record<string, unknown>): HttpMockHandle;\n\n /** Clear all mocks in this scope */\n clear(): void;\n\n /** Get all pending (unused) mocks */\n pending(): HttpMockDefinition[];\n\n /** Check if all mocks were used */\n isDone(): boolean;\n\n /** Assert all mocks were used (throws if not) */\n assertDone(): void;\n\n /** Enable passthrough for unmatched requests (default: false, throws error) */\n allowPassthrough(allow: boolean): void;\n\n /** Restore original fetch/XHR */\n restore(): void;\n}\n\n/**\n * Global HTTP mock manager\n */\nexport interface HttpMockManager {\n /** Create a new HTTP interceptor */\n interceptor(): HttpInterceptor;\n\n /** Enable HTTP mocking globally */\n enable(): void;\n\n /** Disable HTTP mocking and restore originals */\n disable(): void;\n\n /** Check if mocking is enabled */\n isEnabled(): boolean;\n\n /** Clear all scopes and mocks */\n clearAll(): void;\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description Barrel exports for HTTP mock module
|
|
4
|
+
*/
|
|
5
|
+
export { httpMock, httpResponse } from './http-mock';
|
|
6
|
+
export type { HttpMethod, HttpRequestMatcher, HttpMockResponse, HttpMockDefinition, HttpRequestInfo, HttpMockHandle, HttpInterceptor, HttpMockManager, } from './http-mock.types';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file index.ts
|
|
4
|
+
* @description Barrel exports for HTTP mock module
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.httpResponse = exports.httpMock = void 0;
|
|
8
|
+
var http_mock_1 = require("./http-mock");
|
|
9
|
+
Object.defineProperty(exports, "httpMock", { enumerable: true, get: function () { return http_mock_1.httpMock; } });
|
|
10
|
+
Object.defineProperty(exports, "httpResponse", { enumerable: true, get: function () { return http_mock_1.httpResponse; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/http-mock/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yCAAqD;AAA5C,qGAAA,QAAQ,OAAA;AAAE,yGAAA,YAAY,OAAA","sourcesContent":["/**\n * @file index.ts\n * @description Barrel exports for HTTP mock module\n */\n\nexport { httpMock, httpResponse } from './http-mock';\n\nexport type {\n HttpMethod,\n HttpRequestMatcher,\n HttpMockResponse,\n HttpMockDefinition,\n HttpRequestInfo,\n HttpMockHandle,\n HttpInterceptor,\n HttpMockManager,\n} from './http-mock.types';\n"]}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description Main barrel exports for @frontmcp/testing
|
|
4
|
+
*
|
|
5
|
+
* @example Quick Start with Fixtures
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { test, expect } from '@frontmcp/testing';
|
|
8
|
+
*
|
|
9
|
+
* test.use({
|
|
10
|
+
* server: './src/main.ts',
|
|
11
|
+
* port: 3003,
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* test('server exposes tools', async ({ mcp }) => {
|
|
15
|
+
* const tools = await mcp.tools.list();
|
|
16
|
+
* expect(tools).toContainTool('my-tool');
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* test('tool execution works', async ({ mcp }) => {
|
|
20
|
+
* const result = await mcp.tools.call('my-tool', { input: 'test' });
|
|
21
|
+
* expect(result).toBeSuccessful();
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example Manual Client Usage
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { McpTestClient, TestServer } from '@frontmcp/testing';
|
|
28
|
+
*
|
|
29
|
+
* const server = await TestServer.start({ command: 'npx tsx src/main.ts' });
|
|
30
|
+
* const client = await McpTestClient.create({ baseUrl: server.info.baseUrl })
|
|
31
|
+
* .withTransport('streamable-http')
|
|
32
|
+
* .buildAndConnect();
|
|
33
|
+
*
|
|
34
|
+
* const tools = await client.tools.list();
|
|
35
|
+
* console.log(tools);
|
|
36
|
+
*
|
|
37
|
+
* await client.disconnect();
|
|
38
|
+
* await server.stop();
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export { McpTestClient } from './client/mcp-test-client';
|
|
42
|
+
export { McpTestClientBuilder } from './client/mcp-test-client.builder';
|
|
43
|
+
export type { McpTestClientConfig, McpResponse, McpErrorInfo, TestTransportType, TestAuthConfig, ToolResultWrapper, ResourceContentWrapper, PromptResultWrapper, LogEntry, LogLevel, RequestTrace, NotificationEntry, ProgressUpdate, SessionInfo, AuthState, } from './client/mcp-test-client.types';
|
|
44
|
+
export type { McpTransport, TransportConfig, TransportState } from './transport/transport.interface';
|
|
45
|
+
export { StreamableHttpTransport } from './transport/streamable-http.transport';
|
|
46
|
+
export { TestTokenFactory } from './auth/token-factory';
|
|
47
|
+
export type { CreateTokenOptions, TokenFactoryOptions } from './auth/token-factory';
|
|
48
|
+
export { AuthHeaders } from './auth/auth-headers';
|
|
49
|
+
export { TestUsers, createTestUser } from './auth/user-fixtures';
|
|
50
|
+
export type { TestUserFixture } from './auth/user-fixtures';
|
|
51
|
+
export { TestServer } from './server/test-server';
|
|
52
|
+
export type { TestServerOptions, TestServerInfo } from './server/test-server';
|
|
53
|
+
export { McpAssertions, containsTool, containsResource, containsResourceTemplate, containsPrompt, isSuccessful, isError, hasTextContent, hasMimeType, } from './assertions/mcp-assertions';
|
|
54
|
+
export { TestClientError, ConnectionError, TimeoutError, McpProtocolError, ServerStartError, AssertionError, } from './errors/index';
|
|
55
|
+
export type { InitializeResult, ListToolsResult, CallToolResult, ListResourcesResult, ReadResourceResult, ListResourceTemplatesResult, ListPromptsResult, GetPromptResult, Tool, Resource, ResourceTemplate, Prompt, JSONRPCRequest, JSONRPCResponse, } from './client/mcp-test-client.types';
|
|
56
|
+
export { test } from './fixtures';
|
|
57
|
+
export type { TestConfig, TestFixtures, AuthFixture, ServerFixture, TestFn, TestWithFixtures, TestUser, } from './fixtures';
|
|
58
|
+
export { expect } from './expect';
|
|
59
|
+
export { mcpMatchers } from './matchers';
|
|
60
|
+
export type { McpMatchers } from './matchers';
|
|
61
|
+
export { DefaultMockRegistry, DefaultInterceptorChain, mockResponse, interceptors } from './interceptor';
|
|
62
|
+
export type { InterceptorContext, InterceptorResult, RequestInterceptor, ResponseInterceptorContext, ResponseInterceptorResult, ResponseInterceptor, MockDefinition, MockRegistry, MockHandle, InterceptorChain, } from './interceptor';
|
|
63
|
+
export { httpMock, httpResponse } from './http-mock';
|
|
64
|
+
export type { HttpMethod, HttpRequestMatcher, HttpMockResponse, HttpMockDefinition, HttpRequestInfo, HttpMockHandle, HttpInterceptor, HttpMockManager, } from './http-mock';
|
|
65
|
+
export { uiMatchers, UIAssertions } from './ui';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file index.ts
|
|
4
|
+
* @description Main barrel exports for @frontmcp/testing
|
|
5
|
+
*
|
|
6
|
+
* @example Quick Start with Fixtures
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { test, expect } from '@frontmcp/testing';
|
|
9
|
+
*
|
|
10
|
+
* test.use({
|
|
11
|
+
* server: './src/main.ts',
|
|
12
|
+
* port: 3003,
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* test('server exposes tools', async ({ mcp }) => {
|
|
16
|
+
* const tools = await mcp.tools.list();
|
|
17
|
+
* expect(tools).toContainTool('my-tool');
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* test('tool execution works', async ({ mcp }) => {
|
|
21
|
+
* const result = await mcp.tools.call('my-tool', { input: 'test' });
|
|
22
|
+
* expect(result).toBeSuccessful();
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example Manual Client Usage
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { McpTestClient, TestServer } from '@frontmcp/testing';
|
|
29
|
+
*
|
|
30
|
+
* const server = await TestServer.start({ command: 'npx tsx src/main.ts' });
|
|
31
|
+
* const client = await McpTestClient.create({ baseUrl: server.info.baseUrl })
|
|
32
|
+
* .withTransport('streamable-http')
|
|
33
|
+
* .buildAndConnect();
|
|
34
|
+
*
|
|
35
|
+
* const tools = await client.tools.list();
|
|
36
|
+
* console.log(tools);
|
|
37
|
+
*
|
|
38
|
+
* await client.disconnect();
|
|
39
|
+
* await server.stop();
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.UIAssertions = exports.uiMatchers = exports.httpResponse = exports.httpMock = exports.interceptors = exports.mockResponse = exports.DefaultInterceptorChain = exports.DefaultMockRegistry = exports.mcpMatchers = exports.expect = exports.test = exports.AssertionError = exports.ServerStartError = exports.McpProtocolError = exports.TimeoutError = exports.ConnectionError = exports.TestClientError = exports.hasMimeType = exports.hasTextContent = exports.isError = exports.isSuccessful = exports.containsPrompt = exports.containsResourceTemplate = exports.containsResource = exports.containsTool = exports.McpAssertions = exports.TestServer = exports.createTestUser = exports.TestUsers = exports.AuthHeaders = exports.TestTokenFactory = exports.StreamableHttpTransport = exports.McpTestClientBuilder = exports.McpTestClient = void 0;
|
|
44
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
45
|
+
// CLIENT
|
|
46
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
47
|
+
var mcp_test_client_1 = require("./client/mcp-test-client");
|
|
48
|
+
Object.defineProperty(exports, "McpTestClient", { enumerable: true, get: function () { return mcp_test_client_1.McpTestClient; } });
|
|
49
|
+
var mcp_test_client_builder_1 = require("./client/mcp-test-client.builder");
|
|
50
|
+
Object.defineProperty(exports, "McpTestClientBuilder", { enumerable: true, get: function () { return mcp_test_client_builder_1.McpTestClientBuilder; } });
|
|
51
|
+
var streamable_http_transport_1 = require("./transport/streamable-http.transport");
|
|
52
|
+
Object.defineProperty(exports, "StreamableHttpTransport", { enumerable: true, get: function () { return streamable_http_transport_1.StreamableHttpTransport; } });
|
|
53
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
54
|
+
// AUTH
|
|
55
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
56
|
+
var token_factory_1 = require("./auth/token-factory");
|
|
57
|
+
Object.defineProperty(exports, "TestTokenFactory", { enumerable: true, get: function () { return token_factory_1.TestTokenFactory; } });
|
|
58
|
+
var auth_headers_1 = require("./auth/auth-headers");
|
|
59
|
+
Object.defineProperty(exports, "AuthHeaders", { enumerable: true, get: function () { return auth_headers_1.AuthHeaders; } });
|
|
60
|
+
var user_fixtures_1 = require("./auth/user-fixtures");
|
|
61
|
+
Object.defineProperty(exports, "TestUsers", { enumerable: true, get: function () { return user_fixtures_1.TestUsers; } });
|
|
62
|
+
Object.defineProperty(exports, "createTestUser", { enumerable: true, get: function () { return user_fixtures_1.createTestUser; } });
|
|
63
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
64
|
+
// SERVER
|
|
65
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
66
|
+
var test_server_1 = require("./server/test-server");
|
|
67
|
+
Object.defineProperty(exports, "TestServer", { enumerable: true, get: function () { return test_server_1.TestServer; } });
|
|
68
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
69
|
+
// ASSERTIONS
|
|
70
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
71
|
+
var mcp_assertions_1 = require("./assertions/mcp-assertions");
|
|
72
|
+
Object.defineProperty(exports, "McpAssertions", { enumerable: true, get: function () { return mcp_assertions_1.McpAssertions; } });
|
|
73
|
+
Object.defineProperty(exports, "containsTool", { enumerable: true, get: function () { return mcp_assertions_1.containsTool; } });
|
|
74
|
+
Object.defineProperty(exports, "containsResource", { enumerable: true, get: function () { return mcp_assertions_1.containsResource; } });
|
|
75
|
+
Object.defineProperty(exports, "containsResourceTemplate", { enumerable: true, get: function () { return mcp_assertions_1.containsResourceTemplate; } });
|
|
76
|
+
Object.defineProperty(exports, "containsPrompt", { enumerable: true, get: function () { return mcp_assertions_1.containsPrompt; } });
|
|
77
|
+
Object.defineProperty(exports, "isSuccessful", { enumerable: true, get: function () { return mcp_assertions_1.isSuccessful; } });
|
|
78
|
+
Object.defineProperty(exports, "isError", { enumerable: true, get: function () { return mcp_assertions_1.isError; } });
|
|
79
|
+
Object.defineProperty(exports, "hasTextContent", { enumerable: true, get: function () { return mcp_assertions_1.hasTextContent; } });
|
|
80
|
+
Object.defineProperty(exports, "hasMimeType", { enumerable: true, get: function () { return mcp_assertions_1.hasMimeType; } });
|
|
81
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
82
|
+
// ERRORS
|
|
83
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
84
|
+
var index_1 = require("./errors/index");
|
|
85
|
+
Object.defineProperty(exports, "TestClientError", { enumerable: true, get: function () { return index_1.TestClientError; } });
|
|
86
|
+
Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return index_1.ConnectionError; } });
|
|
87
|
+
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return index_1.TimeoutError; } });
|
|
88
|
+
Object.defineProperty(exports, "McpProtocolError", { enumerable: true, get: function () { return index_1.McpProtocolError; } });
|
|
89
|
+
Object.defineProperty(exports, "ServerStartError", { enumerable: true, get: function () { return index_1.ServerStartError; } });
|
|
90
|
+
Object.defineProperty(exports, "AssertionError", { enumerable: true, get: function () { return index_1.AssertionError; } });
|
|
91
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
92
|
+
// FIXTURES (Primary API)
|
|
93
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
94
|
+
var fixtures_1 = require("./fixtures");
|
|
95
|
+
Object.defineProperty(exports, "test", { enumerable: true, get: function () { return fixtures_1.test; } });
|
|
96
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
97
|
+
// EXPECT (Primary API)
|
|
98
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
99
|
+
// Export the pre-typed expect with MCP matchers (Playwright-style approach)
|
|
100
|
+
// This provides proper typing without relying on global namespace augmentation
|
|
101
|
+
var expect_1 = require("./expect");
|
|
102
|
+
Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return expect_1.expect; } });
|
|
103
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
104
|
+
// CUSTOM MATCHERS
|
|
105
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
106
|
+
var matchers_1 = require("./matchers");
|
|
107
|
+
Object.defineProperty(exports, "mcpMatchers", { enumerable: true, get: function () { return matchers_1.mcpMatchers; } });
|
|
108
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
109
|
+
// INTERCEPTORS & MOCKING
|
|
110
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
111
|
+
var interceptor_1 = require("./interceptor");
|
|
112
|
+
Object.defineProperty(exports, "DefaultMockRegistry", { enumerable: true, get: function () { return interceptor_1.DefaultMockRegistry; } });
|
|
113
|
+
Object.defineProperty(exports, "DefaultInterceptorChain", { enumerable: true, get: function () { return interceptor_1.DefaultInterceptorChain; } });
|
|
114
|
+
Object.defineProperty(exports, "mockResponse", { enumerable: true, get: function () { return interceptor_1.mockResponse; } });
|
|
115
|
+
Object.defineProperty(exports, "interceptors", { enumerable: true, get: function () { return interceptor_1.interceptors; } });
|
|
116
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
117
|
+
// HTTP MOCKING (for offline testing)
|
|
118
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
119
|
+
var http_mock_1 = require("./http-mock");
|
|
120
|
+
Object.defineProperty(exports, "httpMock", { enumerable: true, get: function () { return http_mock_1.httpMock; } });
|
|
121
|
+
Object.defineProperty(exports, "httpResponse", { enumerable: true, get: function () { return http_mock_1.httpResponse; } });
|
|
122
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
123
|
+
// UI TESTING
|
|
124
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
125
|
+
var ui_1 = require("./ui");
|
|
126
|
+
Object.defineProperty(exports, "uiMatchers", { enumerable: true, get: function () { return ui_1.uiMatchers; } });
|
|
127
|
+
Object.defineProperty(exports, "UIAssertions", { enumerable: true, get: function () { return ui_1.UIAssertions; } });
|
|
128
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;;;AAEH,sEAAsE;AACtE,SAAS;AACT,sEAAsE;AAEtE,4DAAyD;AAAhD,gHAAA,aAAa,OAAA;AACtB,4EAAwE;AAA/D,+HAAA,oBAAoB,OAAA;AAwB7B,mFAAgF;AAAvE,oIAAA,uBAAuB,OAAA;AAEhC,sEAAsE;AACtE,OAAO;AACP,sEAAsE;AAEtE,sDAAwD;AAA/C,iHAAA,gBAAgB,OAAA;AAEzB,oDAAkD;AAAzC,2GAAA,WAAW,OAAA;AACpB,sDAAiE;AAAxD,0GAAA,SAAS,OAAA;AAAE,+GAAA,cAAc,OAAA;AAGlC,sEAAsE;AACtE,SAAS;AACT,sEAAsE;AAEtE,oDAAkD;AAAzC,yGAAA,UAAU,OAAA;AAGnB,sEAAsE;AACtE,aAAa;AACb,sEAAsE;AAEtE,8DAUqC;AATnC,+GAAA,aAAa,OAAA;AACb,8GAAA,YAAY,OAAA;AACZ,kHAAA,gBAAgB,OAAA;AAChB,0HAAA,wBAAwB,OAAA;AACxB,gHAAA,cAAc,OAAA;AACd,8GAAA,YAAY,OAAA;AACZ,yGAAA,OAAO,OAAA;AACP,gHAAA,cAAc,OAAA;AACd,6GAAA,WAAW,OAAA;AAGb,sEAAsE;AACtE,SAAS;AACT,sEAAsE;AAEtE,wCAOwB;AANtB,wGAAA,eAAe,OAAA;AACf,wGAAA,eAAe,OAAA;AACf,qGAAA,YAAY,OAAA;AACZ,yGAAA,gBAAgB,OAAA;AAChB,yGAAA,gBAAgB,OAAA;AAChB,uGAAA,cAAc,OAAA;AAyBhB,sEAAsE;AACtE,yBAAyB;AACzB,sEAAsE;AAEtE,uCAAkC;AAAzB,gGAAA,IAAI,OAAA;AAWb,sEAAsE;AACtE,uBAAuB;AACvB,sEAAsE;AAEtE,4EAA4E;AAC5E,+EAA+E;AAC/E,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AAEf,sEAAsE;AACtE,kBAAkB;AAClB,sEAAsE;AAEtE,uCAAyC;AAAhC,uGAAA,WAAW,OAAA;AAGpB,sEAAsE;AACtE,yBAAyB;AACzB,sEAAsE;AAEtE,6CAAyG;AAAhG,kHAAA,mBAAmB,OAAA;AAAE,sHAAA,uBAAuB,OAAA;AAAE,2GAAA,YAAY,OAAA;AAAE,2GAAA,YAAY,OAAA;AAejF,sEAAsE;AACtE,qCAAqC;AACrC,sEAAsE;AAEtE,yCAAqD;AAA5C,qGAAA,QAAQ,OAAA;AAAE,yGAAA,YAAY,OAAA;AAa/B,sEAAsE;AACtE,aAAa;AACb,sEAAsE;AAEtE,2BAAgD;AAAvC,gGAAA,UAAU,OAAA;AAAE,kGAAA,YAAY,OAAA","sourcesContent":["/**\n * @file index.ts\n * @description Main barrel exports for @frontmcp/testing\n *\n * @example Quick Start with Fixtures\n * ```typescript\n * import { test, expect } from '@frontmcp/testing';\n *\n * test.use({\n * server: './src/main.ts',\n * port: 3003,\n * });\n *\n * test('server exposes tools', async ({ mcp }) => {\n * const tools = await mcp.tools.list();\n * expect(tools).toContainTool('my-tool');\n * });\n *\n * test('tool execution works', async ({ mcp }) => {\n * const result = await mcp.tools.call('my-tool', { input: 'test' });\n * expect(result).toBeSuccessful();\n * });\n * ```\n *\n * @example Manual Client Usage\n * ```typescript\n * import { McpTestClient, TestServer } from '@frontmcp/testing';\n *\n * const server = await TestServer.start({ command: 'npx tsx src/main.ts' });\n * const client = await McpTestClient.create({ baseUrl: server.info.baseUrl })\n * .withTransport('streamable-http')\n * .buildAndConnect();\n *\n * const tools = await client.tools.list();\n * console.log(tools);\n *\n * await client.disconnect();\n * await server.stop();\n * ```\n */\n\n// ═══════════════════════════════════════════════════════════════════\n// CLIENT\n// ═══════════════════════════════════════════════════════════════════\n\nexport { McpTestClient } from './client/mcp-test-client';\nexport { McpTestClientBuilder } from './client/mcp-test-client.builder';\nexport type {\n McpTestClientConfig,\n McpResponse,\n McpErrorInfo,\n TestTransportType,\n TestAuthConfig,\n ToolResultWrapper,\n ResourceContentWrapper,\n PromptResultWrapper,\n LogEntry,\n LogLevel,\n RequestTrace,\n NotificationEntry,\n ProgressUpdate,\n SessionInfo,\n AuthState,\n} from './client/mcp-test-client.types';\n\n// ═══════════════════════════════════════════════════════════════════\n// TRANSPORT\n// ═══════════════════════════════════════════════════════════════════\n\nexport type { McpTransport, TransportConfig, TransportState } from './transport/transport.interface';\nexport { StreamableHttpTransport } from './transport/streamable-http.transport';\n\n// ═══════════════════════════════════════════════════════════════════\n// AUTH\n// ═══════════════════════════════════════════════════════════════════\n\nexport { TestTokenFactory } from './auth/token-factory';\nexport type { CreateTokenOptions, TokenFactoryOptions } from './auth/token-factory';\nexport { AuthHeaders } from './auth/auth-headers';\nexport { TestUsers, createTestUser } from './auth/user-fixtures';\nexport type { TestUserFixture } from './auth/user-fixtures';\n\n// ═══════════════════════════════════════════════════════════════════\n// SERVER\n// ═══════════════════════════════════════════════════════════════════\n\nexport { TestServer } from './server/test-server';\nexport type { TestServerOptions, TestServerInfo } from './server/test-server';\n\n// ═══════════════════════════════════════════════════════════════════\n// ASSERTIONS\n// ═══════════════════════════════════════════════════════════════════\n\nexport {\n McpAssertions,\n containsTool,\n containsResource,\n containsResourceTemplate,\n containsPrompt,\n isSuccessful,\n isError,\n hasTextContent,\n hasMimeType,\n} from './assertions/mcp-assertions';\n\n// ═══════════════════════════════════════════════════════════════════\n// ERRORS\n// ═══════════════════════════════════════════════════════════════════\n\nexport {\n TestClientError,\n ConnectionError,\n TimeoutError,\n McpProtocolError,\n ServerStartError,\n AssertionError,\n} from './errors/index';\n\n// ═══════════════════════════════════════════════════════════════════\n// RE-EXPORTS FROM MCP SDK\n// ═══════════════════════════════════════════════════════════════════\n\nexport type {\n InitializeResult,\n ListToolsResult,\n CallToolResult,\n ListResourcesResult,\n ReadResourceResult,\n ListResourceTemplatesResult,\n ListPromptsResult,\n GetPromptResult,\n Tool,\n Resource,\n ResourceTemplate,\n Prompt,\n // JSON-RPC types\n JSONRPCRequest,\n JSONRPCResponse,\n} from './client/mcp-test-client.types';\n\n// ═══════════════════════════════════════════════════════════════════\n// FIXTURES (Primary API)\n// ═══════════════════════════════════════════════════════════════════\n\nexport { test } from './fixtures';\nexport type {\n TestConfig,\n TestFixtures,\n AuthFixture,\n ServerFixture,\n TestFn,\n TestWithFixtures,\n TestUser,\n} from './fixtures';\n\n// ═══════════════════════════════════════════════════════════════════\n// EXPECT (Primary API)\n// ═══════════════════════════════════════════════════════════════════\n\n// Export the pre-typed expect with MCP matchers (Playwright-style approach)\n// This provides proper typing without relying on global namespace augmentation\nexport { expect } from './expect';\n\n// ═══════════════════════════════════════════════════════════════════\n// CUSTOM MATCHERS\n// ═══════════════════════════════════════════════════════════════════\n\nexport { mcpMatchers } from './matchers';\nexport type { McpMatchers } from './matchers';\n\n// ═══════════════════════════════════════════════════════════════════\n// INTERCEPTORS & MOCKING\n// ═══════════════════════════════════════════════════════════════════\n\nexport { DefaultMockRegistry, DefaultInterceptorChain, mockResponse, interceptors } from './interceptor';\n\nexport type {\n InterceptorContext,\n InterceptorResult,\n RequestInterceptor,\n ResponseInterceptorContext,\n ResponseInterceptorResult,\n ResponseInterceptor,\n MockDefinition,\n MockRegistry,\n MockHandle,\n InterceptorChain,\n} from './interceptor';\n\n// ═══════════════════════════════════════════════════════════════════\n// HTTP MOCKING (for offline testing)\n// ═══════════════════════════════════════════════════════════════════\n\nexport { httpMock, httpResponse } from './http-mock';\n\nexport type {\n HttpMethod,\n HttpRequestMatcher,\n HttpMockResponse,\n HttpMockDefinition,\n HttpRequestInfo,\n HttpMockHandle,\n HttpInterceptor,\n HttpMockManager,\n} from './http-mock';\n\n// ═══════════════════════════════════════════════════════════════════\n// UI TESTING\n// ═══════════════════════════════════════════════════════════════════\n\nexport { uiMatchers, UIAssertions } from './ui';\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description Barrel exports for interceptor module
|
|
4
|
+
*/
|
|
5
|
+
export type { InterceptorContext, InterceptorResult, RequestInterceptor, ResponseInterceptorContext, ResponseInterceptorResult, ResponseInterceptor, MockDefinition, MockRegistry, MockHandle, InterceptorChain, } from './interceptor.types';
|
|
6
|
+
export { DefaultMockRegistry, mockResponse } from './mock-registry';
|
|
7
|
+
export { DefaultInterceptorChain, interceptors } from './interceptor-chain';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file index.ts
|
|
4
|
+
* @description Barrel exports for interceptor module
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.interceptors = exports.DefaultInterceptorChain = exports.mockResponse = exports.DefaultMockRegistry = void 0;
|
|
8
|
+
// Classes
|
|
9
|
+
var mock_registry_1 = require("./mock-registry");
|
|
10
|
+
Object.defineProperty(exports, "DefaultMockRegistry", { enumerable: true, get: function () { return mock_registry_1.DefaultMockRegistry; } });
|
|
11
|
+
Object.defineProperty(exports, "mockResponse", { enumerable: true, get: function () { return mock_registry_1.mockResponse; } });
|
|
12
|
+
var interceptor_chain_1 = require("./interceptor-chain");
|
|
13
|
+
Object.defineProperty(exports, "DefaultInterceptorChain", { enumerable: true, get: function () { return interceptor_chain_1.DefaultInterceptorChain; } });
|
|
14
|
+
Object.defineProperty(exports, "interceptors", { enumerable: true, get: function () { return interceptor_chain_1.interceptors; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interceptor/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAgBH,UAAU;AACV,iDAAoE;AAA3D,oHAAA,mBAAmB,OAAA;AAAE,6GAAA,YAAY,OAAA;AAC1C,yDAA4E;AAAnE,4HAAA,uBAAuB,OAAA;AAAE,iHAAA,YAAY,OAAA","sourcesContent":["/**\n * @file index.ts\n * @description Barrel exports for interceptor module\n */\n\n// Types\nexport type {\n InterceptorContext,\n InterceptorResult,\n RequestInterceptor,\n ResponseInterceptorContext,\n ResponseInterceptorResult,\n ResponseInterceptor,\n MockDefinition,\n MockRegistry,\n MockHandle,\n InterceptorChain,\n} from './interceptor.types';\n\n// Classes\nexport { DefaultMockRegistry, mockResponse } from './mock-registry';\nexport { DefaultInterceptorChain, interceptors } from './interceptor-chain';\n"]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file interceptor-chain.ts
|
|
3
|
+
* @description Interceptor chain for request/response interception
|
|
4
|
+
*/
|
|
5
|
+
import type { JsonRpcRequest, JsonRpcResponse } from '../transport/transport.interface';
|
|
6
|
+
import type { InterceptorChain, RequestInterceptor, ResponseInterceptor, InterceptorContext, MockRegistry } from './interceptor.types';
|
|
7
|
+
/**
|
|
8
|
+
* Default implementation of InterceptorChain
|
|
9
|
+
*/
|
|
10
|
+
export declare class DefaultInterceptorChain implements InterceptorChain {
|
|
11
|
+
request: RequestInterceptor[];
|
|
12
|
+
response: ResponseInterceptor[];
|
|
13
|
+
mocks: MockRegistry;
|
|
14
|
+
constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Add a request interceptor
|
|
17
|
+
*/
|
|
18
|
+
addRequestInterceptor(interceptor: RequestInterceptor): () => void;
|
|
19
|
+
/**
|
|
20
|
+
* Add a response interceptor
|
|
21
|
+
*/
|
|
22
|
+
addResponseInterceptor(interceptor: ResponseInterceptor): () => void;
|
|
23
|
+
/**
|
|
24
|
+
* Process a request through the interceptor chain
|
|
25
|
+
* Returns either:
|
|
26
|
+
* - { type: 'continue', request } - continue with (possibly modified) request
|
|
27
|
+
* - { type: 'mock', response } - return mock response immediately
|
|
28
|
+
* - { type: 'error', error } - throw error
|
|
29
|
+
*/
|
|
30
|
+
processRequest(request: JsonRpcRequest, meta: InterceptorContext['meta']): Promise<{
|
|
31
|
+
type: 'continue';
|
|
32
|
+
request: JsonRpcRequest;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'mock';
|
|
35
|
+
response: JsonRpcResponse;
|
|
36
|
+
} | {
|
|
37
|
+
type: 'error';
|
|
38
|
+
error: Error;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Process a response through the interceptor chain
|
|
42
|
+
*/
|
|
43
|
+
processResponse(request: JsonRpcRequest, response: JsonRpcResponse, durationMs: number): Promise<JsonRpcResponse>;
|
|
44
|
+
/**
|
|
45
|
+
* Clear all interceptors and mocks
|
|
46
|
+
*/
|
|
47
|
+
clear(): void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Convenience interceptor creators
|
|
51
|
+
*/
|
|
52
|
+
export declare const interceptors: {
|
|
53
|
+
/**
|
|
54
|
+
* Create an interceptor that logs all requests
|
|
55
|
+
*/
|
|
56
|
+
logger(logFn?: (message: string, data?: unknown) => void): RequestInterceptor;
|
|
57
|
+
/**
|
|
58
|
+
* Create an interceptor that adds latency to all requests
|
|
59
|
+
*/
|
|
60
|
+
delay(ms: number): RequestInterceptor;
|
|
61
|
+
/**
|
|
62
|
+
* Create an interceptor that fails requests matching a condition
|
|
63
|
+
*/
|
|
64
|
+
failWhen(condition: (ctx: InterceptorContext) => boolean, error: Error | string): RequestInterceptor;
|
|
65
|
+
/**
|
|
66
|
+
* Create an interceptor that modifies specific methods
|
|
67
|
+
*/
|
|
68
|
+
modifyMethod(method: string, modifier: (request: JsonRpcRequest) => JsonRpcRequest): RequestInterceptor;
|
|
69
|
+
/**
|
|
70
|
+
* Create a response interceptor that logs responses
|
|
71
|
+
*/
|
|
72
|
+
responseLogger(logFn?: (message: string, data?: unknown) => void): ResponseInterceptor;
|
|
73
|
+
/**
|
|
74
|
+
* Create a response interceptor that modifies specific responses
|
|
75
|
+
*/
|
|
76
|
+
modifyResponse(method: string, modifier: (response: JsonRpcResponse) => JsonRpcResponse): ResponseInterceptor;
|
|
77
|
+
};
|