@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.
Files changed (69) hide show
  1. package/README.md +10 -7
  2. package/agent-meta/manifest.json +3 -3
  3. package/agent-meta/skills/testing-ui/SKILL.md +209 -23
  4. package/build/browser/types.d.ts +22 -0
  5. package/build/browser/types.d.ts.map +1 -0
  6. package/build/browser/types.js +2 -0
  7. package/build/browser/types.js.map +1 -0
  8. package/build/browser.d.ts +8 -16
  9. package/build/browser.d.ts.map +1 -1
  10. package/build/browser.js +38 -41
  11. package/build/browser.js.map +1 -1
  12. package/build/consent/types.d.ts +36 -0
  13. package/build/consent/types.d.ts.map +1 -0
  14. package/build/consent/types.js +2 -0
  15. package/build/consent/types.js.map +1 -0
  16. package/build/consent.d.ts +4 -0
  17. package/build/consent.d.ts.map +1 -0
  18. package/build/consent.js +41 -0
  19. package/build/consent.js.map +1 -0
  20. package/build/consts.local.d.ts +9 -0
  21. package/build/consts.local.d.ts.map +1 -0
  22. package/build/consts.local.js +9 -0
  23. package/build/consts.local.js.map +1 -0
  24. package/build/index.d.ts +8 -0
  25. package/build/index.d.ts.map +1 -1
  26. package/build/index.js +3 -0
  27. package/build/index.js.map +1 -1
  28. package/build/marketing-consent.d.ts +5 -0
  29. package/build/marketing-consent.d.ts.map +1 -0
  30. package/build/marketing-consent.js +4 -0
  31. package/build/marketing-consent.js.map +1 -0
  32. package/build/mount.d.ts +2 -27
  33. package/build/mount.d.ts.map +1 -1
  34. package/build/mount.js +11 -4
  35. package/build/mount.js.map +1 -1
  36. package/build/page/types.d.ts +141 -0
  37. package/build/page/types.d.ts.map +1 -0
  38. package/build/page/types.js +2 -0
  39. package/build/page/types.js.map +1 -0
  40. package/build/page.d.ts +4 -0
  41. package/build/page.d.ts.map +1 -0
  42. package/build/page.js +168 -0
  43. package/build/page.js.map +1 -0
  44. package/build/supervisor/types.d.ts +56 -0
  45. package/build/supervisor/types.d.ts.map +1 -0
  46. package/build/supervisor/types.js +2 -0
  47. package/build/supervisor/types.js.map +1 -0
  48. package/build/supervisor.d.ts +9 -86
  49. package/build/supervisor.d.ts.map +1 -1
  50. package/build/supervisor.js +65 -123
  51. package/build/supervisor.js.map +1 -1
  52. package/build/types.d.ts +46 -0
  53. package/build/types.d.ts.map +1 -0
  54. package/build/types.js +2 -0
  55. package/build/types.js.map +1 -0
  56. package/package.json +11 -11
  57. package/src/browser/types.ts +22 -0
  58. package/src/browser.ts +43 -40
  59. package/src/consent/types.ts +38 -0
  60. package/src/consent.ts +48 -0
  61. package/src/consts.local.ts +12 -0
  62. package/src/index.ts +8 -0
  63. package/src/marketing-consent.ts +8 -0
  64. package/src/mount.ts +12 -32
  65. package/src/page/types.ts +144 -0
  66. package/src/page.ts +194 -0
  67. package/src/supervisor/types.ts +55 -0
  68. package/src/supervisor.ts +83 -187
  69. package/src/types.ts +47 -0
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/supervisor/types.ts"],"names":[],"mappings":""}
@@ -1,91 +1,14 @@
1
1
  import type { Page } from 'playwright';
