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

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,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
  */
@@ -71,7 +70,7 @@ import { requireScope, systemTest } from '../internal/testing/scope.js';
71
70
  import { caller, Steps } from '../internal/testing/steps.js';
72
71
  import { Telemetry } from '../internal/testing/telemetry.js';
73
72
  export { Telemetry } from '../internal/testing/telemetry.js';
74
- /** The test session the process's tests run against. */
73
+ /** Returns the active system test session or throws if not in a system test. */
75
74
  function session() {
76
75
  if (systemTest === null) {
77
76
  throw new Error('this is not a system test: only the tests of a system test suite, a directory ' +
@@ -79,31 +78,26 @@ function session() {
79
78
  }
80
79
  return systemTest;
81
80
  }
82
- /** The current test, of a system test's process. */
81
+ /** Returns the active test scope within a system test process. */
83
82
  function current() {
84
83
  session();
85
84
  return requireScope();
86
85
  }
87
86
  /**
88
- * Waits until nothing the test set in motion is still running or queued: no
89
- * request in flight to a service or through a gateway, and no message
90
- * waiting, being handled or due a retry on a subscription. For at most 30
91
- * seconds, or `options.timeout`: it rejects when the app has not settled by
92
- * then, with an error saying what was still under way.
93
- *
94
- * It is the current test's work that is waited for, which is told by the
95
- * test's id travelling with it, and nothing else: not what another test set
96
- * in motion, so tests running side by side do not wait for each other, and
97
- * not what the app does for no test. The work of a service that did not
98
- * pass its request's context on has lost the test's id: it is not waited
99
- * for, and is done on data the test does not see. The test's telemetry says
100
- * which call lost it.
101
- *
102
- * In a suite whose tests share the session's data (`"data": "shared"`),
103
- * everything the app has under way is waited for instead.
104
- *
105
- * What a service does that is neither — work that goes on after its request
106
- * was answered — is not waited for.
87
+ * Waits until all asynchronous work triggered by the current test has finished
88
+ * — no requests are in flight to services or gateways, and no Pub/Sub messages
89
+ * are queued, in progress, or awaiting retry. Rejects after 30 seconds (or
90
+ * `options.timeout`) with details of what is still pending.
91
+ *
92
+ * Only work tagged with the current test's propagated ID is tracked, so
93
+ * parallel tests do not block one another and unrelated background activity is
94
+ * ignored. If a service fails to propagate request context on an outgoing call,
95
+ * that work loses the test ID, runs outside the test's isolated data, and is
96
+ * flagged in {@link telemetry}.
97
+ *
98
+ * In suites configured with `"data": "shared"`, `settled()` waits for all
99
+ * in-flight work across the app. Fire-and-forget work that continues after a
100
+ * handler has already responded is not tracked.
107
101
  *
108
102
  * @example
109
103
  * await orders.fetch("/orders", {method: "POST", body}); // publishes `order-placed`
@@ -113,14 +107,13 @@ export async function settled(options) {
113
107
  await current().native.settled(options?.timeout ?? null);
114
108
  }
115
109
  /**
116
- * The URL of the gateway or frontend `name` in the test session, for a
117
- * client of the test's own, such as a WebSocket client. A frontend starts
118
- * when something first connects to it.
110
+ * Returns the URL of gateway or frontend `name` in the current test session,
111
+ * for use with custom clients (such as WebSockets). Frontends start lazily on
112
+ * first connection.
119
113
  *
120
- * A request made with the SDK's clients, or the suite's generated ones,
121
- * carries the test already: a generated Gateway Client made with no options
122
- * calls the gateway here, for the test making the request. One made with
123
- * another client carries the test with {@link headers}.
114
+ * Encore SDK clients and generated gateway clients automatically attach the
115
+ * current test context. For custom HTTP clients, pass {@link headers} on each
116
+ * request.
124
117
  *
125
118
  * @example
126
119
  * import {Client} from "./encore_gen/gateway/api";
@@ -131,15 +124,15 @@ export function url(name) {
131
124
  const found = system.url(name);
132
125
  if (found === null) {
133
126
  const known = system.gateways();
134
- throw new Error(`the app has no gateway or frontend ${JSON.stringify(name)} ` +
135
- `(its gateways: ${known.length === 0 ? 'none' : known.join(', ')})`);
127
+ throw new Error(`unknown gateway or frontend ${JSON.stringify(name)} ` +
128
+ `(available: ${known.length === 0 ? 'none' : known.join(', ')})`);
136
129
  }
137
130
  return found;
138
131
  }
139
132
  /**
140
- * The headers that make a request part of the current test, for a client of
141
- * the test's own: the test's id, as the Request Context field Encore carries
142
- * it in, and the test's span for the request to continue. By lowercase name.
133
+ * Returns lowercase HTTP headers that bind a custom client's request to the
134
+ * current test (carrying the test ID Request Context field and active trace
135
+ * span).
143
136
  *
144
137
  * @example
145
138
  * const res = await fetch(`${system.url("api")}/health`, {
@@ -150,16 +143,14 @@ export function headers() {
150
143
  return { ...current().carried?.headers };
151
144
  }
152
145
  /**
153
- * What the app recorded for the current test, once it has {@link settled}:
154
- * every span of what the test caused — in the services it reached, in the
155
- * requests between them, in the deliveries of what was published for it —
156
- * and the lines logged in them.
146
+ * Returns all telemetry recorded by the app for the current test (waiting for
147
+ * {@link settled} by default): every span triggered across services,
148
+ * inter-service requests, and Pub/Sub deliveries, along with their logs.
157
149
  *
158
- * Each span says what it is of ({@link Span.what}): a request a service was
159
- * handed, a query, a message published or delivered, for a test to assert
160
- * on. As a string it is the tree of it a failed test prints, and
161
- * {@link Telemetry.shape} the same without what differs between runs, to
162
- * keep as a snapshot of which services a flow touches.
150
+ * Inspect typed span details via {@link Span.what} (requests, queries,
151
+ * publishes, deliveries). Converting the result to a string renders the same
152
+ * trace tree printed on test failure, and {@link Telemetry.shape} strips
153
+ * run-specific values for snapshot testing.
163
154
  *
164
155
  * @example
165
156
  * const recorded = await system.telemetry();
@@ -172,32 +163,24 @@ export async function telemetry(options) {
172
163
  return Telemetry.parse(json);
173
164
  }
174
165
  /**
175
- * The current test's browser: a headless Chromium Encore runs for the test,
176
- * for a tool of the test's own to drive. It is started the first time the
177
- * test asks, and ends with the test.
178
- *
179
- * It is the test's in every way a call the test makes is:
180
- *
181
- * - It reaches the app where `encore run` has it. A frontend says itself
182
- * where its API is, as `http://localhost:4000`: a page's requests there,
183
- * and to the frontends' own addresses, go to the test session.
184
- * - Each request a page makes to the app carries the test, so what the app
185
- * does for a click is done on the test's data, and {@link settled} waits
186
- * for it.
187
- * - What the test has the browser do, and each request a page makes, is in
188
- * the test's {@link telemetry}, with what the app did for a request
189
- * under it. So is what a page says went wrong: an error on its console,
190
- * an exception nothing caught, a request that failed.
191
- * - Its pages are recorded. A test that fails is left a file that plays
192
- * them back beside all of that ({@link Browser.recording}).
193
- *
194
- * The adapters connect a tool to it and say which statement of the test
195
- * is running: `@encore.dev/sdk/testing/puppeteer`,
196
- * `@encore.dev/sdk/testing/playwright`. This is for any other tool that
197
- * speaks the DevTools Protocol.
198
- *
199
- * The browser is the `browser/chromium` component, which Encore downloads
200
- * the first time a test asks for one.
166
+ * Starts (or returns) a headless Chromium instance managed by Encore for the
167
+ * current system test, automatically closed when the test ends.
168
+ *
169
+ * The managed browser integrates directly with the test session:
170
+ * - Pages reach frontends and APIs at their usual `encore run` URLs (such as
171
+ * `http://localhost:4000`), transparently routed to the test session.
172
+ * - Every app request from a page carries the test ID, so backend work uses the
173
+ * test's isolated data and is waited on by {@link settled}.
174
+ * - Browser actions, page requests, console errors, uncaught page exceptions,
175
+ * and failed requests are captured in {@link telemetry} alongside backend
176
+ * spans.
177
+ * - Page sessions are recorded to an HTML file on failure (see
178
+ * {@link Browser.recording}).
179
+ *
180
+ * Prefer the Playwright (`@encore.dev/sdk/testing/playwright`) or Puppeteer
181
+ * (`@encore.dev/sdk/testing/puppeteer`) adapters when using those libraries;
182
+ * use this function directly for other Chrome DevTools Protocol clients.
183
+ * Encore downloads the `browser/chromium` component automatically on first use.
201
184
  *
202
185
  * @example
203
186
  * const {wsEndpoint, url} = await system.browser();
@@ -213,14 +196,14 @@ export async function browser(options) {
213
196
  // connection. Each word is answered before the next thing is done.
214
197
  const steps = new Steps(async (method, params) => {
215
198
  if (info.stepsUrl === '')
216
- throw new Error('the session takes no steps');
199
+ throw new Error('the test session does not support browser steps');
217
200
  const response = await fetch(`${info.stepsUrl}/${method.replace('Encore.', '')}`, {
218
201
  method: 'POST',
219
202
  headers: { 'content-type': 'application/json' },
220
203
  body: JSON.stringify(params),
221
204
  });
222
205
  if (!response.ok)
223
- throw new Error(`the session answered ${response.status}`);
206
+ throw new Error(`test session returned HTTP ${response.status} for browser step`);
224
207
  return response.json();
225
208
  });
226
209
  return {
@@ -245,8 +228,8 @@ export async function browser(options) {
245
228
  const found = info.urls[name];
246
229
  if (found === undefined) {
247
230
  const known = Object.keys(info.urls).filter(n => n !== 'proxy');
248
- throw new Error(`the app has no gateway or frontend ${JSON.stringify(name)} ` +
249
- `(it has: ${known.length === 0 ? 'none' : known.sort().join(', ')})`);
231
+ throw new Error(`unknown gateway or frontend ${JSON.stringify(name)} ` +
232
+ `(available: ${known.length === 0 ? 'none' : known.sort().join(', ')})`);
250
233
  }
251
234
  return found;
252
235
  },
@@ -1 +1 @@
1
- {"version":3,"file":"system.js","sourceRoot":"","sources":["../../testing/system.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,OAAO,EAAC,YAAY,EAAE,UAAU,EAAa,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAC,SAAS,EAAC,MAAM,+BAA+B,CAAC;AAExD,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