@encore.dev/sdk 2.0.0-beta.15 → 2.0.0-beta.17

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 (235) hide show
  1. package/README.md +111 -101
  2. package/app_meta.ts +56 -54
  3. package/config/config.ts +60 -57
  4. package/config/secrets.ts +45 -52
  5. package/config/value.ts +23 -26
  6. package/cron/mod.ts +28 -29
  7. package/dist/app_meta.d.ts +52 -50
  8. package/dist/app_meta.d.ts.map +1 -1
  9. package/dist/app_meta.js +2 -2
  10. package/dist/app_meta.js.map +1 -1
  11. package/dist/config/config.d.ts +58 -55
  12. package/dist/config/config.d.ts.map +1 -1
  13. package/dist/config/config.js +8 -9
  14. package/dist/config/config.js.map +1 -1
  15. package/dist/config/secrets.d.ts +45 -52
  16. package/dist/config/secrets.d.ts.map +1 -1
  17. package/dist/config/secrets.js +8 -9
  18. package/dist/config/secrets.js.map +1 -1
  19. package/dist/config/value.d.ts +20 -23
  20. package/dist/config/value.d.ts.map +1 -1
  21. package/dist/config/value.js +20 -23
  22. package/dist/config/value.js.map +1 -1
  23. package/dist/cron/mod.d.ts +26 -27
  24. package/dist/cron/mod.d.ts.map +1 -1
  25. package/dist/cron/mod.js +13 -14
  26. package/dist/cron/mod.js.map +1 -1
  27. package/dist/frontends/mod.d.ts +20 -19
  28. package/dist/frontends/mod.d.ts.map +1 -1
  29. package/dist/frontends/mod.js +20 -19
  30. package/dist/frontends/mod.js.map +1 -1
  31. package/dist/gateway/errors.d.ts +28 -30
  32. package/dist/gateway/errors.d.ts.map +1 -1
  33. package/dist/gateway/errors.js +29 -31
  34. package/dist/gateway/errors.js.map +1 -1
  35. package/dist/gateway/match.d.ts +54 -54
  36. package/dist/gateway/match.d.ts.map +1 -1
  37. package/dist/gateway/match.js +56 -56
  38. package/dist/gateway/match.js.map +1 -1
  39. package/dist/gateway/middleware.d.ts +62 -64
  40. package/dist/gateway/middleware.d.ts.map +1 -1
  41. package/dist/gateway/middleware.js +1 -1
  42. package/dist/gateway/middleware.js.map +1 -1
  43. package/dist/gateway/mod.d.ts +64 -67
  44. package/dist/gateway/mod.d.ts.map +1 -1
  45. package/dist/gateway/mod.js +72 -76
  46. package/dist/gateway/mod.js.map +1 -1
  47. package/dist/gateway/request.d.ts +138 -134
  48. package/dist/gateway/request.d.ts.map +1 -1
  49. package/dist/gateway/request.js +117 -108
  50. package/dist/gateway/request.js.map +1 -1
  51. package/dist/gateway/serve.d.ts +29 -34
  52. package/dist/gateway/serve.d.ts.map +1 -1
  53. package/dist/gateway/serve.js +51 -56
  54. package/dist/gateway/serve.js.map +1 -1
  55. package/dist/gateways/mod.d.ts +23 -21
  56. package/dist/gateways/mod.d.ts.map +1 -1
  57. package/dist/gateways/mod.js +25 -23
  58. package/dist/gateways/mod.js.map +1 -1
  59. package/dist/internal/runtime/napi/napi.cjs +1 -1
  60. package/dist/internal/runtime/napi/napi.d.cts +10 -3
  61. package/dist/internal/runtime/shutdown.d.ts +75 -57
  62. package/dist/internal/runtime/shutdown.d.ts.map +1 -1
  63. package/dist/internal/runtime/shutdown.js +88 -84
  64. package/dist/internal/runtime/shutdown.js.map +1 -1
  65. package/dist/log/logger.d.ts +43 -37
  66. package/dist/log/logger.d.ts.map +1 -1
  67. package/dist/log/logger.js +26 -25
  68. package/dist/log/logger.js.map +1 -1
  69. package/dist/metrics/mod.d.ts +133 -114
  70. package/dist/metrics/mod.d.ts.map +1 -1
  71. package/dist/metrics/mod.js +109 -101
  72. package/dist/metrics/mod.js.map +1 -1
  73. package/dist/otel.d.ts +6 -3
  74. package/dist/otel.d.ts.map +1 -1
  75. package/dist/otel.js +6 -3
  76. package/dist/otel.js.map +1 -1
  77. package/dist/pubsub/subscription.d.ts +88 -116
  78. package/dist/pubsub/subscription.d.ts.map +1 -1
  79. package/dist/pubsub/subscription.js +14 -17
  80. package/dist/pubsub/subscription.js.map +1 -1
  81. package/dist/pubsub/topic.d.ts +86 -113
  82. package/dist/pubsub/topic.d.ts.map +1 -1
  83. package/dist/pubsub/topic.js +68 -82
  84. package/dist/pubsub/topic.js.map +1 -1
  85. package/dist/reqctx/mod.d.ts +83 -86
  86. package/dist/reqctx/mod.d.ts.map +1 -1
  87. package/dist/reqctx/mod.js +39 -41
  88. package/dist/reqctx/mod.js.map +1 -1
  89. package/dist/services/index.d.ts +76 -75
  90. package/dist/services/index.d.ts.map +1 -1
  91. package/dist/services/index.js +73 -71
  92. package/dist/services/index.js.map +1 -1
  93. package/dist/shutdown/mod.d.ts +26 -25
  94. package/dist/shutdown/mod.d.ts.map +1 -1
  95. package/dist/shutdown/mod.js +26 -25
  96. package/dist/shutdown/mod.js.map +1 -1
  97. package/dist/storage/clickhouse/database.d.ts +113 -115
  98. package/dist/storage/clickhouse/database.d.ts.map +1 -1
  99. package/dist/storage/clickhouse/database.js +65 -79
  100. package/dist/storage/clickhouse/database.js.map +1 -1
  101. package/dist/storage/clickhouse/errors.d.ts +25 -26
  102. package/dist/storage/clickhouse/errors.d.ts.map +1 -1
  103. package/dist/storage/clickhouse/errors.js +15 -17
  104. package/dist/storage/clickhouse/errors.js.map +1 -1
  105. package/dist/storage/clickhouse/mod.d.ts +10 -10
  106. package/dist/storage/clickhouse/mod.js +10 -10
  107. package/dist/storage/objects/bucket.d.ts +196 -225
  108. package/dist/storage/objects/bucket.d.ts.map +1 -1
  109. package/dist/storage/objects/bucket.js +71 -84
  110. package/dist/storage/objects/bucket.js.map +1 -1
  111. package/dist/storage/objects/error.d.ts +4 -4
  112. package/dist/storage/objects/error.js +4 -4
  113. package/dist/storage/postgres/database.d.ts +124 -149
  114. package/dist/storage/postgres/database.d.ts.map +1 -1
  115. package/dist/storage/postgres/database.js +98 -135
  116. package/dist/storage/postgres/database.js.map +1 -1
  117. package/dist/storage/postgres/errors.d.ts +42 -48
  118. package/dist/storage/postgres/errors.d.ts.map +1 -1
  119. package/dist/storage/postgres/errors.js +44 -51
  120. package/dist/storage/postgres/errors.js.map +1 -1
  121. package/dist/storage/postgres/interval.d.ts +19 -19
  122. package/dist/storage/postgres/interval.d.ts.map +1 -1
  123. package/dist/storage/postgres/interval.js +21 -21
  124. package/dist/storage/postgres/interval.js.map +1 -1
  125. package/dist/storage/redis/bitfield.d.ts +48 -23
  126. package/dist/storage/redis/bitfield.d.ts.map +1 -1
  127. package/dist/storage/redis/bitfield.js +38 -19
  128. package/dist/storage/redis/bitfield.js.map +1 -1
  129. package/dist/storage/redis/command.d.ts +16 -12
  130. package/dist/storage/redis/command.d.ts.map +1 -1
  131. package/dist/storage/redis/command.js +16 -12
  132. package/dist/storage/redis/command.js.map +1 -1
  133. package/dist/storage/redis/commands.d.ts +99 -100
  134. package/dist/storage/redis/commands.d.ts.map +1 -1
  135. package/dist/storage/redis/commands.js +84 -85
  136. package/dist/storage/redis/commands.js.map +1 -1
  137. package/dist/storage/redis/database.d.ts +138 -122
  138. package/dist/storage/redis/database.d.ts.map +1 -1
  139. package/dist/storage/redis/database.js +120 -101
  140. package/dist/storage/redis/database.js.map +1 -1
  141. package/dist/storage/redis/mod.d.ts +52 -48
  142. package/dist/storage/redis/mod.d.ts.map +1 -1
  143. package/dist/storage/redis/mod.js +52 -48
  144. package/dist/storage/redis/mod.js.map +1 -1
  145. package/dist/storage/redis/options.d.ts +26 -24
  146. package/dist/storage/redis/options.d.ts.map +1 -1
  147. package/dist/storage/redis/options.js.map +1 -1
  148. package/dist/storage/redis/pubsub.d.ts +16 -16
  149. package/dist/storage/redis/pubsub.d.ts.map +1 -1
  150. package/dist/storage/redis/pubsub.js +14 -14
  151. package/dist/storage/redis/pubsub.js.map +1 -1
  152. package/dist/storage/redis/reply.d.ts +80 -72
  153. package/dist/storage/redis/reply.d.ts.map +1 -1
  154. package/dist/storage/redis/reply.js +53 -46
  155. package/dist/storage/redis/reply.js.map +1 -1
  156. package/dist/storage/redis/scan.d.ts +4 -4
  157. package/dist/storage/redis/scan.d.ts.map +1 -1
  158. package/dist/storage/redis/scan.js +6 -6
  159. package/dist/storage/redis/scan.js.map +1 -1
  160. package/dist/storage/redis/script.d.ts +28 -21
  161. package/dist/storage/redis/script.d.ts.map +1 -1
  162. package/dist/storage/redis/script.js +29 -22
  163. package/dist/storage/redis/script.js.map +1 -1
  164. package/dist/storage/redis/target.d.ts +17 -1
  165. package/dist/storage/redis/target.d.ts.map +1 -1
  166. package/dist/storage/redis/target.js +30 -1
  167. package/dist/storage/redis/target.js.map +1 -1
  168. package/dist/storage/redis/wire.d.ts +6 -6
  169. package/dist/storage/redis/wire.d.ts.map +1 -1
  170. package/dist/storage/redis/wire.js +6 -6
  171. package/dist/storage/redis/wire.js.map +1 -1
  172. package/dist/testing/mod.d.ts +83 -88
  173. package/dist/testing/mod.d.ts.map +1 -1
  174. package/dist/testing/mod.js +75 -81
  175. package/dist/testing/mod.js.map +1 -1
  176. package/dist/testing/playwright.d.ts +28 -32
  177. package/dist/testing/playwright.d.ts.map +1 -1
  178. package/dist/testing/playwright.js +22 -27
  179. package/dist/testing/playwright.js.map +1 -1
  180. package/dist/testing/puppeteer.d.ts +11 -12
  181. package/dist/testing/puppeteer.d.ts.map +1 -1
  182. package/dist/testing/puppeteer.js +17 -18
  183. package/dist/testing/puppeteer.js.map +1 -1
  184. package/dist/testing/system.d.ts +72 -90
  185. package/dist/testing/system.d.ts.map +1 -1
  186. package/dist/testing/system.js +90 -107
  187. package/dist/testing/system.js.map +1 -1
  188. package/dist/tsconfig.build.tsbuildinfo +1 -1
  189. package/frontends/mod.test.ts +6 -2
  190. package/frontends/mod.ts +20 -19
  191. package/gateway/errors.ts +30 -32
  192. package/gateway/match.ts +61 -57
  193. package/gateway/middleware.ts +62 -64
  194. package/gateway/mod.ts +73 -76
  195. package/gateway/request.ts +143 -140
  196. package/gateway/serve.ts +58 -63
  197. package/gateways/mod.ts +25 -23
  198. package/internal/runtime/napi/napi.cjs +1 -1
  199. package/internal/runtime/napi/napi.d.cts +10 -3
  200. package/internal/runtime/shutdown.ts +113 -101
  201. package/log/logger.test.ts +8 -0
  202. package/log/logger.ts +48 -45
  203. package/metrics/mod.ts +138 -122
  204. package/otel.ts +6 -3
  205. package/package.json +1 -1
  206. package/pubsub/subscription.ts +93 -123
  207. package/pubsub/topic.ts +96 -130
  208. package/reqctx/mod.ts +83 -86
  209. package/services/index.ts +78 -78
  210. package/shutdown/mod.ts +26 -25
  211. package/storage/clickhouse/database.ts +115 -129
  212. package/storage/clickhouse/errors.ts +27 -29
  213. package/storage/clickhouse/mod.ts +10 -10
  214. package/storage/objects/bucket.ts +209 -239
  215. package/storage/objects/error.ts +4 -4
  216. package/storage/postgres/database.ts +131 -164
  217. package/storage/postgres/errors.ts +45 -52
  218. package/storage/postgres/interval.ts +21 -21
  219. package/storage/redis/bitfield.ts +51 -26
  220. package/storage/redis/command.ts +16 -12
  221. package/storage/redis/commands.ts +99 -100
  222. package/storage/redis/database.ts +145 -123
  223. package/storage/redis/mod.ts +52 -48
  224. package/storage/redis/options.ts +26 -24
  225. package/storage/redis/pubsub.ts +14 -14
  226. package/storage/redis/redis.test.ts +17 -2
  227. package/storage/redis/reply.ts +85 -77
  228. package/storage/redis/scan.ts +6 -6
  229. package/storage/redis/script.ts +29 -22
  230. package/storage/redis/target.ts +34 -1
  231. package/storage/redis/wire.ts +8 -8
  232. package/testing/mod.ts +99 -105
  233. package/testing/playwright.ts +32 -37
  234. package/testing/puppeteer.ts +22 -23
  235. package/testing/system.ts +117 -133