2
- import type { AuthRole } from '@owlmeans/auth';
3
- export interface PregenerateAuthTokenOptions {
4
- /** Target user id / email the token represents. */
5
- userId: string;
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
- export interface SupervisorFormLoginOptions {
71
- baseUrl: string;
72
- /** Target user id / email. */
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":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,EAAyB,QAAQ,EAAE,MAAM,gBAAgB,CAAA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B;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,gFAAgF;IAChF,EAAE,EAAE,MAAM,CAAA;IACV,6DAA6D;IAC7D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,kGAAkG;IAClG,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,2FAA2F;IAC3F,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAID;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,SAC3B,IAAI,QAAQ,0BAA0B,KAC3C,OAAO,CAAC,IAAI,CAmBd,CAAA"}
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"}
@@ -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
- * Mint a ready-to-use `ED25519-BASIC-TOKEN ...` bearer offline, reusing
10
- * `@owlmeans/test-auth`'s `makeBearer`. This is the "set a token directly"
11
- * fast-path for e2e/integration tests: no UI, no live auth round-trip. The
12
- * backend accepts it because it is signed by the project's own trusted key.
13
- *
14
- * For a faithful end-to-end login (real supervisor plugin + registration), drive
15
- * {@link loginViaSupervisorForm} instead.
16
- */
17
- export const pregenerateAuthToken = async (opts) => {
18
- const auth = {
19
- token: createIdOfLength(32),
20
- userId: opts.userId,
21
- profileId: opts.profileId ?? opts.userId,
22
- entitySlug: opts.entityId,
23
- scopes: opts.scopes ?? ['*'],
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
- return makeBearer(auth, makeKeyPairModel(opts.pk));
31
- };
32
- /**
33
- * Inject a pre-generated bearer into an app that uses the standard owlmeans
34
- * dispatcher: navigate to `/dispatcher?token=...` so the web app authenticates
35
- * and redirects home natively. Note: apps that override the DISPATCHER route
36
- * (e.g. to force an external IdP) should use {@link loginViaSupervisorForm}.
37
- */
38
- export const loginViaDispatcher = async (page, baseUrl, token, opts) => {
39
- const path = opts?.dispatcherPath ?? '/dispatcher';
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
- // 3. Exchange for the intermediate auth-manager token.
90
- const intermediate = await postJson(fetchImpl, base + authPath, credentials);
91
- // 4. Exchange the intermediate token for the final project bearer.
92
- const final = await postJson(fetchImpl, base + dispatchPath, { token: intermediate.token });
93
- return final.token;
94
- };
95
- /**
96
- * Save a full-page screenshot to `<dir>/<name>.png`, creating `dir` if needed.
97
- * Returns the absolute file path. Use a host-backed folder (e.g. the project's
98
- * `tmp/tests/screenshots`) so the file is visible whether the test runs on the
99
- * host or inside a dev container.
100
- */
101
- export const saveScreenshot = async (page, dir, name) => {
102
- const target = resolve(dir);
103
- await mkdir(target, { recursive: true });
104
- const file = join(target, `${name}.png`);
105
- await page.screenshot({ path: file, fullPage: true });
106
- return file;
107
- };
108
- const DEFAULT_SUPERVISOR_PATH = '/authentication/login/pk-supervisor';
109
- /**
110
- * Drive the PK-based supervisor login FORM end-to-end (the faithful path that
111
- * exercises the real supervisor plugin + registration): navigate to the
112
- * supervisor login route, fill the user id + private key, submit, and wait for
113
- * the app to leave the login screen.
114
- */
115
- export const loginViaSupervisorForm = async (page, opts) => {
116
- const path = opts.path ?? DEFAULT_SUPERVISOR_PATH;
117
- const timeout = opts.timeout ?? 60_000;
118
- await page.goto(new URL(path, opts.baseUrl).toString());
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
@@ -1 +1 @@
1
- {"version":3,"file":"supervisor.js","sourceRoot":"","sources":["../src/supervisor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGzC,OAAO,EACL,iBAAiB,EAAE,QAAQ,IAAI,IAAI,EAAE,kBAAkB,EAAE,sBAAsB,EAChF,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAmBhD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,IAAiC,EAAmB,EAAE;IAC/F,MAAM,IAAI,GAAS;QACjB,KAAK,EAAE,gBAAgB,CAAC,EAAE,CAAC;QAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM;QACxC,UAAU,EAAE,IAAI,CAAC,QAAQ;QACzB,MAAM,EAAE,IAAI,CA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AC,IAAI,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;AAEhD,iGAAiG;AACjG,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,IAAU,EAAE,IAAgC,EAAiB,EAAE,CAC1G,MAAM,cAAc,CAAC,IAAI,CAAC,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAA"}
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -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-rc.9",
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-rc.7",
26
- "@owlmeans/basic-envelope": "^0.1.18-rc.9",
27
- "@owlmeans/basic-ids": "^0.1.18-rc.7",
28
- "@owlmeans/basic-keys": "^0.1.18-rc.9",
29
- "@owlmeans/test": "^0.1.18-rc.6",
30
- "@owlmeans/test-auth": "^0.1.18-rc.9",
31
- "playwright": "^1.61.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-rc.6",
47
- "@types/bun": "^1.4.0",
48
- "@types/react": "^19.2.17",
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
- * Launch (or return) a single shared chromium instance for the current
9
- * `bun test` process. UI specs hold a fixture page off this browser; the
10
- * suite calls `closeBrowser()` from `afterAll` to tear it down once.
11
- */
12
- export const launchBrowser = async (opts: LaunchOptions = {}): Promise<Browser> => {
13
- if (shared != null) return shared
14
- if (inflight != null) return inflight
15
- inflight = chromium.launch({ headless: true, ...opts })
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
- * Tear down the shared browser. Idempotent — safe to call from multiple
23
- * `afterAll` hooks.
24
- */
25
- export const closeBrowser = async (): Promise<void> => {
26
- const b = shared
27
- shared = undefined
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
- * Convenience that launches the browser, runs a callback with a fresh
36
- * context + page, and closes the context on completion. The browser
37
- * itself stays alive across calls so multiple specs share it cheaply.
38
- */
39
- export const withPage = async <T>(
40
- fn: (page: import('playwright').Page) => Promise<T>
41
- ): Promise<T> => {
42
- const browser = await launchBrowser()
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
+ }