@gcoredev/fastedge-test 0.1.7 → 0.2.1
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/dist/fastedge-cli/METADATA.json +1 -1
- package/dist/fastedge-cli/fastedge-run-darwin-arm64 +0 -0
- package/dist/fastedge-cli/fastedge-run-linux-x64 +0 -0
- package/dist/fastedge-cli/fastedge-run.exe +0 -0
- package/dist/frontend/assets/{index-BCXfEMSq.js → index-CiqeJ9rz.js} +24 -24
- package/dist/frontend/index.html +1 -1
- package/dist/lib/index.cjs +292 -140
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +292 -140
- package/dist/lib/runner/HeaderManager.d.ts +7 -4
- package/dist/lib/runner/HostFunctions.d.ts +5 -5
- package/dist/lib/runner/HttpWasmRunner.d.ts +13 -4
- package/dist/lib/runner/IStateManager.d.ts +7 -7
- package/dist/lib/runner/IWasmRunner.d.ts +17 -9
- package/dist/lib/runner/PropertyResolver.d.ts +3 -3
- package/dist/lib/runner/ProxyWasmRunner.d.ts +6 -3
- package/dist/lib/runner/standalone.d.ts +1 -1
- package/dist/lib/runner/types.d.ts +17 -8
- package/dist/lib/schemas/api.d.ts +0 -8
- package/dist/lib/schemas/config.d.ts +0 -13
- package/dist/lib/schemas/index.d.ts +2 -2
- package/dist/lib/test-framework/assertions.d.ts +18 -4
- package/dist/lib/test-framework/index.cjs +18754 -189
- package/dist/lib/test-framework/index.d.ts +2 -0
- package/dist/lib/test-framework/index.js +18771 -178
- package/dist/lib/test-framework/mock-origins.d.ts +56 -0
- package/dist/lib/test-framework/types.d.ts +1 -5
- package/dist/server.js +33 -33
- package/docs/API.md +23 -53
- package/docs/DEBUGGER.md +7 -7
- package/docs/INDEX.md +4 -1
- package/docs/RUNNER.md +79 -64
- package/docs/TEST_CONFIG.md +28 -41
- package/docs/TEST_FRAMEWORK.md +205 -32
- package/docs/WEBSOCKET.md +25 -21
- package/docs/quickstart.md +1 -13
- package/package.json +4 -1
- package/schemas/api-config.schema.json +0 -24
- package/schemas/api-send.schema.json +0 -20
- package/schemas/fastedge-config.test.schema.json +0 -24
- package/schemas/full-flow-result.schema.json +17 -7
- package/schemas/hook-call.schema.json +16 -6
- package/schemas/hook-result.schema.json +16 -6
- package/schemas/http-response.schema.json +227 -5
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Origin mocking for tests — a thin lifecycle wrapper around undici's MockAgent.
|
|
3
|
+
*
|
|
4
|
+
* The runner's origin fetch (inside callFullFlow) and every proxy_http_call
|
|
5
|
+
* upstream fetch both go through Node's global fetch, which routes through
|
|
6
|
+
* undici's global dispatcher. Replacing the dispatcher with a MockAgent
|
|
7
|
+
* intercepts all of them. This helper installs the MockAgent, disables real
|
|
8
|
+
* network connections by default, and restores the previous dispatcher on
|
|
9
|
+
* close().
|
|
10
|
+
*
|
|
11
|
+
* The returned handle exposes the raw MockAgent as an escape hatch so
|
|
12
|
+
* advanced undici features (delays, .persist(), .times(), body matching, etc.)
|
|
13
|
+
* remain available without the wrapper having to re-export them.
|
|
14
|
+
*/
|
|
15
|
+
import { MockAgent, type MockPool } from "undici";
|
|
16
|
+
export interface MockOriginsOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Control whether unmocked requests can reach the real network.
|
|
19
|
+
*
|
|
20
|
+
* - `false` (default): block everything except what's mocked. Unmocked
|
|
21
|
+
* requests throw. Safer — missing mocks become loud failures rather
|
|
22
|
+
* than silent live calls in CI.
|
|
23
|
+
* - `true`: allow all unmocked requests to hit the network.
|
|
24
|
+
* - `(string | RegExp)[]`: block everything, then allow-list specific
|
|
25
|
+
* origins or patterns. Use this for HTTP-WASM tests, where the runner
|
|
26
|
+
* forwards to a spawned `fastedge-run` on localhost that the mock
|
|
27
|
+
* dispatcher must not intercept (e.g. `[/^127\.0\.0\.1/, /^localhost/]`).
|
|
28
|
+
*/
|
|
29
|
+
allowNetConnect?: boolean | (string | RegExp)[];
|
|
30
|
+
}
|
|
31
|
+
export interface MockOriginsHandle {
|
|
32
|
+
/**
|
|
33
|
+
* Get or create a MockPool for the given origin URL. Chain
|
|
34
|
+
* `.intercept({ path, method, ... }).reply(status, body)` on the returned
|
|
35
|
+
* pool to register a mock. Despite the name, `method` defaults to `GET`
|
|
36
|
+
* and accepts any HTTP verb (string, RegExp, or predicate function).
|
|
37
|
+
*/
|
|
38
|
+
origin(url: string): MockPool;
|
|
39
|
+
/**
|
|
40
|
+
* The raw undici MockAgent — escape hatch for advanced features not
|
|
41
|
+
* exposed by the wrapper (`.persist()`, `.times(n)`, `.delay(ms)`,
|
|
42
|
+
* custom body matchers, etc.).
|
|
43
|
+
*/
|
|
44
|
+
readonly agent: MockAgent;
|
|
45
|
+
/**
|
|
46
|
+
* Close the MockAgent and restore the previous global dispatcher. Safe
|
|
47
|
+
* to call multiple times; later calls are no-ops.
|
|
48
|
+
*/
|
|
49
|
+
close(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Throw if any registered interceptor was never called. Run this in
|
|
52
|
+
* `afterEach` to catch tests that set up mocks they never exercised.
|
|
53
|
+
*/
|
|
54
|
+
assertAllCalled(): void;
|
|
55
|
+
}
|
|
56
|
+
export declare function mockOrigins(opts?: MockOriginsOptions): MockOriginsHandle;
|
|
@@ -56,7 +56,7 @@ export interface HttpRequestOptions {
|
|
|
56
56
|
body?: string;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
* Options for runFlow() — object-based
|
|
59
|
+
* Options for runFlow() — object-based wrapper around callFullFlow().
|
|
60
60
|
* Pseudo-headers (:method, :path, :authority, :scheme) are derived from url/method
|
|
61
61
|
* automatically and can be overridden via requestHeaders.
|
|
62
62
|
*/
|
|
@@ -65,10 +65,6 @@ export interface FlowOptions {
|
|
|
65
65
|
method?: string;
|
|
66
66
|
requestHeaders?: Record<string, string>;
|
|
67
67
|
requestBody?: string;
|
|
68
|
-
responseStatus?: number;
|
|
69
|
-
responseStatusText?: string;
|
|
70
|
-
responseHeaders?: Record<string, string>;
|
|
71
|
-
responseBody?: string;
|
|
72
68
|
properties?: Record<string, unknown>;
|
|
73
69
|
/** Default: true — matches production FastEdge behaviour */
|
|
74
70
|
enforceProductionPropertyRules?: boolean;
|