@@ -1,22 +1,22 @@
1
1
  /**
2
- * A system test's browser, driven with Puppeteer.
2
+ * Puppeteer adapter for driving Encore's managed system-test browser.
3
3
  *
4
- * {@link connect} connects Puppeteer to the browser Encore runs for the
5
- * current test (see `system.browser` in `@encore.dev/sdk/testing`): a page
6
- * reaches the app where `encore run` has it, in the test session; its
7
- * requests are the test's; and what it shows is recorded.
4
+ * {@link connect} attaches Puppeteer to the Chromium instance Encore starts
5
+ * for the current test (see `system.browser` in `@encore.dev/sdk/testing`).
6
+ * Requests from pages route to the test session under your test's isolated
7
+ * data, and page sessions are recorded.
8
8
  *
9
- * Each call the test makes on a page is reported as it is written, with
10
- * where it is, so that the recording and the test's telemetry say which
11
- * statement had the browser do what, and which requests came of it:
9
+ * Every page call is automatically tracked with its call site so test
10
+ * telemetry and recordings link each test statement to the browser actions and
11
+ * backend requests it triggered:
12
12
  *
13
13
  * page.locator("#pay").click() checkout.test.ts:14
14
14
  * click button "Pay"
15
15
  * POST http://localhost:4000/orders 500
16
16
  * POST orders /orders 500
17
17
  *
18
- * Puppeteer is the test's own, passed in: `puppeteer` or `puppeteer-core`.
19
- * Neither downloads a browser for this, as Encore runs its own.
18
+ * Pass your own `puppeteer` or `puppeteer-core` module; no separate browser
19
+ * download is needed because Encore manages Chromium.
20
20
  *
21
21
  * @example
22
22
  * import puppeteer from "puppeteer-core";
@@ -37,7 +37,7 @@
37
37
  import {Steps, wrap} from '../internal/testing/steps';
38
38
  import {browser as testBrowser, type BrowserOptions} from './system';
39
39
 
40
- /** Puppeteer, as much of it as {@link connect} uses. */
40
+ /** Minimal subset of Puppeteer required by {@link connect}. */
41
41
  export interface Puppeteer<B> {
42
42
  connect(options: {
43
43
  browserWSEndpoint: string;
@@ -46,16 +46,16 @@ export interface Puppeteer<B> {
46
46
  }): Promise<B>;
47
47
  }
48
48
 
49
- /** The options of {@link connect}. */
49
+ /** Options for {@link connect}. */
50
50
  export interface ConnectOptions extends BrowserOptions {
51
51
  /**
52
- * More of Puppeteer's own options for `connect`, such as `slowMo` and
53
- * `protocolTimeout`.
52
+ * Additional Puppeteer options passed to `puppeteer.connect` (such as
53
+ * `slowMo` or `protocolTimeout`).
54
54
  */
55
55
  connect?: Record<string, unknown>;
56
56
  }
57
57
 
58
- /** What {@link connect} uses of a Puppeteer browser. */
58
+ /** Minimal subset of a connected Puppeteer browser used internally. */
59
59
  interface Connected {
60
60
  target(): {
61
61
  createCDPSession(): Promise<{
@@ -65,12 +65,12 @@ interface Connected {
65
65
  }
66
66
 
67
67
  /**
68
- * Connects `puppeteer` to the current test's browser, starting it if the
69
- * test has none yet, and returns Puppeteer's `Browser`. The browser ends
70
- * with the test: there is nothing to close.
68
+ * Connects `puppeteer` to the current test's Encore browser (starting it if
69
+ * needed) and returns the Puppeteer `Browser`. The browser is automatically
70
+ * closed when the test ends.
71
71
  *
72
- * Its pages' viewport is the browser's window (`options.window`), unless
73
- * `options.connect.defaultViewport` says otherwise.
72
+ * Page viewports match `options.window` (defaulting to 1280×800) unless
73
+ * overridden via `options.connect.defaultViewport`.
74
74
  */
75
75
  export async function connect<B>(
76
76
  puppeteer: Puppeteer<B>,
@@ -92,9 +92,8 @@ export async function connect<B>(
92
92
  }
93
93
 
94
94
  /**
95
- * The URL a page of the current test's browser reaches the gateway or
96
- * frontend `name` at: the one `encore run` has it at, which the frontend is
97
- * written against.
95
+ * Returns the URL a page in the current test's browser uses to reach gateway
96
+ * or frontend `name` (matching the local `encore run` origin).
98
97
  */
99
98
  export async function url(name: string): Promise<string> {
100
99
  return (await testBrowser()).url(name);
package/testing/system.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
- * System tests: tests of the whole app, which run as no service.
2
+ * System tests: end-to-end tests that run against the full Encore application
3
+ * rather than inside a single service.
3
4
  *
4
- * A test in a service runs as that service, alone: a call to another service
5
- * is not answered, and what it publishes nothing handles. A test in a system
6
- * test suite — a directory with an `encore.systest.json` — runs against the
7
- * app instead, in its test session: each service starts when something first
8
- * reaches it, as under `encore run`, with the secrets and configs configured
9
- * for tests and data that is the session's own.
5
+ * While a service test runs in isolation (calls to other services are not
6
+ * routed and Pub/Sub messages are not delivered automatically), tests in a
7
+ * system test suite — a directory containing `encore.systest.json` — run
8
+ * against a live test session of the app. Services start lazily on first use
9
+ * with your test secrets, test configs, and session-scoped infrastructure:
10
10
  *
11
11
  * ```ts
12
12
  * import {client} from "@encore.dev/sdk/services";
@@ -22,7 +22,7 @@
22
22
  * body: JSON.stringify({sku: "tee", qty: 2}),
23
23
  * });
24
24
  * const order = await res.json();
25
- * // The order's event has been handled by billing's subscription.
25
+ * // Wait for billing's subscription to process the order event.
26
26
  * await system.settled();
27
27
  *
28
28
  * const row = await billing.queryRow`
@@ -31,39 +31,38 @@
31
31
  * });
32
32
  * ```
33
33
  *
34
- * A system test may use any resource the app declares, bound with `named` or
35
- * through a service's own declaration, and call any service.
34
+ * System tests can call any service and access any resource in the app (via
35
+ * `*.named(...)` or by importing a service's declaration).
36
36
  *
37
- * Each test has data of its own: an instance of every database, Redis
38
- * database and bucket, which starts as a service's test's does, the
39
- * databases migrated and the rest empty. What the services do for the test
40
- * they do on that data, whichever of them it is, so a test reads what they
41
- * wrote for it and nothing of another test's, and tests run side by side.
37
+ * ## Data isolation and fixtures
42
38
  *
43
- * A test can start from a `fixture` instead, as a service's test can. Its
44
- * setup calls the app, and what the services made of that, in every
45
- * database, bucket and Redis database, once what the setup set in motion
46
- * has finished, is what each test that loads the fixture gets a copy of.
39
+ * By default, each test gets its own isolated copy of every database (with
40
+ * migrations applied), Redis database, and object bucket. Any work services
41
+ * perform on behalf of the test operates on that test's data, allowing tests to
42
+ * run in parallel without interfering with one another.
47
43
  *
48
- * What the app does for no request, as a Worker's loop or a job that finds
49
- * its work in a table, is done on the data the services share, which a test
50
- * does not see. A suite that tests such work says `"data": "shared"` in its
51
- * `encore.systest.json`: its tests then share that data too, and each
52
- * other's.
44
+ * You can also start tests from a `fixture`: its setup calls the app, waits for
45
+ * resulting work to finish, and snapshots all databases, buckets, and Redis
46
+ * databases so every test loading the fixture gets its own copy.
53
47
  *
54
- * What a test publishes is sent, and each subscription handles it in the
55
- * service that declares it. {@link settled} waits for that: there is nothing
56
- * to `deliver`.
48
+ * Background work not tied to a request (such as a worker polling loop) runs
49
+ * against the session's shared data. To test that work, set `"data": "shared"`
50
+ * in `encore.systest.json` so tests share that data as well.
57
51
  *
58
- * Each test has an id, which travels with every call and message it makes,
59
- * and with what those cause in turn, so that what the app did for the test
60
- * can be told from the rest. A test that fails prints what it caused in the
61
- * app under its failure, where its runner says how it ended: under vitest
62
- * and `node --test`, and in any runner for a test wrapped in `scoped`.
52
+ * ## Pub/Sub and telemetry
63
53
  *
64
- * The suite needs the runner adapter for its test runner, as a service's
65
- * tests do (such as `@encore.dev/sdk/testing/vitest`). Run the tests with
66
- * `encore test`, or with the runner itself in the suite's directory.
54
+ * Messages published during a system test are delivered to real subscriptions
55
+ * in their declaring services. Wait for asynchronous work to finish with
56
+ * {@link settled} instead of calling `deliver()`.
57
+ *
58
+ * Each test has an ID propagated across all requests and Pub/Sub messages it
59
+ * triggers. On failure, Encore prints the trace tree of what the test caused
60
+ * in the app (supported automatically in Vitest and `node --test`, and in any
61
+ * runner when wrapped with `scoped`).
62
+ *
63
+ * Configure your test runner adapter (e.g. `@encore.dev/sdk/testing/vitest`)
64
+ * and run tests with `encore test` or directly with your runner inside the
65
+ * suite directory.
67
66
  *
68
67
  * @module
69
68
  */
@@ -91,7 +90,7 @@ export type {
91
90
  What,
92
91
  } from '../internal/testing/telemetry';
93
92
 
94
- /** The test session the process's tests run against. */
93
+ /** Returns the active system test session or throws if not in a system test. */
95
94
  function session(): NonNullable<typeof systemTest> {
96
95
  if (systemTest === null) {
97
96
  throw new Error(
@@ -102,38 +101,33 @@ function session(): NonNullable<typeof systemTest> {
102
101
  return systemTest;
103
102
  }
104
103
 
105
- /** The current test, of a system test's process. */
104
+ /** Returns the active test scope within a system test process. */
106
105
  function current(): Scope {
107
106
  session();
108
107
  return requireScope();
109
108
  }
110
109
 
111
- /** The options of {@link settled}. */
110
+ /** Options for {@link settled}. */
112
111
  export interface SettledOptions {
113
- /** How long to wait at most, in milliseconds: 30 seconds when not given. */
112
+ /** Maximum wait time in milliseconds. Defaults to 30,000 ms (30 seconds). */
114
113
  timeout?: number;
115
114
  }
116
115
 
117
116
  /**
118
- * Waits until nothing the test set in motion is still running or queued: no
119
- * request in flight to a service or through a gateway, and no message
120
- * waiting, being handled or due a retry on a subscription. For at most 30
121
- * seconds, or `options.timeout`: it rejects when the app has not settled by
122
- * then, with an error saying what was still under way.
123
- *
124
- * It is the current test's work that is waited for, which is told by the
125
- * test's id travelling with it, and nothing else: not what another test set
126
- * in motion, so tests running side by side do not wait for each other, and
127
- * not what the app does for no test. The work of a service that did not
128
- * pass its request's context on has lost the test's id: it is not waited
129
- * for, and is done on data the test does not see. The test's telemetry says
130
- * which call lost it.
117
+ * Waits until all asynchronous work triggered by the current test has finished
118
+ * — no requests are in flight to services or gateways, and no Pub/Sub messages
119
+ * are queued, in progress, or awaiting retry. Rejects after 30 seconds (or
120
+ * `options.timeout`) with details of what is still pending.
131
121
  *
132
- * In a suite whose tests share the session's data (`"data": "shared"`),
133
- * everything the app has under way is waited for instead.
122
+ * Only work tagged with the current test's propagated ID is tracked, so
123
+ * parallel tests do not block one another and unrelated background activity is
124
+ * ignored. If a service fails to propagate request context on an outgoing call,
125
+ * that work loses the test ID, runs outside the test's isolated data, and is
126
+ * flagged in {@link telemetry}.
134
127
  *
135
- * What a service does that is neither — work that goes on after its request
136
- * was answered — is not waited for.
128
+ * In suites configured with `"data": "shared"`, `settled()` waits for all
129
+ * in-flight work across the app. Fire-and-forget work that continues after a
130
+ * handler has already responded is not tracked.
137
131
  *
138
132
  * @example
139
133
  * await orders.fetch("/orders", {method: "POST", body}); // publishes `order-placed`
@@ -144,14 +138,13 @@ export async function settled(options?: SettledOptions): Promise<void> {
144
138
  }
145
139
 
146
140
  /**
147
- * The URL of the gateway or frontend `name` in the test session, for a
148
- * client of the test's own, such as a WebSocket client. A frontend starts
149
- * when something first connects to it.
141
+ * Returns the URL of gateway or frontend `name` in the current test session,
142
+ * for use with custom clients (such as WebSockets). Frontends start lazily on
143
+ * first connection.
150
144
  *
151
- * A request made with the SDK's clients, or the suite's generated ones,
152
- * carries the test already: a generated Gateway Client made with no options
153
- * calls the gateway here, for the test making the request. One made with
154
- * another client carries the test with {@link headers}.
145
+ * Encore SDK clients and generated gateway clients automatically attach the
146
+ * current test context. For custom HTTP clients, pass {@link headers} on each
147
+ * request.
155
148
  *
156
149
  * @example
157
150
  * import {Client} from "./encore_gen/gateway/api";
@@ -163,17 +156,17 @@ export function url(name: string): string {
163
156
  if (found === null) {
164
157
  const known = system.gateways();
165
158
  throw new Error(
166
- `the app has no gateway or frontend ${JSON.stringify(name)} ` +
167
- `(its gateways: ${known.length === 0 ? 'none' : known.join(', ')})`,
159
+ `unknown gateway or frontend ${JSON.stringify(name)} ` +
160
+ `(available: ${known.length === 0 ? 'none' : known.join(', ')})`,
168
161
  );
169
162
  }
170
163
  return found;
171
164
  }
172
165
 
173
166
  /**
174
- * The headers that make a request part of the current test, for a client of
175
- * the test's own: the test's id, as the Request Context field Encore carries
176
- * it in, and the test's span for the request to continue. By lowercase name.
167
+ * Returns lowercase HTTP headers that bind a custom client's request to the
168
+ * current test (carrying the test ID Request Context field and active trace
169
+ * span).
177
170
  *
178
171
  * @example
179
172
  * const res = await fetch(`${system.url("api")}/health`, {
@@ -184,30 +177,27 @@ export function headers(): Record<string, string> {
184
177
  return {...current().carried?.headers};
185
178
  }
186
179
 
187
- /** The options of {@link telemetry}. */
180
+ /** Options for {@link telemetry}. */
188
181
  export interface TelemetryOptions {
189
182
  /**
190
- * Whether to wait for the app to settle first, as {@link settled} does,
191
- * which is when all of what the test caused is recorded. `false` reads
192
- * what has been recorded by now. Defaults to `true`.
183
+ * Wait for the app to settle (as in {@link settled}) before reading recorded
184
+ * telemetry so all triggered work is captured. Set to `false` to read a
185
+ * snapshot immediately. Defaults to `true`.
193
186
  */
194
187
  settle?: boolean;
195
- /** How long to wait for the app to settle at most, in milliseconds: 30
196
- * seconds when not given. */
188
+ /** Maximum time to wait for settling, in milliseconds. Defaults to 30,000 ms. */
197
189
  timeout?: number;
198
190
  }
199
191
 
200
192
  /**
201
- * What the app recorded for the current test, once it has {@link settled}:
202
- * every span of what the test caused — in the services it reached, in the
203
- * requests between them, in the deliveries of what was published for it —
204
- * and the lines logged in them.
193
+ * Returns all telemetry recorded by the app for the current test (waiting for
194
+ * {@link settled} by default): every span triggered across services,
195
+ * inter-service requests, and Pub/Sub deliveries, along with their logs.
205
196
  *
206
- * Each span says what it is of ({@link Span.what}): a request a service was
207
- * handed, a query, a message published or delivered, for a test to assert
208
- * on. As a string it is the tree of it a failed test prints, and
209
- * {@link Telemetry.shape} the same without what differs between runs, to
210
- * keep as a snapshot of which services a flow touches.
197
+ * Inspect typed span details via {@link Span.what} (requests, queries,
198
+ * publishes, deliveries). Converting the result to a string renders the same
199
+ * trace tree printed on test failure, and {@link Telemetry.shape} strips
200
+ * run-specific values for snapshot testing.
211
201
  *
212
202
  * @example
213
203
  * const recorded = await system.telemetry();
@@ -225,48 +215,47 @@ export async function telemetry(
225
215
  return Telemetry.parse(json);
226
216
  }
227
217
 
228
- /** The options of {@link browser}. */
218
+ /** Options for {@link browser}. */
229
219
  export interface BrowserOptions {
230
220
  /**
231
- * When what the browser recorded is kept: for a test that `'failed'`, or
232
- * whose runner does not say how it ended; for `'all'` tests; or `'off'`.
233
- * Defaults to what `ENCORE_TEST_RECORD` says, else `'failed'`.
221
+ * Controls when browser recordings are saved: `'failed'` (failed tests or
222
+ * runners that do not report outcomes), `'all'`, or `'off'`. Defaults to
223
+ * `ENCORE_TEST_RECORD` if set, otherwise `'failed'`.
234
224
  */
235
225
  record?: 'failed' | 'all' | 'off';
236
- /** More command-line arguments for the browser. */
226
+ /** Additional command-line flags passed to Chromium. */
237
227
  args?: string[];
238
- /** The size of the browser's window, in CSS pixels: 1280×800 by default. */
228
+ /** Browser viewport/window size in CSS pixels. Defaults to 1280×800. */
239
229
  window?: {width: number; height: number};
240
230
  }
241
231
 
242
- /** The current test's browser: see {@link browser}. */
232
+ /** Handle to the current test's managed Chromium instance (see {@link browser}). */
243
233
  export interface Browser {
244
234
  /**
245
- * What a DevTools Protocol client connects to: the address of a WebSocket,
246
- * as a browser gives for itself. Puppeteer's `connect`, Playwright's
247
- * `connectOverCDP`.
235
+ * Chrome DevTools Protocol WebSocket endpoint for connecting tools such as
236
+ * Puppeteer (`connect`) or Playwright (`connectOverCDP`).
248
237
  */
249
238
  readonly wsEndpoint: string;
250
239
  /**
251
- * The file the recording is written to when the test ends, if it is kept:
252
- * one HTML file that plays the pages back beside what the test and the app
253
- * did. `null` when nothing is recorded.
240
+ * Path to the self-contained HTML recording file written when the test ends,
241
+ * replaying page frames alongside test steps and backend telemetry, or `null`
242
+ * if recording is disabled.
254
243
  */
255
244
  readonly recording: string | null;
256
245
  /**
257
- * The URL a page reaches the gateway or frontend `name` at: the one
258
- * `encore run` has it at, which the frontend is written against. The
259
- * browser's requests there go to the test session.
246
+ * Returns the URL a browser page uses to reach gateway or frontend `name`
247
+ * (matching the local `encore run` origin, transparently routed to the test
248
+ * session).
260
249
  */
261
250
  url(name: string): string;
262
251
  /**
263
- * Runs `fn` as one statement of the test, called `name`: what `fn` has the
264
- * browser do, and the requests that come of it, are recorded under it, in
265
- * the test's telemetry and in its recording, with where `step` was called.
266
- * It resolves to what `fn` returns, and a `fn` that throws fails the step.
252
+ * Groups the actions and network requests inside `fn` under a named step in
253
+ * test telemetry and browser recordings (including the call site). Returns
254
+ * the result of `fn`, marking the step failed if `fn` throws.
267
255
  *
268
- * An adapter reports each call a test makes on its tool by itself: this is
269
- * for a tool that has none, and for naming several calls as one.
256
+ * Browser adapters (`@encore.dev/sdk/testing/playwright` and `puppeteer`)
257
+ * record individual page calls automatically; use `step` for custom CDP tools
258
+ * or to group multiple calls under a higher-level label.
270
259
  *
271
260
  * @example
272
261
  * await browser.step("pay with a saved card", async () => {
@@ -278,32 +267,24 @@ export interface Browser {
278
267
  }
279
268
 
280
269
  /**
281
- * The current test's browser: a headless Chromium Encore runs for the test,
282
- * for a tool of the test's own to drive. It is started the first time the
283
- * test asks, and ends with the test.
284
- *
285
- * It is the test's in every way a call the test makes is:
286
- *
287
- * - It reaches the app where `encore run` has it. A frontend says itself
288
- * where its API is, as `http://localhost:4000`: a page's requests there,
289
- * and to the frontends' own addresses, go to the test session.
290
- * - Each request a page makes to the app carries the test, so what the app
291
- * does for a click is done on the test's data, and {@link settled} waits
292
- * for it.
293
- * - What the test has the browser do, and each request a page makes, is in
294
- * the test's {@link telemetry}, with what the app did for a request
295
- * under it. So is what a page says went wrong: an error on its console,
296
- * an exception nothing caught, a request that failed.
297
- * - Its pages are recorded. A test that fails is left a file that plays
298
- * them back beside all of that ({@link Browser.recording}).
270
+ * Starts (or returns) a headless Chromium instance managed by Encore for the
271
+ * current system test, automatically closed when the test ends.
299
272
  *
300
- * The adapters connect a tool to it and say which statement of the test
301
- * is running: `@encore.dev/sdk/testing/puppeteer`,
302
- * `@encore.dev/sdk/testing/playwright`. This is for any other tool that
303
- * speaks the DevTools Protocol.
273
+ * The managed browser integrates directly with the test session:
274
+ * - Pages reach frontends and APIs at their usual `encore run` URLs (such as
275
+ * `http://localhost:4000`), transparently routed to the test session.
276
+ * - Every app request from a page carries the test ID, so backend work uses the
277
+ * test's isolated data and is waited on by {@link settled}.
278
+ * - Browser actions, page requests, console errors, uncaught page exceptions,
279
+ * and failed requests are captured in {@link telemetry} alongside backend
280
+ * spans.
281
+ * - Page sessions are recorded to an HTML file on failure (see
282
+ * {@link Browser.recording}).
304
283
  *
305
- * The browser is the `browser/chromium` component, which Encore downloads
306
- * the first time a test asks for one.
284
+ * Prefer the Playwright (`@encore.dev/sdk/testing/playwright`) or Puppeteer
285
+ * (`@encore.dev/sdk/testing/puppeteer`) adapters when using those libraries;
286
+ * use this function directly for other Chrome DevTools Protocol clients.
287
+ * Encore downloads the `browser/chromium` component automatically on first use.
307
288
  *
308
289
  * @example
309
290
  * const {wsEndpoint, url} = await system.browser();
@@ -328,7 +309,8 @@ export async function browser(options?: BrowserOptions): Promise<Browser> {
328
309
  // endpoint is on: a test with a tool of its own has no hold on the tool's
329
310
  // connection. Each word is answered before the next thing is done.
330
311
  const steps = new Steps(async (method, params) => {
331
- if (info.stepsUrl === '') throw new Error('the session takes no steps');
312
+ if (info.stepsUrl === '')
313
+ throw new Error('the test session does not support browser steps');
332
314
  const response = await fetch(
333
315
  `${info.stepsUrl}/${method.replace('Encore.', '')}`,
334
316
  {
@@ -338,7 +320,9 @@ export async function browser(options?: BrowserOptions): Promise<Browser> {
338
320
  },
339
321
  );
340
322
  if (!response.ok)
341
- throw new Error(`the session answered ${response.status}`);
323
+ throw new Error(
324
+ `test session returned HTTP ${response.status} for browser step`,
325
+ );
342
326
  return response.json();
343
327
  });
344
328
  return {
@@ -363,8 +347,8 @@ export async function browser(options?: BrowserOptions): Promise<Browser> {
363
347
  if (found === undefined) {
364
348
  const known = Object.keys(info.urls).filter(n => n !== 'proxy');
365
349
  throw new Error(
366
- `the app has no gateway or frontend ${JSON.stringify(name)} ` +
367
- `(it has: ${known.length === 0 ? 'none' : known.sort().join(', ')})`,
350
+ `unknown gateway or frontend ${JSON.stringify(name)} ` +
351
+ `(available: ${known.length === 0 ? 'none' : known.sort().join(', ')})`,
368
352
  );
369
353
  }
370
354
  return found;