@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.
- package/README.md +111 -101
- package/app_meta.ts +56 -54
- package/config/config.ts +60 -57
- package/config/secrets.ts +45 -52
- package/config/value.ts +23 -26
- package/cron/mod.ts +28 -29
- package/dist/app_meta.d.ts +52 -50
- package/dist/app_meta.d.ts.map +1 -1
- package/dist/app_meta.js +2 -2
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +58 -55
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +8 -9
- package/dist/config/config.js.map +1 -1
- package/dist/config/secrets.d.ts +45 -52
- package/dist/config/secrets.d.ts.map +1 -1
- package/dist/config/secrets.js +8 -9
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +20 -23
- package/dist/config/value.d.ts.map +1 -1
- package/dist/config/value.js +20 -23
- package/dist/config/value.js.map +1 -1
- package/dist/cron/mod.d.ts +26 -27
- package/dist/cron/mod.d.ts.map +1 -1
- package/dist/cron/mod.js +13 -14
- package/dist/cron/mod.js.map +1 -1
- package/dist/frontends/mod.d.ts +20 -19
- package/dist/frontends/mod.d.ts.map +1 -1
- package/dist/frontends/mod.js +20 -19
- package/dist/frontends/mod.js.map +1 -1
- package/dist/gateway/errors.d.ts +28 -30
- package/dist/gateway/errors.d.ts.map +1 -1
- package/dist/gateway/errors.js +29 -31
- package/dist/gateway/errors.js.map +1 -1
- package/dist/gateway/match.d.ts +54 -54
- package/dist/gateway/match.d.ts.map +1 -1
- package/dist/gateway/match.js +56 -56
- package/dist/gateway/match.js.map +1 -1
- package/dist/gateway/middleware.d.ts +62 -64
- package/dist/gateway/middleware.d.ts.map +1 -1
- package/dist/gateway/middleware.js +1 -1
- package/dist/gateway/middleware.js.map +1 -1
- package/dist/gateway/mod.d.ts +64 -67
- package/dist/gateway/mod.d.ts.map +1 -1
- package/dist/gateway/mod.js +72 -76
- package/dist/gateway/mod.js.map +1 -1
- package/dist/gateway/request.d.ts +138 -134
- package/dist/gateway/request.d.ts.map +1 -1
- package/dist/gateway/request.js +117 -108
- package/dist/gateway/request.js.map +1 -1
- package/dist/gateway/serve.d.ts +29 -34
- package/dist/gateway/serve.d.ts.map +1 -1
- package/dist/gateway/serve.js +51 -56
- package/dist/gateway/serve.js.map +1 -1
- package/dist/gateways/mod.d.ts +23 -21
- package/dist/gateways/mod.d.ts.map +1 -1
- package/dist/gateways/mod.js +25 -23
- package/dist/gateways/mod.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +1 -1
- package/dist/internal/runtime/napi/napi.d.cts +10 -3
- package/dist/internal/runtime/shutdown.d.ts +75 -57
- package/dist/internal/runtime/shutdown.d.ts.map +1 -1
- package/dist/internal/runtime/shutdown.js +88 -84
- package/dist/internal/runtime/shutdown.js.map +1 -1
- package/dist/log/logger.d.ts +43 -37
- package/dist/log/logger.d.ts.map +1 -1
- package/dist/log/logger.js +26 -25
- package/dist/log/logger.js.map +1 -1
- package/dist/metrics/mod.d.ts +133 -114
- package/dist/metrics/mod.d.ts.map +1 -1
- package/dist/metrics/mod.js +109 -101
- package/dist/metrics/mod.js.map +1 -1
- package/dist/otel.d.ts +6 -3
- package/dist/otel.d.ts.map +1 -1
- package/dist/otel.js +6 -3
- package/dist/otel.js.map +1 -1
- package/dist/pubsub/subscription.d.ts +88 -116
- package/dist/pubsub/subscription.d.ts.map +1 -1
- package/dist/pubsub/subscription.js +14 -17
- package/dist/pubsub/subscription.js.map +1 -1
- package/dist/pubsub/topic.d.ts +86 -113
- package/dist/pubsub/topic.d.ts.map +1 -1
- package/dist/pubsub/topic.js +68 -82
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +83 -86
- package/dist/reqctx/mod.d.ts.map +1 -1
- package/dist/reqctx/mod.js +39 -41
- package/dist/reqctx/mod.js.map +1 -1
- package/dist/services/index.d.ts +76 -75
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +73 -71
- package/dist/services/index.js.map +1 -1
- package/dist/shutdown/mod.d.ts +26 -25
- package/dist/shutdown/mod.d.ts.map +1 -1
- package/dist/shutdown/mod.js +26 -25
- package/dist/shutdown/mod.js.map +1 -1
- package/dist/storage/clickhouse/database.d.ts +113 -115
- package/dist/storage/clickhouse/database.d.ts.map +1 -1
- package/dist/storage/clickhouse/database.js +65 -79
- package/dist/storage/clickhouse/database.js.map +1 -1
- package/dist/storage/clickhouse/errors.d.ts +25 -26
- package/dist/storage/clickhouse/errors.d.ts.map +1 -1
- package/dist/storage/clickhouse/errors.js +15 -17
- package/dist/storage/clickhouse/errors.js.map +1 -1
- package/dist/storage/clickhouse/mod.d.ts +10 -10
- package/dist/storage/clickhouse/mod.js +10 -10
- package/dist/storage/objects/bucket.d.ts +196 -225
- package/dist/storage/objects/bucket.d.ts.map +1 -1
- package/dist/storage/objects/bucket.js +71 -84
- package/dist/storage/objects/bucket.js.map +1 -1
- package/dist/storage/objects/error.d.ts +4 -4
- package/dist/storage/objects/error.js +4 -4
- package/dist/storage/postgres/database.d.ts +124 -149
- package/dist/storage/postgres/database.d.ts.map +1 -1
- package/dist/storage/postgres/database.js +98 -135
- package/dist/storage/postgres/database.js.map +1 -1
- package/dist/storage/postgres/errors.d.ts +42 -48
- package/dist/storage/postgres/errors.d.ts.map +1 -1
- package/dist/storage/postgres/errors.js +44 -51
- package/dist/storage/postgres/errors.js.map +1 -1
- package/dist/storage/postgres/interval.d.ts +19 -19
- package/dist/storage/postgres/interval.d.ts.map +1 -1
- package/dist/storage/postgres/interval.js +21 -21
- package/dist/storage/postgres/interval.js.map +1 -1
- package/dist/storage/redis/bitfield.d.ts +48 -23
- package/dist/storage/redis/bitfield.d.ts.map +1 -1
- package/dist/storage/redis/bitfield.js +38 -19
- package/dist/storage/redis/bitfield.js.map +1 -1
- package/dist/storage/redis/command.d.ts +16 -12
- package/dist/storage/redis/command.d.ts.map +1 -1
- package/dist/storage/redis/command.js +16 -12
- package/dist/storage/redis/command.js.map +1 -1
- package/dist/storage/redis/commands.d.ts +99 -100
- package/dist/storage/redis/commands.d.ts.map +1 -1
- package/dist/storage/redis/commands.js +84 -85
- package/dist/storage/redis/commands.js.map +1 -1
- package/dist/storage/redis/database.d.ts +138 -122
- package/dist/storage/redis/database.d.ts.map +1 -1
- package/dist/storage/redis/database.js +120 -101
- package/dist/storage/redis/database.js.map +1 -1
- package/dist/storage/redis/mod.d.ts +52 -48
- package/dist/storage/redis/mod.d.ts.map +1 -1
- package/dist/storage/redis/mod.js +52 -48
- package/dist/storage/redis/mod.js.map +1 -1
- package/dist/storage/redis/options.d.ts +26 -24
- package/dist/storage/redis/options.d.ts.map +1 -1
- package/dist/storage/redis/options.js.map +1 -1
- package/dist/storage/redis/pubsub.d.ts +16 -16
- package/dist/storage/redis/pubsub.d.ts.map +1 -1
- package/dist/storage/redis/pubsub.js +14 -14
- package/dist/storage/redis/pubsub.js.map +1 -1
- package/dist/storage/redis/reply.d.ts +80 -72
- package/dist/storage/redis/reply.d.ts.map +1 -1
- package/dist/storage/redis/reply.js +53 -46
- package/dist/storage/redis/reply.js.map +1 -1
- package/dist/storage/redis/scan.d.ts +4 -4
- package/dist/storage/redis/scan.d.ts.map +1 -1
- package/dist/storage/redis/scan.js +6 -6
- package/dist/storage/redis/scan.js.map +1 -1
- package/dist/storage/redis/script.d.ts +28 -21
- package/dist/storage/redis/script.d.ts.map +1 -1
- package/dist/storage/redis/script.js +29 -22
- package/dist/storage/redis/script.js.map +1 -1
- package/dist/storage/redis/target.d.ts +17 -1
- package/dist/storage/redis/target.d.ts.map +1 -1
- package/dist/storage/redis/target.js +30 -1
- package/dist/storage/redis/target.js.map +1 -1
- package/dist/storage/redis/wire.d.ts +6 -6
- package/dist/storage/redis/wire.d.ts.map +1 -1
- package/dist/storage/redis/wire.js +6 -6
- package/dist/storage/redis/wire.js.map +1 -1
- package/dist/testing/mod.d.ts +83 -88
- package/dist/testing/mod.d.ts.map +1 -1
- package/dist/testing/mod.js +75 -81
- package/dist/testing/mod.js.map +1 -1
- package/dist/testing/playwright.d.ts +28 -32
- package/dist/testing/playwright.d.ts.map +1 -1
- package/dist/testing/playwright.js +22 -27
- package/dist/testing/playwright.js.map +1 -1
- package/dist/testing/puppeteer.d.ts +11 -12
- package/dist/testing/puppeteer.d.ts.map +1 -1
- package/dist/testing/puppeteer.js +17 -18
- package/dist/testing/puppeteer.js.map +1 -1
- package/dist/testing/system.d.ts +72 -90
- package/dist/testing/system.d.ts.map +1 -1
- package/dist/testing/system.js +90 -107
- package/dist/testing/system.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/frontends/mod.test.ts +6 -2
- package/frontends/mod.ts +20 -19
- package/gateway/errors.ts +30 -32
- package/gateway/match.ts +61 -57
- package/gateway/middleware.ts +62 -64
- package/gateway/mod.ts +73 -76
- package/gateway/request.ts +143 -140
- package/gateway/serve.ts +58 -63
- package/gateways/mod.ts +25 -23
- package/internal/runtime/napi/napi.cjs +1 -1
- package/internal/runtime/napi/napi.d.cts +10 -3
- package/internal/runtime/shutdown.ts +113 -101
- package/log/logger.test.ts +8 -0
- package/log/logger.ts +48 -45
- package/metrics/mod.ts +138 -122
- package/otel.ts +6 -3
- package/package.json +1 -1
- package/pubsub/subscription.ts +93 -123
- package/pubsub/topic.ts +96 -130
- package/reqctx/mod.ts +83 -86
- package/services/index.ts +78 -78
- package/shutdown/mod.ts +26 -25
- package/storage/clickhouse/database.ts +115 -129
- package/storage/clickhouse/errors.ts +27 -29
- package/storage/clickhouse/mod.ts +10 -10
- package/storage/objects/bucket.ts +209 -239
- package/storage/objects/error.ts +4 -4
- package/storage/postgres/database.ts +131 -164
- package/storage/postgres/errors.ts +45 -52
- package/storage/postgres/interval.ts +21 -21
- package/storage/redis/bitfield.ts +51 -26
- package/storage/redis/command.ts +16 -12
- package/storage/redis/commands.ts +99 -100
- package/storage/redis/database.ts +145 -123
- package/storage/redis/mod.ts +52 -48
- package/storage/redis/options.ts +26 -24
- package/storage/redis/pubsub.ts +14 -14
- package/storage/redis/redis.test.ts +17 -2
- package/storage/redis/reply.ts +85 -77
- package/storage/redis/scan.ts +6 -6
- package/storage/redis/script.ts +29 -22
- package/storage/redis/target.ts +34 -1
- package/storage/redis/wire.ts +8 -8
- package/testing/mod.ts +99 -105
- package/testing/playwright.ts +32 -37
- package/testing/puppeteer.ts +22 -23
- package/testing/system.ts +117 -133
package/dist/testing/system.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* System tests: tests
|
|
2
|
+
* System tests: end-to-end tests that run against the full Encore application
|
|
3
|
+
* rather than inside a single service.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* test suite — a directory
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
-
* //
|
|
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
|
-
*
|
|
35
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
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
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
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
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
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
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
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
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
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(`
|
|
135
|
-
`(
|
|
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
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
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
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* requests
|
|
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
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
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
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* -
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
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
|
|
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(`
|
|
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(`
|
|
249
|
-
`(
|
|
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
|
|
1
|
+
{"version":3,"file":"system.js","sourceRoot":"","sources":["../../testing/system.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;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,OAAO,EAAC,SAAS,EAAC,MAAM,+BAA+B,CAAC;AAoBx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