@http-forge/core 0.1.0 → 0.2.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 +194 -41
- package/dist/auth/interfaces.d.ts +63 -0
- package/dist/auth/oauth2-token-manager.d.ts +103 -0
- package/dist/collection/collection-loader-factory.d.ts +20 -0
- package/dist/{services → collection}/collection-loader.d.ts +3 -3
- package/dist/collection/collection-service-interfaces.d.ts +119 -0
- package/dist/collection/collection-service.d.ts +75 -0
- package/dist/collection/collection-store.d.ts +109 -0
- package/dist/collection/folder-collection-loader.d.ts +256 -0
- package/dist/collection/folder-collection-store.d.ts +168 -0
- package/dist/collection/interfaces.d.ts +32 -0
- package/dist/collection/json-collection-loader.d.ts +95 -0
- package/dist/{services → collection}/parser-registry.d.ts +1 -2
- package/dist/config/config-service.d.ts +79 -0
- package/dist/config/config.interface.d.ts +140 -0
- package/dist/config/default-config.d.ts +29 -0
- package/dist/config/index.d.ts +6 -0
- package/dist/container.d.ts +22 -14
- package/dist/{implementations → cookie}/cookie-jar.d.ts +2 -3
- package/dist/cookie/cookie-service.d.ts +98 -0
- package/dist/{implementations → cookie}/cookie-utils.d.ts +1 -2
- package/dist/cookie/in-memory-cookie-jar.d.ts +44 -0
- package/dist/{interfaces/cookie.d.ts → cookie/interfaces.d.ts} +22 -3
- package/dist/cookie/persistent-cookie-jar.d.ts +35 -0
- package/dist/environment/environment-config-service.d.ts +95 -0
- package/dist/{services → environment}/environment-resolver.d.ts +6 -5
- package/dist/{services → environment}/forge-env.d.ts +1 -2
- package/dist/environment/interfaces.d.ts +139 -0
- package/dist/environment/variable-interpolator.d.ts +100 -0
- package/dist/execution/collection-request-executor-interfaces.d.ts +36 -0
- package/dist/execution/collection-request-executor.d.ts +78 -0
- package/dist/{services → execution}/request-executor.d.ts +23 -11
- package/dist/execution/request-preparer-interfaces.d.ts +36 -0
- package/dist/execution/request-preparer.d.ts +35 -0
- package/dist/graphql/graphql-completion-provider.d.ts +39 -0
- package/dist/graphql/graphql-schema-service.d.ts +89 -0
- package/dist/{interfaces/history.d.ts → history/history-interfaces.d.ts} +29 -6
- package/dist/history/request-history-service-interfaces.d.ts +43 -0
- package/dist/history/request-history-service.d.ts +133 -0
- package/dist/{implementations → history}/request-history.d.ts +2 -3
- package/dist/{implementations → http}/fetch-http-client.d.ts +4 -5
- package/dist/http/http-request-service.d.ts +36 -0
- package/dist/{implementations → http}/interceptor-chain.d.ts +1 -2
- package/dist/http/interfaces.d.ts +25 -0
- package/dist/http/merge-request-settings.d.ts +12 -0
- package/dist/{implementations → http}/native-http-client.d.ts +6 -15
- package/dist/{implementations → http}/request-preprocessor.d.ts +1 -2
- package/dist/{services → http}/url-builder.d.ts +7 -10
- package/dist/import-export/import-postman-environment.d.ts +21 -0
- package/dist/import-export/rest-client-export.d.ts +35 -0
- package/dist/index.d.ts +88 -6
- package/dist/index.js +262 -35
- package/dist/index.mjs +262 -35
- package/dist/openapi/example-generator.d.ts +26 -0
- package/dist/openapi/history-analyzer.d.ts +29 -0
- package/dist/openapi/index.d.ts +16 -0
- package/dist/openapi/interfaces.d.ts +42 -0
- package/dist/openapi/openapi-exporter.d.ts +73 -0
- package/dist/openapi/openapi-importer.d.ts +72 -0
- package/dist/openapi/ref-resolver.d.ts +28 -0
- package/dist/openapi/schema-inference-service.d.ts +40 -0
- package/dist/openapi/schema-inferrer.d.ts +26 -0
- package/dist/openapi/script-analyzer.d.ts +41 -0
- package/dist/parsers/http-forge-parser.d.ts +2 -3
- package/dist/parsers/index.d.ts +0 -1
- package/dist/{implementations → platform}/data-file-parser.d.ts +0 -1
- package/dist/{implementations → platform}/node-file-system.d.ts +1 -2
- package/dist/script/interfaces.d.ts +149 -0
- package/dist/script/module-loader.d.ts +115 -0
- package/dist/script/request-script-session.d.ts +70 -0
- package/dist/script/script-executor.d.ts +60 -0
- package/dist/script/script-factories.d.ts +83 -0
- package/dist/script/script-utils.d.ts +41 -0
- package/dist/test-suite/index.d.ts +10 -0
- package/dist/test-suite/interfaces.d.ts +164 -0
- package/dist/test-suite/result-storage-service.d.ts +70 -0
- package/dist/test-suite/result-storage.d.ts +296 -0
- package/dist/test-suite/statistics-service.d.ts +51 -0
- package/dist/test-suite/test-suite-service.d.ts +97 -0
- package/dist/test-suite/test-suite-store.d.ts +155 -0
- package/dist/types/console-service.d.ts +40 -0
- package/dist/types/platform.d.ts +206 -0
- package/dist/{interfaces → types}/types.d.ts +282 -12
- package/dist/utils/dynamic-variables.d.ts +38 -0
- package/dist/utils/expression-evaluator.d.ts +34 -0
- package/dist/utils/filter-engine.d.ts +47 -0
- package/dist/utils/helpers.d.ts +47 -0
- package/package.json +11 -3
- package/dist/container.d.ts.map +0 -1
- package/dist/implementations/cookie-jar.d.ts.map +0 -1
- package/dist/implementations/cookie-utils.d.ts.map +0 -1
- package/dist/implementations/data-file-parser.d.ts.map +0 -1
- package/dist/implementations/fetch-http-client.d.ts.map +0 -1
- package/dist/implementations/index.d.ts +0 -22
- package/dist/implementations/index.d.ts.map +0 -1
- package/dist/implementations/interceptor-chain.d.ts.map +0 -1
- package/dist/implementations/module-loader.d.ts +0 -74
- package/dist/implementations/module-loader.d.ts.map +0 -1
- package/dist/implementations/native-http-client.d.ts.map +0 -1
- package/dist/implementations/node-file-system.d.ts.map +0 -1
- package/dist/implementations/request-history.d.ts.map +0 -1
- package/dist/implementations/request-preprocessor.d.ts.map +0 -1
- package/dist/implementations/variable-interpolator.d.ts +0 -55
- package/dist/implementations/variable-interpolator.d.ts.map +0 -1
- package/dist/implementations/vm2-script-runner.d.ts +0 -76
- package/dist/implementations/vm2-script-runner.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/interfaces/cookie.d.ts.map +0 -1
- package/dist/interfaces/history.d.ts.map +0 -1
- package/dist/interfaces/index.d.ts +0 -170
- package/dist/interfaces/index.d.ts.map +0 -1
- package/dist/interfaces/types.d.ts.map +0 -1
- package/dist/parsers/http-forge-parser.d.ts.map +0 -1
- package/dist/parsers/index.d.ts.map +0 -1
- package/dist/services/collection-loader.d.ts.map +0 -1
- package/dist/services/environment-resolver.d.ts.map +0 -1
- package/dist/services/folder-collection-loader.d.ts +0 -91
- package/dist/services/folder-collection-loader.d.ts.map +0 -1
- package/dist/services/forge-env.d.ts.map +0 -1
- package/dist/services/index.d.ts +0 -20
- package/dist/services/index.d.ts.map +0 -1
- package/dist/services/parser-registry.d.ts.map +0 -1
- package/dist/services/request-executor.d.ts.map +0 -1
- package/dist/services/script-pipeline.d.ts +0 -43
- package/dist/services/script-pipeline.d.ts.map +0 -1
- package/dist/services/script-session.d.ts +0 -66
- package/dist/services/script-session.d.ts.map +0 -1
- package/dist/services/url-builder.d.ts.map +0 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module Loader Implementation
|
|
3
|
+
*
|
|
4
|
+
* Single Responsibility: Load custom modules from workspace for script execution
|
|
5
|
+
*
|
|
6
|
+
* Provides consistent module loading behavior across all packages:
|
|
7
|
+
* - VS Code Extension
|
|
8
|
+
* - @http-forge/standalone
|
|
9
|
+
* - @http-forge/playwright
|
|
10
|
+
*
|
|
11
|
+
* All packages provide module paths, resulting in identical behavior.
|
|
12
|
+
*
|
|
13
|
+
* SECURITY NOTE: This loader is designed to work within Node.js vm sandbox.
|
|
14
|
+
* The returned require function should ONLY be exposed within the vm context.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Module loader configuration options
|
|
18
|
+
*/
|
|
19
|
+
export interface ModuleLoaderOptions {
|
|
20
|
+
/** Whether to allow loading custom modules (default: true) */
|
|
21
|
+
allowCustomModules?: boolean;
|
|
22
|
+
/** Maximum module resolution depth (prevents circular dependencies) */
|
|
23
|
+
maxResolveDepth?: number;
|
|
24
|
+
/** Output channel for logging (VS Code environment) */
|
|
25
|
+
outputChannel?: {
|
|
26
|
+
appendLine: (message: string) => void;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create a lightweight moment.js replacement (when not available)
|
|
31
|
+
*/
|
|
32
|
+
export declare function createMomentShim(): any;
|
|
33
|
+
/**
|
|
34
|
+
* Create a lightweight lodash replacement (when not available)
|
|
35
|
+
*/
|
|
36
|
+
export declare function createLodashShim(): any;
|
|
37
|
+
/**
|
|
38
|
+
* ModuleLoader handles loading custom modules from the workspace's modules/ folder.
|
|
39
|
+
*
|
|
40
|
+
* Directory structure:
|
|
41
|
+
* ```
|
|
42
|
+
* http-forge-assets/modules/ ← modulePath
|
|
43
|
+
* ├── package.json ← Declares dependencies
|
|
44
|
+
* ├── global-setup.js ← Global exports injected into sandbox
|
|
45
|
+
* └── auth-helpers.js ← User's custom code
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* SECURITY IMPORTANT:
|
|
49
|
+
* 1. The require function returned by createRequireFunction() should ONLY be used inside vm sandbox
|
|
50
|
+
* 2. Built-in modules are carefully whitelisted - review before adding new ones
|
|
51
|
+
* 3. Relative paths are restricted to modules/ directory subtree
|
|
52
|
+
*/
|
|
53
|
+
export declare class ModuleLoader {
|
|
54
|
+
private availableModules;
|
|
55
|
+
private customModulesRequire?;
|
|
56
|
+
private globalSetupExports?;
|
|
57
|
+
private options;
|
|
58
|
+
private modulesPath;
|
|
59
|
+
private moduleCache;
|
|
60
|
+
private resolveStack;
|
|
61
|
+
/**
|
|
62
|
+
* Built-in modules with fallback loading support
|
|
63
|
+
*/
|
|
64
|
+
private readonly builtinModules;
|
|
65
|
+
/**
|
|
66
|
+
* Create a new ModuleLoader
|
|
67
|
+
*
|
|
68
|
+
* @param modulePaths - Array of paths to modules directories. First valid path is used.
|
|
69
|
+
* @param options - Configuration options
|
|
70
|
+
*/
|
|
71
|
+
constructor(modulePaths?: string[], options?: ModuleLoaderOptions);
|
|
72
|
+
/**
|
|
73
|
+
* Unified fallback module loader
|
|
74
|
+
*/
|
|
75
|
+
private loadOptionalModule;
|
|
76
|
+
private logModuleWarning;
|
|
77
|
+
private getModuleInstallInstructions;
|
|
78
|
+
/**
|
|
79
|
+
* Initialize modules from the resolved path
|
|
80
|
+
* @returns true if successfully initialized
|
|
81
|
+
*/
|
|
82
|
+
private initializeModules;
|
|
83
|
+
private loadAvailableModules;
|
|
84
|
+
private loadGlobalSetup;
|
|
85
|
+
/**
|
|
86
|
+
* Create require function for use in VM sandbox
|
|
87
|
+
*
|
|
88
|
+
* Resolution order:
|
|
89
|
+
* 1. Built-in modules (lodash, moment, crypto, etc.)
|
|
90
|
+
* 2. Relative paths (./helpers, ../utils) - restricted to modules/ directory
|
|
91
|
+
* 3. Workspace dependencies from modules/package.json
|
|
92
|
+
*/
|
|
93
|
+
createRequireFunction(): (moduleName: string) => any;
|
|
94
|
+
private getModuleSuggestions;
|
|
95
|
+
private cacheModule;
|
|
96
|
+
/** Get global setup exports for sandbox injection */
|
|
97
|
+
getGlobalSetupExports(): Record<string, any> | undefined;
|
|
98
|
+
/** Check if custom modules are available */
|
|
99
|
+
hasCustomModules(): boolean;
|
|
100
|
+
/** Get list of available module names (built-ins + workspace) */
|
|
101
|
+
getAvailableModules(): string[];
|
|
102
|
+
/** Clear module cache */
|
|
103
|
+
clearCache(): void;
|
|
104
|
+
/** Get cache statistics */
|
|
105
|
+
getCacheStats(): {
|
|
106
|
+
size: number;
|
|
107
|
+
hits: number;
|
|
108
|
+
};
|
|
109
|
+
private logDebug;
|
|
110
|
+
private logError;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Factory function: create a pre-configured ModuleLoader instance
|
|
114
|
+
*/
|
|
115
|
+
export declare function createModuleLoader(modulePaths: string[], options?: ModuleLoaderOptions): ModuleLoader;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request Script Session
|
|
3
|
+
*
|
|
4
|
+
* Single Responsibility: Manage shared VM context between pre-request and post-response scripts
|
|
5
|
+
*
|
|
6
|
+
* This class creates a single VM sandbox that persists across both script phases,
|
|
7
|
+
* allowing JavaScript variables declared in pre-request to be accessible in post-response.
|
|
8
|
+
* This matches Postman's behavior for per-request script execution.
|
|
9
|
+
*/
|
|
10
|
+
import * as vm from 'vm';
|
|
11
|
+
import { CommonScriptContext, IRequestScriptSession, PostResponseScriptResult, PreRequestScriptContext, PreRequestScriptResult, ResponseContext } from './interfaces';
|
|
12
|
+
/**
|
|
13
|
+
* Dependencies injected from ScriptExecutor
|
|
14
|
+
* Interface Segregation: Only the methods needed by the session
|
|
15
|
+
*/
|
|
16
|
+
export interface SessionDependencies {
|
|
17
|
+
createVM: (ctx: any, scriptConsole: any) => vm.Context;
|
|
18
|
+
createCommonContext: (context: CommonScriptContext, eventName: 'prerequest' | 'test') => any;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Request Script Session Implementation
|
|
22
|
+
*
|
|
23
|
+
* Manages a shared VM context for executing pre-request and post-response scripts.
|
|
24
|
+
* Variables declared in pre-request are accessible in post-response.
|
|
25
|
+
*/
|
|
26
|
+
export declare class RequestScriptSession implements IRequestScriptSession {
|
|
27
|
+
private readonly deps;
|
|
28
|
+
private readonly initialContext;
|
|
29
|
+
private vmContext;
|
|
30
|
+
private ctx;
|
|
31
|
+
private modifiedRequest;
|
|
32
|
+
private assertions;
|
|
33
|
+
private consoleMessages;
|
|
34
|
+
private _variables;
|
|
35
|
+
private _collectionVariables;
|
|
36
|
+
private _globals;
|
|
37
|
+
private _sessionVariables;
|
|
38
|
+
private _environmentVariables;
|
|
39
|
+
constructor(deps: SessionDependencies, initialContext: PreRequestScriptContext);
|
|
40
|
+
/**
|
|
41
|
+
* Initialize the shared VM context
|
|
42
|
+
*/
|
|
43
|
+
private initializeSession;
|
|
44
|
+
/**
|
|
45
|
+
* Create shared context object that will be augmented with response data later
|
|
46
|
+
*/
|
|
47
|
+
private createSharedContext;
|
|
48
|
+
/**
|
|
49
|
+
* Create request object with getters/setters for modification tracking
|
|
50
|
+
* Maps HTTP Forge body types to Postman modes for script API compatibility
|
|
51
|
+
*/
|
|
52
|
+
private createRequestObject;
|
|
53
|
+
/**
|
|
54
|
+
* Execute pre-request scripts in the shared session
|
|
55
|
+
*/
|
|
56
|
+
executePreRequest(script: string | string[]): Promise<PreRequestScriptResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Execute post-response scripts in the shared session
|
|
59
|
+
* The response data is injected into the existing VM context
|
|
60
|
+
*/
|
|
61
|
+
executePostResponse(script: string | string[], responseContext: ResponseContext): Promise<PostResponseScriptResult>;
|
|
62
|
+
/**
|
|
63
|
+
* Compare two RequestBody objects for equality
|
|
64
|
+
*/
|
|
65
|
+
private bodiesEqual;
|
|
66
|
+
/**
|
|
67
|
+
* Clean up the session resources
|
|
68
|
+
*/
|
|
69
|
+
dispose(): void;
|
|
70
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Script Executor
|
|
3
|
+
*
|
|
4
|
+
* Single Responsibility: Orchestrate script execution and VM configuration
|
|
5
|
+
* Open/Closed: Uses composition to delegate to specialized modules
|
|
6
|
+
* Dependency Inversion: Depends on abstractions (IRequestScriptSession, IScriptExecutor)
|
|
7
|
+
*
|
|
8
|
+
* This is the main entry point for script execution.
|
|
9
|
+
* It configures the VM sandbox and delegates session management to RequestScriptSession.
|
|
10
|
+
*/
|
|
11
|
+
import { IRequestScriptSession, IScriptExecutor, PreRequestScriptContext } from './interfaces';
|
|
12
|
+
import { IHttpRequestService } from '../http/interfaces';
|
|
13
|
+
/**
|
|
14
|
+
* Script Executor Implementation
|
|
15
|
+
*
|
|
16
|
+
* Orchestrates script execution by:
|
|
17
|
+
* - Configuring VM sandbox with built-in libraries
|
|
18
|
+
* - Creating common context for variable scopes
|
|
19
|
+
* - Delegating session management to RequestScriptSession
|
|
20
|
+
*/
|
|
21
|
+
export declare class ScriptExecutor implements IScriptExecutor {
|
|
22
|
+
private readonly httpService?;
|
|
23
|
+
private readonly moduleLoader;
|
|
24
|
+
constructor(httpService?: IHttpRequestService | undefined, modulePaths?: string[]);
|
|
25
|
+
/**
|
|
26
|
+
* Create a request execution session
|
|
27
|
+
* Factory method implementing IScriptExecutor
|
|
28
|
+
*/
|
|
29
|
+
createRequestSession(context: PreRequestScriptContext): IRequestScriptSession;
|
|
30
|
+
/**
|
|
31
|
+
* Create VM context with sandbox configuration
|
|
32
|
+
* Returns a context object that can be used with vm.runInContext()
|
|
33
|
+
*/
|
|
34
|
+
private createVM;
|
|
35
|
+
/**
|
|
36
|
+
* Create common context object for variable scopes
|
|
37
|
+
* Used by RequestScriptSession for pre-request and test scripts
|
|
38
|
+
*/
|
|
39
|
+
private createCommonContext;
|
|
40
|
+
/**
|
|
41
|
+
* Create a basic variable scope with get/set/has/unset/clear/toObject
|
|
42
|
+
*/
|
|
43
|
+
private createVariableScope;
|
|
44
|
+
/**
|
|
45
|
+
* Create merged variable scope (Postman-style cascading lookup)
|
|
46
|
+
*/
|
|
47
|
+
private createMergedVariableScope;
|
|
48
|
+
/**
|
|
49
|
+
* Create environment variable scope with change callbacks
|
|
50
|
+
*/
|
|
51
|
+
private createEnvironmentScope;
|
|
52
|
+
/**
|
|
53
|
+
* Create session variable scope with change callbacks
|
|
54
|
+
*/
|
|
55
|
+
private createSessionScope;
|
|
56
|
+
/**
|
|
57
|
+
* Create sendRequest function using httpService
|
|
58
|
+
*/
|
|
59
|
+
private createSendRequest;
|
|
60
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Script Factories
|
|
3
|
+
*
|
|
4
|
+
* Single Responsibility: Create objects used in script execution contexts
|
|
5
|
+
* Open/Closed: New factory methods can be added without modifying existing ones
|
|
6
|
+
*/
|
|
7
|
+
import { ResponseContext } from './interfaces';
|
|
8
|
+
/**
|
|
9
|
+
* Response object interface for script context
|
|
10
|
+
*/
|
|
11
|
+
export interface ScriptResponse {
|
|
12
|
+
status: number;
|
|
13
|
+
code: number;
|
|
14
|
+
statusText: string;
|
|
15
|
+
headers: Record<string, string>;
|
|
16
|
+
body: any;
|
|
17
|
+
cookies: Record<string, string>;
|
|
18
|
+
responseTime?: number;
|
|
19
|
+
responseSize?: number;
|
|
20
|
+
getHeader(name: string): string | undefined;
|
|
21
|
+
getCookie(name: string): string | undefined;
|
|
22
|
+
reason(): string;
|
|
23
|
+
json(): any;
|
|
24
|
+
text(): string;
|
|
25
|
+
cookie(name: string): string | undefined;
|
|
26
|
+
hasCookie(name: string): boolean;
|
|
27
|
+
to: ResponseAssertions;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Response assertion helpers (Postman-style)
|
|
31
|
+
*/
|
|
32
|
+
export interface ResponseAssertions {
|
|
33
|
+
have: {
|
|
34
|
+
status(expectedStatus: number): void;
|
|
35
|
+
header(headerName: string, expectedValue?: string): void;
|
|
36
|
+
body(expectedBody?: string): void;
|
|
37
|
+
jsonBody(expectedJson?: any): void;
|
|
38
|
+
};
|
|
39
|
+
be: {
|
|
40
|
+
ok(): void;
|
|
41
|
+
error(): void;
|
|
42
|
+
clientError(): void;
|
|
43
|
+
serverError(): void;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create response object with helper methods for script context
|
|
48
|
+
* Provides Postman-compatible response API
|
|
49
|
+
*/
|
|
50
|
+
export declare function createResponseObject(response: ResponseContext): ScriptResponse;
|
|
51
|
+
/**
|
|
52
|
+
* Expect chain interface for Chai-style assertions
|
|
53
|
+
*/
|
|
54
|
+
export interface ExpectChain {
|
|
55
|
+
_value: any;
|
|
56
|
+
_negated: boolean;
|
|
57
|
+
not: ExpectChain;
|
|
58
|
+
to: ExpectChain;
|
|
59
|
+
be: ExpectChain;
|
|
60
|
+
have: ExpectChain;
|
|
61
|
+
equal(expected: any): ExpectChain;
|
|
62
|
+
eql(expected: any): ExpectChain;
|
|
63
|
+
property(name: string, value?: any): ExpectChain;
|
|
64
|
+
ok: ExpectChain;
|
|
65
|
+
include(value: any): ExpectChain;
|
|
66
|
+
oneOf(values: any[]): ExpectChain;
|
|
67
|
+
match(pattern: RegExp): ExpectChain;
|
|
68
|
+
above(num: number): ExpectChain;
|
|
69
|
+
below(num: number): ExpectChain;
|
|
70
|
+
greaterThan(num: number): ExpectChain;
|
|
71
|
+
lessThan(num: number): ExpectChain;
|
|
72
|
+
within(start: number, end: number): ExpectChain;
|
|
73
|
+
true: ExpectChain;
|
|
74
|
+
false: ExpectChain;
|
|
75
|
+
null: ExpectChain;
|
|
76
|
+
undefined: ExpectChain;
|
|
77
|
+
empty: ExpectChain;
|
|
78
|
+
length(len: number): ExpectChain;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create Chai-style expect chain for assertions
|
|
82
|
+
*/
|
|
83
|
+
export declare function createExpectChain(value: any): ExpectChain;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Script Utilities
|
|
3
|
+
*
|
|
4
|
+
* Single Responsibility: Pure utility functions for script execution
|
|
5
|
+
* These are stateless helper functions with no side effects
|
|
6
|
+
*/
|
|
7
|
+
import { TestAssertion } from '../types/types';
|
|
8
|
+
/**
|
|
9
|
+
* Console message structure for script output
|
|
10
|
+
*/
|
|
11
|
+
export interface ConsoleMessage {
|
|
12
|
+
level: 'log' | 'info' | 'warn' | 'error';
|
|
13
|
+
args: any[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Concatenate multiple scripts into one with clear separators
|
|
17
|
+
* Enables variables defined in earlier scripts to be accessible in later scripts
|
|
18
|
+
*/
|
|
19
|
+
export declare function concatenateScripts(scripts: string | string[]): string;
|
|
20
|
+
/**
|
|
21
|
+
* Check if an object has changed from its original value
|
|
22
|
+
* Uses JSON serialization for deep comparison
|
|
23
|
+
*/
|
|
24
|
+
export declare function hasChanged(current: any, original: any): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Format console messages into output strings
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatConsoleOutput(messages: ConsoleMessage[]): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Create a script console that captures output
|
|
31
|
+
*/
|
|
32
|
+
export declare function createScriptConsole(messages: ConsoleMessage[]): Console;
|
|
33
|
+
/**
|
|
34
|
+
* Create a test function that records assertions
|
|
35
|
+
*/
|
|
36
|
+
export declare function createTestFunction(assertions: TestAssertion[]): (name: string, fn: () => void) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Normalize HTTP headers to Record<string, string>
|
|
39
|
+
* Converts multi-value headers (string[]) to comma-separated strings
|
|
40
|
+
*/
|
|
41
|
+
export declare function normalizeHeaders(headers: Record<string, string | string[]>): Record<string, string>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Suite Services
|
|
3
|
+
*/
|
|
4
|
+
export * from './interfaces';
|
|
5
|
+
export * from './result-storage';
|
|
6
|
+
export { ResultStorageService } from './result-storage-service';
|
|
7
|
+
export { StatisticsService } from './statistics-service';
|
|
8
|
+
export { TestSuiteService } from './test-suite-service';
|
|
9
|
+
export { TestSuiteStore } from './test-suite-store';
|
|
10
|
+
export type { ITestSuiteStore, SuiteRequestEntry } from './test-suite-store';
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Suite Interfaces
|
|
3
|
+
*
|
|
4
|
+
* Defines data structures for Test Suite functionality
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Request reference within a Test Suite
|
|
8
|
+
* References a request from a Collection (not a copy)
|
|
9
|
+
*/
|
|
10
|
+
export interface SuiteRequest {
|
|
11
|
+
/** Collection ID where the request lives */
|
|
12
|
+
collectionId: string;
|
|
13
|
+
/** Collection name for display purposes */
|
|
14
|
+
collectionName: string;
|
|
15
|
+
/** Request ID within the collection */
|
|
16
|
+
requestId: string;
|
|
17
|
+
/** Cached display info (avoid querying collection each time) */
|
|
18
|
+
name: string;
|
|
19
|
+
method: string;
|
|
20
|
+
folderPath: string;
|
|
21
|
+
/** Whether this request is enabled for execution */
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Test Suite run configuration
|
|
26
|
+
*/
|
|
27
|
+
export interface SuiteConfig {
|
|
28
|
+
/** Number of iterations to run */
|
|
29
|
+
iterations: number;
|
|
30
|
+
/** Delay between requests in milliseconds */
|
|
31
|
+
delayBetweenRequests: number;
|
|
32
|
+
/** Stop execution on first error */
|
|
33
|
+
stopOnError: boolean;
|
|
34
|
+
/** Read variables from shared session */
|
|
35
|
+
readFromSharedSession: boolean;
|
|
36
|
+
/** Write variables to shared session */
|
|
37
|
+
writeToSharedSession: boolean;
|
|
38
|
+
/** Data file path for variable injection */
|
|
39
|
+
dataFilePath?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Test Suite definition
|
|
43
|
+
*/
|
|
44
|
+
export interface TestSuite {
|
|
45
|
+
/** Unique identifier */
|
|
46
|
+
id: string;
|
|
47
|
+
/** Suite name */
|
|
48
|
+
name: string;
|
|
49
|
+
/** Optional description */
|
|
50
|
+
description?: string;
|
|
51
|
+
/** Ordered list of request references */
|
|
52
|
+
requests: SuiteRequest[];
|
|
53
|
+
/** Run configuration */
|
|
54
|
+
config: SuiteConfig;
|
|
55
|
+
/** Whether this is a temporary suite (not saved) */
|
|
56
|
+
isTemporary?: boolean;
|
|
57
|
+
/** Creation timestamp */
|
|
58
|
+
createdAt: number;
|
|
59
|
+
/** Last update timestamp */
|
|
60
|
+
updatedAt: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Per-request statistics
|
|
64
|
+
*/
|
|
65
|
+
export interface RequestStatistics {
|
|
66
|
+
/** Request name */
|
|
67
|
+
name: string;
|
|
68
|
+
/** Number of executions */
|
|
69
|
+
count: number;
|
|
70
|
+
/** Number of passed executions */
|
|
71
|
+
passed: number;
|
|
72
|
+
/** Number of failed executions */
|
|
73
|
+
failed: number;
|
|
74
|
+
/** Number of skipped executions */
|
|
75
|
+
skipped: number;
|
|
76
|
+
/** Minimum response time (ms) */
|
|
77
|
+
min: number;
|
|
78
|
+
/** Maximum response time (ms) */
|
|
79
|
+
max: number;
|
|
80
|
+
/** Average response time (ms) */
|
|
81
|
+
avg: number;
|
|
82
|
+
/** 50th percentile (median) */
|
|
83
|
+
p50: number;
|
|
84
|
+
/** 90th percentile */
|
|
85
|
+
p90: number;
|
|
86
|
+
/** 95th percentile */
|
|
87
|
+
p95: number;
|
|
88
|
+
/** 99th percentile */
|
|
89
|
+
p99: number;
|
|
90
|
+
/** Raw duration data for recalculation */
|
|
91
|
+
durations: number[];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Run statistics summary
|
|
95
|
+
*/
|
|
96
|
+
export interface RunSummary {
|
|
97
|
+
/** Total requests executed */
|
|
98
|
+
totalRequests: number;
|
|
99
|
+
/** Number of passed requests */
|
|
100
|
+
passed: number;
|
|
101
|
+
/** Number of failed requests */
|
|
102
|
+
failed: number;
|
|
103
|
+
/** Number of skipped requests */
|
|
104
|
+
skipped: number;
|
|
105
|
+
/** Pass rate percentage */
|
|
106
|
+
passRate: number;
|
|
107
|
+
/** Total duration in milliseconds */
|
|
108
|
+
duration: number;
|
|
109
|
+
/** Whether run is still in progress */
|
|
110
|
+
isRunning: boolean;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Error summary entry
|
|
114
|
+
*/
|
|
115
|
+
export interface ErrorSummary {
|
|
116
|
+
/** Error message or status */
|
|
117
|
+
message: string;
|
|
118
|
+
/** Number of occurrences */
|
|
119
|
+
count: number;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Complete run statistics
|
|
123
|
+
*/
|
|
124
|
+
export interface RunStatistics {
|
|
125
|
+
/** Summary statistics */
|
|
126
|
+
summary: RunSummary;
|
|
127
|
+
/** Statistics grouped by request name */
|
|
128
|
+
byRequest: Map<string, RequestStatistics>;
|
|
129
|
+
/** Overall statistics across all requests */
|
|
130
|
+
overall: RequestStatistics;
|
|
131
|
+
/** Error summary */
|
|
132
|
+
errors: ErrorSummary[];
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Test Suite Service Interface
|
|
136
|
+
*/
|
|
137
|
+
export interface ITestSuiteService {
|
|
138
|
+
createSuite(name: string, requests?: SuiteRequest[]): Promise<TestSuite>;
|
|
139
|
+
getSuite(id: string): Promise<TestSuite | undefined>;
|
|
140
|
+
getAllSuites(): Promise<TestSuite[]>;
|
|
141
|
+
updateSuite(suite: TestSuite): Promise<void>;
|
|
142
|
+
deleteSuite(id: string): Promise<boolean>;
|
|
143
|
+
createTempSuiteFromCollection(collectionId: string): Promise<TestSuite | undefined>;
|
|
144
|
+
saveTempSuite(suite: TestSuite, name: string): Promise<TestSuite>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Statistics Service Interface
|
|
148
|
+
*/
|
|
149
|
+
export interface IStatisticsService {
|
|
150
|
+
/** Add a result and update statistics */
|
|
151
|
+
addResult(requestName: string, duration: number, passed: boolean, skipped: boolean, error?: string): void;
|
|
152
|
+
/** Get current statistics */
|
|
153
|
+
getStatistics(): RunStatistics;
|
|
154
|
+
/** Reset statistics for a new run */
|
|
155
|
+
reset(): void;
|
|
156
|
+
/** Mark run as complete */
|
|
157
|
+
complete(): void;
|
|
158
|
+
/** Set start time for duration tracking */
|
|
159
|
+
start(): void;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Default suite configuration
|
|
163
|
+
*/
|
|
164
|
+
export declare const DEFAULT_SUITE_CONFIG: SuiteConfig;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result Storage Service for Test Suite
|
|
3
|
+
*
|
|
4
|
+
* Architecture (JMeter-inspired):
|
|
5
|
+
* - Append-only index pages for fast writes
|
|
6
|
+
* - Individual JSON files for full details
|
|
7
|
+
* - Aggregated stats in memory (constant size)
|
|
8
|
+
* - On-demand result loading
|
|
9
|
+
*/
|
|
10
|
+
import { ExecutionResult } from '../types/types';
|
|
11
|
+
import { IConfigService } from '../config';
|
|
12
|
+
import { FullResultDetails, IndexPage, IResultStorageService, RecentError, RequestStats, ResultSummary, RunConfig, RunManifest, RunStats } from './result-storage';
|
|
13
|
+
/**
|
|
14
|
+
* File-based Result Storage Service for Test Suite
|
|
15
|
+
*/
|
|
16
|
+
export declare class ResultStorageService implements IResultStorageService {
|
|
17
|
+
private configService;
|
|
18
|
+
private basePath;
|
|
19
|
+
private currentRunPath;
|
|
20
|
+
private currentRunId;
|
|
21
|
+
private currentSuiteId;
|
|
22
|
+
private currentManifest;
|
|
23
|
+
private currentIndexPage;
|
|
24
|
+
private currentPageNumber;
|
|
25
|
+
private readonly indexPageSize;
|
|
26
|
+
private recentErrors;
|
|
27
|
+
private readonly recentErrorsLimit;
|
|
28
|
+
private resultIndex;
|
|
29
|
+
private requestDurations;
|
|
30
|
+
constructor(configService: IConfigService);
|
|
31
|
+
/**
|
|
32
|
+
* Get the base path for result storage
|
|
33
|
+
*/
|
|
34
|
+
getBasePath(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Initialize a new run
|
|
37
|
+
*/
|
|
38
|
+
initializeRun(suiteId: string, suiteName: string, environment: string, config: RunConfig): Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Save a request result
|
|
41
|
+
* Returns lightweight summary for UI
|
|
42
|
+
*/
|
|
43
|
+
saveResult(iteration: number, result: ExecutionResult): Promise<ResultSummary>;
|
|
44
|
+
/**
|
|
45
|
+
* Finalize run
|
|
46
|
+
*/
|
|
47
|
+
finalizeRun(status?: 'completed' | 'aborted' | 'error'): Promise<void>;
|
|
48
|
+
getCurrentStats(): {
|
|
49
|
+
stats: RunStats;
|
|
50
|
+
requestStats: Record<string, RequestStats>;
|
|
51
|
+
recentErrors: RecentError[];
|
|
52
|
+
} | null;
|
|
53
|
+
getCurrentRunId(): string | null;
|
|
54
|
+
getCurrentSuiteId(): string | null;
|
|
55
|
+
getResultDetails(suiteId: string, runId: string, resultFile: string): Promise<FullResultDetails>;
|
|
56
|
+
getIndexPage(suiteId: string, runId: string, page: number): Promise<IndexPage>;
|
|
57
|
+
getManifest(suiteId: string, runId: string): Promise<RunManifest>;
|
|
58
|
+
listRuns(suiteId: string): Promise<RunManifest[]>;
|
|
59
|
+
listSuites(): Promise<string[]>;
|
|
60
|
+
deleteRun(suiteId: string, runId: string): Promise<void>;
|
|
61
|
+
cleanupOldRuns(): Promise<{
|
|
62
|
+
deleted: number;
|
|
63
|
+
freed: number;
|
|
64
|
+
}>;
|
|
65
|
+
private generateRunId;
|
|
66
|
+
private saveManifest;
|
|
67
|
+
private writeCurrentIndexPage;
|
|
68
|
+
private updateStats;
|
|
69
|
+
private getDirectorySize;
|
|
70
|
+
}
|