@somewhere-cloud/cli 0.38.152 → 0.38.153
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/CHANGELOG.md +7 -0
- package/README.md +6 -0
- package/dist/lib/bundle.js +1171 -444
- package/dist/lib/bundle.js.map +3 -3
- package/dist/testing.js +1 -1
- package/dist/types/lib/app-test.d.ts +1 -20
- package/dist/types/lib/client.d.ts +1 -0
- package/dist/types/lib/preview-credential.d.ts +3 -1
- package/dist/types/lib/test-control.d.ts +5 -0
- package/dist/types/lib/test-identities.d.ts +9 -2
- package/dist/types/lib/test-response-capture.d.ts +24 -0
- package/dist/types/lib/test-session.d.ts +43 -0
- package/dist/types/lib/testing-app.d.ts +22 -0
- package/dist/types/lib/testing-jobs.d.ts +20 -0
- package/dist/types/testing.d.ts +10 -35
- package/npm-shrinkwrap.json +2 -2
- package/package.json +4 -3
- package/src/testing.ts +14 -78
package/dist/testing.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { loadEntry } from "./lib/bundle.js";
|
|
2
2
|
const entry = loadEntry("testing.js");
|
|
3
|
-
export const { UserSession, createUser, data, expect, expectRefusal, expectRefused, expectStatus, ready, signIn, test, waitForApp } = entry;
|
|
3
|
+
export const { UserSession, assertNoLeak, captureResponses, createUser, data, expect, expectRefusal, expectRefused, expectStatus, openTestApp, ready, signIn, test, waitForApp } = entry;
|
|
@@ -143,26 +143,7 @@ export declare class AppTest {
|
|
|
143
143
|
}
|
|
144
144
|
/** Open a linked project for a plain script: reads its live origin, release and data contract. */
|
|
145
145
|
export declare function openAppTest(options?: OpenOptions): Promise<AppTest>;
|
|
146
|
-
export
|
|
147
|
-
url: string;
|
|
148
|
-
status: number;
|
|
149
|
-
contentType: string;
|
|
150
|
-
body: string;
|
|
151
|
-
}
|
|
152
|
-
/** Record every response this page receives (documents, scripts, data) with its body, so a
|
|
153
|
-
* privacy check can wait for all of them and say exactly where a secret appeared. */
|
|
154
|
-
export declare function captureResponses(page: Page): {
|
|
155
|
-
/** Every captured response, after each body has been read. */
|
|
156
|
-
all(): Promise<Captured[]>;
|
|
157
|
-
/** Where `secret` appeared: URL, status, content type and the text around it. Use a unique value you planted. */
|
|
158
|
-
find(secret: string): Promise<{
|
|
159
|
-
url: string;
|
|
160
|
-
status: number;
|
|
161
|
-
contentType: string;
|
|
162
|
-
around: string;
|
|
163
|
-
}[]>;
|
|
164
|
-
stop(): void;
|
|
165
|
-
};
|
|
146
|
+
export { captureResponses, type Captured } from './test-response-capture.js';
|
|
166
147
|
/** Wait until the page's data views have finished loading: the starter marks each with
|
|
167
148
|
* data-sw-data="loading" | "ready" | "error". Signed-in is not "the list has loaded". */
|
|
168
149
|
export declare function dataReady(scope: Page | Locator, timeout?: number): Promise<'ready' | 'error'>;
|
|
@@ -49,6 +49,7 @@ export declare class ApiClient {
|
|
|
49
49
|
baseUrl?: string;
|
|
50
50
|
refresh?: false;
|
|
51
51
|
signal?: AbortSignal;
|
|
52
|
+
onRetryAfter?: (ms: number) => void;
|
|
52
53
|
}): Promise<T>;
|
|
53
54
|
/** Authenticated request whose body and response remain streams. The body is
|
|
54
55
|
* supplied by a factory so a file can be reopened if an expired access key
|
|
@@ -5,7 +5,9 @@ export declare function forgetPreviewCredential(projectId: string, previewSessio
|
|
|
5
5
|
export declare function mintPreviewCredential(client: ApiClient, projectId: string, previewSessionId: string): Promise<string>;
|
|
6
6
|
/** A client that carries ONLY the preview credential: no stored-login refresh, no fallback. */
|
|
7
7
|
export declare function previewToolClient(credential: string): {
|
|
8
|
-
call<T>(method: string, path: string, body?: unknown, query?: Record<string, string | number | undefined
|
|
8
|
+
call: <T>(method: string, path: string, body?: unknown, query?: Record<string, string | number | undefined>, opts?: {
|
|
9
|
+
onRetryAfter?: (ms: number) => void;
|
|
10
|
+
}) => Promise<T>;
|
|
9
11
|
};
|
|
10
12
|
/** True when the platform refused the credential itself (closed, promoted, expired or revoked preview). */
|
|
11
13
|
export declare function isDeadPreviewCredential(err: unknown): boolean;
|
|
@@ -30,6 +30,11 @@ export interface TestControl {
|
|
|
30
30
|
/** End anything the control itself holds open (the preview browser session). */
|
|
31
31
|
close(): Promise<void>;
|
|
32
32
|
/** Preview only: a managed test user through the preview's developer tool, and its removal by id. */
|
|
33
|
+
previewCookie?(): Promise<{
|
|
34
|
+
name: string;
|
|
35
|
+
value: string;
|
|
36
|
+
expiresAt: number;
|
|
37
|
+
}>;
|
|
33
38
|
createManagedUser?(): Promise<ManagedUser>;
|
|
34
39
|
deleteManagedUser?(id: string): Promise<string | null>;
|
|
35
40
|
}
|
|
@@ -4,6 +4,8 @@ export declare const TEST_STATE_GITIGNORE_LINE = ".somewhere/test/";
|
|
|
4
4
|
export declare const MANIFEST_FILE = "manifest.json";
|
|
5
5
|
export declare const CLEANUP_RECEIPT_FILE = "cleanup-receipt.json";
|
|
6
6
|
export declare const MAX_PER_CREATE = 5;
|
|
7
|
+
export declare const ACCESS_COOKIE = "__Host-token";
|
|
8
|
+
export declare const REFRESH_COOKIE = "__Host-sw_refresh_token";
|
|
7
9
|
export type TestRole = 'user' | 'admin';
|
|
8
10
|
export interface ActorSpec {
|
|
9
11
|
name: string;
|
|
@@ -49,16 +51,21 @@ export declare function ensureGitignored(root: string): 'present' | 'added' | 'c
|
|
|
49
51
|
* `<name>.state.json` for a valid actor name, so cleanup can never delete outside .somewhere/test/. */
|
|
50
52
|
export declare function readManifest(root: string): TestManifest | null;
|
|
51
53
|
/** Read the prepared actor's app session for this exact linked target. */
|
|
52
|
-
export declare function
|
|
54
|
+
export declare function preparedActorState(root: string, target: {
|
|
53
55
|
projectId: string;
|
|
54
56
|
origin: string;
|
|
55
|
-
}, name: string):
|
|
57
|
+
}, name: string): {
|
|
58
|
+
path: string;
|
|
59
|
+
state: PlaywrightStorageState;
|
|
60
|
+
access: string;
|
|
61
|
+
};
|
|
56
62
|
export declare function writeManifest(root: string, manifest: TestManifest): void;
|
|
57
63
|
/** The server's own times, read from the access token (not verified here; the server does that). */
|
|
58
64
|
export declare function tokenTimes(accessToken: string): {
|
|
59
65
|
iat: number;
|
|
60
66
|
exp: number;
|
|
61
67
|
} | null;
|
|
68
|
+
export declare function testAccessNeedsRefresh(token: string | undefined, now?: number): boolean;
|
|
62
69
|
export interface IssuedIdentity {
|
|
63
70
|
user: {
|
|
64
71
|
id: string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Page } from '@playwright/test';
|
|
2
|
+
export declare function privateMarker(): string;
|
|
3
|
+
export interface Captured {
|
|
4
|
+
url: string;
|
|
5
|
+
status: number;
|
|
6
|
+
contentType: string;
|
|
7
|
+
body: string;
|
|
8
|
+
}
|
|
9
|
+
/** Record every response this page receives (documents, scripts, data) with its body, so a
|
|
10
|
+
* privacy check can wait for all of them and say exactly where a secret appeared. */
|
|
11
|
+
export declare function captureResponses(page: Page): {
|
|
12
|
+
/** Every captured response, after each body has been read. */
|
|
13
|
+
all(): Promise<Captured[]>;
|
|
14
|
+
/** Where `secret` appeared: URL, status, content type and the text around it. Use a unique value you planted. */
|
|
15
|
+
find(secret: string): Promise<{
|
|
16
|
+
url: string;
|
|
17
|
+
status: number;
|
|
18
|
+
contentType: string;
|
|
19
|
+
around: string;
|
|
20
|
+
}[]>;
|
|
21
|
+
stop(): void;
|
|
22
|
+
};
|
|
23
|
+
/** Report where a marker appeared without embedding response bodies in test output. */
|
|
24
|
+
export declare function assertNoLeak(marker: string, responses: Iterable<Response | Captured>): Promise<void>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type TestTarget } from './test-target.js';
|
|
2
|
+
import { type PlaywrightStorageState } from './test-identities.js';
|
|
3
|
+
export declare class UserSession {
|
|
4
|
+
readonly origin: string;
|
|
5
|
+
private cookies;
|
|
6
|
+
private target?;
|
|
7
|
+
private readonly seed;
|
|
8
|
+
private refreshing?;
|
|
9
|
+
constructor(baseUrl: string, options?: {
|
|
10
|
+
target?: TestTarget;
|
|
11
|
+
storageState?: PlaywrightStorageState;
|
|
12
|
+
});
|
|
13
|
+
/** Standard Playwright state. Treat this value like a signed-in session. */
|
|
14
|
+
storageState(): Promise<PlaywrightStorageState>;
|
|
15
|
+
request(path: string, init?: RequestInit): Promise<Response>;
|
|
16
|
+
private ensureFresh;
|
|
17
|
+
private refresh;
|
|
18
|
+
private send;
|
|
19
|
+
post(path: string, body: unknown): Promise<Response>;
|
|
20
|
+
/** Use this session's cookies and the linked app's declared data contract. */
|
|
21
|
+
data(table: string, request: DataRequest): Promise<Response>;
|
|
22
|
+
data(table: string, contract: string, request: DataRequest): Promise<Response>;
|
|
23
|
+
}
|
|
24
|
+
export type DataRequest = {
|
|
25
|
+
operation: 'list';
|
|
26
|
+
limit?: number;
|
|
27
|
+
after?: string | number;
|
|
28
|
+
where?: Record<string, unknown>;
|
|
29
|
+
} | {
|
|
30
|
+
operation: 'get' | 'delete';
|
|
31
|
+
id: string | number;
|
|
32
|
+
} | {
|
|
33
|
+
operation: 'create';
|
|
34
|
+
values: Record<string, unknown>;
|
|
35
|
+
} | {
|
|
36
|
+
operation: 'update';
|
|
37
|
+
id: string | number;
|
|
38
|
+
values: Record<string, unknown>;
|
|
39
|
+
};
|
|
40
|
+
export declare function expectStatus(response: Response, expected: number): Promise<void>;
|
|
41
|
+
export declare function expectRefusal(response: Response, status: 401 | 403, code: string): Promise<void>;
|
|
42
|
+
export declare function signIn(baseUrl: string, email: string, password: string): Promise<UserSession>;
|
|
43
|
+
export declare function createUser(baseUrl: string): Promise<UserSession>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type TestJob, type TestJobOptions, type TestJobTarget } from './testing-jobs.js';
|
|
2
|
+
import { UserSession } from './test-session.js';
|
|
3
|
+
export interface TestActor {
|
|
4
|
+
id: string;
|
|
5
|
+
email: string;
|
|
6
|
+
session: UserSession;
|
|
7
|
+
}
|
|
8
|
+
export interface TestApp {
|
|
9
|
+
origin: string;
|
|
10
|
+
anonymous: UserSession;
|
|
11
|
+
users(count: number): Promise<TestActor[]>;
|
|
12
|
+
create(user: TestActor, table: string, values: Record<string, unknown>, key?: string): Promise<string | number>;
|
|
13
|
+
plantMarker(user: TestActor, table: string, field: string, values?: Record<string, unknown>): Promise<string>;
|
|
14
|
+
onCleanup(label: string, action: () => Promise<void>): void;
|
|
15
|
+
runJob(job: TestJobTarget, options?: TestJobOptions): Promise<TestJob>;
|
|
16
|
+
cleanup(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
/** Open the linked deployment or this folder's exact saved preview. */
|
|
19
|
+
export declare function openTestApp(options?: {
|
|
20
|
+
preview?: boolean;
|
|
21
|
+
projectDir?: string;
|
|
22
|
+
}): Promise<TestApp>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TestTarget } from './test-target.js';
|
|
2
|
+
export type TestJobTarget = {
|
|
3
|
+
schedule: string;
|
|
4
|
+
} | {
|
|
5
|
+
handler: string;
|
|
6
|
+
payload?: unknown;
|
|
7
|
+
};
|
|
8
|
+
export interface TestJobOptions {
|
|
9
|
+
timeoutSeconds?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface TestJob {
|
|
12
|
+
job_id?: string;
|
|
13
|
+
request_id?: string;
|
|
14
|
+
status: string;
|
|
15
|
+
timed_out: boolean;
|
|
16
|
+
duration_ms?: number | null;
|
|
17
|
+
error_code?: string | null;
|
|
18
|
+
}
|
|
19
|
+
export declare function testingDeveloperToken(): string;
|
|
20
|
+
export declare function runTestJob(target: TestTarget, job: TestJobTarget, options?: TestJobOptions, previewCredential?: string): Promise<TestJob>;
|
package/dist/types/testing.d.ts
CHANGED
|
@@ -1,40 +1,15 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
post(path: string, body: unknown): Promise<Response>;
|
|
8
|
-
/** Use this session's cookies and the linked app's declared data contract. */
|
|
9
|
-
data(table: string, request: DataRequest): Promise<Response>;
|
|
10
|
-
data(table: string, contract: string, request: DataRequest): Promise<Response>;
|
|
1
|
+
export { UserSession, signIn, createUser, expectStatus, expectRefusal, type DataRequest } from './lib/test-session.js';
|
|
2
|
+
interface ReadyLocator {
|
|
3
|
+
first?(): ReadyLocator;
|
|
4
|
+
waitFor(options: {
|
|
5
|
+
state: 'visible';
|
|
6
|
+
}): Promise<void>;
|
|
11
7
|
}
|
|
12
|
-
export type DataRequest = {
|
|
13
|
-
operation: 'list';
|
|
14
|
-
limit?: number;
|
|
15
|
-
after?: string | number;
|
|
16
|
-
where?: Record<string, unknown>;
|
|
17
|
-
} | {
|
|
18
|
-
operation: 'get' | 'delete';
|
|
19
|
-
id: string | number;
|
|
20
|
-
} | {
|
|
21
|
-
operation: 'create';
|
|
22
|
-
values: Record<string, unknown>;
|
|
23
|
-
} | {
|
|
24
|
-
operation: 'update';
|
|
25
|
-
id: string | number;
|
|
26
|
-
values: Record<string, unknown>;
|
|
27
|
-
};
|
|
28
|
-
export declare function expectStatus(response: Response, expected: number): Promise<void>;
|
|
29
|
-
export declare function expectRefusal(response: Response, status: 401 | 403, code: string): Promise<void>;
|
|
30
|
-
export declare function signIn(baseUrl: string, email: string, password: string): Promise<UserSession>;
|
|
31
|
-
export declare function createUser(baseUrl: string): Promise<UserSession>;
|
|
32
8
|
interface BrowserPage {
|
|
33
|
-
locator(selector: string):
|
|
34
|
-
waitFor(options: {
|
|
35
|
-
state: 'visible';
|
|
36
|
-
}): Promise<void>;
|
|
37
|
-
};
|
|
9
|
+
locator(selector: string): ReadyLocator;
|
|
38
10
|
}
|
|
39
11
|
export declare function waitForApp(page: BrowserPage, state?: 'ready' | 'signed-in' | 'signed-out'): Promise<void>;
|
|
40
12
|
export { test, expect, expectRefused, data, ready, type RefusalOptions, type TestUser, type NewUserOptions, type Person, type SignUpOptions, type SignInOptions, type FormSteps, type CodeSteps } from './lib/playwright-fixtures.js';
|
|
13
|
+
export { openTestApp, type TestApp, type TestActor } from './lib/testing-app.js';
|
|
14
|
+
export { assertNoLeak, captureResponses } from './lib/test-response-capture.js';
|
|
15
|
+
export type { TestJob, TestJobOptions, TestJobTarget } from './lib/testing-jobs.js';
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@somewhere-cloud/cli",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.153",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@somewhere-cloud/cli",
|
|
9
|
-
"version": "0.38.
|
|
9
|
+
"version": "0.38.153",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"bin": {
|
|
12
12
|
"somewhere": "bin/somewhere.js",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@somewhere-cloud/cli",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.153",
|
|
4
4
|
"description": "CLI for somewhere.cloud — auth, projects, deploy, pull, promote, db, logs, env, MCP bridge.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"somewhere",
|
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
"exports": {
|
|
57
57
|
"./testing": {
|
|
58
58
|
"types": "./dist/types/testing.d.ts",
|
|
59
|
-
"import": "./dist/testing.js"
|
|
59
|
+
"import": "./dist/testing.js",
|
|
60
|
+
"default": "./dist/testing.js"
|
|
60
61
|
},
|
|
61
62
|
"./package.json": "./package.json",
|
|
62
63
|
"./script": {
|
|
@@ -66,5 +67,5 @@
|
|
|
66
67
|
},
|
|
67
68
|
"bundleDependencies": [],
|
|
68
69
|
"bundledDependencies": [],
|
|
69
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "af9a0fd1effcf34aa1a07e5c97c6a654529d381b"
|
|
70
71
|
}
|
package/src/testing.ts
CHANGED
|
@@ -1,85 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
import { getToken, loadProjectConfig } from './lib/config.js';
|
|
3
|
-
import { fixtureTestTarget, type TestTarget } from './lib/test-target.js';
|
|
1
|
+
export { UserSession, signIn, createUser, expectStatus, expectRefusal, type DataRequest } from './lib/test-session.js';
|
|
4
2
|
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
private target?: Promise<TestTarget>;
|
|
10
|
-
constructor(baseUrl: string) { this.origin = new URL(baseUrl).origin; }
|
|
11
|
-
async request(path: string, init: RequestInit = {}): Promise<Response> {
|
|
12
|
-
const url = new URL(path, this.origin);
|
|
13
|
-
if (url.origin !== this.origin) throw new Error('Fixture requests must stay on the app origin');
|
|
14
|
-
const headers = new Headers(init.headers);
|
|
15
|
-
headers.set('Origin', this.origin);
|
|
16
|
-
headers.set('Cookie', [...this.cookies].map(([k, v]) => k + '=' + v).join('; '));
|
|
17
|
-
const response = await fetch(url, { ...init, headers, redirect: 'error' });
|
|
18
|
-
for (const cookie of response.headers.getSetCookie()) {
|
|
19
|
-
const pair = cookie.split(';')[0];
|
|
20
|
-
const split = pair.indexOf('=');
|
|
21
|
-
this.cookies.set(pair.slice(0, split), pair.slice(split + 1));
|
|
22
|
-
}
|
|
23
|
-
return response;
|
|
24
|
-
}
|
|
25
|
-
post(path: string, body: unknown): Promise<Response> {
|
|
26
|
-
return this.request(path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
|
|
27
|
-
}
|
|
28
|
-
/** Use this session's cookies and the linked app's declared data contract. */
|
|
29
|
-
data(table: string, request: DataRequest): Promise<Response>;
|
|
30
|
-
data(table: string, contract: string, request: DataRequest): Promise<Response>;
|
|
31
|
-
async data(table: string, requestOrContract: DataRequest | string, request?: DataRequest): Promise<Response> {
|
|
32
|
-
if (typeof requestOrContract === 'string') {
|
|
33
|
-
return this.post('/__sw/data', { ...request, table, contract: requestOrContract });
|
|
34
|
-
}
|
|
35
|
-
const projectId = loadProjectConfig()?.project_id;
|
|
36
|
-
if (!projectId) throw new Error('Use the data helper from a linked project folder.');
|
|
37
|
-
const target = await (this.target ??= fixtureTestTarget(new ApiClient(process.env.SW_TEST_TARGET ? null : getToken()), projectId));
|
|
38
|
-
if (target.origin !== this.origin) throw new Error('This session belongs to a different app than the linked test target.');
|
|
39
|
-
return this.post('/__sw/data', { ...requestOrContract, table, contract: target.contractDigest ?? '' });
|
|
40
|
-
}
|
|
3
|
+
// Structurally compatible with Playwright without loading its browser.
|
|
4
|
+
interface ReadyLocator {
|
|
5
|
+
first?(): ReadyLocator;
|
|
6
|
+
waitFor(options: { state: 'visible' }): Promise<void>;
|
|
41
7
|
}
|
|
42
|
-
|
|
43
|
-
| { operation: 'list'; limit?: number; after?: string | number; where?: Record<string, unknown> }
|
|
44
|
-
| { operation: 'get' | 'delete'; id: string | number }
|
|
45
|
-
| { operation: 'create'; values: Record<string, unknown> }
|
|
46
|
-
| { operation: 'update'; id: string | number; values: Record<string, unknown> };
|
|
47
|
-
|
|
48
|
-
export async function expectStatus(response: Response, expected: number): Promise<void> {
|
|
49
|
-
if (response.status !== expected) throw new Error('Expected HTTP ' + expected + ', received ' + response.status);
|
|
50
|
-
}
|
|
51
|
-
export async function expectRefusal(response: Response, status: 401 | 403, code: string): Promise<void> {
|
|
52
|
-
await expectStatus(response, status);
|
|
53
|
-
const body: unknown = await response.json();
|
|
54
|
-
if (!body || typeof body !== 'object' || !('error' in body) || body.error !== code) {
|
|
55
|
-
throw new Error('Refusal did not have the exact expected error code: ' + code);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
export async function signIn(baseUrl: string, email: string, password: string): Promise<UserSession> {
|
|
59
|
-
const session = new UserSession(baseUrl);
|
|
60
|
-
const response = await session.post('/api/auth/login', { email, password });
|
|
61
|
-
await expectStatus(response, 200);
|
|
62
|
-
const body = await response.json() as { cookie_session?: boolean };
|
|
63
|
-
if (!body.cookie_session) throw new Error('Sign-in did not establish a cookie session');
|
|
64
|
-
return session;
|
|
65
|
-
}
|
|
66
|
-
export async function createUser(baseUrl: string): Promise<UserSession> {
|
|
67
|
-
const session = new UserSession(baseUrl);
|
|
68
|
-
// Reserved platform test domain: no real recipient, no admin credential.
|
|
69
|
-
const email = 'starter-' + crypto.randomUUID() + '@fixture.test.somewhere.site';
|
|
70
|
-
const password = 'Fixture!9-' + crypto.randomUUID();
|
|
71
|
-
const response = await session.post('/api/auth/signup', { email, password });
|
|
72
|
-
await expectStatus(response, 200);
|
|
73
|
-
const body = await response.json() as { cookie_session?: boolean };
|
|
74
|
-
if (!body.cookie_session) throw new Error('Signup did not establish a cookie session');
|
|
75
|
-
return session;
|
|
76
|
-
}
|
|
77
|
-
// Structurally compatible with Playwright Page; no browser dependency required.
|
|
78
|
-
interface BrowserPage { locator(selector: string): { waitFor(options: { state: 'visible' }): Promise<void> } }
|
|
8
|
+
interface BrowserPage { locator(selector: string): ReadyLocator }
|
|
79
9
|
export function waitForApp(page: BrowserPage, state: 'ready' | 'signed-in' | 'signed-out' = 'ready'): Promise<void> {
|
|
80
|
-
const
|
|
81
|
-
|
|
10
|
+
const values = state === 'ready' ? ['signed-in', 'signed-out'] : [state];
|
|
11
|
+
const matches = values.flatMap(value => [`html[data-sw-auth="${value}"]`, `[data-app-state="${value}"]`]);
|
|
12
|
+
const locator = page.locator(matches.join(', '));
|
|
13
|
+
return (locator.first?.() ?? locator).waitFor({ state: 'visible' });
|
|
82
14
|
}
|
|
83
15
|
|
|
84
16
|
// Lazy project-local Playwright resolution keeps UserSession dependency-free.
|
|
85
17
|
export { test, expect, expectRefused, data, ready, type RefusalOptions, type TestUser, type NewUserOptions, type Person, type SignUpOptions, type SignInOptions, type FormSteps, type CodeSteps } from './lib/playwright-fixtures.js';
|
|
18
|
+
|
|
19
|
+
export { openTestApp, type TestApp, type TestActor } from './lib/testing-app.js';
|
|
20
|
+
export { assertNoLeak, captureResponses } from './lib/test-response-capture.js';
|
|
21
|
+
export type { TestJob, TestJobOptions, TestJobTarget } from './lib/testing-jobs.js';
|