@zitadel/testing 0.0.0 → 0.1.0-alpha.19
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 +124 -42
- package/dist/{app-env-D3W0GYhA.d.mts → app-env-Btmfcflb.d.mts} +4 -4
- package/dist/{app-env-D3W0GYhA.d.mts.map → app-env-Btmfcflb.d.mts.map} +1 -1
- package/dist/app-runner.cjs +1 -1
- package/dist/app-runner.mjs +1 -1
- package/dist/{handshake-CggSIoxF.cjs → handshake-CRKcgkfN.cjs} +3 -2
- package/dist/{handshake-CggSIoxF.cjs.map → handshake-CRKcgkfN.cjs.map} +1 -1
- package/dist/{handshake-BPtWruO8.mjs → handshake-ClzWvG8z.mjs} +3 -2
- package/dist/{handshake-BPtWruO8.mjs.map → handshake-ClzWvG8z.mjs.map} +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.mts +4 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/playwright.cjs +273 -15
- package/dist/playwright.cjs.map +1 -1
- package/dist/playwright.d.mts +173 -6
- package/dist/playwright.d.mts.map +1 -1
- package/dist/playwright.mjs +265 -16
- package/dist/playwright.mjs.map +1 -1
- package/dist/{src-DkG0V4A6.mjs → src-9dFjTIAw.mjs} +19 -17
- package/dist/src-9dFjTIAw.mjs.map +1 -0
- package/dist/{src-BIL0PdSd.cjs → src-I0KAh1zU.cjs} +447 -429
- package/dist/src-I0KAh1zU.cjs.map +1 -0
- package/dist/supervisor.cjs +2 -2
- package/dist/supervisor.mjs +2 -2
- package/package.json +5 -5
- package/dist/src-BIL0PdSd.cjs.map +0 -1
- package/dist/src-DkG0V4A6.mjs.map +0 -1
package/dist/playwright.d.mts
CHANGED
|
@@ -1,8 +1,151 @@
|
|
|
1
|
-
import { a as Identity, d as SeedUserInput, f as SeedUsersTemplate, i as ConnectedZitadel, l as MintedSession, n as applyAppEnvTemplate, o as InstanceHandle, p as SeededUser, r as nextAppEnv, t as AppEnvTemplate, u as SeedSessionInput } from "./app-env-
|
|
1
|
+
import { a as Identity, d as SeedUserInput, f as SeedUsersTemplate, i as ConnectedZitadel, l as MintedSession, n as applyAppEnvTemplate, o as InstanceHandle, p as SeededUser, r as nextAppEnv, t as AppEnvTemplate, u as SeedSessionInput } from "./app-env-Btmfcflb.mjs";
|
|
2
2
|
import { SetupPreset, SetupUseCase } from "@zitadel/config/defaults";
|
|
3
3
|
import * as _$_playwright_test0 from "@playwright/test";
|
|
4
|
-
import { Page, PlaywrightTestConfig, expect } from "@playwright/test";
|
|
4
|
+
import { Locator, Page, PlaywrightTestConfig, expect } from "@playwright/test";
|
|
5
5
|
|
|
6
|
+
//#region src/passkey.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* A virtual WebAuthn authenticator attached to one page. Ceremonies started
|
|
9
|
+
* from that page (passkey registration, passkey login) complete automatically
|
|
10
|
+
* — no OS authenticator dialog, no touch.
|
|
11
|
+
*/
|
|
12
|
+
interface VirtualPasskey {
|
|
13
|
+
/** CDP id of the virtual authenticator, for advanced raw-protocol use. */
|
|
14
|
+
authenticatorId: string;
|
|
15
|
+
/** Number of credentials the authenticator currently stores. */
|
|
16
|
+
credentialCount(): Promise<number>;
|
|
17
|
+
/** Remove the authenticator and detach the CDP session. */
|
|
18
|
+
dispose(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Attach a virtual passkey authenticator to the page via the Chrome DevTools
|
|
22
|
+
* Protocol. The options mirror a platform authenticator with discoverable
|
|
23
|
+
* credentials and automatic user presence — the profile the consumer journey
|
|
24
|
+
* has run in CI since passkey coverage became mandatory there.
|
|
25
|
+
*
|
|
26
|
+
* Chromium only: the CDP WebAuthn domain does not exist in WebKit or Firefox.
|
|
27
|
+
* The authenticator is bound to this page — drive registration and the later
|
|
28
|
+
* login from the same page, or the credential is gone. Serve the app under
|
|
29
|
+
* test on an origin WebAuthn accepts as a relying-party ID: HTTPS on a real
|
|
30
|
+
* domain, or `http://localhost` for local runs — raw IP origins such as
|
|
31
|
+
* `http://127.0.0.1` are invalid RP IDs.
|
|
32
|
+
*/
|
|
33
|
+
declare function enableVirtualPasskey(page: Page): Promise<VirtualPasskey>;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/flows.d.ts
|
|
36
|
+
/**
|
|
37
|
+
* Helpers that drive the `<zitadel-login>` widget through complete auth
|
|
38
|
+
* ceremonies, built on the widget's documented automation hooks
|
|
39
|
+
* (`zitadel-field-*` / `zitadel-input-*` on fields, `zitadel-action-*` on
|
|
40
|
+
* actions — see packages/components/README.md). Field names use the
|
|
41
|
+
* normalised hook token: the flow engine names credential fields
|
|
42
|
+
* `x-auth-methods#password`, but the hook (and this API) says `password`.
|
|
43
|
+
*
|
|
44
|
+
* The ceremony helpers assume the default flow vocabulary — steps that
|
|
45
|
+
* declare `submit` / `passkey` / `passkey_register` actions and `email` /
|
|
46
|
+
* password fields, as `default-login.json` does. They branch only on
|
|
47
|
+
* widget-observable state (which fields and actions the flow renders),
|
|
48
|
+
* because customer flow configurations legitimately vary; they never
|
|
49
|
+
* assert app state. Callers navigate to the widget first and assert their
|
|
50
|
+
* own signed-in surface afterwards. Flows with renamed actions or custom
|
|
51
|
+
* steps drive the widget directly via `flowAction` / `flowField`.
|
|
52
|
+
*/
|
|
53
|
+
interface FlowActionOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Accessible-name fallback for templates that do not emit the documented
|
|
56
|
+
* `data-testid` hooks: adds role-based button/link candidates.
|
|
57
|
+
*/
|
|
58
|
+
name?: RegExp;
|
|
59
|
+
}
|
|
60
|
+
interface FlowFieldOptions {
|
|
61
|
+
/** Label fallback for templates that do not emit the documented hooks. */
|
|
62
|
+
label?: RegExp;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* One optional registration field, filled only when the flow renders it.
|
|
66
|
+
* The value's type picks the control: a boolean drives a checkbox
|
|
67
|
+
* (`zl-checkbox`), a string first tries a select (`zl-select`) and falls
|
|
68
|
+
* back to filling a text-like input.
|
|
69
|
+
*/
|
|
70
|
+
interface ProfileEntry {
|
|
71
|
+
/** Normalised field hook token, e.g. `givenName`. */
|
|
72
|
+
field: string;
|
|
73
|
+
value: string | boolean;
|
|
74
|
+
/** Label fallback for text-like inputs on templates without hooks. */
|
|
75
|
+
label?: RegExp;
|
|
76
|
+
}
|
|
77
|
+
interface LoginCredentials {
|
|
78
|
+
email: string;
|
|
79
|
+
password: string;
|
|
80
|
+
}
|
|
81
|
+
interface RegistrationDetails {
|
|
82
|
+
email: string;
|
|
83
|
+
/** Extra fields some flows require at registration, filled if rendered. */
|
|
84
|
+
profile?: ProfileEntry[];
|
|
85
|
+
}
|
|
86
|
+
interface PasswordRegistrationDetails extends RegistrationDetails {
|
|
87
|
+
password: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Locator for a flow action control by its declared action name. Matches
|
|
91
|
+
* every hook shape the default template emits — host testid, native
|
|
92
|
+
* shadow button/link testids, and the raw `action`/`data-action`
|
|
93
|
+
* attributes (the recover link carries only `data-action`).
|
|
94
|
+
*/
|
|
95
|
+
declare function flowAction(page: Page, action: string, options?: FlowActionOptions): Locator;
|
|
96
|
+
/**
|
|
97
|
+
* Locator for a flow field's input by its normalised hook token
|
|
98
|
+
* (`email`, `password`, a user-schema property name).
|
|
99
|
+
*/
|
|
100
|
+
declare function flowField(page: Page, field: string, options?: FlowFieldOptions): Locator;
|
|
101
|
+
/** Click a flow action (auto-waits like any locator click). */
|
|
102
|
+
declare function clickFlowAction(page: Page, action: string, options?: FlowActionOptions): Promise<void>;
|
|
103
|
+
/** Fill a flow field (auto-waits like any locator fill). */
|
|
104
|
+
declare function fillFlowField(page: Page, field: string, value: string, options?: FlowFieldOptions): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Sign in with email and password from the flow's entry step. Handles both
|
|
107
|
+
* the default split shape (identifier → password) and flows that render
|
|
108
|
+
* the password field on the entry step.
|
|
109
|
+
*/
|
|
110
|
+
declare function loginWithPassword(page: Page, {
|
|
111
|
+
email,
|
|
112
|
+
password
|
|
113
|
+
}: LoginCredentials): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Sign in with a passkey. With `email`, fills the identifier and takes the
|
|
116
|
+
* step's passkey action; without, taps the entry step's passkey action
|
|
117
|
+
* directly (discoverable-credential one-tap, e.g. the passkey-first
|
|
118
|
+
* preset). Pair with `enableVirtualPasskey` / the `passkey` fixture in
|
|
119
|
+
* headless runs — the ceremony completes automatically once the widget
|
|
120
|
+
* issues the WebAuthn challenge.
|
|
121
|
+
*/
|
|
122
|
+
declare function loginWithPasskey(page: Page, options?: {
|
|
123
|
+
email?: string;
|
|
124
|
+
}): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Register a new user with a password: enter the (unknown) identifier,
|
|
127
|
+
* advance into the registration step, continue on the password path, and
|
|
128
|
+
* submit the password. Ends when the final submit is clicked — assert your
|
|
129
|
+
* app's signed-in surface afterwards. Flows that route through steps the
|
|
130
|
+
* default flow does not (e.g. a passkey upsell) need caller-side handling
|
|
131
|
+
* after this returns.
|
|
132
|
+
*/
|
|
133
|
+
declare function registerWithPassword(page: Page, {
|
|
134
|
+
email,
|
|
135
|
+
password,
|
|
136
|
+
profile
|
|
137
|
+
}: PasswordRegistrationDetails): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Register a new user with a passkey: enter the (unknown) identifier,
|
|
140
|
+
* advance into the registration step, and take its `passkey_register`
|
|
141
|
+
* action. Requires an authenticator (see `loginWithPasskey`). The default
|
|
142
|
+
* flow completes registration from the ceremony directly.
|
|
143
|
+
*/
|
|
144
|
+
declare function registerWithPasskey(page: Page, {
|
|
145
|
+
email,
|
|
146
|
+
profile
|
|
147
|
+
}: RegistrationDetails): Promise<void>;
|
|
148
|
+
//#endregion
|
|
6
149
|
//#region src/orchestration.d.ts
|
|
7
150
|
interface SupervisorConfig {
|
|
8
151
|
/** Fixed port: the config process must know the health URL up front. */
|
|
@@ -51,8 +194,20 @@ interface WithZitadelOptions {
|
|
|
51
194
|
keep?: boolean; /** webServer readiness timeout for the boot; cold boot dominates it. */
|
|
52
195
|
bootTimeoutMs?: number;
|
|
53
196
|
};
|
|
54
|
-
/**
|
|
55
|
-
|
|
197
|
+
/**
|
|
198
|
+
* The app dev server to run against the instance.
|
|
199
|
+
*
|
|
200
|
+
* Omit it when the **instance itself serves the app** — the Zitadel binary
|
|
201
|
+
* embeds the console and hosted login shells at `/ui/console/` and
|
|
202
|
+
* `/ui/login/`, so there is no second server to boot and no env to hand it.
|
|
203
|
+
* Only the supervisor entry is generated, and `appOrigin` must then be the
|
|
204
|
+
* instance's own local origin — `http://localhost:<port>` (or another
|
|
205
|
+
* loopback alias); nothing else is served in this mode. This is the only
|
|
206
|
+
* configuration that exercises the production path — under a dev server,
|
|
207
|
+
* the app's proxy rewrites API requests that the binary would serve
|
|
208
|
+
* directly.
|
|
209
|
+
*/
|
|
210
|
+
app?: {
|
|
56
211
|
/** Spawn argv (no shell), e.g. ["corepack", "pnpm", "--filter", "my-app", "dev"]. */command: string[]; /** Working directory for the app command. */
|
|
57
212
|
cwd: string; /** Path on `appOrigin` Playwright polls for readiness, e.g. "/login". */
|
|
58
213
|
readyPath: string;
|
|
@@ -81,13 +236,19 @@ interface WithZitadelOptions {
|
|
|
81
236
|
* });
|
|
82
237
|
* ```
|
|
83
238
|
*
|
|
239
|
+
* Omit `app` when the instance serves the app itself (the binary's embedded
|
|
240
|
+
* `/ui/console/` and `/ui/login/` surfaces): only the boot entry is
|
|
241
|
+
* generated, and `appOrigin` must be the instance's own origin.
|
|
242
|
+
*
|
|
84
243
|
* Also points ZITADEL_TESTING_HANDSHAKE at the handshake file so the
|
|
85
244
|
* `@zitadel/testing/playwright` fixtures resolve the instance — Playwright
|
|
86
245
|
* workers re-evaluate the config, which re-applies this for every process
|
|
87
246
|
* that needs it. The returned value is plain data; append your own entries
|
|
88
247
|
* to `webServer` if the suite needs additional servers.
|
|
89
248
|
*/
|
|
90
|
-
declare function withZitadel(options: WithZitadelOptions, /** Test seam: alternative executable resolution. */
|
|
249
|
+
declare function withZitadel(options: WithZitadelOptions, /** Test seam: alternative executable resolution. */
|
|
250
|
+
|
|
251
|
+
resolveEntry?: (name: "supervisor" | "app-runner") => string): {
|
|
91
252
|
webServer: WebServerEntry[];
|
|
92
253
|
};
|
|
93
254
|
//#endregion
|
|
@@ -113,6 +274,12 @@ interface ZitadelTestFixtures {
|
|
|
113
274
|
* `use.baseURL` (every withZitadel consumer sets it).
|
|
114
275
|
*/
|
|
115
276
|
authenticatedPage: AuthenticatedPage;
|
|
277
|
+
/**
|
|
278
|
+
* Virtual passkey authenticator attached to the default `page`, disposed on
|
|
279
|
+
* teardown. On-demand: tests that don't request it pay nothing. Chromium
|
|
280
|
+
* only — see `enableVirtualPasskey` for the constraints.
|
|
281
|
+
*/
|
|
282
|
+
passkey: VirtualPasskey;
|
|
116
283
|
}
|
|
117
284
|
interface ZitadelWorkerFixtures {
|
|
118
285
|
/** Connection to the suite's instance, resolved once per worker. */
|
|
@@ -120,5 +287,5 @@ interface ZitadelWorkerFixtures {
|
|
|
120
287
|
}
|
|
121
288
|
declare const test: _$_playwright_test0.TestType<_$_playwright_test0.PlaywrightTestArgs & _$_playwright_test0.PlaywrightTestOptions & ZitadelTestFixtures, _$_playwright_test0.PlaywrightWorkerArgs & _$_playwright_test0.PlaywrightWorkerOptions & ZitadelWorkerFixtures>;
|
|
122
289
|
//#endregion
|
|
123
|
-
export { type AppEnvTemplate, AuthenticatedPage, type ConnectedZitadel, type Identity, type InstanceHandle, type MintedSession, type SeedSessionInput, type SeedUserInput, type SeedUsersTemplate, type SeededUser, type WithZitadelOptions, ZitadelTestFixtures, ZitadelWorkerFixtures, applyAppEnvTemplate, expect, nextAppEnv, test, withZitadel };
|
|
290
|
+
export { type AppEnvTemplate, AuthenticatedPage, type ConnectedZitadel, type FlowActionOptions, type FlowFieldOptions, type Identity, type InstanceHandle, type LoginCredentials, type MintedSession, type PasswordRegistrationDetails, type ProfileEntry, type RegistrationDetails, type SeedSessionInput, type SeedUserInput, type SeedUsersTemplate, type SeededUser, type VirtualPasskey, type WithZitadelOptions, ZitadelTestFixtures, ZitadelWorkerFixtures, applyAppEnvTemplate, clickFlowAction, enableVirtualPasskey, expect, fillFlowField, flowAction, flowField, loginWithPasskey, loginWithPassword, nextAppEnv, registerWithPasskey, registerWithPassword, test, withZitadel };
|
|
124
291
|
//# sourceMappingURL=playwright.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playwright.d.mts","names":[],"sources":["../src/orchestration.ts","../src/playwright-config.ts","../src/playwright.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"playwright.d.mts","names":[],"sources":["../src/passkey.ts","../src/flows.ts","../src/orchestration.ts","../src/playwright-config.ts","../src/playwright.ts"],"mappings":"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"}
|
package/dist/playwright.mjs
CHANGED
|
@@ -1,10 +1,236 @@
|
|
|
1
|
-
import { a as nextAppEnv, i as applyAppEnvTemplate,
|
|
2
|
-
import { t as connectZitadel } from "./src-
|
|
1
|
+
import { a as nextAppEnv, i as applyAppEnvTemplate, n as waitForHandshake } from "./handshake-ClzWvG8z.mjs";
|
|
2
|
+
import { t as connectZitadel } from "./src-9dFjTIAw.mjs";
|
|
3
3
|
import { n as HANDSHAKE_ENV, r as SUPERVISOR_CONFIG_ENV, t as APP_RUNNER_CONFIG_ENV } from "./orchestration-C640_1Lg.mjs";
|
|
4
4
|
import { extname, isAbsolute, join } from "node:path";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { expect, test as test$1 } from "@playwright/test";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
+
//#region src/passkey.ts
|
|
9
|
+
/**
|
|
10
|
+
* Attach a virtual passkey authenticator to the page via the Chrome DevTools
|
|
11
|
+
* Protocol. The options mirror a platform authenticator with discoverable
|
|
12
|
+
* credentials and automatic user presence — the profile the consumer journey
|
|
13
|
+
* has run in CI since passkey coverage became mandatory there.
|
|
14
|
+
*
|
|
15
|
+
* Chromium only: the CDP WebAuthn domain does not exist in WebKit or Firefox.
|
|
16
|
+
* The authenticator is bound to this page — drive registration and the later
|
|
17
|
+
* login from the same page, or the credential is gone. Serve the app under
|
|
18
|
+
* test on an origin WebAuthn accepts as a relying-party ID: HTTPS on a real
|
|
19
|
+
* domain, or `http://localhost` for local runs — raw IP origins such as
|
|
20
|
+
* `http://127.0.0.1` are invalid RP IDs.
|
|
21
|
+
*/
|
|
22
|
+
async function enableVirtualPasskey(page) {
|
|
23
|
+
let client;
|
|
24
|
+
try {
|
|
25
|
+
client = await page.context().newCDPSession(page);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
throw new Error("enableVirtualPasskey: could not open a CDP session — passkey testing needs Chromium's virtual authenticator, so run passkey specs in a Chromium project.", { cause: error });
|
|
28
|
+
}
|
|
29
|
+
let authenticatorId;
|
|
30
|
+
try {
|
|
31
|
+
await client.send("WebAuthn.enable");
|
|
32
|
+
({authenticatorId} = await client.send("WebAuthn.addVirtualAuthenticator", { options: {
|
|
33
|
+
protocol: "ctap2",
|
|
34
|
+
transport: "internal",
|
|
35
|
+
hasResidentKey: true,
|
|
36
|
+
hasUserVerification: true,
|
|
37
|
+
isUserVerified: true,
|
|
38
|
+
automaticPresenceSimulation: true
|
|
39
|
+
} }));
|
|
40
|
+
} catch (error) {
|
|
41
|
+
await client.detach().catch(() => void 0);
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
authenticatorId,
|
|
46
|
+
async credentialCount() {
|
|
47
|
+
const { credentials } = await client.send("WebAuthn.getCredentials", { authenticatorId });
|
|
48
|
+
return credentials.length;
|
|
49
|
+
},
|
|
50
|
+
async dispose() {
|
|
51
|
+
try {
|
|
52
|
+
await client.send("WebAuthn.removeVirtualAuthenticator", { authenticatorId });
|
|
53
|
+
} catch {} finally {
|
|
54
|
+
await client.detach().catch(() => void 0);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/flows.ts
|
|
61
|
+
/**
|
|
62
|
+
* A union locator resolves in DOM order across the whole page, so every
|
|
63
|
+
* candidate built from a broad selector — accessible names, labels, the
|
|
64
|
+
* generic `data-action` attribute — is scoped to the `<zitadel-login>`
|
|
65
|
+
* host; otherwise a same-named control in the app's own chrome (header
|
|
66
|
+
* nav, footer forms) could win the union. The host element exists no
|
|
67
|
+
* matter what the tenant's template renders, so these fallbacks keep
|
|
68
|
+
* working for custom templates that emit no automation hooks — the case
|
|
69
|
+
* they exist for. The `zitadel-*` testid hooks and the `zl-button` atom
|
|
70
|
+
* are namespaced and stay page-global.
|
|
71
|
+
*/
|
|
72
|
+
function widgetRoot(page) {
|
|
73
|
+
return page.locator("zitadel-login");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Escape a value for use inside a double-quoted CSS attribute selector,
|
|
77
|
+
* per the CSSOM "serialize a string" rules: NUL becomes U+FFFD, control
|
|
78
|
+
* characters become hex code-point escapes, quote and backslash are
|
|
79
|
+
* backslash-escaped. C1 controls (U+0080–U+009F) are escaped too — CSSOM
|
|
80
|
+
* itself leaves them literal, but the escaped form is equivalent and
|
|
81
|
+
* survives stricter-than-spec selector parsers. Anything the flow schema
|
|
82
|
+
* accepts as an action name yields a parseable selector.
|
|
83
|
+
*/
|
|
84
|
+
function cssAttributeValue(value) {
|
|
85
|
+
let out = "";
|
|
86
|
+
for (const ch of value) {
|
|
87
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
88
|
+
if (code === 0) out += "�";
|
|
89
|
+
else if (code <= 31 || code >= 127 && code <= 159) out += `\\${code.toString(16)} `;
|
|
90
|
+
else if (ch === "\"" || ch === "\\") out += `\\${ch}`;
|
|
91
|
+
else out += ch;
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Locator for a flow action control by its declared action name. Matches
|
|
97
|
+
* every hook shape the default template emits — host testid, native
|
|
98
|
+
* shadow button/link testids, and the raw `action`/`data-action`
|
|
99
|
+
* attributes (the recover link carries only `data-action`).
|
|
100
|
+
*/
|
|
101
|
+
function flowAction(page, action, options = {}) {
|
|
102
|
+
const attributeSafe = cssAttributeValue(action);
|
|
103
|
+
let candidates = page.getByTestId(`zitadel-action-${action}`).or(page.getByTestId(`zitadel-action-${action}-button`)).or(page.getByTestId(`zitadel-action-${action}-link`)).or(page.locator(`zl-button[action="${attributeSafe}"]`)).or(widgetRoot(page).locator(`[data-action="${attributeSafe}"]`));
|
|
104
|
+
if (options.name) candidates = candidates.or(widgetRoot(page).getByRole("button", { name: options.name })).or(widgetRoot(page).getByRole("link", { name: options.name }));
|
|
105
|
+
return candidates.first();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Locator for a flow field's input by its normalised hook token
|
|
109
|
+
* (`email`, `password`, a user-schema property name).
|
|
110
|
+
*/
|
|
111
|
+
function flowField(page, field, options = {}) {
|
|
112
|
+
let candidates = page.getByTestId(`zitadel-input-${field}`).or(page.getByTestId(`zitadel-field-${field}`).locator("input"));
|
|
113
|
+
if (options.label) candidates = candidates.or(widgetRoot(page).getByLabel(options.label));
|
|
114
|
+
return candidates.first();
|
|
115
|
+
}
|
|
116
|
+
/** Click a flow action (auto-waits like any locator click). */
|
|
117
|
+
async function clickFlowAction(page, action, options) {
|
|
118
|
+
await flowAction(page, action, options).click();
|
|
119
|
+
}
|
|
120
|
+
/** Fill a flow field (auto-waits like any locator fill). */
|
|
121
|
+
async function fillFlowField(page, field, value, options) {
|
|
122
|
+
await flowField(page, field, options).fill(value);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Sign in with email and password from the flow's entry step. Handles both
|
|
126
|
+
* the default split shape (identifier → password) and flows that render
|
|
127
|
+
* the password field on the entry step.
|
|
128
|
+
*/
|
|
129
|
+
async function loginWithPassword(page, { email, password }) {
|
|
130
|
+
await emailField(page).fill(email);
|
|
131
|
+
const password_ = passwordField(page);
|
|
132
|
+
if (!await password_.isVisible().catch(() => false)) await flowAction(page, "submit").click();
|
|
133
|
+
await password_.fill(password);
|
|
134
|
+
await flowAction(page, "submit").click();
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Sign in with a passkey. With `email`, fills the identifier and takes the
|
|
138
|
+
* step's passkey action; without, taps the entry step's passkey action
|
|
139
|
+
* directly (discoverable-credential one-tap, e.g. the passkey-first
|
|
140
|
+
* preset). Pair with `enableVirtualPasskey` / the `passkey` fixture in
|
|
141
|
+
* headless runs — the ceremony completes automatically once the widget
|
|
142
|
+
* issues the WebAuthn challenge.
|
|
143
|
+
*/
|
|
144
|
+
async function loginWithPasskey(page, options = {}) {
|
|
145
|
+
if (options.email !== void 0) await emailField(page).fill(options.email);
|
|
146
|
+
await flowAction(page, "passkey").click();
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Register a new user with a password: enter the (unknown) identifier,
|
|
150
|
+
* advance into the registration step, continue on the password path, and
|
|
151
|
+
* submit the password. Ends when the final submit is clicked — assert your
|
|
152
|
+
* app's signed-in surface afterwards. Flows that route through steps the
|
|
153
|
+
* default flow does not (e.g. a passkey upsell) need caller-side handling
|
|
154
|
+
* after this returns.
|
|
155
|
+
*/
|
|
156
|
+
async function registerWithPassword(page, { email, password, profile }) {
|
|
157
|
+
await advanceToRegistration(page, email, profile);
|
|
158
|
+
const password_ = passwordField(page);
|
|
159
|
+
if (!await password_.isVisible().catch(() => false)) await flowAction(page, "submit").click();
|
|
160
|
+
await password_.fill(password);
|
|
161
|
+
await flowAction(page, "submit").click();
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Register a new user with a passkey: enter the (unknown) identifier,
|
|
165
|
+
* advance into the registration step, and take its `passkey_register`
|
|
166
|
+
* action. Requires an authenticator (see `loginWithPasskey`). The default
|
|
167
|
+
* flow completes registration from the ceremony directly.
|
|
168
|
+
*/
|
|
169
|
+
async function registerWithPasskey(page, { email, profile }) {
|
|
170
|
+
await advanceToRegistration(page, email, profile);
|
|
171
|
+
await flowAction(page, "passkey_register").click();
|
|
172
|
+
}
|
|
173
|
+
function emailField(page) {
|
|
174
|
+
return flowField(page, "email", { label: /email/i });
|
|
175
|
+
}
|
|
176
|
+
function passwordField(page) {
|
|
177
|
+
return flowField(page, "password", { label: /password/i });
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* From the entry step: submit the unknown identifier (the default flow's
|
|
181
|
+
* `user_not_found` transition routes to registration), or take an explicit
|
|
182
|
+
* `register` navigate action when the entry step is a combined
|
|
183
|
+
* email+password step — there, submitting would attempt a password sign-in
|
|
184
|
+
* instead. Then wait for the registration step and fill what it renders.
|
|
185
|
+
*/
|
|
186
|
+
async function advanceToRegistration(page, email, profile) {
|
|
187
|
+
await emailField(page).fill(email);
|
|
188
|
+
if (await passwordField(page).isVisible().catch(() => false)) await flowAction(page, "register").click();
|
|
189
|
+
else await flowAction(page, "submit").click();
|
|
190
|
+
await expectRegistrationStep(page);
|
|
191
|
+
await fillIfVisible(emailField(page), email);
|
|
192
|
+
for (const entry of profile ?? []) await fillProfileEntry(page, entry);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Fill one registration field with the verb its control needs: booleans
|
|
196
|
+
* check the `zl-checkbox` native input, strings prefer the `zl-select`
|
|
197
|
+
* native select (option matched by value, falling back to label) and
|
|
198
|
+
* otherwise fill a text-like input. The select/checkbox natives carry the
|
|
199
|
+
* name-first testids the atoms document (`zitadel-select-*`,
|
|
200
|
+
* `zitadel-checkbox-*`); templates without those hooks drive such fields
|
|
201
|
+
* via their own locators.
|
|
202
|
+
*/
|
|
203
|
+
async function fillProfileEntry(page, entry) {
|
|
204
|
+
if (typeof entry.value === "boolean") {
|
|
205
|
+
const checkbox = page.getByTestId(`zitadel-checkbox-${entry.field}`).first();
|
|
206
|
+
if (await checkbox.isVisible().catch(() => false)) await checkbox.setChecked(entry.value);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const select = page.getByTestId(`zitadel-select-${entry.field}`).first();
|
|
210
|
+
if (await select.isVisible().catch(() => false)) {
|
|
211
|
+
await select.selectOption(entry.value);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
await fillIfVisible(flowField(page, entry.field, { label: entry.label }), entry.value);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Barrier between the entry submit and probing the registration step's
|
|
218
|
+
* fields: without it, optional-field probes race the re-render and read
|
|
219
|
+
* the outgoing step. The default flow's registration step declares
|
|
220
|
+
* `passkey_register` — a structural, locale-independent signal; the
|
|
221
|
+
* heading regex covers password-only flows on the default English
|
|
222
|
+
* template.
|
|
223
|
+
*/
|
|
224
|
+
async function expectRegistrationStep(page) {
|
|
225
|
+
await flowAction(page, "passkey_register").or(widgetRoot(page).getByRole("heading", { name: /create|register|sign up|no-account/i })).first().waitFor({
|
|
226
|
+
state: "visible",
|
|
227
|
+
timeout: 3e4
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
async function fillIfVisible(field, value) {
|
|
231
|
+
if (await field.isVisible().catch(() => false)) await field.fill(value);
|
|
232
|
+
}
|
|
233
|
+
//#endregion
|
|
8
234
|
//#region src/playwright-config.ts
|
|
9
235
|
/**
|
|
10
236
|
* Generate the Playwright `webServer` entries that boot an ephemeral seeded
|
|
@@ -18,6 +244,10 @@ import { fileURLToPath } from "node:url";
|
|
|
18
244
|
* });
|
|
19
245
|
* ```
|
|
20
246
|
*
|
|
247
|
+
* Omit `app` when the instance serves the app itself (the binary's embedded
|
|
248
|
+
* `/ui/console/` and `/ui/login/` surfaces): only the boot entry is
|
|
249
|
+
* generated, and `appOrigin` must be the instance's own origin.
|
|
250
|
+
*
|
|
21
251
|
* Also points ZITADEL_TESTING_HANDSHAKE at the handshake file so the
|
|
22
252
|
* `@zitadel/testing/playwright` fixtures resolve the instance — Playwright
|
|
23
253
|
* workers re-evaluate the config, which re-applies this for every process
|
|
@@ -30,9 +260,18 @@ function withZitadel(options, resolveEntry = entryPoint) {
|
|
|
30
260
|
if (!Number.isInteger(port) || port <= 0) throw new Error(`withZitadel: port must be a positive integer, got ${port}`);
|
|
31
261
|
const origin = URL.canParse(appOrigin) ? new URL(appOrigin) : void 0;
|
|
32
262
|
if (!origin || origin.protocol !== "http:" && origin.protocol !== "https:" || origin.pathname !== "/" || origin.search !== "" || origin.hash !== "") throw new Error(`withZitadel: appOrigin must be an origin like "http://localhost:3002", got "${appOrigin}"`);
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
263
|
+
if (app === void 0) {
|
|
264
|
+
const loopbackHosts = new Set([
|
|
265
|
+
"localhost",
|
|
266
|
+
"127.0.0.1",
|
|
267
|
+
"[::1]"
|
|
268
|
+
]);
|
|
269
|
+
if (origin.protocol !== "http:" || !loopbackHosts.has(origin.hostname) || (origin.port || "80") !== String(port)) throw new Error(`withZitadel: with no \`app\`, the instance itself serves the app, so appOrigin must be its local origin (http://localhost:${port}); got "${appOrigin}".`);
|
|
270
|
+
} else {
|
|
271
|
+
if (!app.readyPath.startsWith("/")) throw new Error(`withZitadel: app.readyPath must start with "/", got "${app.readyPath}"`);
|
|
272
|
+
if (app.command.length === 0) throw new Error("withZitadel: app.command must not be empty");
|
|
273
|
+
if (!isAbsolute(app.cwd)) throw new Error(`withZitadel: app.cwd must be absolute, got "${app.cwd}"`);
|
|
274
|
+
}
|
|
36
275
|
for (const [label, value] of [
|
|
37
276
|
["zitadel.serverBinary", options.zitadel?.serverBinary],
|
|
38
277
|
["zitadel.dir", options.zitadel?.dir],
|
|
@@ -51,13 +290,7 @@ function withZitadel(options, resolveEntry = entryPoint) {
|
|
|
51
290
|
preset: options.zitadel?.preset,
|
|
52
291
|
useCase: options.zitadel?.useCase
|
|
53
292
|
};
|
|
54
|
-
const
|
|
55
|
-
command: app.command,
|
|
56
|
-
cwd: app.cwd,
|
|
57
|
-
env: app.env,
|
|
58
|
-
handshakeTimeoutMs: app.readyTimeoutMs ?? 18e4
|
|
59
|
-
};
|
|
60
|
-
return { webServer: [{
|
|
293
|
+
const supervisorEntry = {
|
|
61
294
|
command: `node ${JSON.stringify(resolveEntry("supervisor"))}`,
|
|
62
295
|
url: `http://localhost:${port}/healthz`,
|
|
63
296
|
reuseExistingServer: false,
|
|
@@ -73,7 +306,15 @@ function withZitadel(options, resolveEntry = entryPoint) {
|
|
|
73
306
|
signal: "SIGTERM",
|
|
74
307
|
timeout: 3e4
|
|
75
308
|
}
|
|
76
|
-
}
|
|
309
|
+
};
|
|
310
|
+
if (app === void 0) return { webServer: [supervisorEntry] };
|
|
311
|
+
const appRunnerConfig = {
|
|
312
|
+
command: app.command,
|
|
313
|
+
cwd: app.cwd,
|
|
314
|
+
env: app.env,
|
|
315
|
+
handshakeTimeoutMs: app.readyTimeoutMs ?? 18e4
|
|
316
|
+
};
|
|
317
|
+
return { webServer: [supervisorEntry, {
|
|
77
318
|
command: `node ${JSON.stringify(resolveEntry("app-runner"))}`,
|
|
78
319
|
url: new URL(app.readyPath, appOrigin).toString(),
|
|
79
320
|
reuseExistingServer: false,
|
|
@@ -110,8 +351,11 @@ const test = test$1.extend({
|
|
|
110
351
|
zitadel: [async ({}, use) => {
|
|
111
352
|
const handshakePath = process.env.ZITADEL_TESTING_HANDSHAKE;
|
|
112
353
|
if (!handshakePath) throw new Error("ZITADEL_TESTING_HANDSHAKE is not set. Point it at the handshake file written by the script that boots the instance (see @zitadel/testing docs).");
|
|
113
|
-
await use(connectZitadel(
|
|
114
|
-
}, {
|
|
354
|
+
await use(connectZitadel(await waitForHandshake(handshakePath)));
|
|
355
|
+
}, {
|
|
356
|
+
scope: "worker",
|
|
357
|
+
auto: true
|
|
358
|
+
}],
|
|
115
359
|
seed: async ({ zitadel, baseURL }, use) => {
|
|
116
360
|
await use({
|
|
117
361
|
user: (input) => zitadel.seedUser(input),
|
|
@@ -123,6 +367,11 @@ const test = test$1.extend({
|
|
|
123
367
|
})
|
|
124
368
|
});
|
|
125
369
|
},
|
|
370
|
+
passkey: async ({ page }, use) => {
|
|
371
|
+
const passkey = await enableVirtualPasskey(page);
|
|
372
|
+
await use(passkey);
|
|
373
|
+
await passkey.dispose();
|
|
374
|
+
},
|
|
126
375
|
authenticatedPage: async ({ browser, zitadel, baseURL }, use) => {
|
|
127
376
|
if (!baseURL) throw new Error("authenticatedPage requires `use.baseURL` so the session cookie can be scoped to the app under test.");
|
|
128
377
|
const session = await zitadel.seedSession({ origin: baseURL });
|
|
@@ -141,6 +390,6 @@ const test = test$1.extend({
|
|
|
141
390
|
}
|
|
142
391
|
});
|
|
143
392
|
//#endregion
|
|
144
|
-
export { applyAppEnvTemplate, expect, nextAppEnv, test, withZitadel };
|
|
393
|
+
export { applyAppEnvTemplate, clickFlowAction, enableVirtualPasskey, expect, fillFlowField, flowAction, flowField, loginWithPasskey, loginWithPassword, nextAppEnv, registerWithPasskey, registerWithPassword, test, withZitadel };
|
|
145
394
|
|
|
146
395
|
//# sourceMappingURL=playwright.mjs.map
|