@gcoredev/fastedge-test 0.1.6 → 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.
Files changed (43) hide show
  1. package/dist/frontend/assets/{index-BpdzhbRl.js → index-CiqeJ9rz.js} +24 -24
  2. package/dist/frontend/index.html +1 -1
  3. package/dist/lib/index.cjs +164 -66
  4. package/dist/lib/index.d.ts +1 -0
  5. package/dist/lib/index.js +164 -66
  6. package/dist/lib/runner/HeaderManager.d.ts +6 -4
  7. package/dist/lib/runner/HostFunctions.d.ts +5 -5
  8. package/dist/lib/runner/HttpWasmRunner.d.ts +22 -5
  9. package/dist/lib/runner/IStateManager.d.ts +7 -7
  10. package/dist/lib/runner/IWasmRunner.d.ts +42 -10
  11. package/dist/lib/runner/PortManager.d.ts +4 -1
  12. package/dist/lib/runner/PropertyResolver.d.ts +3 -3
  13. package/dist/lib/runner/ProxyWasmRunner.d.ts +5 -2
  14. package/dist/lib/runner/standalone.d.ts +1 -1
  15. package/dist/lib/runner/types.d.ts +17 -8
  16. package/dist/lib/schemas/api.d.ts +2 -8
  17. package/dist/lib/schemas/config.d.ts +2 -13
  18. package/dist/lib/schemas/index.d.ts +2 -2
  19. package/dist/lib/test-framework/assertions.d.ts +18 -4
  20. package/dist/lib/test-framework/index.cjs +18634 -115
  21. package/dist/lib/test-framework/index.d.ts +2 -0
  22. package/dist/lib/test-framework/index.js +18651 -104
  23. package/dist/lib/test-framework/mock-origins.d.ts +56 -0
  24. package/dist/lib/test-framework/suite-runner.d.ts +16 -0
  25. package/dist/lib/test-framework/types.d.ts +1 -5
  26. package/dist/server.js +33 -33
  27. package/docs/API.md +48 -54
  28. package/docs/DEBUGGER.md +7 -8
  29. package/docs/INDEX.md +4 -1
  30. package/docs/RUNNER.md +126 -74
  31. package/docs/TEST_CONFIG.md +79 -40
  32. package/docs/TEST_FRAMEWORK.md +235 -36
  33. package/docs/WEBSOCKET.md +25 -21
  34. package/docs/quickstart.md +1 -13
  35. package/package.json +4 -1
  36. package/schemas/api-config.schema.json +5 -24
  37. package/schemas/api-load.schema.json +5 -0
  38. package/schemas/api-send.schema.json +0 -20
  39. package/schemas/fastedge-config.test.schema.json +5 -24
  40. package/schemas/full-flow-result.schema.json +17 -7
  41. package/schemas/hook-call.schema.json +16 -6
  42. package/schemas/hook-result.schema.json +16 -6
  43. 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;
@@ -36,6 +36,22 @@ export declare function runFlow(runner: IWasmRunner, options: FlowOptions): Prom
36
36
  * - method defaults to "GET"
37
37
  * - headers defaults to {}
38
38
  * - body defaults to ""
39
+ *
40
+ * Redirects are surfaced verbatim — a 302 from the WASM is returned to the
41
+ * caller with its `Location` header preserved, matching FastEdge edge
42
+ * behaviour.
43
+ *
44
+ * `runHttpRequest` targets the WASM app under test only (`options.path` is a
45
+ * path on the local `fastedge-run` server, not a full URL). Following a
46
+ * redirect therefore depends on the shape of `response.headers.location`:
47
+ *
48
+ * - Relative (e.g. `/auth/complete`) — pass it directly as `path` in a second
49
+ * `runHttpRequest` call.
50
+ * - Absolute with the app's own host — parse with `new URL(...)`, then
51
+ * re-issue against `url.pathname + url.search`.
52
+ * - Absolute with an external host — cannot be followed through the runner;
53
+ * that redirect is the end of the test, assert on status + Location and
54
+ * stop there.
39
55
  */
40
56
  export declare function runHttpRequest(runner: IWasmRunner, options: HttpRequestOptions): Promise<HttpResponse>;
41
57
  /**
@@ -56,7 +56,7 @@ export interface HttpRequestOptions {
56
56
  body?: string;
57
57
  }
58
58
  /**
59
- * Options for runFlow() — object-based alternative to the 10-arg callFullFlow().
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;