@owlmeans/test-ui 0.1.18-rc.9 → 0.1.18
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 +10 -7
- package/agent-meta/manifest.json +3 -3
- package/agent-meta/skills/testing-ui/SKILL.md +209 -23
- package/build/browser/types.d.ts +22 -0
- package/build/browser/types.d.ts.map +1 -0
- package/build/browser/types.js +2 -0
- package/build/browser/types.js.map +1 -0
- package/build/browser.d.ts +8 -16
- package/build/browser.d.ts.map +1 -1
- package/build/browser.js +38 -41
- package/build/browser.js.map +1 -1
- package/build/consent/types.d.ts +36 -0
- package/build/consent/types.d.ts.map +1 -0
- package/build/consent/types.js +2 -0
- package/build/consent/types.js.map +1 -0
- package/build/consent.d.ts +4 -0
- package/build/consent.d.ts.map +1 -0
- package/build/consent.js +41 -0
- package/build/consent.js.map +1 -0
- package/build/consts.local.d.ts +9 -0
- package/build/consts.local.d.ts.map +1 -0
- package/build/consts.local.js +9 -0
- package/build/consts.local.js.map +1 -0
- package/build/index.d.ts +8 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -0
- package/build/index.js.map +1 -1
- package/build/marketing-consent.d.ts +5 -0
- package/build/marketing-consent.d.ts.map +1 -0
- package/build/marketing-consent.js +4 -0
- package/build/marketing-consent.js.map +1 -0
- package/build/mount.d.ts +2 -27
- package/build/mount.d.ts.map +1 -1
- package/build/mount.js +11 -4
- package/build/mount.js.map +1 -1
- package/build/page/types.d.ts +141 -0
- package/build/page/types.d.ts.map +1 -0
- package/build/page/types.js +2 -0
- package/build/page/types.js.map +1 -0
- package/build/page.d.ts +4 -0
- package/build/page.d.ts.map +1 -0
- package/build/page.js +168 -0
- package/build/page.js.map +1 -0
- package/build/supervisor/types.d.ts +56 -0
- package/build/supervisor/types.d.ts.map +1 -0
- package/build/supervisor/types.js +2 -0
- package/build/supervisor/types.js.map +1 -0
- package/build/supervisor.d.ts +9 -86
- package/build/supervisor.d.ts.map +1 -1
- package/build/supervisor.js +65 -123
- package/build/supervisor.js.map +1 -1
- package/build/types.d.ts +46 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/package.json +11 -11
- package/src/browser/types.ts +22 -0
- package/src/browser.ts +43 -40
- package/src/consent/types.ts +38 -0
- package/src/consent.ts +48 -0
- package/src/consts.local.ts +12 -0
- package/src/index.ts +8 -0
- package/src/marketing-consent.ts +8 -0
- package/src/mount.ts +12 -32
- package/src/page/types.ts +144 -0
- package/src/page.ts +194 -0
- package/src/supervisor/types.ts +55 -0
- package/src/supervisor.ts +83 -187
- package/src/types.ts +47 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/supervisor/types.ts"],"names":[],"mappings":""}
|
package/build/supervisor.d.ts
CHANGED
|
@@ -1,91 +1,14 @@
|
|
|
1
1
|
import type { Page } from 'playwright';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* Private key to sign the bearer with, e.g. `ed25519:<base64>` from
|
|
8
|
-
* `.env.dev.secrets`. MUST be the key the target backend trusts as its own
|
|
9
|
-
* signing key (it verifies bearers against `cfg.alias`/`cfg.service`).
|
|
10
|
-
*/
|
|
11
|
-
pk: string;
|
|
12
|
-
scopes?: string[];
|
|
13
|
-
role?: AuthRole;
|
|
14
|
-
entityId?: string;
|
|
15
|
-
profileId?: string;
|
|
16
|
-
/** `source` recorded in the Auth payload (usually the backend service alias). */
|
|
17
|
-
source?: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Mint a ready-to-use `ED25519-BASIC-TOKEN ...` bearer offline, reusing
|
|
21
|
-
* `@owlmeans/test-auth`'s `makeBearer`. This is the "set a token directly"
|
|
22
|
-
* fast-path for e2e/integration tests: no UI, no live auth round-trip. The
|
|
23
|
-
* backend accepts it because it is signed by the project's own trusted key.
|
|
24
|
-
*
|
|
25
|
-
* For a faithful end-to-end login (real supervisor plugin + registration), drive
|
|
26
|
-
* {@link loginViaSupervisorForm} instead.
|
|
27
|
-
*/
|
|
28
|
-
export declare const pregenerateAuthToken: (opts: PregenerateAuthTokenOptions) => Promise<string>;
|
|
29
|
-
/**
|
|
30
|
-
* Inject a pre-generated bearer into an app that uses the standard owlmeans
|
|
31
|
-
* dispatcher: navigate to `/dispatcher?token=...` so the web app authenticates
|
|
32
|
-
* and redirects home natively. Note: apps that override the DISPATCHER route
|
|
33
|
-
* (e.g. to force an external IdP) should use {@link loginViaSupervisorForm}.
|
|
34
|
-
*/
|
|
35
|
-
export declare const loginViaDispatcher: (page: Page, baseUrl: string, token: string, opts?: {
|
|
36
|
-
dispatcherPath?: string;
|
|
37
|
-
}) => Promise<void>;
|
|
38
|
-
export interface SupervisorApiAuthOptions {
|
|
39
|
-
/** Auth-manager API base URL (the backend serving /authentication/* and /authenticate). */
|
|
40
|
-
apiBaseUrl: string;
|
|
41
|
-
/** Target user id / email to authenticate (and register on first use). */
|
|
42
|
-
userId: string;
|
|
43
|
-
/** Supervisor private key, e.g. `ed25519:<base64>` from `.env.dev.secrets`. */
|
|
44
|
-
pk: string;
|
|
45
|
-
/** Paths, overridable for non-default routing. */
|
|
46
|
-
paths?: {
|
|
47
|
-
init?: string;
|
|
48
|
-
authenticate?: string;
|
|
49
|
-
dispatch?: string;
|
|
50
|
-
};
|
|
51
|
-
fetchImpl?: typeof fetch;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Pregenerate a real bearer by driving the live PK-based supervisor flow over the
|
|
55
|
-
* backend API (no browser): `/authentication/init` -> sign the challenge with the
|
|
56
|
-
* supervisor key -> `/authentication/authenticate` -> `/authenticate` (dispatcher
|
|
57
|
-
* exchange). This is the faithful "set a token directly via API" path
|
|
58
|
-
* (registers the user on first use), independent of any front-end routing.
|
|
59
|
-
*
|
|
60
|
-
* Returns the final `ED25519-BASIC-TOKEN ...` bearer the backend accepts.
|
|
61
|
-
*/
|
|
2
|
+
import type { AcceptConsentOptions, SupervisorFormLoginOptions } from './page/types.js';
|
|
3
|
+
import type { SupervisorApiAuthOptions, SupervisorAuthHelper } from './supervisor/types.js';
|
|
4
|
+
export declare const createSupervisorAuthHelper: () => SupervisorAuthHelper;
|
|
5
|
+
export declare const supervisorAuthHelper: SupervisorAuthHelper;
|
|
6
|
+
/** @deprecated compat:factory-refactor — use `supervisorAuthHelper.authenticateViaSupervisorApi(…)` */
|
|
62
7
|
export declare const authenticateViaSupervisorApi: (opts: SupervisorApiAuthOptions) => Promise<string>;
|
|
63
|
-
/**
|
|
64
|
-
* Save a full-page screenshot to `<dir>/<name>.png`, creating `dir` if needed.
|
|
65
|
-
* Returns the absolute file path. Use a host-backed folder (e.g. the project's
|
|
66
|
-
* `tmp/tests/screenshots`) so the file is visible whether the test runs on the
|
|
67
|
-
* host or inside a dev container.
|
|
68
|
-
*/
|
|
8
|
+
/** @deprecated compat:factory-refactor — use `makePageHelper(page).saveScreenshot(…)` */
|
|
69
9
|
export declare const saveScreenshot: (page: Page, dir: string, name: string) => Promise<string>;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
userId: string;
|
|
74
|
-
/** Supervisor private key (e.g. `ed25519:<base64>` from `.env.dev.secrets`). */
|
|
75
|
-
pk: string;
|
|
76
|
-
/** Login path; defaults to the standard supervisor route. */
|
|
77
|
-
path?: string;
|
|
78
|
-
/** Predicate/URL fragment that signals a successful landing (default: leaving the login path). */
|
|
79
|
-
expectPath?: string;
|
|
80
|
-
timeout?: number;
|
|
81
|
-
/** When set, capture the filled login form (`supervisor-login-form.png`) before submit. */
|
|
82
|
-
screenshotDir?: string;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Drive the PK-based supervisor login FORM end-to-end (the faithful path that
|
|
86
|
-
* exercises the real supervisor plugin + registration): navigate to the
|
|
87
|
-
* supervisor login route, fill the user id + private key, submit, and wait for
|
|
88
|
-
* the app to leave the login screen.
|
|
89
|
-
*/
|
|
10
|
+
/** @deprecated compat:factory-refactor — use `makePageHelper(page).acceptConsent(…)` */
|
|
11
|
+
export declare const acceptConsent: (page: Page, opts?: AcceptConsentOptions) => Promise<boolean>;
|
|
12
|
+
/** @deprecated compat:factory-refactor — use `makePageHelper(page).loginViaSupervisorForm(…)` */
|
|
90
13
|
export declare const loginViaSupervisorForm: (page: Page, opts: SupervisorFormLoginOptions) => Promise<void>;
|
|
91
14
|
//# sourceMappingURL=supervisor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../src/supervisor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../src/supervisor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAOtC,OAAO,KAAK,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAA;AACvF,OAAO,KAAK,EAA+B,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAExH,eAAO,MAAM,0BAA0B,QAAO,oBAuE7C,CAAA;AAED,eAAO,MAAM,oBAAoB,sBAA+B,CAAA;AAEhE,uGAAuG;AACvG,eAAO,MAAM,4BAA4B,SAAgB,wBAAwB,KAAG,OAAO,CAAC,MAAM,CACnC,CAAA;AAE/D,yFAAyF;AACzF,eAAO,MAAM,cAAc,SAAgB,IAAI,OAAO,MAAM,QAAQ,MAAM,KAAG,OAAO,CAAC,MAAM,CACrC,CAAA;AAEtD,wFAAwF;AACxF,eAAO,MAAM,aAAa,SAAgB,IAAI,SAAS,oBAAoB,KAAG,OAAO,CAAC,OAAO,CAC7C,CAAA;AAEhD,iGAAiG;AACjG,eAAO,MAAM,sBAAsB,SAAgB,IAAI,QAAQ,0BAA0B,KAAG,OAAO,CAAC,IAAI,CAC/C,CAAA"}
|
package/build/supervisor.js
CHANGED
|
@@ -1,132 +1,74 @@
|
|
|
1
|
-
import { mkdir } from 'node:fs/promises';
|
|
2
|
-
import { join, resolve } from 'node:path';
|
|
3
1
|
import { AuthroizationType, AuthRole as Role, AuthenticationType, buildSupervisorPayload } from '@owlmeans/auth';
|
|
4
2
|
import { makeKeyPairModel } from '@owlmeans/basic-keys';
|
|
5
3
|
import { createIdOfLength } from '@owlmeans/basic-ids';
|
|
6
4
|
import { EnvelopeKind, makeEnvelopeModel } from '@owlmeans/basic-envelope';
|
|
7
5
|
import { makeBearer } from '@owlmeans/test-auth';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
role: opts.role ?? Role.User,
|
|
25
|
-
type: AuthroizationType.Ed25519BasicToken,
|
|
26
|
-
source: opts.source ?? '',
|
|
27
|
-
isUser: true,
|
|
28
|
-
createdAt: new Date()
|
|
6
|
+
import { makePageHelper } from './page.js';
|
|
7
|
+
export const createSupervisorAuthHelper = () => {
|
|
8
|
+
const pregenerateAuthToken = async (opts) => {
|
|
9
|
+
const auth = {
|
|
10
|
+
token: createIdOfLength(32),
|
|
11
|
+
userId: opts.userId,
|
|
12
|
+
profileId: opts.profileId ?? opts.userId,
|
|
13
|
+
entitySlug: opts.entityId,
|
|
14
|
+
scopes: opts.scopes ?? ['*'],
|
|
15
|
+
role: opts.role ?? Role.User,
|
|
16
|
+
type: AuthroizationType.Ed25519BasicToken,
|
|
17
|
+
source: opts.source ?? '',
|
|
18
|
+
isUser: true,
|
|
19
|
+
createdAt: new Date()
|
|
20
|
+
};
|
|
21
|
+
return makeBearer(auth, makeKeyPairModel(opts.pk));
|
|
29
22
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const url = new URL(path, baseUrl);
|
|
41
|
-
url.searchParams.set('token', token);
|
|
42
|
-
await page.goto(url.toString());
|
|
43
|
-
// Wait until the dispatcher has navigated away (token consumed).
|
|
44
|
-
await page.waitForURL(u => !u.pathname.startsWith(path), { timeout: 30_000 });
|
|
45
|
-
};
|
|
46
|
-
const postJson = async (fetchImpl, url, body) => {
|
|
47
|
-
const res = await fetchImpl(url, {
|
|
48
|
-
method: 'POST',
|
|
49
|
-
headers: { 'Content-Type': 'application/json' },
|
|
50
|
-
body: JSON.stringify(body)
|
|
51
|
-
});
|
|
52
|
-
if (!res.ok) {
|
|
53
|
-
throw new Error(`supervisor api ${url} -> ${res.status} ${await res.text().catch(() => '')}`);
|
|
54
|
-
}
|
|
55
|
-
return res.json();
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Pregenerate a real bearer by driving the live PK-based supervisor flow over the
|
|
59
|
-
* backend API (no browser): `/authentication/init` -> sign the challenge with the
|
|
60
|
-
* supervisor key -> `/authentication/authenticate` -> `/authenticate` (dispatcher
|
|
61
|
-
* exchange). This is the faithful "set a token directly via API" path
|
|
62
|
-
* (registers the user on first use), independent of any front-end routing.
|
|
63
|
-
*
|
|
64
|
-
* Returns the final `ED25519-BASIC-TOKEN ...` bearer the backend accepts.
|
|
65
|
-
*/
|
|
66
|
-
export const authenticateViaSupervisorApi = async (opts) => {
|
|
67
|
-
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
68
|
-
const base = opts.apiBaseUrl.replace(/\/$/, '');
|
|
69
|
-
const initPath = opts.paths?.init ?? '/authentication/init';
|
|
70
|
-
const authPath = opts.paths?.authenticate ?? '/authentication/authenticate';
|
|
71
|
-
const dispatchPath = opts.paths?.dispatch ?? '/authenticate';
|
|
72
|
-
// 1. Ask the auth manager for a fresh, signed challenge envelope.
|
|
73
|
-
const { challenge } = await postJson(fetchImpl, base + initPath, {
|
|
74
|
-
type: AuthenticationType.Supervisor
|
|
75
|
-
});
|
|
76
|
-
// 2. Sign the unwrapped challenge + userId + salt with the supervisor key.
|
|
77
|
-
const challengeMsg = makeEnvelopeModel(challenge, EnvelopeKind.Wrap).message();
|
|
78
|
-
const salt = createIdOfLength(16);
|
|
79
|
-
const signature = await makeKeyPairModel(opts.pk)
|
|
80
|
-
.sign(buildSupervisorPayload(challengeMsg, opts.userId, salt));
|
|
81
|
-
const credentials = {
|
|
82
|
-
type: AuthenticationType.Supervisor,
|
|
83
|
-
challenge,
|
|
84
|
-
credential: JSON.stringify({ salt, signature }),
|
|
85
|
-
userId: opts.userId,
|
|
86
|
-
role: Role.User,
|
|
87
|
-
scopes: ['*']
|
|
23
|
+
const postJson = async (fetchImpl, url, body) => {
|
|
24
|
+
const res = await fetchImpl(url, {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: { 'Content-Type': 'application/json' },
|
|
27
|
+
body: JSON.stringify(body)
|
|
28
|
+
});
|
|
29
|
+
if (!res.ok) {
|
|
30
|
+
throw new Error(`supervisor api ${url} -> ${res.status} ${await res.text().catch(() => '')}`);
|
|
31
|
+
}
|
|
32
|
+
return res.json();
|
|
88
33
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
*
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
await page.getByTestId('supervisor-user-id').fill(opts.userId);
|
|
120
|
-
await page.getByTestId('supervisor-pk').fill(opts.pk);
|
|
121
|
-
if (opts.screenshotDir != null) {
|
|
122
|
-
await saveScreenshot(page, opts.screenshotDir, 'supervisor-login-form');
|
|
123
|
-
}
|
|
124
|
-
await page.getByTestId('supervisor-submit').click();
|
|
125
|
-
if (opts.expectPath != null) {
|
|
126
|
-
await page.waitForURL(url => url.toString().includes(opts.expectPath), { timeout });
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
await page.waitForURL(url => !url.pathname.startsWith(path), { timeout });
|
|
130
|
-
}
|
|
34
|
+
const authenticateViaSupervisorApi = async (opts) => {
|
|
35
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
36
|
+
const base = opts.apiBaseUrl.replace(/\/$/, '');
|
|
37
|
+
const initPath = opts.paths?.init ?? '/authentication/init';
|
|
38
|
+
const authPath = opts.paths?.authenticate ?? '/authentication/authenticate';
|
|
39
|
+
const dispatchPath = opts.paths?.dispatch ?? '/authenticate';
|
|
40
|
+
// 1. Ask the auth manager for a fresh, signed challenge envelope.
|
|
41
|
+
const { challenge } = await postJson(fetchImpl, base + initPath, {
|
|
42
|
+
type: AuthenticationType.Supervisor
|
|
43
|
+
});
|
|
44
|
+
// 2. Sign the unwrapped challenge + userId + salt with the supervisor key.
|
|
45
|
+
const challengeMsg = makeEnvelopeModel(challenge, EnvelopeKind.Wrap).message();
|
|
46
|
+
const salt = createIdOfLength(16);
|
|
47
|
+
const signature = await makeKeyPairModel(opts.pk)
|
|
48
|
+
.sign(buildSupervisorPayload(challengeMsg, opts.userId, salt));
|
|
49
|
+
const credentials = {
|
|
50
|
+
type: AuthenticationType.Supervisor,
|
|
51
|
+
challenge,
|
|
52
|
+
credential: JSON.stringify({ salt, signature }),
|
|
53
|
+
userId: opts.userId,
|
|
54
|
+
role: Role.User,
|
|
55
|
+
scopes: ['*']
|
|
56
|
+
};
|
|
57
|
+
// 3. Exchange for the intermediate auth-manager token.
|
|
58
|
+
const intermediate = await postJson(fetchImpl, base + authPath, credentials);
|
|
59
|
+
// 4. Exchange the intermediate token for the final project bearer.
|
|
60
|
+
const final = await postJson(fetchImpl, base + dispatchPath, { token: intermediate.token });
|
|
61
|
+
return final.token;
|
|
62
|
+
};
|
|
63
|
+
return { pregenerateAuthToken, authenticateViaSupervisorApi };
|
|
131
64
|
};
|
|
65
|
+
export const supervisorAuthHelper = createSupervisorAuthHelper();
|
|
66
|
+
/** @deprecated compat:factory-refactor — use `supervisorAuthHelper.authenticateViaSupervisorApi(…)` */
|
|
67
|
+
export const authenticateViaSupervisorApi = async (opts) => await supervisorAuthHelper.authenticateViaSupervisorApi(opts);
|
|
68
|
+
/** @deprecated compat:factory-refactor — use `makePageHelper(page).saveScreenshot(…)` */
|
|
69
|
+
export const saveScreenshot = async (page, dir, name) => await makePageHelper(page).saveScreenshot(dir, name);
|
|
70
|
+
/** @deprecated compat:factory-refactor — use `makePageHelper(page).acceptConsent(…)` */
|
|
71
|
+
export const acceptConsent = async (page, opts) => await makePageHelper(page).acceptConsent(opts);
|
|
72
|
+
/** @deprecated compat:factory-refactor — use `makePageHelper(page).loginViaSupervisorForm(…)` */
|
|
73
|
+
export const loginViaSupervisorForm = async (page, opts) => await makePageHelper(page).loginViaSupervisorForm(opts);
|
|
132
74
|
//# sourceMappingURL=supervisor.js.map
|
package/build/supervisor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor.js","sourceRoot":"","sources":["../src/supervisor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"supervisor.js","sourceRoot":"","sources":["../src/supervisor.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,iBAAiB,EAAE,QAAQ,IAAI,IAAI,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AACjJ,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BA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AsB,CAAC,IAAI,CAAC,CAAA"}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Page } from 'playwright';
|
|
2
|
+
import type { ConsentGeoMock } from './consent/types.js';
|
|
3
|
+
export interface MountOptions {
|
|
4
|
+
/**
|
|
5
|
+
* URL the harness is reachable at. The consuming package is in charge
|
|
6
|
+
* of producing it — typically a Vite dev server pointed at
|
|
7
|
+
* `node_modules/@owlmeans/test-ui/harness/` plus a per-package
|
|
8
|
+
* `mount.tsx` that registers the components under test, OR an
|
|
9
|
+
* inlined `data:text/html,...` URL for the simplest smoke tests.
|
|
10
|
+
*/
|
|
11
|
+
url: string;
|
|
12
|
+
/**
|
|
13
|
+
* Component name registered in the harness. Appended as `?component=`.
|
|
14
|
+
* Omit when the harness mounts a single fixed root.
|
|
15
|
+
*/
|
|
16
|
+
component?: string;
|
|
17
|
+
/**
|
|
18
|
+
* JSON-serialisable props passed to the component. Encoded into the
|
|
19
|
+
* URL as `?props=<json>` for the harness's `mount.tsx` to read.
|
|
20
|
+
*/
|
|
21
|
+
props?: Record<string, unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* What counts as "arrived". Defaults to `domcontentloaded`.
|
|
24
|
+
*
|
|
25
|
+
* NOT `load`, which is playwright's own default and is wrong for any page that is a real
|
|
26
|
+
* application: `load` waits for EVERY subresource, and an analytics beacon, a long-poll or a
|
|
27
|
+
* third-party pixel that never settles holds it open until the navigation times out — with the
|
|
28
|
+
* page fully rendered and working the whole time. The failure reads as "the site is down".
|
|
29
|
+
*
|
|
30
|
+
* A spec waits for the selector it actually needs; that is the assertion, not the load event.
|
|
31
|
+
*/
|
|
32
|
+
waitUntil?: 'commit' | 'domcontentloaded' | 'load' | 'networkidle';
|
|
33
|
+
/** Navigation timeout in ms. */
|
|
34
|
+
timeout?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Answer the page's Cloudflare trace with this — installed BEFORE the first navigation, so the
|
|
37
|
+
* consent geo gate sees it on the very first load. See `consentGeoTestHelper.mockConsentGeo`.
|
|
38
|
+
*/
|
|
39
|
+
consentGeo?: ConsentGeoMock;
|
|
40
|
+
}
|
|
41
|
+
export interface Mounted {
|
|
42
|
+
page: Page;
|
|
43
|
+
/** Closes the page's browser context — the shared browser stays alive. */
|
|
44
|
+
close: () => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,QAAQ,GAAG,kBAAkB,GAAG,MAAM,GAAG,aAAa,CAAA;IAClE,gCAAgC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,cAAc,CAAA;CAC5B;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,IAAI,CAAA;IACV,0EAA0E;IAC1E,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B"}
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/test-ui",
|
|
3
|
-
"version": "0.1.18
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"./harness": "./harness/index.html"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@owlmeans/auth": "^0.1.18
|
|
26
|
-
"@owlmeans/basic-envelope": "^0.1.18
|
|
27
|
-
"@owlmeans/basic-ids": "^0.1.18
|
|
28
|
-
"@owlmeans/basic-keys": "^0.1.18
|
|
29
|
-
"@owlmeans/test": "^0.1.18
|
|
30
|
-
"@owlmeans/test-auth": "^0.1.18
|
|
31
|
-
"playwright": "^1.
|
|
25
|
+
"@owlmeans/auth": "^0.1.18",
|
|
26
|
+
"@owlmeans/basic-envelope": "^0.1.18",
|
|
27
|
+
"@owlmeans/basic-ids": "^0.1.18",
|
|
28
|
+
"@owlmeans/basic-keys": "^0.1.18",
|
|
29
|
+
"@owlmeans/test": "^0.1.18",
|
|
30
|
+
"@owlmeans/test-auth": "^0.1.18",
|
|
31
|
+
"playwright": "^1.63.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"react": "*",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@owlmeans/dep-config": "^0.1.18
|
|
47
|
-
"@types/bun": "^1.4.
|
|
48
|
-
"@types/react": "^19.
|
|
46
|
+
"@owlmeans/dep-config": "^0.1.18",
|
|
47
|
+
"@types/bun": "^1.4.2",
|
|
48
|
+
"@types/react": "^19.3.0",
|
|
49
49
|
"nodemon": "^3.1.14",
|
|
50
50
|
"typescript": "^7.0.2"
|
|
51
51
|
},
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Browser, LaunchOptions, Page } from 'playwright'
|
|
2
|
+
|
|
3
|
+
/** The one chromium a `bun test` process shares, and the pages specs drive off it. */
|
|
4
|
+
export interface BrowserHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Launch (or return) a single shared chromium instance for the current
|
|
7
|
+
* `bun test` process. UI specs hold a fixture page off this browser; the
|
|
8
|
+
* suite calls {@link BrowserHelper.closeBrowser} from `afterAll` to tear it down once.
|
|
9
|
+
*/
|
|
10
|
+
launchBrowser: (opts?: LaunchOptions) => Promise<Browser>
|
|
11
|
+
/**
|
|
12
|
+
* Tear down the shared browser. Idempotent — safe to call from multiple
|
|
13
|
+
* `afterAll` hooks.
|
|
14
|
+
*/
|
|
15
|
+
closeBrowser: () => Promise<void>
|
|
16
|
+
/**
|
|
17
|
+
* Convenience that launches the browser, runs a callback with a fresh
|
|
18
|
+
* context + page, and closes the context on completion. The browser
|
|
19
|
+
* itself stays alive across calls so multiple specs share it cheaply.
|
|
20
|
+
*/
|
|
21
|
+
withPage: <T>(fn: (page: Page) => Promise<T>) => Promise<T>
|
|
22
|
+
}
|
package/src/browser.ts
CHANGED
|
@@ -1,50 +1,53 @@
|
|
|
1
1
|
import { chromium } from 'playwright'
|
|
2
|
-
import type { Browser, LaunchOptions } from 'playwright'
|
|
2
|
+
import type { Browser, LaunchOptions, Page } from 'playwright'
|
|
3
|
+
import type { BrowserHelper } from './browser/types.js'
|
|
3
4
|
|
|
5
|
+
// Process-wide on purpose: every spec of a `bun test` run shares one browser.
|
|
4
6
|
let shared: Browser | undefined
|
|
5
7
|
let inflight: Promise<Browser> | undefined
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
shared = await inflight
|
|
17
|
-
inflight = undefined
|
|
18
|
-
return shared
|
|
19
|
-
}
|
|
9
|
+
export const createBrowserHelper = (): BrowserHelper => {
|
|
10
|
+
const launchBrowser = async (opts: LaunchOptions = {}): Promise<Browser> => {
|
|
11
|
+
if (shared != null) return shared
|
|
12
|
+
if (inflight != null) return inflight
|
|
13
|
+
inflight = chromium.launch({ headless: true, ...opts })
|
|
14
|
+
shared = await inflight
|
|
15
|
+
inflight = undefined
|
|
16
|
+
return shared
|
|
17
|
+
}
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
inflight = undefined
|
|
29
|
-
if (b != null) {
|
|
30
|
-
await b.close()
|
|
19
|
+
const closeBrowser = async (): Promise<void> => {
|
|
20
|
+
const b = shared
|
|
21
|
+
shared = undefined
|
|
22
|
+
inflight = undefined
|
|
23
|
+
if (b != null) {
|
|
24
|
+
await b.close()
|
|
25
|
+
}
|
|
31
26
|
}
|
|
32
|
-
}
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
const context = await browser.newContext()
|
|
44
|
-
const page = await context.newPage()
|
|
45
|
-
try {
|
|
46
|
-
return await fn(page)
|
|
47
|
-
} finally {
|
|
48
|
-
await context.close()
|
|
28
|
+
const withPage = async <T>(fn: (page: Page) => Promise<T>): Promise<T> => {
|
|
29
|
+
const browser = await launchBrowser()
|
|
30
|
+
const context = await browser.newContext()
|
|
31
|
+
const page = await context.newPage()
|
|
32
|
+
try {
|
|
33
|
+
return await fn(page)
|
|
34
|
+
} finally {
|
|
35
|
+
await context.close()
|
|
36
|
+
}
|
|
49
37
|
}
|
|
38
|
+
|
|
39
|
+
return { launchBrowser, closeBrowser, withPage }
|
|
50
40
|
}
|
|
41
|
+
|
|
42
|
+
export const browserHelper = createBrowserHelper()
|
|
43
|
+
|
|
44
|
+
/** @deprecated compat:factory-refactor — use `browserHelper.launchBrowser(…)` */
|
|
45
|
+
export const launchBrowser = async (opts: LaunchOptions = {}): Promise<Browser> =>
|
|
46
|
+
await browserHelper.launchBrowser(opts)
|
|
47
|
+
|
|
48
|
+
/** @deprecated compat:factory-refactor — use `browserHelper.closeBrowser()` */
|
|
49
|
+
export const closeBrowser = async (): Promise<void> => await browserHelper.closeBrowser()
|
|
50
|
+
|
|
51
|
+
/** @deprecated compat:factory-refactor — use `browserHelper.withPage(…)` */
|
|
52
|
+
export const withPage = async <T>(fn: (page: Page) => Promise<T>): Promise<T> =>
|
|
53
|
+
await browserHelper.withPage(fn)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { BrowserContext, Page } from 'playwright'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A fake answer from Cloudflare's trace endpoint: a country code (`'US'`), or
|
|
5
|
+
* `{ country?, fail?, delayMs?, gpc? }`.
|
|
6
|
+
*/
|
|
7
|
+
export type ConsentGeoMock = string | ConsentGeoMockOptions
|
|
8
|
+
|
|
9
|
+
export interface ConsentGeoMockOptions {
|
|
10
|
+
/** The `loc=` the fake trace answers with. Defaults to `PL` — a consent country. */
|
|
11
|
+
country?: string
|
|
12
|
+
/** `true` answers 404 (the host is not behind Cloudflare); `'hang'` never answers. */
|
|
13
|
+
fail?: boolean | 'hang'
|
|
14
|
+
/** Answer only after this many ms — long enough to see the spinner. */
|
|
15
|
+
delayMs?: number
|
|
16
|
+
/** Send Global Privacy Control (`navigator.globalPrivacyControl`). */
|
|
17
|
+
gpc?: boolean
|
|
18
|
+
/** The trace path the page asks. Defaults to `/cdn-cgi/trace`. */
|
|
19
|
+
path?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Pinning where a visitor is, so a consent test does not depend on where its runner happens to be:
|
|
24
|
+
* every app behind Cloudflare answers the trace with the RUNNER's country.
|
|
25
|
+
*/
|
|
26
|
+
export interface ConsentGeoTestHelper {
|
|
27
|
+
/**
|
|
28
|
+
* Answer the page's same-origin trace request from inside the page: an init script that wraps
|
|
29
|
+
* `window.fetch` before any page script runs, and counts the calls in
|
|
30
|
+
* `window.__consentTraceCalls`. Never `page.route` — interception disables the cache for every
|
|
31
|
+
* request, and a vite-served application stalls on its hundreds of unbundled modules.
|
|
32
|
+
*
|
|
33
|
+
* Applies to the NEXT navigation of the page or context it is installed on.
|
|
34
|
+
*/
|
|
35
|
+
mockConsentGeo: (target: Page | BrowserContext, geo: ConsentGeoMock) => Promise<void>
|
|
36
|
+
/** How many trace requests the page made since it loaded (`mockConsentGeo` only). */
|
|
37
|
+
traceCalls: (page: Page) => Promise<number>
|
|
38
|
+
}
|