testsurfer 0.1.2 → 0.3.0

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 (84) hide show
  1. package/README.md +52 -149
  2. package/dist/browser.d.ts +135 -1
  3. package/dist/browser.js +378 -2
  4. package/dist/browser.js.map +1 -1
  5. package/dist/cli.d.ts +16 -0
  6. package/dist/cli.js +140 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/client.d.ts +12 -2
  9. package/dist/client.js +73 -4
  10. package/dist/client.js.map +1 -1
  11. package/dist/diff.d.ts +19 -0
  12. package/dist/diff.js +116 -0
  13. package/dist/diff.js.map +1 -0
  14. package/dist/events.d.ts +386 -0
  15. package/dist/events.js +1035 -0
  16. package/dist/events.js.map +1 -0
  17. package/dist/expect.d.ts +135 -26
  18. package/dist/expect.js +634 -130
  19. package/dist/expect.js.map +1 -1
  20. package/dist/frame.d.ts +88 -0
  21. package/dist/frame.js +194 -0
  22. package/dist/frame.js.map +1 -0
  23. package/dist/global.d.ts +12 -0
  24. package/dist/global.js +136 -0
  25. package/dist/global.js.map +1 -0
  26. package/dist/hooks.d.ts +28 -0
  27. package/dist/hooks.js +48 -0
  28. package/dist/hooks.js.map +1 -0
  29. package/dist/index.d.ts +22 -3
  30. package/dist/index.js +21 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/injected.d.ts +15 -0
  33. package/dist/injected.js +2025 -0
  34. package/dist/injected.js.map +1 -0
  35. package/dist/locator.d.ts +374 -86
  36. package/dist/locator.js +845 -244
  37. package/dist/locator.js.map +1 -1
  38. package/dist/media.d.ts +15 -0
  39. package/dist/media.js +83 -0
  40. package/dist/media.js.map +1 -0
  41. package/dist/net.d.ts +110 -0
  42. package/dist/net.js +498 -0
  43. package/dist/net.js.map +1 -0
  44. package/dist/page.d.ts +448 -5
  45. package/dist/page.js +1187 -31
  46. package/dist/page.js.map +1 -1
  47. package/dist/png.d.ts +28 -0
  48. package/dist/png.js +197 -0
  49. package/dist/png.js.map +1 -0
  50. package/dist/pwconfig.d.ts +66 -0
  51. package/dist/pwconfig.js +77 -0
  52. package/dist/pwconfig.js.map +1 -0
  53. package/dist/register.d.ts +6 -0
  54. package/dist/register.js +9 -0
  55. package/dist/register.js.map +1 -0
  56. package/dist/request.d.ts +29 -0
  57. package/dist/request.js +75 -0
  58. package/dist/request.js.map +1 -0
  59. package/dist/runner.d.ts +99 -15
  60. package/dist/runner.js +354 -58
  61. package/dist/runner.js.map +1 -1
  62. package/dist/screenshot.d.ts +35 -0
  63. package/dist/screenshot.js +171 -0
  64. package/dist/screenshot.js.map +1 -0
  65. package/dist/selector.d.ts +55 -0
  66. package/dist/selector.js +208 -0
  67. package/dist/selector.js.map +1 -0
  68. package/dist/selectors.d.ts +13 -0
  69. package/dist/selectors.js +16 -0
  70. package/dist/selectors.js.map +1 -0
  71. package/dist/serialize.d.ts +17 -0
  72. package/dist/serialize.js +149 -0
  73. package/dist/serialize.js.map +1 -0
  74. package/dist/shim.d.ts +15 -0
  75. package/dist/shim.js +211 -0
  76. package/dist/shim.js.map +1 -0
  77. package/dist/testinfo.d.ts +62 -0
  78. package/dist/testinfo.js +23 -0
  79. package/dist/testinfo.js.map +1 -0
  80. package/dist/values.d.ts +67 -0
  81. package/dist/values.js +293 -0
  82. package/dist/values.js.map +1 -0
  83. package/package.json +10 -3
  84. package/skills/testsurfer/SKILL.md +55 -0
