@encore.dev/sdk 2.0.0-beta.15 → 2.0.0-beta.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/storage/redis/target.ts
CHANGED
|
@@ -52,10 +52,43 @@ export class PoolTarget implements Target {
|
|
|
52
52
|
runtime.RedisDatabase,
|
|
53
53
|
string | null
|
|
54
54
|
>();
|
|
55
|
+
/** A reading target's native handles, by the database's own each was
|
|
56
|
+
* made from. */
|
|
57
|
+
private readonly readers = new WeakMap<
|
|
58
|
+
runtime.RedisDatabase,
|
|
59
|
+
runtime.RedisDatabase
|
|
60
|
+
>();
|
|
55
61
|
|
|
56
|
-
|
|
62
|
+
/**
|
|
63
|
+
* @param readerOf The target a reading one reads through. Unset, the
|
|
64
|
+
* target reads and writes.
|
|
65
|
+
* @param primary Whether a reading target reads from the primary.
|
|
66
|
+
*/
|
|
67
|
+
constructor(
|
|
68
|
+
readonly name: string,
|
|
69
|
+
private readonly readerOf?: PoolTarget,
|
|
70
|
+
private readonly primary = false,
|
|
71
|
+
) {}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A target on the database for a handle that only reads: from the primary
|
|
75
|
+
* if `primary`, and otherwise from a read replica where the database has a
|
|
76
|
+
* read-only pool on one. The runtime refuses its commands that write.
|
|
77
|
+
*/
|
|
78
|
+
reader(primary: boolean): PoolTarget {
|
|
79
|
+
return new PoolTarget(this.name, this, primary);
|
|
80
|
+
}
|
|
57
81
|
|
|
58
82
|
database(): runtime.RedisDatabase {
|
|
83
|
+
if (this.readerOf) {
|
|
84
|
+
const own = this.readerOf.database();
|
|
85
|
+
let reader = this.readers.get(own);
|
|
86
|
+
if (!reader) {
|
|
87
|
+
reader = own.reader(this.primary);
|
|
88
|
+
this.readers.set(own, reader);
|
|
89
|
+
}
|
|
90
|
+
return reader;
|
|
91
|
+
}
|
|
59
92
|
return testDatabase(this.name) ?? (this.impl ??= openDatabase(this.name));
|
|
60
93
|
}
|
|
61
94
|
|
package/storage/redis/wire.ts
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
/** A value
|
|
11
|
+
/** A value that can be passed to Redis as an argument: text, bytes, or a number. */
|
|
12
12
|
export type RedisArg = string | number | bigint | Buffer | Uint8Array;
|
|
13
13
|
|
|
14
|
-
/**
|
|
14
|
+
/** Key-value or field-value pairs passed as a plain object or a `ReadonlyMap`. */
|
|
15
15
|
export type Pairs<V> = Record<string, V> | ReadonlyMap<string, V>;
|
|
16
16
|
|
|
17
17
|
/** One argument of a command. */
|
|
@@ -122,8 +122,8 @@ export function toArg(value: unknown, operation: string): Buffer {
|
|
|
122
122
|
return Buffer.from(String(value), 'ascii');
|
|
123
123
|
}
|
|
124
124
|
throw new TypeError(
|
|
125
|
-
`redis: ${operation}: cannot send ${describe(value)} as an argument
|
|
126
|
-
`
|
|
125
|
+
`redis: ${operation}: cannot send ${describe(value)} as an argument; ` +
|
|
126
|
+
`expected a string, number, bigint, or Buffer`,
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -213,12 +213,12 @@ export function encodeList(items: readonly string[]): Buffer {
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
/**
|
|
216
|
-
*
|
|
216
|
+
* Error returned when the Redis server rejects a command.
|
|
217
217
|
*/
|
|
218
218
|
export class ServerError extends Error {
|
|
219
219
|
/**
|
|
220
|
-
* The
|
|
221
|
-
* `WRONGTYPE Operation against a key holding the wrong kind of value
|
|
220
|
+
* The raw error message returned by Redis (for example,
|
|
221
|
+
* `WRONGTYPE Operation against a key holding the wrong kind of value`).
|
|
222
222
|
*/
|
|
223
223
|
readonly serverMessage: string;
|
|
224
224
|
|
|
@@ -233,7 +233,7 @@ export class ServerError extends Error {
|
|
|
233
233
|
Object.setPrototypeOf(this, ServerError.prototype);
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
-
/** The error
|
|
236
|
+
/** The Redis error code: the first word of `serverMessage` (for example, `WRONGTYPE`). */
|
|
237
237
|
get code(): string {
|
|
238
238
|
const space = this.serverMessage.indexOf(' ');
|
|
239
239
|
return space < 0 ? this.serverMessage : this.serverMessage.slice(0, space);
|
package/testing/mod.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* databases, buckets, Redis databases and topics
|
|
4
|
-
*
|
|
2
|
+
* Testing helpers for Encore apps. Every test receives isolated infrastructure
|
|
3
|
+
* — databases, buckets, Redis databases, and Pub/Sub topics invisible to other
|
|
4
|
+
* tests — with a single line of runner configuration:
|
|
5
5
|
*
|
|
6
6
|
* | Runner | Config |
|
|
7
7
|
* |-----------|---------------------------------------------------------------------|
|
|
@@ -10,17 +10,17 @@
|
|
|
10
10
|
* | bun | `bunfig.toml`: `[test] preload = ["@encore.dev/sdk/testing/bun"]` |
|
|
11
11
|
* | node:test | `import "@encore.dev/sdk/testing/node"` at the top of each test file |
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
* `bun test`,
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* Run tests with `encore test` or directly via your test runner (`vitest`,
|
|
14
|
+
* `bun test`, or your editor's test button): Encore detects the app and starts
|
|
15
|
+
* its daemon automatically if needed. Set `ENCORE_TEST=0` to disable this, or
|
|
16
|
+
* `ENCORE_TEST=1` to enable it for an unrecognized runner.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
* to
|
|
20
|
-
* {@link deliver}.
|
|
18
|
+
* In unit tests, background work does not run automatically: messages published
|
|
19
|
+
* to Pub/Sub topics are captured so you can inspect them with {@link published}
|
|
20
|
+
* and trigger subscription handlers explicitly with {@link deliver}.
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
* `encore.systest.json
|
|
22
|
+
* For end-to-end tests in a system test suite (a directory with an
|
|
23
|
+
* `encore.systest.json`), tests run against the full app instead — see
|
|
24
24
|
* {@link system}.
|
|
25
25
|
*
|
|
26
26
|
* @example
|
|
@@ -58,28 +58,29 @@ import {
|
|
|
58
58
|
export type {Hooks} from '../internal/testing/scope';
|
|
59
59
|
export * as system from './system';
|
|
60
60
|
|
|
61
|
-
/**
|
|
61
|
+
/** Options for {@link setup} and {@link scoped}. */
|
|
62
62
|
export interface ScopeOptions {
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
65
|
-
* resources
|
|
64
|
+
* Initial resource state for each test: a {@link Fixture}, or `null` to start
|
|
65
|
+
* from freshly provisioned empty resources regardless of {@link useFixture}.
|
|
66
66
|
*/
|
|
67
67
|
fixture?: Fixture | null;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
/**
|
|
70
|
+
/** Runner hooks registered via {@link setup}, used by {@link useFixture}. */
|
|
71
71
|
let registered: Hooks | undefined;
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
* Registers per-test infrastructure with a runner
|
|
75
|
-
* with resources
|
|
76
|
-
* (`@encore.dev/sdk/testing/vitest
|
|
74
|
+
* Registers per-test infrastructure lifecycle hooks with a test runner so each
|
|
75
|
+
* test starts with isolated resources that are released when it finishes. The
|
|
76
|
+
* runner adapters (`@encore.dev/sdk/testing/vitest`, etc.) call this
|
|
77
|
+
* automatically.
|
|
77
78
|
*
|
|
78
|
-
* Once
|
|
79
|
-
* module level
|
|
80
|
-
* test
|
|
79
|
+
* Once registered, accessing infrastructure outside a test (for example in
|
|
80
|
+
* `beforeAll` or at module top level) throws because no test would see those
|
|
81
|
+
* writes. Seed shared test data in `beforeEach` or with a {@link fixture}.
|
|
81
82
|
*
|
|
82
|
-
* Outside test mode
|
|
83
|
+
* Outside test mode, this is a no-op so test files can still be imported.
|
|
83
84
|
*/
|
|
84
85
|
export function setup(hooks: Hooks, options?: ScopeOptions): void {
|
|
85
86
|
registered = hooks;
|
|
@@ -91,19 +92,20 @@ export function setup(hooks: Hooks, options?: ScopeOptions): void {
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
/**
|
|
94
|
-
* Wraps a test
|
|
95
|
-
* which
|
|
95
|
+
* Wraps a test function in its own isolated resource scope. Use this for
|
|
96
|
+
* concurrent tests (which runner lifecycle hooks cannot distinguish) or runners
|
|
97
|
+
* without hooks.
|
|
96
98
|
*
|
|
97
99
|
* ```ts
|
|
98
100
|
* test.concurrent("x", scoped(async () => { ... }));
|
|
99
101
|
* ```
|
|
100
102
|
*
|
|
101
|
-
*
|
|
102
|
-
* {@link useFixture}
|
|
103
|
-
*
|
|
103
|
+
* Starts from `options.fixture` if specified, otherwise from any fixture
|
|
104
|
+
* configured via {@link useFixture} (when the runner supplies a test context,
|
|
105
|
+
* as in Vitest and `node:test`). Outside test mode, runs `fn` directly.
|
|
104
106
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
+
* Wrapping a system test in `scoped` also reports its pass/fail outcome in any
|
|
108
|
+
* runner and prints app telemetry when it fails (see {@link system}).
|
|
107
109
|
*/
|
|
108
110
|
export function scoped<A extends unknown[], R>(
|
|
109
111
|
fn: (...args: A) => Promise<R> | R,
|
|
@@ -135,20 +137,21 @@ export function scoped<A extends unknown[], R>(
|
|
|
135
137
|
}
|
|
136
138
|
|
|
137
139
|
/**
|
|
138
|
-
*
|
|
139
|
-
* published
|
|
140
|
-
*
|
|
140
|
+
* Returns all messages published to `topic` during the current test (whether
|
|
141
|
+
* published directly by the test or by code it called), in publish order.
|
|
142
|
+
* Messages are not delivered automatically in unit tests; pass the subscription
|
|
143
|
+
* to {@link deliver} to invoke its handler.
|
|
141
144
|
*
|
|
142
|
-
* Each message's `data` is
|
|
143
|
-
* bytes published as bytes.
|
|
145
|
+
* Each message's `data` is JSON-decoded unless it was published as raw bytes.
|
|
144
146
|
*
|
|
145
|
-
* Not in
|
|
147
|
+
* Not available in system tests, where published messages are delivered to
|
|
148
|
+
* running services automatically.
|
|
146
149
|
*/
|
|
147
150
|
export function published<T>(topic: Topic<T> | OrderedTopic<T>): Message<T>[] {
|
|
148
151
|
if (systemTest !== null) {
|
|
149
152
|
throw new Error(
|
|
150
|
-
'
|
|
151
|
-
'
|
|
153
|
+
'published() is not available in system tests because messages are delivered ' +
|
|
154
|
+
'to running services: await system.settled() and assert on the resulting state instead',
|
|
152
155
|
);
|
|
153
156
|
}
|
|
154
157
|
const scope = requireScope();
|
|
@@ -166,32 +169,30 @@ export function published<T>(topic: Topic<T> | OrderedTopic<T>): Message<T>[] {
|
|
|
166
169
|
}
|
|
167
170
|
|
|
168
171
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* the test. Resolves to how many it handled.
|
|
172
|
+
* Invokes `subscription`'s handler sequentially for every matching undelivered
|
|
173
|
+
* message published to its topic during the current test, returning the number
|
|
174
|
+
* of messages handled.
|
|
173
175
|
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* the
|
|
178
|
-
* over in the same call.
|
|
176
|
+
* Just like in production, messages are filtered by the subscription's filter,
|
|
177
|
+
* decoded using its encoding settings, and delivered with their propagated
|
|
178
|
+
* Request Context fields (starting at `deliveryAttempt: 1`). Messages published
|
|
179
|
+
* back to the same topic by the handler are also delivered during the same call.
|
|
179
180
|
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
181
|
+
* Stops on the first handler error and rejects with it. The failed message
|
|
182
|
+
* remains pending and will be retried on the next `deliver()` call with an
|
|
183
|
+
* incremented `deliveryAttempt`. Retry policies, ack deadlines, and dead-letter
|
|
184
|
+
* queues do not apply.
|
|
184
185
|
*
|
|
185
|
-
* Not in
|
|
186
|
-
*
|
|
186
|
+
* Not available in system tests, where subscriptions run automatically — use
|
|
187
|
+
* `system.settled()` instead.
|
|
187
188
|
*/
|
|
188
189
|
export async function deliver<T>(
|
|
189
190
|
subscription: Subscription<T>,
|
|
190
191
|
): Promise<number> {
|
|
191
192
|
if (systemTest !== null) {
|
|
192
193
|
throw new Error(
|
|
193
|
-
'
|
|
194
|
-
'
|
|
194
|
+
'deliver() is not available in system tests because subscriptions run automatically ' +
|
|
195
|
+
'in their declaring services: await system.settled() instead',
|
|
195
196
|
);
|
|
196
197
|
}
|
|
197
198
|
const scope = requireScope();
|
|
@@ -203,69 +204,68 @@ export async function deliver<T>(
|
|
|
203
204
|
}
|
|
204
205
|
|
|
205
206
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
207
|
+
* Overrides `secret` with `value` for the current test only. Other tests do
|
|
208
|
+
* not see the override, and it is cleared when the test ends.
|
|
208
209
|
*
|
|
209
|
-
* Not in
|
|
210
|
-
* secret
|
|
210
|
+
* Not available in system tests, where services read their own secrets — set
|
|
211
|
+
* test secret values in `secrets.test.toml` instead.
|
|
211
212
|
*/
|
|
212
213
|
export function setSecret(secret: AnySecret, value: string | Uint8Array): void {
|
|
213
214
|
if (systemTest !== null) {
|
|
214
215
|
throw new Error(
|
|
215
|
-
|
|
216
|
-
|
|
216
|
+
'setSecret() is not available in system tests because running services read their ' +
|
|
217
|
+
'own secrets: configure test secret values in secrets.test.toml instead',
|
|
217
218
|
);
|
|
218
219
|
}
|
|
219
220
|
requireScope().native.setSecret(secret.name, Buffer.from(value));
|
|
220
221
|
}
|
|
221
222
|
|
|
222
223
|
/**
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* satisfy the config's schema.
|
|
224
|
+
* Overrides `config` with `value` for the current test only. Other tests do
|
|
225
|
+
* not see the override, and it is cleared when the test ends. Throws if
|
|
226
|
+
* `value` fails schema validation.
|
|
227
227
|
*
|
|
228
|
-
* Not in
|
|
229
|
-
*
|
|
228
|
+
* Not available in system tests, where services read their own config files —
|
|
229
|
+
* set test config values in `<name>.test.config.toml` instead.
|
|
230
230
|
*/
|
|
231
231
|
export function setConfig<T>(config: Config<T>, value: T): void {
|
|
232
232
|
if (systemTest !== null) {
|
|
233
233
|
throw new Error(
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
'file (<name>.test.config.toml)',
|
|
234
|
+
'setConfig() is not available in system tests because running services read their ' +
|
|
235
|
+
'own config files: configure test values in <name>.test.config.toml instead',
|
|
237
236
|
);
|
|
238
237
|
}
|
|
239
238
|
setTestValue(requireScope(), config, value);
|
|
240
239
|
}
|
|
241
240
|
|
|
242
241
|
/**
|
|
243
|
-
* A
|
|
244
|
-
*
|
|
242
|
+
* A reusable snapshot of resource state (such as seeded database rows) that
|
|
243
|
+
* tests can start from instead of empty resources. Create one with
|
|
245
244
|
* {@link fixture}.
|
|
246
245
|
*/
|
|
247
246
|
export interface Fixture {
|
|
248
|
-
/**
|
|
247
|
+
/** Unique name identifying this fixture across all test files in the app. */
|
|
249
248
|
readonly name: string;
|
|
250
|
-
/**
|
|
249
|
+
/** Optional parent fixture whose snapshot is loaded before this fixture's setup runs. */
|
|
251
250
|
readonly parent?: Fixture;
|
|
252
251
|
/**
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
252
|
+
* Loads this fixture into the current test, building it first if it has not
|
|
253
|
+
* been built yet in this test run. Must be called before the test accesses
|
|
254
|
+
* any resource.
|
|
256
255
|
*/
|
|
257
256
|
load(): Promise<void>;
|
|
258
257
|
}
|
|
259
258
|
|
|
260
|
-
/**
|
|
259
|
+
/** Options for {@link fixture}. */
|
|
261
260
|
export interface FixtureOptions {
|
|
262
|
-
/**
|
|
261
|
+
/** Parent fixture to build on; this fixture's setup starts from its saved state. */
|
|
263
262
|
extends?: Fixture;
|
|
264
263
|
}
|
|
265
264
|
|
|
266
265
|
/**
|
|
267
|
-
* Declares a
|
|
268
|
-
*
|
|
266
|
+
* Declares a reusable {@link Fixture}: runs `setup` once per test run, saves
|
|
267
|
+
* the resulting state of all touched databases, buckets, and Redis databases,
|
|
268
|
+
* and gives each test that loads it an isolated copy.
|
|
269
269
|
*
|
|
270
270
|
* ```ts
|
|
271
271
|
* const seeded = fixture("users.seeded", async () => {
|
|
@@ -274,15 +274,9 @@ export interface FixtureOptions {
|
|
|
274
274
|
* useFixture(seeded);
|
|
275
275
|
* ```
|
|
276
276
|
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
* Redis database it touched is saved; each test that loads the fixture gets
|
|
281
|
-
* a copy of its own. Other kinds of resource start each test from their
|
|
282
|
-
* initial state.
|
|
283
|
-
*
|
|
284
|
-
* The name identifies the fixture across the app's test files: two fixtures
|
|
285
|
-
* of one name are one fixture, built by whichever is loaded first.
|
|
277
|
+
* `setup` runs normal application code on the first load across all test files
|
|
278
|
+
* and workers. Other resource types start from their initial empty state.
|
|
279
|
+
* Fixtures with the same `name` refer to the same snapshot across files.
|
|
286
280
|
*/
|
|
287
281
|
export function fixture(
|
|
288
282
|
name: string,
|
|
@@ -299,18 +293,18 @@ export function fixture(
|
|
|
299
293
|
}
|
|
300
294
|
|
|
301
295
|
/**
|
|
302
|
-
*
|
|
303
|
-
* `describe` block
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
296
|
+
* Sets `f` as the default starting fixture for subsequent tests in the current
|
|
297
|
+
* file or `describe` block (pass `null` to reset to freshly provisioned empty
|
|
298
|
+
* resources). Also applies to {@link scoped} tests unless overridden.
|
|
299
|
+
*
|
|
300
|
+
* Requires a test runner adapter (or {@link setup}). No-op outside test mode.
|
|
307
301
|
*/
|
|
308
302
|
export function useFixture(f: Fixture | null): void {
|
|
309
303
|
if (!testMode) return;
|
|
310
304
|
if (registered === undefined) {
|
|
311
305
|
throw new Error(
|
|
312
|
-
'useFixture
|
|
313
|
-
"@encore.dev/sdk/testing/vitest
|
|
306
|
+
'useFixture() requires a test runner adapter (e.g. add ' +
|
|
307
|
+
'"@encore.dev/sdk/testing/vitest" to Vitest setupFiles)',
|
|
314
308
|
);
|
|
315
309
|
}
|
|
316
310
|
registered.beforeEach((...args: unknown[]) => {
|
|
@@ -321,29 +315,29 @@ export function useFixture(f: Fixture | null): void {
|
|
|
321
315
|
});
|
|
322
316
|
}
|
|
323
317
|
|
|
324
|
-
/**
|
|
318
|
+
/** Maps each fixture handle to its setup function. */
|
|
325
319
|
const setups = new WeakMap<Fixture, () => Promise<void> | void>();
|
|
326
320
|
|
|
327
|
-
/**
|
|
321
|
+
/** Maps runner test contexts to the fixture selected via `useFixture`. */
|
|
328
322
|
const chosenFor = new WeakMap<object, Fixture | null>();
|
|
329
323
|
|
|
330
324
|
function chosen(ctx: unknown): Fixture | null | undefined {
|
|
331
325
|
return isContext(ctx) ? chosenFor.get(ctx) : undefined;
|
|
332
326
|
}
|
|
333
327
|
|
|
334
|
-
/**
|
|
328
|
+
/** Applies fixture `f` (or clears the fixture when `null`) on `scope`. */
|
|
335
329
|
async function choose(scope: Scope, f: Fixture | null): Promise<void> {
|
|
336
330
|
if (f === null) scope.native.useFixture(null);
|
|
337
331
|
else await load(f, scope);
|
|
338
332
|
}
|
|
339
333
|
|
|
340
|
-
/**
|
|
334
|
+
/** Ensures fixture `f` is built and applies it to `scope`. */
|
|
341
335
|
async function load(f: Fixture, scope: Scope): Promise<void> {
|
|
342
336
|
await ensureBuilt(f);
|
|
343
337
|
scope.native.useFixture(f.name);
|
|
344
338
|
}
|
|
345
339
|
|
|
346
|
-
/**
|
|
340
|
+
/** Tracks in-flight or completed fixture builds in this process. */
|
|
347
341
|
const builds = new WeakMap<Fixture, Promise<void>>();
|
|
348
342
|
|
|
349
343
|
function ensureBuilt(f: Fixture): Promise<void> {
|
|
@@ -355,12 +349,12 @@ function ensureBuilt(f: Fixture): Promise<void> {
|
|
|
355
349
|
return built;
|
|
356
350
|
}
|
|
357
351
|
|
|
358
|
-
/** Builds
|
|
352
|
+
/** Builds fixture `f` if no process has built it yet in this test run. */
|
|
359
353
|
async function build(f: Fixture): Promise<void> {
|
|
360
354
|
if (f.parent !== undefined) await ensureBuilt(f.parent);
|
|
361
355
|
const scopes = requireScopes();
|
|
362
356
|
const failed = (reason: string, cause?: unknown) =>
|
|
363
|
-
new Error(`
|
|
357
|
+
new Error(`failed to load fixture ${JSON.stringify(f.name)}: ${reason}`, {
|
|
364
358
|
cause,
|
|
365
359
|
});
|
|
366
360
|
let native;
|
|
@@ -377,7 +371,7 @@ async function build(f: Fixture): Promise<void> {
|
|
|
377
371
|
await runIn(scope, async () => setups.get(f)!());
|
|
378
372
|
} catch (err) {
|
|
379
373
|
const error = failed(
|
|
380
|
-
`
|
|
374
|
+
`setup failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
381
375
|
err,
|
|
382
376
|
);
|
|
383
377
|
scopes.failFixture(f.name, error.message);
|
package/testing/playwright.ts
CHANGED
|
@@ -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,7 +45,7 @@ import {Steps, wrap} from '../internal/testing/steps';
|
|
|
48
45
|
import {setup} from './mod';
|
|
49
46
|
import {browser as testBrowser, type BrowserOptions} from './system';
|
|
50
47
|
|
|
51
|
-
/** Playwright's `chromium
|
|
48
|
+
/** Minimal subset of Playwright's `chromium` required by {@link connect}. */
|
|
52
49
|
export interface Chromium<B> {
|
|
53
50
|
connectOverCDP(
|
|
54
51
|
endpointURL: string,
|
|
@@ -56,13 +53,13 @@ export interface Chromium<B> {
|
|
|
56
53
|
): Promise<B>;
|
|
57
54
|
}
|
|
58
55
|
|
|
59
|
-
/**
|
|
56
|
+
/** Options for {@link connect}. */
|
|
60
57
|
export interface ConnectOptions extends BrowserOptions {
|
|
61
|
-
/**
|
|
58
|
+
/** Additional Playwright options passed to `connectOverCDP` (e.g. `slowMo`). */
|
|
62
59
|
connect?: Record<string, unknown>;
|
|
63
60
|
}
|
|
64
61
|
|
|
65
|
-
/**
|
|
62
|
+
/** Minimal subset of a connected Playwright browser used internally. */
|
|
66
63
|
interface Connected {
|
|
67
64
|
newBrowserCDPSession(): Promise<{
|
|
68
65
|
send(method: string, params?: Record<string, unknown>): Promise<unknown>;
|
|
@@ -70,9 +67,9 @@ interface Connected {
|
|
|
70
67
|
}
|
|
71
68
|
|
|
72
69
|
/**
|
|
73
|
-
* Connects `chromium` to the current test's browser
|
|
74
|
-
*
|
|
75
|
-
*
|
|
70
|
+
* Connects Playwright's `chromium` to the current test's Encore browser
|
|
71
|
+
* (starting it if needed) and returns the Playwright `Browser`. The browser is
|
|
72
|
+
* automatically closed when the test ends.
|
|
76
73
|
*/
|
|
77
74
|
export async function connect<B>(
|
|
78
75
|
chromium: Chromium<B>,
|
|
@@ -91,31 +88,30 @@ export async function connect<B>(
|
|
|
91
88
|
}
|
|
92
89
|
|
|
93
90
|
/**
|
|
94
|
-
*
|
|
95
|
-
* frontend `name`
|
|
96
|
-
* written against.
|
|
91
|
+
* Returns the URL a page in the current test's browser uses to reach gateway
|
|
92
|
+
* or frontend `name` (matching the local `encore run` origin).
|
|
97
93
|
*/
|
|
98
94
|
export async function url(name: string): Promise<string> {
|
|
99
95
|
return (await testBrowser()).url(name);
|
|
100
96
|
}
|
|
101
97
|
|
|
102
|
-
/**
|
|
98
|
+
/** Extra Playwright Test options added by {@link extend}. */
|
|
103
99
|
export interface Options {
|
|
104
100
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
101
|
+
* Name of the frontend to use as `baseURL` so `page.goto("/")` opens it.
|
|
102
|
+
* Falls back to Playwright's configured `baseURL` when unset.
|
|
107
103
|
*/
|
|
108
104
|
frontend: string | undefined;
|
|
109
|
-
/**
|
|
105
|
+
/** Encore browser options for each test (see `system.browser`). */
|
|
110
106
|
encoreBrowser: BrowserOptions;
|
|
111
107
|
}
|
|
112
108
|
|
|
113
|
-
/** Playwright Test's `test
|
|
109
|
+
/** Minimal subset of Playwright Test's `test` object required by {@link extend}. */
|
|
114
110
|
interface Extendable {
|
|
115
111
|
extend(fixtures: Record<string, unknown>): unknown;
|
|
116
112
|
}
|
|
117
113
|
|
|
118
|
-
/**
|
|
114
|
+
/** Minimal subset of Playwright Test's `TestInfo` used internally. */
|
|
119
115
|
interface TestInfo {
|
|
120
116
|
titlePath: string[];
|
|
121
117
|
status?: string;
|
|
@@ -128,8 +124,7 @@ interface TestInfo {
|
|
|
128
124
|
|
|
129
125
|
type Hook = (ctx: {name: string; passed?: boolean}) => unknown;
|
|
130
126
|
|
|
131
|
-
/**
|
|
132
|
-
* call: Playwright Test has no hooks of its own outside a test file. */
|
|
127
|
+
/** Captures Encore's per-test scope hooks for Playwright Test fixtures. */
|
|
133
128
|
let hooks: {before: Hook; after: Hook} | undefined;
|
|
134
129
|
|
|
135
130
|
function scopeHooks(): {before: Hook; after: Hook} | undefined {
|
|
@@ -150,13 +145,13 @@ function scopeHooks(): {before: Hook; after: Hook} | undefined {
|
|
|
150
145
|
}
|
|
151
146
|
|
|
152
147
|
/**
|
|
153
|
-
* Playwright Test's `test
|
|
154
|
-
*
|
|
155
|
-
*
|
|
148
|
+
* Extends Playwright Test's `test` so each test runs in an Encore system test
|
|
149
|
+
* scope with `context` and `page` connected to Encore's managed browser
|
|
150
|
+
* (Playwright does not launch its own browser).
|
|
156
151
|
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
152
|
+
* Adds {@link Options.frontend} and {@link Options.encoreBrowser} for use with
|
|
153
|
+
* `test.use(...)`, and attaches the HTML recording to Playwright's report when
|
|
154
|
+
* a test fails.
|
|
160
155
|
*
|
|
161
156
|
* ```ts
|
|
162
157
|
* const test = extend(base);
|