@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/testing/puppeteer.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Puppeteer adapter for driving Encore's managed system-test browser.
|
|
3
3
|
*
|
|
4
|
-
* {@link connect}
|
|
5
|
-
* current test (see `system.browser` in `@encore.dev/sdk/testing`)
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
-
*
|
|
19
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
49
|
+
/** Options for {@link connect}. */
|
|
50
50
|
export interface ConnectOptions extends BrowserOptions {
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
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
|
-
/**
|
|
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
|
|
69
|
-
*
|
|
70
|
-
*
|
|
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
|
-
*
|
|
73
|
-
* `options.connect.defaultViewport
|
|
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
|
-
*
|
|
96
|
-
* frontend `name`
|
|
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
|
|
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
|
*/
|
|
@@ -91,7 +90,7 @@ export type {
|
|
|
91
90
|
What,
|
|
92
91
|
} from '../internal/testing/telemetry';
|
|
93
92
|
|
|
94
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
110
|
+
/** Options for {@link settled}. */
|
|
112
111
|
export interface SettledOptions {
|
|
113
|
-
/**
|
|
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
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
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
|
-
*
|
|
133
|
-
*
|
|
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
|
-
*
|
|
136
|
-
*
|
|
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
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
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
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
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
|
-
`
|
|
167
|
-
`(
|
|
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
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
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
|
-
/**
|
|
180
|
+
/** Options for {@link telemetry}. */
|
|
188
181
|
export interface TelemetryOptions {
|
|
189
182
|
/**
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* requests
|
|
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
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
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
|
-
/**
|
|
218
|
+
/** Options for {@link browser}. */
|
|
229
219
|
export interface BrowserOptions {
|
|
230
220
|
/**
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
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
|
-
/**
|
|
226
|
+
/** Additional command-line flags passed to Chromium. */
|
|
237
227
|
args?: string[];
|
|
238
|
-
/**
|
|
228
|
+
/** Browser viewport/window size in CSS pixels. Defaults to 1280×800. */
|
|
239
229
|
window?: {width: number; height: number};
|
|
240
230
|
}
|
|
241
231
|
|
|
242
|
-
/**
|
|
232
|
+
/** Handle to the current test's managed Chromium instance (see {@link browser}). */
|
|
243
233
|
export interface Browser {
|
|
244
234
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
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
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
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
|
-
*
|
|
258
|
-
* `encore run`
|
|
259
|
-
*
|
|
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
|
-
*
|
|
264
|
-
*
|
|
265
|
-
* the
|
|
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
|
-
*
|
|
269
|
-
*
|
|
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
|
-
*
|
|
282
|
-
*
|
|
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
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
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
|
-
*
|
|
306
|
-
*
|
|
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 === '')
|
|
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(
|
|
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
|
-
`
|
|
367
|
-
`(
|
|
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;
|