@@ -0,0 +1,386 @@
1
+ /**
2
+ * page.route() and page.on(), driven by the page shim (src/shim.ts).
3
+ *
4
+ * A poller on its own daemon connection takes the shim's queue every
5
+ * few milliseconds while the page has routes or listeners. It emits
6
+ * events and runs route handlers, then settles each held request in
7
+ * the page. Its own connection means a long call on the test's
8
+ * connection (a wait) cannot stall a request the page is waiting on.
9
+ */
10
+ import type { WireClient } from './client.ts';
11
+ import { type NetDecider } from './net.ts';
12
+ export type UrlMatcher = string | RegExp | ((url: URL) => boolean);
13
+ /** Playwright-style glob: `**` any characters, `*` any but `/`, `{a,b}` alternatives. */
14
+ export declare function globToRegExp(glob: string): RegExp;
15
+ export declare function urlMatches(matcher: UrlMatcher, url: string, baseURL?: string): boolean;
16
+ interface RequestInfo {
17
+ id: number;
18
+ url: string;
19
+ method: string;
20
+ headers: Record<string, string>;
21
+ body: string | null;
22
+ /** fetch, xhr, document, script, stylesheet, image, font, media, websocket, manifest or other. */
23
+ type: string;
24
+ /** The main-frame or iframe navigation (proxy mode). */
25
+ navigation?: boolean;
26
+ frame?: 'main' | 'sub';
27
+ /** Headers in their original case and order, as sent (proxy mode). */
28
+ raw?: {
29
+ name: string;
30
+ value: string;
31
+ }[];
32
+ /** The request body's bytes (proxy mode). */
33
+ bodyBytes?: Buffer | null;
34
+ }
35
+ /** A fetch or XHR the page made. */
36
+ export declare class Request {
37
+ private readonly info;
38
+ /** Set once the response (or failure) arrives. */
39
+ responseValue: Response | null;
40
+ /** The frame that made the request. */
41
+ frameValue: unknown;
42
+ /** Redirect chain, when the proxy saw a 3xx before this request. */
43
+ redirectedFromValue: Request | null;
44
+ redirectedToValue: Request | null;
45
+ /** The route aborted it. */
46
+ abortedByRoute: boolean;
47
+ /** Proxy mode: the page's service worker handed it on; its response is fromServiceWorker(). */
48
+ viaServiceWorker: boolean;
49
+ frame(): any;
50
+ failureText: string | null;
51
+ constructor(info: RequestInfo);
52
+ /** The shim's id for this request. */
53
+ get id(): number;
54
+ url(): string;
55
+ method(): string;
56
+ headers(): Record<string, string>;
57
+ /** @internal setExtraHTTPHeaders() values join the request's headers. */
58
+ addHeader(name: string, value: string): void;
59
+ postData(): string | null;
60
+ postDataJSON(): unknown;
61
+ /** `fetch`, `xhr`, or `document` for the main-frame navigation goto() returns. */
62
+ resourceType(): string;
63
+ isNavigationRequest(): boolean;
64
+ /** `main` or `sub` (an iframe), as far as the proxy can tell. */
65
+ frameKind(): 'main' | 'sub';
66
+ headersArray(): {
67
+ name: string;
68
+ value: string;
69
+ }[];
70
+ redirectedFrom(): Request | null;
71
+ redirectedTo(): Request | null;
72
+ timing(): Record<string, number>;
73
+ allHeaders(): Promise<Record<string, string>>;
74
+ headerValue(name: string): Promise<string | null>;
75
+ /** The response, when it has arrived (no waiting). */
76
+ existingResponse(): Response | null;
77
+ sizes(): Promise<{
78
+ requestBodySize: number;
79
+ requestHeadersSize: number;
80
+ responseBodySize: number;
81
+ responseHeadersSize: number;
82
+ }>;
83
+ serviceWorker(): null;
84
+ postDataBuffer(): Buffer | null;
85
+ failure(): {
86
+ errorText: string;
87
+ } | null;
88
+ /** Proxy mode: response() waits for the response or the failure. */
89
+ awaitsResponse: boolean;
90
+ private settled;
91
+ private waiters;
92
+ /** @internal The response arrived, or the request failed or finished. */
93
+ markSettled(): void;
94
+ response(): Promise<Response | null>;
95
+ }
96
+ /**
97
+ * Response metadata. The body is read on demand by fetching the URL
98
+ * again from the page (GET only), since it is not captured in flight.
99
+ */
100
+ export declare class Response {
101
+ private readonly req;
102
+ private readonly data;
103
+ /** Reads the body; set by whoever built the response. */
104
+ bodyLoader: (() => Promise<Buffer>) | null;
105
+ /** Headers in their original case and order (proxy mode). */
106
+ rawHeaders: {
107
+ name: string;
108
+ value: string;
109
+ }[] | null;
110
+ constructor(req: Request, data: {
111
+ url: string;
112
+ status: number;
113
+ statusText: string;
114
+ headers: Record<string, string>;
115
+ });
116
+ headersArray(): {
117
+ name: string;
118
+ value: string;
119
+ }[];
120
+ headersArrayAsync(): Promise<{
121
+ name: string;
122
+ value: string;
123
+ }[]>;
124
+ headerValues(name: string): Promise<string[]>;
125
+ /** Proxy mode: the page's service worker handed the request on (see PageEvents.netViaServiceWorker). */
126
+ viaServiceWorker: boolean;
127
+ fromServiceWorker(): boolean;
128
+ httpVersion(): string;
129
+ serverAddr(): Promise<null>;
130
+ securityDetails(): Promise<null>;
131
+ allHeaders(): Promise<Record<string, string>>;
132
+ headerValue(name: string): Promise<string | null>;
133
+ body(): Promise<Buffer>;
134
+ text(): Promise<string>;
135
+ json(): Promise<unknown>;
136
+ finished(): Promise<null>;
137
+ frame(): unknown;
138
+ url(): string;
139
+ status(): number;
140
+ statusText(): string;
141
+ ok(): boolean;
142
+ headers(): Record<string, string>;
143
+ request(): Request;
144
+ }
145
+ /** The real response route.fetch() fetched, with its body. */
146
+ interface APIResponseData {
147
+ status: number;
148
+ statusText: string;
149
+ headers: Record<string, string>;
150
+ body: Buffer;
151
+ url: string;
152
+ }
153
+ export declare class APIResponse {
154
+ private readonly data;
155
+ constructor(data: APIResponseData);
156
+ url(): string;
157
+ status(): number;
158
+ statusText(): string;
159
+ ok(): boolean;
160
+ headers(): Record<string, string>;
161
+ body(): Promise<Buffer>;
162
+ text(): Promise<string>;
163
+ json(): Promise<unknown>;
164
+ }
165
+ /**
166
+ * An `alert`, `confirm` or `prompt` the page is blocked on (proxy
167
+ * mode). A `dialog` listener must accept or dismiss it; with no
168
+ * listener it is dismissed, as in Playwright.
169
+ */
170
+ export declare class Dialog {
171
+ private handled;
172
+ private readonly kind;
173
+ private readonly text;
174
+ private readonly defaultText;
175
+ private readonly pageValue;
176
+ private readonly answer;
177
+ constructor(kind: string, text: string, defaultText: string, page: unknown, answer: (accept: boolean, text?: string) => Promise<void>);
178
+ /** @internal Whether accept() or dismiss() ran. */
179
+ isHandled(): boolean;
180
+ type(): string;
181
+ message(): string;
182
+ defaultValue(): string;
183
+ page(): any;
184
+ accept(promptText?: string): Promise<void>;
185
+ dismiss(): Promise<void>;
186
+ }
187
+ /** A console argument, as a value already copied out of the page. */
188
+ export declare class ConsoleArg {
189
+ private readonly value;
190
+ constructor(value: unknown);
191
+ jsonValue(): Promise<unknown>;
192
+ dispose(): Promise<void>;
193
+ toString(): string;
194
+ }
195
+ export declare class ConsoleMessage {
196
+ private readonly kind;
197
+ private readonly message;
198
+ private readonly values;
199
+ private readonly owner;
200
+ constructor(kind: string, message: string, values?: {
201
+ v?: unknown;
202
+ u?: number;
203
+ }[], owner?: unknown);
204
+ /** The arguments passed to console.*, as handles whose jsonValue() is the value. */
205
+ args(): ConsoleArg[];
206
+ page(): unknown;
207
+ location(): {
208
+ url: string;
209
+ lineNumber: number;
210
+ columnNumber: number;
211
+ };
212
+ /** `log`, `info`, `warning`, `error` or `debug`. */
213
+ type(): string;
214
+ text(): string;
215
+ }
216
+ export interface FulfillOptions {
217
+ status?: number;
218
+ headers?: Record<string, string>;
219
+ contentType?: string;
220
+ body?: string | Buffer;
221
+ json?: unknown;
222
+ /** File whose contents are the body. */
223
+ path?: string;
224
+ /** Start from a response route.fetch() returned; the other options override it. */
225
+ response?: APIResponse;
226
+ }
227
+ export interface ContinueOptions {
228
+ url?: string;
229
+ method?: string;
230
+ headers?: Record<string, string>;
231
+ postData?: string | Buffer;
232
+ }
233
+ type Decision = Record<string, unknown> & {
234
+ kind: string;
235
+ };
236
+ /** A request held by page.route(), waiting for the handler's decision. */
237
+ export declare class Route {
238
+ /** Set by the first decision; a second one is an error. */
239
+ handled: boolean;
240
+ /** fallback() was called: try the next matching handler. */
241
+ fellBack: ContinueOptions | null;
242
+ private readonly req;
243
+ private readonly settle;
244
+ private readonly fetchVia;
245
+ constructor(req: Request, settle: (d: Decision) => Promise<void>, fetchVia: (opts: ContinueOptions) => Promise<APIResponse>);
246
+ request(): Request;
247
+ private claim;
248
+ fulfill(options?: FulfillOptions): Promise<void>;
249
+ continue(options?: ContinueOptions): Promise<void>;
250
+ abort(errorCode?: string): Promise<void>;
251
+ /** Let the next matching handler decide (or the network, when none does). */
252
+ fallback(options?: ContinueOptions): Promise<void>;
253
+ /** Perform the request for real and return the response, to modify and fulfill with. */
254
+ fetch(options?: ContinueOptions): Promise<APIResponse>;
255
+ }
256
+ export type RouteHandler = (route: Route, request: Request) => Promise<void> | void;
257
+ type Listener = (arg: never) => void;
258
+ /** What PageEvents needs from its page. */
259
+ export interface EventsHost {
260
+ /** A second daemon connection for the poller. */
261
+ openPoller: () => Promise<WireClient>;
262
+ target: () => {
263
+ pageId: string | null;
264
+ sessionId: string;
265
+ };
266
+ baseURL: string | undefined;
267
+ /** Make sure the shim is installed for this and later documents. */
268
+ ensureShim: () => Promise<void>;
269
+ /** Add a document-start script for later documents. */
270
+ addInitScript: (source: string) => Promise<void>;
271
+ /** The session routes through vibesurfer's proxy (`--intercept`); see src/net.ts. */
272
+ proxied?: () => boolean;
273
+ /** The page's main frame, for request.frame(). */
274
+ mainFrame?: () => unknown;
275
+ /** The iframe loading `url` (or the newest one), for an iframe's request.frame(). */
276
+ childFrame?: (url: string) => unknown;
277
+ /** setExtraHTTPHeaders() values for this page and its context. */
278
+ extraHeaders?: () => Record<string, string>;
279
+ /** A service worker controlled the page as of the last engine call. */
280
+ swControlled?: () => boolean;
281
+ /** The page's URL as of the last engine call. */
282
+ pageURL?: () => string;
283
+ /** The page is a popup another page opened. */
284
+ isPopup?: () => boolean;
285
+ }
286
+ /** Per-page routing and event state. The Page owns one. */
287
+ export declare class PageEvents {
288
+ private routes;
289
+ private listeners;
290
+ private requests;
291
+ private pendingFetch;
292
+ private timer;
293
+ private poller;
294
+ private pollerP;
295
+ private routingOn;
296
+ private readonly host;
297
+ /** Routing default last given to new documents. */
298
+ private routingDefault;
299
+ constructor(host: EventsHost);
300
+ get active(): boolean;
301
+ /** exposeBinding() callbacks by name; the page calls them through the shim queue. */
302
+ private bindings;
303
+ /** Register a binding and return the page-side script that defines it. */
304
+ addBinding(name: string, fn: (...args: unknown[]) => unknown): string;
305
+ private bindingDepth;
306
+ private runBinding;
307
+ get routing(): boolean;
308
+ addRoute(matcher: UrlMatcher, handler: RouteHandler, times: number | null): void;
309
+ removeRoutes(matcher?: UrlMatcher, handler?: RouteHandler): void;
310
+ on(name: string, fn: Listener): void;
311
+ off(name: string, fn: Listener): void;
312
+ private emit;
313
+ /** Start or stop polling and tell the page whether to hold requests. */
314
+ private hub;
315
+ /** Proxy mode: the session's network hub carries requests, responses and routes. */
316
+ private get proxied();
317
+ netEmit(name: string, arg: unknown): void;
318
+ netRoutes(): boolean;
319
+ netExtraHeaders(): Record<string, string>;
320
+ netFrame(kind: 'main' | 'sub', url: string): unknown;
321
+ /**
322
+ * A request this page's service worker handed on: the page is
323
+ * controlled and the request comes from its document. WebKit sends
324
+ * the same headers either way, so this is as close as the proxy gets.
325
+ */
326
+ netViaServiceWorker(referer: string): boolean;
327
+ private navAborted;
328
+ /** A route aborted the last main-frame navigation (read once). */
329
+ abortedNavigation(): boolean;
330
+ netNavAborted(): void;
331
+ /** Proxy mode: the main document's response from the hub, redirect chain and all. */
332
+ proxiedNavResponse(): Promise<Response | null>;
333
+ /** Proxy mode: make sure the hub is attached before a navigation, so it sees the document. */
334
+ beforeNavigation(): Promise<void>;
335
+ /** Proxy mode: join the session's hub now (a popup, before its first request). */
336
+ attachHub(): void;
337
+ netIsPopup(): boolean;
338
+ /** Report an event that is not network traffic (popup, close). */
339
+ emitPageEvent(name: string, arg: unknown): void;
340
+ /** Whether anyone listens for `name`. */
341
+ hasListeners(name: string): boolean;
342
+ /**
343
+ * Shim mode: run this page's routes for a main-document navigation
344
+ * to `url`, which the in-page shim cannot see. A fulfilled document
345
+ * is loaded under `url` (vs goto --html); `continue` may change the
346
+ * URL; null means no route decided and the page navigates as usual.
347
+ */
348
+ routeDocument(url: string): Promise<{
349
+ kind: 'fulfill';
350
+ status: number;
351
+ headers: Record<string, string>;
352
+ body: Buffer;
353
+ req: Request;
354
+ } | {
355
+ kind: 'continue';
356
+ url: string;
357
+ } | {
358
+ kind: 'abort';
359
+ } | null>;
360
+ netHandle(req: Request, decide: NetDecider, fallthrough: ContinueOptions): Promise<boolean>;
361
+ sync(): Promise<void>;
362
+ /** A new document starts with routing off; the next sync turns it on again. */
363
+ documentChanged(): void;
364
+ private closedEvents;
365
+ private client;
366
+ private evalPage;
367
+ private tickP;
368
+ private pendingBindings;
369
+ private tick;
370
+ private drain;
371
+ get hasBindings(): boolean;
372
+ /**
373
+ * Take the page's queue now and wait for the exposed functions it
374
+ * called, so a binding fired by an action has run when the action
375
+ * returns, as in Playwright.
376
+ */
377
+ flush(): Promise<void>;
378
+ private onEvent;
379
+ private settle;
380
+ private onHeld;
381
+ private fetchFor;
382
+ /** Resolve with the first `name` event `predicate` accepts, or reject on timeout. */
383
+ waitFor<T>(name: string, predicate: (arg: T) => boolean | Promise<boolean>, timeout: number): Promise<T>;
384
+ close(): void;
385
+ }
386
+ export {};