@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/mod.js
CHANGED
|
@@ -3,18 +3,19 @@ import { Subscription } from '../pubsub/subscription.js';
|
|
|
3
3
|
import { fromMessageAttributes } from '../internal/reqfields.js';
|
|
4
4
|
import { begin, hookScope, isContext, requireScope, requireScopes, runIn, Scope, setupHooks, systemTest, testMode, testName, } from '../internal/testing/scope.js';
|
|
5
5
|
export * as system from './system.js';
|
|
6
|
-
/**
|
|
6
|
+
/** Runner hooks registered via {@link setup}, used by {@link useFixture}. */
|
|
7
7
|
let registered;
|
|
8
8
|
/**
|
|
9
|
-
* Registers per-test infrastructure with a runner
|
|
10
|
-
* with resources
|
|
11
|
-
* (`@encore.dev/sdk/testing/vitest
|
|
9
|
+
* Registers per-test infrastructure lifecycle hooks with a test runner so each
|
|
10
|
+
* test starts with isolated resources that are released when it finishes. The
|
|
11
|
+
* runner adapters (`@encore.dev/sdk/testing/vitest`, etc.) call this
|
|
12
|
+
* automatically.
|
|
12
13
|
*
|
|
13
|
-
* Once
|
|
14
|
-
* module level
|
|
15
|
-
* test
|
|
14
|
+
* Once registered, accessing infrastructure outside a test (for example in
|
|
15
|
+
* `beforeAll` or at module top level) throws because no test would see those
|
|
16
|
+
* writes. Seed shared test data in `beforeEach` or with a {@link fixture}.
|
|
16
17
|
*
|
|
17
|
-
* Outside test mode
|
|
18
|
+
* Outside test mode, this is a no-op so test files can still be imported.
|
|
18
19
|
*/
|
|
19
20
|
export function setup(hooks, options) {
|
|
20
21
|
registered = hooks;
|
|
@@ -22,19 +23,20 @@ export function setup(hooks, options) {
|
|
|
22
23
|
setupHooks(hooks, fixture === undefined ? undefined : scope => choose(scope, fixture));
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
|
-
* Wraps a test
|
|
26
|
-
* which
|
|
26
|
+
* Wraps a test function in its own isolated resource scope. Use this for
|
|
27
|
+
* concurrent tests (which runner lifecycle hooks cannot distinguish) or runners
|
|
28
|
+
* without hooks.
|
|
27
29
|
*
|
|
28
30
|
* ```ts
|
|
29
31
|
* test.concurrent("x", scoped(async () => { ... }));
|
|
30
32
|
* ```
|
|
31
33
|
*
|
|
32
|
-
*
|
|
33
|
-
* {@link useFixture}
|
|
34
|
-
*
|
|
34
|
+
* Starts from `options.fixture` if specified, otherwise from any fixture
|
|
35
|
+
* configured via {@link useFixture} (when the runner supplies a test context,
|
|
36
|
+
* as in Vitest and `node:test`). Outside test mode, runs `fn` directly.
|
|
35
37
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
+
* Wrapping a system test in `scoped` also reports its pass/fail outcome in any
|
|
39
|
+
* runner and prints app telemetry when it fails (see {@link system}).
|
|
38
40
|
*/
|
|
39
41
|
export function scoped(fn, options) {
|
|
40
42
|
// No parameters by name: jest and bun pass a test with parameters a
|
|
@@ -65,19 +67,20 @@ export function scoped(fn, options) {
|
|
|
65
67
|
};
|
|
66
68
|
}
|
|
67
69
|
/**
|
|
68
|
-
*
|
|
69
|
-
* published
|
|
70
|
-
*
|
|
70
|
+
* Returns all messages published to `topic` during the current test (whether
|
|
71
|
+
* published directly by the test or by code it called), in publish order.
|
|
72
|
+
* Messages are not delivered automatically in unit tests; pass the subscription
|
|
73
|
+
* to {@link deliver} to invoke its handler.
|
|
71
74
|
*
|
|
72
|
-
* Each message's `data` is
|
|
73
|
-
* bytes published as bytes.
|
|
75
|
+
* Each message's `data` is JSON-decoded unless it was published as raw bytes.
|
|
74
76
|
*
|
|
75
|
-
* Not in
|
|
77
|
+
* Not available in system tests, where published messages are delivered to
|
|
78
|
+
* running services automatically.
|
|
76
79
|
*/
|
|
77
80
|
export function published(topic) {
|
|
78
81
|
if (systemTest !== null) {
|
|
79
|
-
throw new Error('
|
|
80
|
-
'
|
|
82
|
+
throw new Error('published() is not available in system tests because messages are delivered ' +
|
|
83
|
+
'to running services: await system.settled() and assert on the resulting state instead');
|
|
81
84
|
}
|
|
82
85
|
const scope = requireScope();
|
|
83
86
|
return scope.native.published(topic.name).map(msg => ({
|
|
@@ -93,67 +96,64 @@ export function published(topic) {
|
|
|
93
96
|
}));
|
|
94
97
|
}
|
|
95
98
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* the test. Resolves to how many it handled.
|
|
99
|
+
* Invokes `subscription`'s handler sequentially for every matching undelivered
|
|
100
|
+
* message published to its topic during the current test, returning the number
|
|
101
|
+
* of messages handled.
|
|
100
102
|
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* the
|
|
105
|
-
* over in the same call.
|
|
103
|
+
* Just like in production, messages are filtered by the subscription's filter,
|
|
104
|
+
* decoded using its encoding settings, and delivered with their propagated
|
|
105
|
+
* Request Context fields (starting at `deliveryAttempt: 1`). Messages published
|
|
106
|
+
* back to the same topic by the handler are also delivered during the same call.
|
|
106
107
|
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
108
|
+
* Stops on the first handler error and rejects with it. The failed message
|
|
109
|
+
* remains pending and will be retried on the next `deliver()` call with an
|
|
110
|
+
* incremented `deliveryAttempt`. Retry policies, ack deadlines, and dead-letter
|
|
111
|
+
* queues do not apply.
|
|
111
112
|
*
|
|
112
|
-
* Not in
|
|
113
|
-
*
|
|
113
|
+
* Not available in system tests, where subscriptions run automatically — use
|
|
114
|
+
* `system.settled()` instead.
|
|
114
115
|
*/
|
|
115
116
|
export async function deliver(subscription) {
|
|
116
117
|
if (systemTest !== null) {
|
|
117
|
-
throw new Error('
|
|
118
|
-
'
|
|
118
|
+
throw new Error('deliver() is not available in system tests because subscriptions run automatically ' +
|
|
119
|
+
'in their declaring services: await system.settled() instead');
|
|
119
120
|
}
|
|
120
121
|
const scope = requireScope();
|
|
121
122
|
return Subscription.deliverIn(subscription, scope, requireScopes().maxDeliveries);
|
|
122
123
|
}
|
|
123
124
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
125
|
+
* Overrides `secret` with `value` for the current test only. Other tests do
|
|
126
|
+
* not see the override, and it is cleared when the test ends.
|
|
126
127
|
*
|
|
127
|
-
* Not in
|
|
128
|
-
* secret
|
|
128
|
+
* Not available in system tests, where services read their own secrets — set
|
|
129
|
+
* test secret values in `secrets.test.toml` instead.
|
|
129
130
|
*/
|
|
130
131
|
export function setSecret(secret, value) {
|
|
131
132
|
if (systemTest !== null) {
|
|
132
|
-
throw new Error(
|
|
133
|
-
|
|
133
|
+
throw new Error('setSecret() is not available in system tests because running services read their ' +
|
|
134
|
+
'own secrets: configure test secret values in secrets.test.toml instead');
|
|
134
135
|
}
|
|
135
136
|
requireScope().native.setSecret(secret.name, Buffer.from(value));
|
|
136
137
|
}
|
|
137
138
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* satisfy the config's schema.
|
|
139
|
+
* Overrides `config` with `value` for the current test only. Other tests do
|
|
140
|
+
* not see the override, and it is cleared when the test ends. Throws if
|
|
141
|
+
* `value` fails schema validation.
|
|
142
142
|
*
|
|
143
|
-
* Not in
|
|
144
|
-
*
|
|
143
|
+
* Not available in system tests, where services read their own config files —
|
|
144
|
+
* set test config values in `<name>.test.config.toml` instead.
|
|
145
145
|
*/
|
|
146
146
|
export function setConfig(config, value) {
|
|
147
147
|
if (systemTest !== null) {
|
|
148
|
-
throw new Error(
|
|
149
|
-
|
|
150
|
-
'file (<name>.test.config.toml)');
|
|
148
|
+
throw new Error('setConfig() is not available in system tests because running services read their ' +
|
|
149
|
+
'own config files: configure test values in <name>.test.config.toml instead');
|
|
151
150
|
}
|
|
152
151
|
setTestValue(requireScope(), config, value);
|
|
153
152
|
}
|
|
154
153
|
/**
|
|
155
|
-
* Declares a
|
|
156
|
-
*
|
|
154
|
+
* Declares a reusable {@link Fixture}: runs `setup` once per test run, saves
|
|
155
|
+
* the resulting state of all touched databases, buckets, and Redis databases,
|
|
156
|
+
* and gives each test that loads it an isolated copy.
|
|
157
157
|
*
|
|
158
158
|
* ```ts
|
|
159
159
|
* const seeded = fixture("users.seeded", async () => {
|
|
@@ -162,15 +162,9 @@ export function setConfig(config, value) {
|
|
|
162
162
|
* useFixture(seeded);
|
|
163
163
|
* ```
|
|
164
164
|
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* Redis database it touched is saved; each test that loads the fixture gets
|
|
169
|
-
* a copy of its own. Other kinds of resource start each test from their
|
|
170
|
-
* initial state.
|
|
171
|
-
*
|
|
172
|
-
* The name identifies the fixture across the app's test files: two fixtures
|
|
173
|
-
* of one name are one fixture, built by whichever is loaded first.
|
|
165
|
+
* `setup` runs normal application code on the first load across all test files
|
|
166
|
+
* and workers. Other resource types start from their initial empty state.
|
|
167
|
+
* Fixtures with the same `name` refer to the same snapshot across files.
|
|
174
168
|
*/
|
|
175
169
|
export function fixture(name, setup, options) {
|
|
176
170
|
const f = {
|
|
@@ -182,18 +176,18 @@ export function fixture(name, setup, options) {
|
|
|
182
176
|
return f;
|
|
183
177
|
}
|
|
184
178
|
/**
|
|
185
|
-
*
|
|
186
|
-
* `describe` block
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
179
|
+
* Sets `f` as the default starting fixture for subsequent tests in the current
|
|
180
|
+
* file or `describe` block (pass `null` to reset to freshly provisioned empty
|
|
181
|
+
* resources). Also applies to {@link scoped} tests unless overridden.
|
|
182
|
+
*
|
|
183
|
+
* Requires a test runner adapter (or {@link setup}). No-op outside test mode.
|
|
190
184
|
*/
|
|
191
185
|
export function useFixture(f) {
|
|
192
186
|
if (!testMode)
|
|
193
187
|
return;
|
|
194
188
|
if (registered === undefined) {
|
|
195
|
-
throw new Error('useFixture
|
|
196
|
-
"@encore.dev/sdk/testing/vitest
|
|
189
|
+
throw new Error('useFixture() requires a test runner adapter (e.g. add ' +
|
|
190
|
+
'"@encore.dev/sdk/testing/vitest" to Vitest setupFiles)');
|
|
197
191
|
}
|
|
198
192
|
registered.beforeEach((...args) => {
|
|
199
193
|
const ctx = args[0];
|
|
@@ -203,26 +197,26 @@ export function useFixture(f) {
|
|
|
203
197
|
return scope === null ? undefined : choose(scope, f);
|
|
204
198
|
});
|
|
205
199
|
}
|
|
206
|
-
/**
|
|
200
|
+
/** Maps each fixture handle to its setup function. */
|
|
207
201
|
const setups = new WeakMap();
|
|
208
|
-
/**
|
|
202
|
+
/** Maps runner test contexts to the fixture selected via `useFixture`. */
|
|
209
203
|
const chosenFor = new WeakMap();
|
|
210
204
|
function chosen(ctx) {
|
|
211
205
|
return isContext(ctx) ? chosenFor.get(ctx) : undefined;
|
|
212
206
|
}
|
|
213
|
-
/**
|
|
207
|
+
/** Applies fixture `f` (or clears the fixture when `null`) on `scope`. */
|
|
214
208
|
async function choose(scope, f) {
|
|
215
209
|
if (f === null)
|
|
216
210
|
scope.native.useFixture(null);
|
|
217
211
|
else
|
|
218
212
|
await load(f, scope);
|
|
219
213
|
}
|
|
220
|
-
/**
|
|
214
|
+
/** Ensures fixture `f` is built and applies it to `scope`. */
|
|
221
215
|
async function load(f, scope) {
|
|
222
216
|
await ensureBuilt(f);
|
|
223
217
|
scope.native.useFixture(f.name);
|
|
224
218
|
}
|
|
225
|
-
/**
|
|
219
|
+
/** Tracks in-flight or completed fixture builds in this process. */
|
|
226
220
|
const builds = new WeakMap();
|
|
227
221
|
function ensureBuilt(f) {
|
|
228
222
|
let built = builds.get(f);
|
|
@@ -232,12 +226,12 @@ function ensureBuilt(f) {
|
|
|
232
226
|
}
|
|
233
227
|
return built;
|
|
234
228
|
}
|
|
235
|
-
/** Builds
|
|
229
|
+
/** Builds fixture `f` if no process has built it yet in this test run. */
|
|
236
230
|
async function build(f) {
|
|
237
231
|
if (f.parent !== undefined)
|
|
238
232
|
await ensureBuilt(f.parent);
|
|
239
233
|
const scopes = requireScopes();
|
|
240
|
-
const failed = (reason, cause) => new Error(`
|
|
234
|
+
const failed = (reason, cause) => new Error(`failed to load fixture ${JSON.stringify(f.name)}: ${reason}`, {
|
|
241
235
|
cause,
|
|
242
236
|
});
|
|
243
237
|
let native;
|
|
@@ -255,7 +249,7 @@ async function build(f) {
|
|
|
255
249
|
await runIn(scope, async () => setups.get(f)());
|
|
256
250
|
}
|
|
257
251
|
catch (err) {
|
|
258
|
-
const error = failed(`
|
|
252
|
+
const error = failed(`setup failed: ${err instanceof Error ? err.message : String(err)}`, err);
|
|
259
253
|
scopes.failFixture(f.name, error.message);
|
|
260
254
|
scope.end();
|
|
261
255
|
throw error;
|
package/dist/testing/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../testing/mod.ts"],"names":[],"mappings":"AAqCA,OAAO,EAAC,YAAY,EAAc,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAC,qBAAqB,EAAC,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,KAAK,EACL,SAAS,EACT,SAAS,EACT,YAAY,EACZ,aAAa,EACb,KAAK,EACL,KAAK,EACL,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,GAET,MAAM,2BAA2B,CAAC;AAGnC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AAWnC,
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../testing/mod.ts"],"names":[],"mappings":"AAqCA,OAAO,EAAC,YAAY,EAAc,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAC,qBAAqB,EAA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CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO;IAE5B,kEAAkE;IAClE,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,EAAE,WAAW,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrE,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAE,EAAE,CAAC,CAAC;IACnD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,KAAK,GAAG,MAAM,CAClB,iBAAiB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EACnE,GAAG,CACJ,CAAC;QACF,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1C,KAAK,CAAC,GAAG,EAAE,CAAC;QACZ,MAAM,KAAK,CAAC;IACd,CAAC;IACD,2DAA2D;IAC3D,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,MAAM,CAAE,GAAa,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC"}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Playwright 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
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* where it is, so that the recording and the test's telemetry say which
|
|
10
|
-
* statement had the browser do what.
|
|
4
|
+
* {@link connect} attaches Playwright 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, pages are recorded, and every page or locator call is automatically
|
|
8
|
+
* tracked with its call site in test telemetry and recordings.
|
|
11
9
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* is Chromium that is driven.
|
|
10
|
+
* Pass your own `playwright` or `playwright-core` `chromium` module; because
|
|
11
|
+
* Playwright connects over CDP (`connectOverCDP`), no separate Playwright
|
|
12
|
+
* browser download is required.
|
|
16
13
|
*
|
|
17
14
|
* @example
|
|
18
15
|
* // With any test runner:
|
|
@@ -28,7 +25,7 @@
|
|
|
28
25
|
* });
|
|
29
26
|
*
|
|
30
27
|
* @example
|
|
31
|
-
* // With Playwright Test
|
|
28
|
+
* // With Playwright Test:
|
|
32
29
|
* import {test as base, expect} from "@playwright/test";
|
|
33
30
|
* import {extend} from "@encore.dev/sdk/testing/playwright";
|
|
34
31
|
*
|
|
@@ -45,45 +42,44 @@
|
|
|
45
42
|
*/
|
|
46
43
|
import '../internal/testing/runner.js';
|
|
47
44
|
import { type BrowserOptions } from './system.js';
|
|
48
|
-
/** Playwright's `chromium
|
|
45
|
+
/** Minimal subset of Playwright's `chromium` required by {@link connect}. */
|
|
49
46
|
export interface Chromium<B> {
|
|
50
47
|
connectOverCDP(endpointURL: string, options?: Record<string, unknown>): Promise<B>;
|
|
51
48
|
}
|
|
52
|
-
/**
|
|
49
|
+
/** Options for {@link connect}. */
|
|
53
50
|
export interface ConnectOptions extends BrowserOptions {
|
|
54
|
-
/**
|
|
51
|
+
/** Additional Playwright options passed to `connectOverCDP` (e.g. `slowMo`). */
|
|
55
52
|
connect?: Record<string, unknown>;
|
|
56
53
|
}
|
|
57
54
|
/**
|
|
58
|
-
* Connects `chromium` to the current test's browser
|
|
59
|
-
*
|
|
60
|
-
*
|
|
55
|
+
* Connects Playwright's `chromium` to the current test's Encore browser
|
|
56
|
+
* (starting it if needed) and returns the Playwright `Browser`. The browser is
|
|
57
|
+
* automatically closed when the test ends.
|
|
61
58
|
*/
|
|
62
59
|
export declare function connect<B>(chromium: Chromium<B>, options?: ConnectOptions): Promise<B>;
|
|
63
60
|
/**
|
|
64
|
-
*
|
|
65
|
-
* frontend `name`
|
|
66
|
-
* written against.
|
|
61
|
+
* Returns the URL a page in the current test's browser uses to reach gateway
|
|
62
|
+
* or frontend `name` (matching the local `encore run` origin).
|
|
67
63
|
*/
|
|
68
64
|
export declare function url(name: string): Promise<string>;
|
|
69
|
-
/**
|
|
65
|
+
/** Extra Playwright Test options added by {@link extend}. */
|
|
70
66
|
export interface Options {
|
|
71
67
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
68
|
+
* Name of the frontend to use as `baseURL` so `page.goto("/")` opens it.
|
|
69
|
+
* Falls back to Playwright's configured `baseURL` when unset.
|
|
74
70
|
*/
|
|
75
71
|
frontend: string | undefined;
|
|
76
|
-
/**
|
|
72
|
+
/** Encore browser options for each test (see `system.browser`). */
|
|
77
73
|
encoreBrowser: BrowserOptions;
|
|
78
74
|
}
|
|
79
75
|
/**
|
|
80
|
-
* Playwright Test's `test
|
|
81
|
-
*
|
|
82
|
-
*
|
|
76
|
+
* Extends Playwright Test's `test` so each test runs in an Encore system test
|
|
77
|
+
* scope with `context` and `page` connected to Encore's managed browser
|
|
78
|
+
* (Playwright does not launch its own browser).
|
|
83
79
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
80
|
+
* Adds {@link Options.frontend} and {@link Options.encoreBrowser} for use with
|
|
81
|
+
* `test.use(...)`, and attaches the HTML recording to Playwright's report when
|
|
82
|
+
* a test fails.
|
|
87
83
|
*
|
|
88
84
|
* ```ts
|
|
89
85
|
* const test = extend(base);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playwright.d.ts","sourceRoot":"","sources":["../../testing/playwright.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"playwright.d.ts","sourceRoot":"","sources":["../../testing/playwright.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,OAAO,4BAA4B,CAAC;AAGpC,OAAO,EAAyB,KAAK,cAAc,EAAC,MAAM,UAAU,CAAC;AAErE,6EAA6E;AAC7E,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,cAAc,CACZ,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,CAAC,CAAC,CAAC;CACf;AAED,mCAAmC;AACnC,MAAM,WAAW,cAAe,SAAQ,cAAc;IACpD,gFAAgF;IAChF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AASD;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC,CAWZ;AAED;;;GAGG;AACH,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEvD;AAED,6DAA6D;AAC7D,MAAM,WAAW,OAAO;IACtB;;;OAGG;IACH,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,mEAAmE;IACnE,aAAa,EAAE,cAAc,CAAC;CAC/B;AAwCD;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAkFpC"}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Playwright 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
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* where it is, so that the recording and the test's telemetry say which
|
|
10
|
-
* statement had the browser do what.
|
|
4
|
+
* {@link connect} attaches Playwright 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, pages are recorded, and every page or locator call is automatically
|
|
8
|
+
* tracked with its call site in test telemetry and recordings.
|
|
11
9
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* is Chromium that is driven.
|
|
10
|
+
* Pass your own `playwright` or `playwright-core` `chromium` module; because
|
|
11
|
+
* Playwright connects over CDP (`connectOverCDP`), no separate Playwright
|
|
12
|
+
* browser download is required.
|
|
16
13
|
*
|
|
17
14
|
* @example
|
|
18
15
|
* // With any test runner:
|
|
@@ -28,7 +25,7 @@
|
|
|
28
25
|
* });
|
|
29
26
|
*
|
|
30
27
|
* @example
|
|
31
|
-
* // With Playwright Test
|
|
28
|
+
* // With Playwright Test:
|
|
32
29
|
* import {test as base, expect} from "@playwright/test";
|
|
33
30
|
* import {extend} from "@encore.dev/sdk/testing/playwright";
|
|
34
31
|
*
|
|
@@ -48,9 +45,9 @@ import { Steps, wrap } from '../internal/testing/steps.js';
|
|
|
48
45
|
import { setup } from './mod.js';
|
|
49
46
|
import { browser as testBrowser } from './system.js';
|
|
50
47
|
/**
|
|
51
|
-
* Connects `chromium` to the current test's browser
|
|
52
|
-
*
|
|
53
|
-
*
|
|
48
|
+
* Connects Playwright's `chromium` to the current test's Encore browser
|
|
49
|
+
* (starting it if needed) and returns the Playwright `Browser`. The browser is
|
|
50
|
+
* automatically closed when the test ends.
|
|
54
51
|
*/
|
|
55
52
|
export async function connect(chromium, options) {
|
|
56
53
|
const info = await testBrowser(options);
|
|
@@ -60,15 +57,13 @@ export async function connect(chromium, options) {
|
|
|
60
57
|
return wrap(browser, 'browser', steps);
|
|
61
58
|
}
|
|
62
59
|
/**
|
|
63
|
-
*
|
|
64
|
-
* frontend `name`
|
|
65
|
-
* written against.
|
|
60
|
+
* Returns the URL a page in the current test's browser uses to reach gateway
|
|
61
|
+
* or frontend `name` (matching the local `encore run` origin).
|
|
66
62
|
*/
|
|
67
63
|
export async function url(name) {
|
|
68
64
|
return (await testBrowser()).url(name);
|
|
69
65
|
}
|
|
70
|
-
/**
|
|
71
|
-
* call: Playwright Test has no hooks of its own outside a test file. */
|
|
66
|
+
/** Captures Encore's per-test scope hooks for Playwright Test fixtures. */
|
|
72
67
|
let hooks;
|
|
73
68
|
function scopeHooks() {
|
|
74
69
|
if (hooks !== undefined)
|
|
@@ -89,13 +84,13 @@ function scopeHooks() {
|
|
|
89
84
|
return hooks;
|
|
90
85
|
}
|
|
91
86
|
/**
|
|
92
|
-
* Playwright Test's `test
|
|
93
|
-
*
|
|
94
|
-
*
|
|
87
|
+
* Extends Playwright Test's `test` so each test runs in an Encore system test
|
|
88
|
+
* scope with `context` and `page` connected to Encore's managed browser
|
|
89
|
+
* (Playwright does not launch its own browser).
|
|
95
90
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
91
|
+
* Adds {@link Options.frontend} and {@link Options.encoreBrowser} for use with
|
|
92
|
+
* `test.use(...)`, and attaches the HTML recording to Playwright's report when
|
|
93
|
+
* a test fails.
|
|
99
94
|
*
|
|
100
95
|
* ```ts
|
|
101
96
|
* const test = extend(base);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playwright.js","sourceRoot":"","sources":["../../testing/playwright.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"playwright.js","sourceRoot":"","sources":["../../testing/playwright.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,OAAO,4BAA4B,CAAC;AACpC,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
2
|
-
/**
|
|
2
|
+
/** Minimal subset of Puppeteer required by {@link connect}. */
|
|
3
3
|
export interface Puppeteer<B> {
|
|
4
4
|
connect(options: {
|
|
5
5
|
browserWSEndpoint: string;
|
|
@@ -10,27 +10,26 @@ export interface Puppeteer<B> {
|
|
|
10
10
|
[option: string]: unknown;
|
|
11
11
|
}): Promise<B>;
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
13
|
+
/** Options for {@link connect}. */
|
|
14
14
|
export interface ConnectOptions extends BrowserOptions {
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
* `protocolTimeout
|
|
16
|
+
* Additional Puppeteer options passed to `puppeteer.connect` (such as
|
|
17
|
+
* `slowMo` or `protocolTimeout`).
|
|
18
18
|
*/
|
|
19
19
|
connect?: Record<string, unknown>;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* Connects `puppeteer` to the current test's browser
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* Connects `puppeteer` to the current test's Encore browser (starting it if
|
|
23
|
+
* needed) and returns the Puppeteer `Browser`. The browser is automatically
|
|
24
|
+
* closed when the test ends.
|
|
25
25
|
*
|
|
26
|
-
*
|
|
27
|
-
* `options.connect.defaultViewport
|
|
26
|
+
* Page viewports match `options.window` (defaulting to 1280×800) unless
|
|
27
|
+
* overridden via `options.connect.defaultViewport`.
|
|
28
28
|
*/
|
|
29
29
|
export declare function connect<B>(puppeteer: Puppeteer<B>, options?: ConnectOptions): Promise<B>;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
* frontend `name`
|
|
33
|
-
* written against.
|
|
31
|
+
* Returns the URL a page in the current test's browser uses to reach gateway
|
|
32
|
+
* or frontend `name` (matching the local `encore run` origin).
|
|
34
33
|
*/
|
|
35
34
|
export declare function url(name: string): Promise<string>;
|
|
36
35
|
//# sourceMappingURL=puppeteer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"puppeteer.d.ts","sourceRoot":"","sources":["../../testing/puppeteer.ts"],"names":[],"mappings":"AAqCA,OAAO,EAAyB,KAAK,cAAc,EAAC,MAAM,UAAU,CAAC;AAErE
|
|
1
|
+
{"version":3,"file":"puppeteer.d.ts","sourceRoot":"","sources":["../../testing/puppeteer.ts"],"names":[],"mappings":"AAqCA,OAAO,EAAyB,KAAK,cAAc,EAAC,MAAM,UAAU,CAAC;AAErE,+DAA+D;AAC/D,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,OAAO,CAAC,OAAO,EAAE;QACf,iBAAiB,EAAE,MAAM,CAAC;QAC1B,eAAe,CAAC,EAAE;YAAC,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAC,GAAG,IAAI,CAAC;QACzD,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;KAC3B,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAChB;AAED,mCAAmC;AACnC,MAAM,WAAW,cAAe,SAAQ,cAAc;IACpD;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAWD;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,EACvB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC,CAcZ;AAED;;;GAGG;AACH,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEvD"}
|