@encore.dev/sdk 2.0.0-beta.8 → 2.0.0-beta.9
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 +54 -0
- package/app_meta.test.ts +25 -5
- package/app_meta.ts +43 -12
- package/config/config.test.ts +8 -12
- package/config/config.ts +16 -12
- package/config/secrets.ts +19 -10
- package/config/value.ts +13 -17
- package/cron/mod.test.ts +52 -0
- package/cron/mod.ts +9 -2
- package/dist/app_meta.d.ts +37 -12
- package/dist/app_meta.d.ts.map +1 -1
- package/dist/app_meta.js +1 -0
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +16 -12
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +5 -2
- package/dist/config/config.js.map +1 -1
- package/dist/config/secrets.d.ts +19 -10
- package/dist/config/secrets.d.ts.map +1 -1
- package/dist/config/secrets.js +19 -10
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +7 -5
- package/dist/config/value.d.ts.map +1 -1
- package/dist/config/value.js +10 -7
- package/dist/config/value.js.map +1 -1
- package/dist/cron/mod.d.ts +5 -1
- package/dist/cron/mod.d.ts.map +1 -1
- package/dist/cron/mod.js +8 -1
- package/dist/cron/mod.js.map +1 -1
- package/dist/frontends/mod.d.ts +39 -0
- package/dist/frontends/mod.d.ts.map +1 -0
- package/dist/frontends/mod.js +47 -0
- package/dist/frontends/mod.js.map +1 -0
- package/dist/gateway/mod.d.ts +3 -2
- package/dist/gateway/mod.d.ts.map +1 -1
- package/dist/gateway/mod.js +3 -2
- package/dist/gateway/mod.js.map +1 -1
- package/dist/gateways/mod.d.ts +42 -0
- package/dist/gateways/mod.d.ts.map +1 -0
- package/dist/gateways/mod.js +55 -0
- package/dist/gateways/mod.js.map +1 -0
- package/dist/internal/fetch.d.ts +4 -0
- package/dist/internal/fetch.d.ts.map +1 -1
- package/dist/internal/fetch.js +12 -1
- package/dist/internal/fetch.js.map +1 -1
- package/dist/internal/otel/http.d.ts +11 -0
- package/dist/internal/otel/http.d.ts.map +1 -0
- package/dist/internal/otel/http.js +64 -0
- package/dist/internal/otel/http.js.map +1 -0
- package/dist/internal/otel/index.d.ts +1 -1
- package/dist/internal/otel/index.d.ts.map +1 -1
- package/dist/internal/otel/index.js +1 -1
- package/dist/internal/otel/index.js.map +1 -1
- package/dist/internal/otel/provider.d.ts +3 -0
- package/dist/internal/otel/provider.d.ts.map +1 -1
- package/dist/internal/otel/provider.js +3 -0
- package/dist/internal/otel/provider.js.map +1 -1
- package/dist/internal/otel/span.d.ts +11 -1
- package/dist/internal/otel/span.d.ts.map +1 -1
- package/dist/internal/otel/span.js +25 -2
- package/dist/internal/otel/span.js.map +1 -1
- package/dist/internal/reqfields.d.ts +26 -6
- package/dist/internal/reqfields.d.ts.map +1 -1
- package/dist/internal/reqfields.js +44 -7
- package/dist/internal/reqfields.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +36 -4
- package/dist/internal/runtime/napi/napi.d.cts +99 -4
- package/dist/internal/testing/carry.d.ts +49 -0
- package/dist/internal/testing/carry.d.ts.map +1 -0
- package/dist/internal/testing/carry.js +77 -0
- package/dist/internal/testing/carry.js.map +1 -0
- package/dist/internal/testing/scope.d.ts +34 -6
- package/dist/internal/testing/scope.d.ts.map +1 -1
- package/dist/internal/testing/scope.js +103 -5
- package/dist/internal/testing/scope.js.map +1 -1
- package/dist/internal/testing/steps.d.ts +55 -0
- package/dist/internal/testing/steps.d.ts.map +1 -0
- package/dist/internal/testing/steps.js +295 -0
- package/dist/internal/testing/steps.js.map +1 -0
- package/dist/internal/testing/telemetry.d.ts +305 -0
- package/dist/internal/testing/telemetry.d.ts.map +1 -0
- package/dist/internal/testing/telemetry.js +188 -0
- package/dist/internal/testing/telemetry.js.map +1 -0
- package/dist/mod.d.ts +1 -1
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js.map +1 -1
- package/dist/pubsub/mod.d.ts +1 -1
- package/dist/pubsub/mod.d.ts.map +1 -1
- package/dist/pubsub/subscription.d.ts +6 -5
- package/dist/pubsub/subscription.d.ts.map +1 -1
- package/dist/pubsub/subscription.js.map +1 -1
- package/dist/pubsub/topic.d.ts +14 -8
- package/dist/pubsub/topic.d.ts.map +1 -1
- package/dist/pubsub/topic.js +36 -22
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +1 -18
- package/dist/reqctx/mod.d.ts.map +1 -1
- package/dist/reqctx/mod.js +1 -17
- package/dist/reqctx/mod.js.map +1 -1
- package/dist/services/index.d.ts +2 -1
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +2 -1
- package/dist/services/index.js.map +1 -1
- package/dist/storage/objects/bucket.d.ts +2 -1
- package/dist/storage/objects/bucket.d.ts.map +1 -1
- package/dist/storage/objects/bucket.js +2 -1
- package/dist/storage/objects/bucket.js.map +1 -1
- package/dist/storage/postgres/database.d.ts +5 -1
- package/dist/storage/postgres/database.d.ts.map +1 -1
- package/dist/storage/postgres/database.js +7 -3
- package/dist/storage/postgres/database.js.map +1 -1
- package/dist/storage/redis/commands.d.ts +5 -5
- package/dist/storage/redis/commands.d.ts.map +1 -1
- package/dist/storage/redis/commands.js +5 -5
- package/dist/storage/redis/commands.js.map +1 -1
- package/dist/testing/mod.d.ts +28 -5
- package/dist/testing/mod.d.ts.map +1 -1
- package/dist/testing/mod.js +52 -8
- package/dist/testing/mod.js.map +1 -1
- package/dist/testing/playwright.d.ts +93 -0
- package/dist/testing/playwright.d.ts.map +1 -0
- package/dist/testing/playwright.js +164 -0
- package/dist/testing/playwright.js.map +1 -0
- package/dist/testing/puppeteer.d.ts +36 -0
- package/dist/testing/puppeteer.d.ts.map +1 -0
- package/dist/testing/puppeteer.js +70 -0
- package/dist/testing/puppeteer.js.map +1 -0
- package/dist/testing/system.d.ts +181 -0
- package/dist/testing/system.d.ts.map +1 -0
- package/dist/testing/system.js +255 -0
- package/dist/testing/system.js.map +1 -0
- package/dist/tracing/http.d.ts +11 -0
- package/dist/tracing/http.d.ts.map +1 -0
- package/dist/tracing/http.js +34 -0
- package/dist/tracing/http.js.map +1 -0
- package/dist/tracing/mod.d.ts +1 -0
- package/dist/tracing/mod.d.ts.map +1 -1
- package/dist/tracing/mod.js +1 -0
- package/dist/tracing/mod.js.map +1 -1
- package/dist/tracing/node.d.ts +10 -0
- package/dist/tracing/node.d.ts.map +1 -0
- package/dist/tracing/node.js +142 -0
- package/dist/tracing/node.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/frontends/mod.test.ts +51 -0
- package/frontends/mod.ts +50 -0
- package/gateway/mod.ts +3 -2
- package/gateways/mod.ts +60 -0
- package/internal/fetch.ts +12 -1
- package/internal/otel/http.ts +91 -0
- package/internal/otel/index.ts +1 -1
- package/internal/otel/provider.ts +3 -0
- package/internal/otel/span.ts +25 -2
- package/internal/reqfields.ts +43 -10
- package/internal/runtime/napi/napi.cjs +36 -4
- package/internal/runtime/napi/napi.d.cts +99 -4
- package/internal/testing/carry.test.ts +242 -0
- package/internal/testing/carry.ts +101 -0
- package/internal/testing/scope.ts +106 -7
- package/internal/testing/steps.test.ts +152 -0
- package/internal/testing/steps.ts +342 -0
- package/internal/testing/telemetry.test.ts +210 -0
- package/internal/testing/telemetry.ts +466 -0
- package/mod.ts +1 -0
- package/package.json +26 -1
- package/pubsub/mod.ts +6 -1
- package/pubsub/pubsub.test.ts +1 -0
- package/pubsub/subscription.ts +6 -5
- package/pubsub/topic.ts +45 -21
- package/reqctx/mod.ts +1 -18
- package/reqctx/reqctx.test.ts +23 -0
- package/scripts/postprocess-docs.test.ts +11 -1
- package/services/index.ts +2 -1
- package/storage/objects/bucket.ts +2 -1
- package/storage/postgres/database.ts +7 -3
- package/storage/redis/commands.ts +5 -5
- package/testing/mod.ts +63 -7
- package/testing/playwright.ts +247 -0
- package/testing/puppeteer.ts +101 -0
- package/testing/system.test.ts +108 -0
- package/testing/system.ts +373 -0
- package/tracing/http.ts +49 -0
- package/tracing/mod.ts +1 -0
- package/tracing/native.test.ts +101 -4
- package/tracing/node.ts +176 -0
- package/tracing/tracing.test.ts +660 -24
package/dist/testing/mod.d.ts
CHANGED
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
* to read back with {@link published} and hand to a subscription with
|
|
20
20
|
* {@link deliver}.
|
|
21
21
|
*
|
|
22
|
+
* The tests of a system test suite, a directory with an
|
|
23
|
+
* `encore.systest.json`, run against the whole app instead: see
|
|
24
|
+
* {@link system}.
|
|
25
|
+
*
|
|
22
26
|
* @example
|
|
23
27
|
* import {deliver, published} from "@encore.dev/sdk/testing";
|
|
24
28
|
*
|
|
@@ -37,6 +41,7 @@ import { Subscription } from '../pubsub/subscription.js';
|
|
|
37
41
|
import type { OrderedTopic, Topic } from '../pubsub/topic.js';
|
|
38
42
|
import { type Hooks } from '../internal/testing/scope.js';
|
|
39
43
|
export type { Hooks } from '../internal/testing/scope.js';
|
|
44
|
+
export * as system from './system.js';
|
|
40
45
|
/** The options of {@link setup} and {@link scoped}. */
|
|
41
46
|
export interface ScopeOptions {
|
|
42
47
|
/**
|
|
@@ -61,11 +66,16 @@ export declare function setup(hooks: Hooks, options?: ScopeOptions): void;
|
|
|
61
66
|
* Wraps a test body to run in a scope of its own: for concurrent tests,
|
|
62
67
|
* which the runner's hooks cannot tell apart, or a runner without hooks.
|
|
63
68
|
*
|
|
64
|
-
*
|
|
69
|
+
* ```ts
|
|
70
|
+
* test.concurrent("x", scoped(async () => { ... }));
|
|
71
|
+
* ```
|
|
65
72
|
*
|
|
66
73
|
* The test starts from `options.fixture` if given, else from the fixture
|
|
67
74
|
* {@link useFixture} chose for it, where the runner hands the test its
|
|
68
75
|
* context (vitest, node:test). Outside test mode it runs `fn` as it is.
|
|
76
|
+
*
|
|
77
|
+
* A system test wrapped in it says how it ended in any runner, and prints
|
|
78
|
+
* what it caused in the app when it fails: see {@link system}.
|
|
69
79
|
*/
|
|
70
80
|
export declare function scoped<A extends unknown[], R>(fn: (...args: A) => Promise<R> | R, options?: ScopeOptions): (...args: A) => Promise<R>;
|
|
71
81
|
/**
|
|
@@ -75,6 +85,8 @@ export declare function scoped<A extends unknown[], R>(fn: (...args: A) => Promi
|
|
|
75
85
|
*
|
|
76
86
|
* Each message's `data` is what was published: decoded from JSON, or the
|
|
77
87
|
* bytes published as bytes.
|
|
88
|
+
*
|
|
89
|
+
* Not in a system test, where what a test publishes is sent.
|
|
78
90
|
*/
|
|
79
91
|
export declare function published<T>(topic: Topic<T> | OrderedTopic<T>): Message<T>[];
|
|
80
92
|
/**
|
|
@@ -93,11 +105,17 @@ export declare function published<T>(topic: Topic<T> | OrderedTopic<T>): Message
|
|
|
93
105
|
* error. That message stays unhandled: the next call hands it over again,
|
|
94
106
|
* its `deliveryAttempt` one more. Retry policies, ack deadlines and dead
|
|
95
107
|
* letters play no part.
|
|
108
|
+
*
|
|
109
|
+
* Not in a system test, where the subscriptions run on their own: wait for
|
|
110
|
+
* them with `system.settled()`.
|
|
96
111
|
*/
|
|
97
112
|
export declare function deliver<T>(subscription: Subscription<T>): Promise<number>;
|
|
98
113
|
/**
|
|
99
114
|
* Gives `secret` a value for the current test, in place of the app's. No
|
|
100
115
|
* other test sees it, and it is gone when the test ends.
|
|
116
|
+
*
|
|
117
|
+
* Not in a system test, whose services read their own values: give the
|
|
118
|
+
* secret its value for tests in `secrets.test.toml` instead.
|
|
101
119
|
*/
|
|
102
120
|
export declare function setSecret(secret: AnySecret, value: string | Uint8Array): void;
|
|
103
121
|
/**
|
|
@@ -105,6 +123,9 @@ export declare function setSecret(secret: AnySecret, value: string | Uint8Array)
|
|
|
105
123
|
* calling the config returns in the test from then on. No other test sees
|
|
106
124
|
* it, and it is gone when the test ends. Throws if the value does not
|
|
107
125
|
* satisfy the config's schema.
|
|
126
|
+
*
|
|
127
|
+
* Not in a system test, whose services read their own values: give the
|
|
128
|
+
* config its value for tests in its `test` config file instead.
|
|
108
129
|
*/
|
|
109
130
|
export declare function setConfig<T>(config: Config<T>, value: T): void;
|
|
110
131
|
/**
|
|
@@ -133,10 +154,12 @@ export interface FixtureOptions {
|
|
|
133
154
|
* Declares a fixture: a state `setup` leaves the app's resources in,
|
|
134
155
|
* built once per test run and copied for each test that starts from it.
|
|
135
156
|
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* const seeded = fixture("users.seeded", async () => {
|
|
159
|
+
* await db.exec`INSERT INTO users (name) VALUES ('ada'), ('grace')`;
|
|
160
|
+
* });
|
|
161
|
+
* useFixture(seeded);
|
|
162
|
+
* ```
|
|
140
163
|
*
|
|
141
164
|
* The setup is ordinary app code: its resources are the fixture's while it
|
|
142
165
|
* runs. It runs the first time a test loads the fixture, however many test
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../testing/mod.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../testing/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAe,KAAK,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,EAAC,YAAY,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAYL,KAAK,KAAK,EACX,MAAM,2BAA2B,CAAC;AAEnC,YAAY,EAAC,KAAK,EAAC,MAAM,2BAA2B,CAAC;AACrD,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AAEnC,uDAAuD;AACvD,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,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;AACtC,MAAM,WAAW,cAAc;IAC7B,kEAAkE;IAClE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,EACjC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAQT;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAclD"}
|
package/dist/testing/mod.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { setTestValue } from '../config/config.js';
|
|
2
2
|
import { Subscription } from '../pubsub/subscription.js';
|
|
3
3
|
import { fromMessageAttributes } from '../internal/reqfields.js';
|
|
4
|
-
import { begin, hookScope, isContext, requireScope, requireScopes, runIn, Scope, setupHooks, testMode, testName, } from '../internal/testing/scope.js';
|
|
4
|
+
import { begin, hookScope, isContext, requireScope, requireScopes, runIn, Scope, setupHooks, systemTest, testMode, testName, } from '../internal/testing/scope.js';
|
|
5
|
+
export * as system from './system.js';
|
|
5
6
|
/** The hooks {@link setup} was given, for {@link useFixture}. */
|
|
6
7
|
let registered;
|
|
7
8
|
/**
|
|
@@ -24,11 +25,16 @@ export function setup(hooks, options) {
|
|
|
24
25
|
* Wraps a test body to run in a scope of its own: for concurrent tests,
|
|
25
26
|
* which the runner's hooks cannot tell apart, or a runner without hooks.
|
|
26
27
|
*
|
|
27
|
-
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* test.concurrent("x", scoped(async () => { ... }));
|
|
30
|
+
* ```
|
|
28
31
|
*
|
|
29
32
|
* The test starts from `options.fixture` if given, else from the fixture
|
|
30
33
|
* {@link useFixture} chose for it, where the runner hands the test its
|
|
31
34
|
* context (vitest, node:test). Outside test mode it runs `fn` as it is.
|
|
35
|
+
*
|
|
36
|
+
* A system test wrapped in it says how it ended in any runner, and prints
|
|
37
|
+
* what it caused in the app when it fails: see {@link system}.
|
|
32
38
|
*/
|
|
33
39
|
export function scoped(fn, options) {
|
|
34
40
|
// No parameters by name: jest and bun pass a test with parameters a
|
|
@@ -37,16 +43,24 @@ export function scoped(fn, options) {
|
|
|
37
43
|
const scope = begin(testName(args[0]));
|
|
38
44
|
if (scope === null)
|
|
39
45
|
return fn(...args);
|
|
46
|
+
let failed = true;
|
|
40
47
|
try {
|
|
41
|
-
|
|
48
|
+
const result = await runIn(scope, async () => {
|
|
42
49
|
const fixture = options?.fixture !== undefined ? options.fixture : chosen(args[0]);
|
|
43
50
|
if (fixture !== undefined)
|
|
44
51
|
await choose(scope, fixture);
|
|
45
52
|
return fn(...args);
|
|
46
53
|
});
|
|
54
|
+
failed = false;
|
|
55
|
+
return result;
|
|
47
56
|
}
|
|
48
57
|
finally {
|
|
49
|
-
|
|
58
|
+
try {
|
|
59
|
+
await scope.ended(failed ? 'failed' : 'passed');
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
scope.end();
|
|
63
|
+
}
|
|
50
64
|
}
|
|
51
65
|
};
|
|
52
66
|
}
|
|
@@ -57,8 +71,14 @@ export function scoped(fn, options) {
|
|
|
57
71
|
*
|
|
58
72
|
* Each message's `data` is what was published: decoded from JSON, or the
|
|
59
73
|
* bytes published as bytes.
|
|
74
|
+
*
|
|
75
|
+
* Not in a system test, where what a test publishes is sent.
|
|
60
76
|
*/
|
|
61
77
|
export function published(topic) {
|
|
78
|
+
if (systemTest !== null) {
|
|
79
|
+
throw new Error('what a system test published is sent, and is not kept by the test: read what ' +
|
|
80
|
+
'the app did with it instead, once it has `settled`');
|
|
81
|
+
}
|
|
62
82
|
const scope = requireScope();
|
|
63
83
|
return scope.native.published(topic.name).map(msg => ({
|
|
64
84
|
data: (scope.raw.has(msg.id)
|
|
@@ -88,16 +108,30 @@ export function published(topic) {
|
|
|
88
108
|
* error. That message stays unhandled: the next call hands it over again,
|
|
89
109
|
* its `deliveryAttempt` one more. Retry policies, ack deadlines and dead
|
|
90
110
|
* letters play no part.
|
|
111
|
+
*
|
|
112
|
+
* Not in a system test, where the subscriptions run on their own: wait for
|
|
113
|
+
* them with `system.settled()`.
|
|
91
114
|
*/
|
|
92
115
|
export async function deliver(subscription) {
|
|
116
|
+
if (systemTest !== null) {
|
|
117
|
+
throw new Error('subscriptions run on their own in a system test, in the services that declare ' +
|
|
118
|
+
'them: wait for them to have handled what was published with `system.settled()`');
|
|
119
|
+
}
|
|
93
120
|
const scope = requireScope();
|
|
94
121
|
return Subscription.deliverIn(subscription, scope, requireScopes().maxDeliveries);
|
|
95
122
|
}
|
|
96
123
|
/**
|
|
97
124
|
* Gives `secret` a value for the current test, in place of the app's. No
|
|
98
125
|
* other test sees it, and it is gone when the test ends.
|
|
126
|
+
*
|
|
127
|
+
* Not in a system test, whose services read their own values: give the
|
|
128
|
+
* secret its value for tests in `secrets.test.toml` instead.
|
|
99
129
|
*/
|
|
100
130
|
export function setSecret(secret, value) {
|
|
131
|
+
if (systemTest !== null) {
|
|
132
|
+
throw new Error("a system test can't give a secret a value of its own: the services it calls read " +
|
|
133
|
+
"theirs, not the test's. Give the secret its value for tests in secrets.test.toml");
|
|
134
|
+
}
|
|
101
135
|
requireScope().native.setSecret(secret.name, Buffer.from(value));
|
|
102
136
|
}
|
|
103
137
|
/**
|
|
@@ -105,18 +139,28 @@ export function setSecret(secret, value) {
|
|
|
105
139
|
* calling the config returns in the test from then on. No other test sees
|
|
106
140
|
* it, and it is gone when the test ends. Throws if the value does not
|
|
107
141
|
* satisfy the config's schema.
|
|
142
|
+
*
|
|
143
|
+
* Not in a system test, whose services read their own values: give the
|
|
144
|
+
* config its value for tests in its `test` config file instead.
|
|
108
145
|
*/
|
|
109
146
|
export function setConfig(config, value) {
|
|
147
|
+
if (systemTest !== null) {
|
|
148
|
+
throw new Error("a system test can't give a config a value of its own: the services it calls read " +
|
|
149
|
+
"theirs, not the test's. Give the config its value for tests in its `test` config " +
|
|
150
|
+
'file (<name>.test.config.toml)');
|
|
151
|
+
}
|
|
110
152
|
setTestValue(requireScope(), config, value);
|
|
111
153
|
}
|
|
112
154
|
/**
|
|
113
155
|
* Declares a fixture: a state `setup` leaves the app's resources in,
|
|
114
156
|
* built once per test run and copied for each test that starts from it.
|
|
115
157
|
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
158
|
+
* ```ts
|
|
159
|
+
* const seeded = fixture("users.seeded", async () => {
|
|
160
|
+
* await db.exec`INSERT INTO users (name) VALUES ('ada'), ('grace')`;
|
|
161
|
+
* });
|
|
162
|
+
* useFixture(seeded);
|
|
163
|
+
* ```
|
|
120
164
|
*
|
|
121
165
|
* The setup is ordinary app code: its resources are the fixture's while it
|
|
122
166
|
* runs. It runs the first time a test loads the fixture, however many test
|
package/dist/testing/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../testing/mod.ts"],"names":[],"mappings":"
|
|
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,iEAAiE;AACjE,IAAI,UAA6B,CAAC;AAElC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,KAAK,CAAC,KAAY,EAAE,OAAsB;IACxD,UAAU,GAAG,KAAK,CAAC;IACnB,MAAM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AAG,EAAE,CAAC;QACb,MAAM,KAAK,GAAG,MAAM,CAClB,qBAAqB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EACvE,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"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A system test's browser, driven with Playwright.
|
|
3
|
+
*
|
|
4
|
+
* {@link connect} connects Playwright to the browser Encore runs for the
|
|
5
|
+
* current test (see `system.browser` in `@encore.dev/sdk/testing`): a page
|
|
6
|
+
* reaches the app where `encore run` has it, in the test session; its
|
|
7
|
+
* requests are the test's; and what it shows is recorded. Each call the
|
|
8
|
+
* test makes on a page or a locator is reported as it is written, with
|
|
9
|
+
* where it is, so that the recording and the test's telemetry say which
|
|
10
|
+
* statement had the browser do what.
|
|
11
|
+
*
|
|
12
|
+
* Playwright is the test's own, passed in: `playwright` or
|
|
13
|
+
* `playwright-core`. It drives Encore's browser over the DevTools Protocol
|
|
14
|
+
* (`connectOverCDP`), so it needs no browser of its own installed, and it
|
|
15
|
+
* is Chromium that is driven.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // With any test runner:
|
|
19
|
+
* import {chromium} from "playwright-core";
|
|
20
|
+
* import {connect, url} from "@encore.dev/sdk/testing/playwright";
|
|
21
|
+
*
|
|
22
|
+
* test("pays from the browser", async () => {
|
|
23
|
+
* const browser = await connect(chromium);
|
|
24
|
+
* const page = await browser.newPage();
|
|
25
|
+
* await page.goto(await url("web"));
|
|
26
|
+
* await page.getByRole("button", {name: "Pay"}).click();
|
|
27
|
+
* await page.getByText("Thanks!").waitFor();
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // With Playwright Test, which is its own runner:
|
|
32
|
+
* import {test as base, expect} from "@playwright/test";
|
|
33
|
+
* import {extend} from "@encore.dev/sdk/testing/playwright";
|
|
34
|
+
*
|
|
35
|
+
* const test = extend(base);
|
|
36
|
+
* test.use({frontend: "web"}); // page.goto("/") opens it
|
|
37
|
+
*
|
|
38
|
+
* test("pays from the browser", async ({page}) => {
|
|
39
|
+
* await page.goto("/");
|
|
40
|
+
* await page.getByRole("button", {name: "Pay"}).click();
|
|
41
|
+
* await expect(page.getByText("Thanks!")).toBeVisible();
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* @module
|
|
45
|
+
*/
|
|
46
|
+
import '../internal/testing/runner.js';
|
|
47
|
+
import { type BrowserOptions } from './system.js';
|
|
48
|
+
/** Playwright's `chromium`, as much of it as {@link connect} uses. */
|
|
49
|
+
export interface Chromium<B> {
|
|
50
|
+
connectOverCDP(endpointURL: string, options?: Record<string, unknown>): Promise<B>;
|
|
51
|
+
}
|
|
52
|
+
/** The options of {@link connect}. */
|
|
53
|
+
export interface ConnectOptions extends BrowserOptions {
|
|
54
|
+
/** More of Playwright's own options for `connectOverCDP`, such as `slowMo`. */
|
|
55
|
+
connect?: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Connects `chromium` to the current test's browser, starting it if the
|
|
59
|
+
* test has none yet, and returns Playwright's `Browser`. The browser ends
|
|
60
|
+
* with the test: there is nothing to close.
|
|
61
|
+
*/
|
|
62
|
+
export declare function connect<B>(chromium: Chromium<B>, options?: ConnectOptions): Promise<B>;
|
|
63
|
+
/**
|
|
64
|
+
* The URL a page of the current test's browser reaches the gateway or
|
|
65
|
+
* frontend `name` at: the one `encore run` has it at, which the frontend is
|
|
66
|
+
* written against.
|
|
67
|
+
*/
|
|
68
|
+
export declare function url(name: string): Promise<string>;
|
|
69
|
+
/** What {@link extend} adds to Playwright Test's options. */
|
|
70
|
+
export interface Options {
|
|
71
|
+
/**
|
|
72
|
+
* The frontend whose address is the tests' `baseURL`, by name: `goto("/")`
|
|
73
|
+
* then opens it. Without it the `baseURL` is the config's.
|
|
74
|
+
*/
|
|
75
|
+
frontend: string | undefined;
|
|
76
|
+
/** How each test wants its browser: see `system.browser`. */
|
|
77
|
+
encoreBrowser: BrowserOptions;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Playwright Test's `test`, made a system test's: each test runs as a test
|
|
81
|
+
* of the suite, as under any runner's adapter, and its `context` and `page`
|
|
82
|
+
* are of the browser Encore runs for it. Playwright launches no browser.
|
|
83
|
+
*
|
|
84
|
+
* It adds two options, set with `test.use`: {@link Options.frontend} and
|
|
85
|
+
* {@link Options.encoreBrowser}. A test that failed has its recording
|
|
86
|
+
* attached to its report.
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* const test = extend(base);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function extend<T>(base: T): T;
|
|
93
|
+
//# sourceMappingURL=playwright.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playwright.d.ts","sourceRoot":"","sources":["../../testing/playwright.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,OAAO,4BAA4B,CAAC;AAGpC,OAAO,EAAyB,KAAK,cAAc,EAAC,MAAM,UAAU,CAAC;AAErE,sEAAsE;AACtE,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,sCAAsC;AACtC,MAAM,WAAW,cAAe,SAAQ,cAAc;IACpD,+EAA+E;IAC/E,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;;;;GAIG;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,6DAA6D;IAC7D,aAAa,EAAE,cAAc,CAAC;CAC/B;AAyCD;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAkFpC"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A system test's browser, driven with Playwright.
|
|
3
|
+
*
|
|
4
|
+
* {@link connect} connects Playwright to the browser Encore runs for the
|
|
5
|
+
* current test (see `system.browser` in `@encore.dev/sdk/testing`): a page
|
|
6
|
+
* reaches the app where `encore run` has it, in the test session; its
|
|
7
|
+
* requests are the test's; and what it shows is recorded. Each call the
|
|
8
|
+
* test makes on a page or a locator is reported as it is written, with
|
|
9
|
+
* where it is, so that the recording and the test's telemetry say which
|
|
10
|
+
* statement had the browser do what.
|
|
11
|
+
*
|
|
12
|
+
* Playwright is the test's own, passed in: `playwright` or
|
|
13
|
+
* `playwright-core`. It drives Encore's browser over the DevTools Protocol
|
|
14
|
+
* (`connectOverCDP`), so it needs no browser of its own installed, and it
|
|
15
|
+
* is Chromium that is driven.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // With any test runner:
|
|
19
|
+
* import {chromium} from "playwright-core";
|
|
20
|
+
* import {connect, url} from "@encore.dev/sdk/testing/playwright";
|
|
21
|
+
*
|
|
22
|
+
* test("pays from the browser", async () => {
|
|
23
|
+
* const browser = await connect(chromium);
|
|
24
|
+
* const page = await browser.newPage();
|
|
25
|
+
* await page.goto(await url("web"));
|
|
26
|
+
* await page.getByRole("button", {name: "Pay"}).click();
|
|
27
|
+
* await page.getByText("Thanks!").waitFor();
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // With Playwright Test, which is its own runner:
|
|
32
|
+
* import {test as base, expect} from "@playwright/test";
|
|
33
|
+
* import {extend} from "@encore.dev/sdk/testing/playwright";
|
|
34
|
+
*
|
|
35
|
+
* const test = extend(base);
|
|
36
|
+
* test.use({frontend: "web"}); // page.goto("/") opens it
|
|
37
|
+
*
|
|
38
|
+
* test("pays from the browser", async ({page}) => {
|
|
39
|
+
* await page.goto("/");
|
|
40
|
+
* await page.getByRole("button", {name: "Pay"}).click();
|
|
41
|
+
* await expect(page.getByText("Thanks!")).toBeVisible();
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* @module
|
|
45
|
+
*/
|
|
46
|
+
import '../internal/testing/runner.js';
|
|
47
|
+
import { Steps, wrap } from '../internal/testing/steps.js';
|
|
48
|
+
import { setup } from './mod.js';
|
|
49
|
+
import { browser as testBrowser } from './system.js';
|
|
50
|
+
/**
|
|
51
|
+
* Connects `chromium` to the current test's browser, starting it if the
|
|
52
|
+
* test has none yet, and returns Playwright's `Browser`. The browser ends
|
|
53
|
+
* with the test: there is nothing to close.
|
|
54
|
+
*/
|
|
55
|
+
export async function connect(chromium, options) {
|
|
56
|
+
const info = await testBrowser(options);
|
|
57
|
+
const browser = await chromium.connectOverCDP(info.wsEndpoint, options?.connect);
|
|
58
|
+
const session = await browser.newBrowserCDPSession();
|
|
59
|
+
const steps = new Steps((method, params) => session.send(method, params));
|
|
60
|
+
return wrap(browser, 'browser', steps);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The URL a page of the current test's browser reaches the gateway or
|
|
64
|
+
* frontend `name` at: the one `encore run` has it at, which the frontend is
|
|
65
|
+
* written against.
|
|
66
|
+
*/
|
|
67
|
+
export async function url(name) {
|
|
68
|
+
return (await testBrowser()).url(name);
|
|
69
|
+
}
|
|
70
|
+
/** The hooks that begin and end a test's scope, kept for the fixture to
|
|
71
|
+
* call: Playwright Test has no hooks of its own outside a test file. */
|
|
72
|
+
let hooks;
|
|
73
|
+
function scopeHooks() {
|
|
74
|
+
if (hooks !== undefined)
|
|
75
|
+
return hooks;
|
|
76
|
+
let before;
|
|
77
|
+
let after;
|
|
78
|
+
setup({
|
|
79
|
+
beforeEach: fn => {
|
|
80
|
+
before = fn;
|
|
81
|
+
},
|
|
82
|
+
afterEach: fn => {
|
|
83
|
+
after = fn;
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
// Outside test mode nothing is registered, and the tests run as they are.
|
|
87
|
+
if (before !== undefined && after !== undefined)
|
|
88
|
+
hooks = { before, after };
|
|
89
|
+
return hooks;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Playwright Test's `test`, made a system test's: each test runs as a test
|
|
93
|
+
* of the suite, as under any runner's adapter, and its `context` and `page`
|
|
94
|
+
* are of the browser Encore runs for it. Playwright launches no browser.
|
|
95
|
+
*
|
|
96
|
+
* It adds two options, set with `test.use`: {@link Options.frontend} and
|
|
97
|
+
* {@link Options.encoreBrowser}. A test that failed has its recording
|
|
98
|
+
* attached to its report.
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* const test = extend(base);
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export function extend(base) {
|
|
105
|
+
const fixtures = {
|
|
106
|
+
frontend: [undefined, { option: true }],
|
|
107
|
+
encoreBrowser: [{}, { option: true }],
|
|
108
|
+
// The test's scope: begun before anything of the test's, ended after.
|
|
109
|
+
_encoreTest: [
|
|
110
|
+
async (
|
|
111
|
+
// Playwright Test reads a fixture's needs off this pattern, and
|
|
112
|
+
// takes nothing else for it: this one needs none.
|
|
113
|
+
// eslint-disable-next-line no-empty-pattern
|
|
114
|
+
{}, use, testInfo) => {
|
|
115
|
+
const scope = scopeHooks();
|
|
116
|
+
const ctx = {
|
|
117
|
+
name: testInfo.titlePath.slice(1).join(' › '),
|
|
118
|
+
};
|
|
119
|
+
await scope?.before(ctx);
|
|
120
|
+
try {
|
|
121
|
+
await use();
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
if (testInfo.status !== 'skipped') {
|
|
125
|
+
ctx.passed = testInfo.status === testInfo.expectedStatus;
|
|
126
|
+
}
|
|
127
|
+
await scope?.after(ctx);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{ auto: true },
|
|
131
|
+
],
|
|
132
|
+
context: async ({ playwright, contextOptions, frontend, encoreBrowser,
|
|
133
|
+
// Named so that the test's scope is begun first.
|
|
134
|
+
_encoreTest: _scope, }, use, testInfo) => {
|
|
135
|
+
const info = await testBrowser(encoreBrowser);
|
|
136
|
+
const browser = (await connect(playwright.chromium, encoreBrowser));
|
|
137
|
+
const context = await browser.newContext({
|
|
138
|
+
...contextOptions,
|
|
139
|
+
...(frontend === undefined ? {} : { baseURL: info.url(frontend) }),
|
|
140
|
+
});
|
|
141
|
+
try {
|
|
142
|
+
await use(context);
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
const failed = testInfo.status !== testInfo.expectedStatus;
|
|
146
|
+
if (failed && info.recording !== null) {
|
|
147
|
+
// Written when the test ends, a moment from now: named, so that
|
|
148
|
+
// the report says where to find it.
|
|
149
|
+
await testInfo
|
|
150
|
+
.attach('encore-recording', {
|
|
151
|
+
path: info.recording,
|
|
152
|
+
contentType: 'text/html',
|
|
153
|
+
})
|
|
154
|
+
.catch(() => undefined);
|
|
155
|
+
}
|
|
156
|
+
await context.close().catch(() => undefined);
|
|
157
|
+
await browser.close().catch(() => undefined);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
// `context` waits for the test's scope by naming it among its fixtures.
|
|
162
|
+
return base.extend(fixtures);
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=playwright.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playwright.js","sourceRoot":"","sources":["../../testing/playwright.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,OAAO,4BAA4B,CAAC;AACpC,OAAO,EAAC,KAAK,EAAE,IAAI,EAAC,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAC,KAAK,EAAC,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAC,OAAO,IAAI,WAAW,EAAsB,MAAM,UAAU,CAAC;AAuBrE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,QAAqB,EACrB,OAAwB;IAExB,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,cAAc,CAC3C,IAAI,CAAC,UAAU,EACf,OAAO,EAAE,OAAO,CACjB,CAAC;IACF,MAAM,OAAO,GAAG,MACd,OACD,CAAC,oBAAoB,EAAE,CAAC;IACzB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC,OAAiB,EAAE,SAAS,EAAE,KAAK,CAAM,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,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AAC,SAAS;wBACpB,WAAW,EAAE,WAAW;qBACzB,CAAC;yBACD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;gBAC5B,CAAC;gBACD,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;gBAC7C,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;KACF,CAAC;IACF,wEAAwE;IACxE,OAAQ,IAA8B,CAAC,MAAM,CAAC,QAAQ,CAAM,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type BrowserOptions } from './system.js';
|
|
2
|
+
/** Puppeteer, as much of it as {@link connect} uses. */
|
|
3
|
+
export interface Puppeteer<B> {
|
|
4
|
+
connect(options: {
|
|
5
|
+
browserWSEndpoint: string;
|
|
6
|
+
defaultViewport?: {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
} | null;
|
|
10
|
+
[option: string]: unknown;
|
|
11
|
+
}): Promise<B>;
|
|
12
|
+
}
|
|
13
|
+
/** The options of {@link connect}. */
|
|
14
|
+
export interface ConnectOptions extends BrowserOptions {
|
|
15
|
+
/**
|
|
16
|
+
* More of Puppeteer's own options for `connect`, such as `slowMo` and
|
|
17
|
+
* `protocolTimeout`.
|
|
18
|
+
*/
|
|
19
|
+
connect?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Connects `puppeteer` to the current test's browser, starting it if the
|
|
23
|
+
* test has none yet, and returns Puppeteer's `Browser`. The browser ends
|
|
24
|
+
* with the test: there is nothing to close.
|
|
25
|
+
*
|
|
26
|
+
* Its pages' viewport is the browser's window (`options.window`), unless
|
|
27
|
+
* `options.connect.defaultViewport` says otherwise.
|
|
28
|
+
*/
|
|
29
|
+
export declare function connect<B>(puppeteer: Puppeteer<B>, options?: ConnectOptions): Promise<B>;
|
|
30
|
+
/**
|
|
31
|
+
* The URL a page of the current test's browser reaches the gateway or
|
|
32
|
+
* frontend `name` at: the one `encore run` has it at, which the frontend is
|
|
33
|
+
* written against.
|
|
34
|
+
*/
|
|
35
|
+
export declare function url(name: string): Promise<string>;
|
|
36
|
+
//# sourceMappingURL=puppeteer.d.ts.map
|
|
@@ -0,0 +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,wDAAwD;AACxD,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,sCAAsC;AACtC,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;;;;GAIG;AACH,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEvD"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A system test's browser, driven with Puppeteer.
|
|
3
|
+
*
|
|
4
|
+
* {@link connect} connects Puppeteer to the browser Encore runs for the
|
|
5
|
+
* current test (see `system.browser` in `@encore.dev/sdk/testing`): a page
|
|
6
|
+
* reaches the app where `encore run` has it, in the test session; its
|
|
7
|
+
* requests are the test's; and what it shows is recorded.
|
|
8
|
+
*
|
|
9
|
+
* Each call the test makes on a page is reported as it is written, with
|
|
10
|
+
* where it is, so that the recording and the test's telemetry say which
|
|
11
|
+
* statement had the browser do what, and which requests came of it:
|
|
12
|
+
*
|
|
13
|
+
* page.locator("#pay").click() checkout.test.ts:14
|
|
14
|
+
* click button "Pay"
|
|
15
|
+
* POST http://localhost:4000/orders 500
|
|
16
|
+
* POST orders /orders 500
|
|
17
|
+
*
|
|
18
|
+
* Puppeteer is the test's own, passed in: `puppeteer` or `puppeteer-core`.
|
|
19
|
+
* Neither downloads a browser for this, as Encore runs its own.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* import puppeteer from "puppeteer-core";
|
|
23
|
+
* import {system} from "@encore.dev/sdk/testing";
|
|
24
|
+
* import {connect, url} from "@encore.dev/sdk/testing/puppeteer";
|
|
25
|
+
*
|
|
26
|
+
* test("pays from the browser", async () => {
|
|
27
|
+
* const browser = await connect(puppeteer);
|
|
28
|
+
* const page = await browser.newPage();
|
|
29
|
+
* await page.goto(await url("web"));
|
|
30
|
+
* await page.locator("button#pay").click();
|
|
31
|
+
* await page.waitForSelector("#thanks");
|
|
32
|
+
* await system.settled();
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* @module
|
|
36
|
+
*/
|
|
37
|
+
import { Steps, wrap } from '../internal/testing/steps.js';
|
|
38
|
+
import { browser as testBrowser } from './system.js';
|
|
39
|
+
/**
|
|
40
|
+
* Connects `puppeteer` to the current test's browser, starting it if the
|
|
41
|
+
* test has none yet, and returns Puppeteer's `Browser`. The browser ends
|
|
42
|
+
* with the test: there is nothing to close.
|
|
43
|
+
*
|
|
44
|
+
* Its pages' viewport is the browser's window (`options.window`), unless
|
|
45
|
+
* `options.connect.defaultViewport` says otherwise.
|
|
46
|
+
*/
|
|
47
|
+
export async function connect(puppeteer, options) {
|
|
48
|
+
const info = await testBrowser(options);
|
|
49
|
+
const browser = await puppeteer.connect({
|
|
50
|
+
defaultViewport: options?.window ?? { width: 1280, height: 800 },
|
|
51
|
+
...options?.connect,
|
|
52
|
+
browserWSEndpoint: info.wsEndpoint,
|
|
53
|
+
});
|
|
54
|
+
// The commands that say which statement is running go over the
|
|
55
|
+
// connection Puppeteer's own do, so they arrive in order with them.
|
|
56
|
+
const session = await browser
|
|
57
|
+
.target()
|
|
58
|
+
.createCDPSession();
|
|
59
|
+
const steps = new Steps((method, params) => session.send(method, params));
|
|
60
|
+
return wrap(browser, 'browser', steps);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The URL a page of the current test's browser reaches the gateway or
|
|
64
|
+
* frontend `name` at: the one `encore run` has it at, which the frontend is
|
|
65
|
+
* written against.
|
|
66
|
+
*/
|
|
67
|
+
export async function url(name) {
|
|
68
|
+
return (await testBrowser()).url(name);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=puppeteer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"puppeteer.js","sourceRoot":"","sources":["../../testing/puppeteer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,EAAC,KAAK,EAAE,IAAI,EAAC,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAC,OAAO,IAAI,WAAW,EAAsB,MAAM,UAAU,CAAC;AA6BrE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,SAAuB,EACvB,OAAwB;IAExB,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC;QACtC,eAAe,EAAE,OAAO,EAAE,MAAM,IAAI,EAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAC;QAC9D,GAAG,OAAO,EAAE,OAAO;QACnB,iBAAiB,EAAE,IAAI,CAAC,UAAU;KACnC,CAAC,CAAC;IACH,+DAA+D;IAC/D,oEAAoE;IACpE,MAAM,OAAO,GAAG,MAAO,OAAgC;SACpD,MAAM,EAAE;SACR,gBAAgB,EAAE,CAAC;IACtB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC,OAAiB,EAAE,SAAS,EAAE,KAAK,CAAM,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,IAAY;IACpC,OAAO,CAAC,MAAM,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC"}
|