@ricsam/isolate-client 0.1.1 → 0.1.5
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 +313 -39
- package/dist/cjs/connection.cjs +785 -104
- package/dist/cjs/connection.cjs.map +3 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/connection.mjs +790 -105
- package/dist/mjs/connection.mjs.map +3 -3
- package/dist/mjs/index.mjs.map +1 -1
- package/dist/mjs/package.json +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types.d.ts +207 -82
- package/package.json +10 -1
package/dist/types/types.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Types for the isolate client.
|
|
3
3
|
*/
|
|
4
|
-
import type { RunTestsResult, TestResult as ProtocolTestResult,
|
|
5
|
-
export type
|
|
4
|
+
import type { RunTestsResult, TestResult as ProtocolTestResult, TestInfo as ProtocolTestInfo, TestError as ProtocolTestError, TestEvent as ProtocolTestEvent, SuiteInfo as ProtocolSuiteInfo, SuiteResult as ProtocolSuiteResult, CollectedData as ProtocolCollectedData, ConsoleEntry as ProtocolConsoleEntry, PlaywrightEvent as ProtocolPlaywrightEvent, CustomFunctionType } from "@ricsam/isolate-protocol";
|
|
5
|
+
export type RunResults = RunTestsResult;
|
|
6
6
|
export type TestResult = ProtocolTestResult;
|
|
7
|
-
export type
|
|
7
|
+
export type TestInfo = ProtocolTestInfo;
|
|
8
|
+
export type TestError = ProtocolTestError;
|
|
9
|
+
export type TestEvent = ProtocolTestEvent;
|
|
10
|
+
export type SuiteInfo = ProtocolSuiteInfo;
|
|
11
|
+
export type SuiteResult = ProtocolSuiteResult;
|
|
8
12
|
export type CollectedData = ProtocolCollectedData;
|
|
13
|
+
export type ConsoleEntry = ProtocolConsoleEntry;
|
|
14
|
+
export type PlaywrightEvent = ProtocolPlaywrightEvent;
|
|
9
15
|
/**
|
|
10
16
|
* Options for connecting to the daemon.
|
|
11
17
|
*/
|
|
@@ -30,29 +36,63 @@ export interface DaemonConnection {
|
|
|
30
36
|
/** Check if connected */
|
|
31
37
|
isConnected(): boolean;
|
|
32
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Test environment options for createRuntime.
|
|
41
|
+
*/
|
|
42
|
+
export interface TestEnvironmentOptions {
|
|
43
|
+
/** Receive test lifecycle events */
|
|
44
|
+
onEvent?: (event: TestEvent) => void;
|
|
45
|
+
/** Timeout for individual tests (ms) */
|
|
46
|
+
testTimeout?: number;
|
|
47
|
+
}
|
|
33
48
|
/**
|
|
34
49
|
* Options for creating a runtime.
|
|
35
50
|
*/
|
|
36
51
|
export interface RuntimeOptions {
|
|
37
|
-
/** Memory limit in
|
|
38
|
-
|
|
52
|
+
/** Memory limit in megabytes (optional) */
|
|
53
|
+
memoryLimitMB?: number;
|
|
39
54
|
/** Console callback handlers */
|
|
40
55
|
console?: ConsoleCallbacks;
|
|
41
56
|
/** Fetch callback handler */
|
|
42
57
|
fetch?: FetchCallback;
|
|
43
58
|
/** File system callback handlers */
|
|
44
59
|
fs?: FileSystemCallbacks;
|
|
60
|
+
/** Module loader callback for resolving dynamic imports */
|
|
61
|
+
moduleLoader?: ModuleLoaderCallback;
|
|
62
|
+
/** Custom functions callable from within the isolate */
|
|
63
|
+
customFunctions?: CustomFunctions;
|
|
64
|
+
/** Current working directory for path.resolve(). Defaults to "/" */
|
|
65
|
+
cwd?: string;
|
|
66
|
+
/** Enable test environment (describe, it, expect, etc.) */
|
|
67
|
+
testEnvironment?: boolean | TestEnvironmentOptions;
|
|
68
|
+
/** Playwright options - user provides page */
|
|
69
|
+
playwright?: PlaywrightOptions;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Options for Playwright integration.
|
|
73
|
+
* User provides the page object - client owns the browser.
|
|
74
|
+
*/
|
|
75
|
+
export interface PlaywrightOptions {
|
|
76
|
+
/** Playwright page object */
|
|
77
|
+
page: import("playwright").Page;
|
|
78
|
+
/** Default timeout for operations in ms */
|
|
79
|
+
timeout?: number;
|
|
80
|
+
/** Base URL for navigation */
|
|
81
|
+
baseUrl?: string;
|
|
82
|
+
/** If true, browser console logs are routed through console handler (or printed to stdout if no handler) */
|
|
83
|
+
console?: boolean;
|
|
84
|
+
/** Unified event callback for all playwright events */
|
|
85
|
+
onEvent?: (event: PlaywrightEvent) => void;
|
|
45
86
|
}
|
|
46
87
|
/**
|
|
47
|
-
* Console callback handlers.
|
|
88
|
+
* Console callback handlers with single structured callback.
|
|
48
89
|
*/
|
|
49
90
|
export interface ConsoleCallbacks {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
dir?: (...args: unknown[]) => void;
|
|
91
|
+
/**
|
|
92
|
+
* Callback invoked for each console operation.
|
|
93
|
+
* Receives a structured entry with all data needed to render the output.
|
|
94
|
+
*/
|
|
95
|
+
onEntry?: (entry: ConsoleEntry) => void;
|
|
56
96
|
}
|
|
57
97
|
/**
|
|
58
98
|
* Fetch callback type.
|
|
@@ -77,33 +117,169 @@ export interface FileSystemCallbacks {
|
|
|
77
117
|
}>;
|
|
78
118
|
rename?: (from: string, to: string) => Promise<void>;
|
|
79
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Module loader callback type.
|
|
122
|
+
* Called when the isolate imports a module dynamically.
|
|
123
|
+
* Returns the JavaScript source code for the module.
|
|
124
|
+
*/
|
|
125
|
+
export type ModuleLoaderCallback = (moduleName: string) => string | Promise<string>;
|
|
126
|
+
export type { CustomFunctionType };
|
|
127
|
+
/**
|
|
128
|
+
* A custom function that can be called from within the isolate.
|
|
129
|
+
*/
|
|
130
|
+
export type CustomFunction = (...args: unknown[]) => unknown | Promise<unknown>;
|
|
131
|
+
/**
|
|
132
|
+
* An async generator function that can be consumed in the isolate via for await...of.
|
|
133
|
+
*/
|
|
134
|
+
export type CustomAsyncGeneratorFunction = (...args: unknown[]) => AsyncGenerator<unknown, unknown, unknown>;
|
|
135
|
+
/**
|
|
136
|
+
* Custom function definition with metadata.
|
|
137
|
+
*/
|
|
138
|
+
export interface CustomFunctionDefinition {
|
|
139
|
+
/** The function implementation */
|
|
140
|
+
fn: CustomFunction | CustomAsyncGeneratorFunction;
|
|
141
|
+
/** Function type: 'sync', 'async', or 'asyncIterator' */
|
|
142
|
+
type: CustomFunctionType;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Custom functions to register in the runtime.
|
|
146
|
+
*/
|
|
147
|
+
export type CustomFunctions = Record<string, CustomFunctionDefinition>;
|
|
148
|
+
/**
|
|
149
|
+
* Options for eval() method.
|
|
150
|
+
*/
|
|
151
|
+
export interface EvalOptions {
|
|
152
|
+
/** Filename for stack traces */
|
|
153
|
+
filename?: string;
|
|
154
|
+
/** Maximum execution time in milliseconds. If exceeded, throws a timeout error. */
|
|
155
|
+
maxExecutionMs?: number;
|
|
156
|
+
/**
|
|
157
|
+
* @deprecated Always uses module mode now. This option is ignored.
|
|
158
|
+
*/
|
|
159
|
+
module?: boolean;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* WebSocket upgrade request info.
|
|
163
|
+
*/
|
|
164
|
+
export interface UpgradeRequest {
|
|
165
|
+
requested: true;
|
|
166
|
+
connectionId: string;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* WebSocket command from isolate.
|
|
170
|
+
*/
|
|
171
|
+
export interface WebSocketCommand {
|
|
172
|
+
type: "message" | "close";
|
|
173
|
+
connectionId: string;
|
|
174
|
+
data?: string | ArrayBuffer;
|
|
175
|
+
code?: number;
|
|
176
|
+
reason?: string;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Remote fetch handle - provides access to fetch/serve operations.
|
|
180
|
+
* All methods are async since they communicate over IPC.
|
|
181
|
+
*/
|
|
182
|
+
export interface RemoteFetchHandle {
|
|
183
|
+
/** Dispatch HTTP request to serve() handler */
|
|
184
|
+
dispatchRequest(request: Request, options?: DispatchOptions): Promise<Response>;
|
|
185
|
+
/** Check if isolate requested WebSocket upgrade */
|
|
186
|
+
getUpgradeRequest(): Promise<UpgradeRequest | null>;
|
|
187
|
+
/** Dispatch WebSocket open event to isolate */
|
|
188
|
+
dispatchWebSocketOpen(connectionId: string): Promise<void>;
|
|
189
|
+
/** Dispatch WebSocket message event to isolate */
|
|
190
|
+
dispatchWebSocketMessage(connectionId: string, message: string | ArrayBuffer): Promise<void>;
|
|
191
|
+
/** Dispatch WebSocket close event to isolate */
|
|
192
|
+
dispatchWebSocketClose(connectionId: string, code: number, reason: string): Promise<void>;
|
|
193
|
+
/** Dispatch WebSocket error event to isolate */
|
|
194
|
+
dispatchWebSocketError(connectionId: string, error: Error): Promise<void>;
|
|
195
|
+
/** Register callback for WebSocket commands from isolate */
|
|
196
|
+
onWebSocketCommand(callback: (cmd: WebSocketCommand) => void): () => void;
|
|
197
|
+
/** Check if serve() has been called */
|
|
198
|
+
hasServeHandler(): Promise<boolean>;
|
|
199
|
+
/** Check if there are active WebSocket connections */
|
|
200
|
+
hasActiveConnections(): Promise<boolean>;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Remote timers handle - provides access to timer operations.
|
|
204
|
+
* Timers fire automatically based on real time.
|
|
205
|
+
* All methods are async since they communicate over IPC.
|
|
206
|
+
*/
|
|
207
|
+
export interface RemoteTimersHandle {
|
|
208
|
+
/** Clear all pending timers */
|
|
209
|
+
clearAll(): Promise<void>;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Remote console handle - provides access to console state.
|
|
213
|
+
* All methods are async since they communicate over IPC.
|
|
214
|
+
*/
|
|
215
|
+
export interface RemoteConsoleHandle {
|
|
216
|
+
/** Reset all console state (timers, counters, group depth) */
|
|
217
|
+
reset(): Promise<void>;
|
|
218
|
+
/** Get console.time() timers */
|
|
219
|
+
getTimers(): Promise<Map<string, number>>;
|
|
220
|
+
/** Get console.count() counters */
|
|
221
|
+
getCounters(): Promise<Map<string, number>>;
|
|
222
|
+
/** Get current console.group() nesting depth */
|
|
223
|
+
getGroupDepth(): Promise<number>;
|
|
224
|
+
}
|
|
80
225
|
/**
|
|
81
226
|
* Remote runtime handle.
|
|
82
227
|
*/
|
|
83
228
|
export interface RemoteRuntime {
|
|
84
|
-
/**
|
|
229
|
+
/** Unique runtime identifier */
|
|
230
|
+
readonly id: string;
|
|
231
|
+
/**
|
|
232
|
+
* @deprecated Use id instead
|
|
233
|
+
*/
|
|
85
234
|
readonly isolateId: string;
|
|
86
|
-
/**
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
235
|
+
/** Fetch handle - access to fetch/serve operations */
|
|
236
|
+
readonly fetch: RemoteFetchHandle;
|
|
237
|
+
/** Timers handle - access to timer operations */
|
|
238
|
+
readonly timers: RemoteTimersHandle;
|
|
239
|
+
/** Console handle - access to console state */
|
|
240
|
+
readonly console: RemoteConsoleHandle;
|
|
241
|
+
/** Test environment handle (methods throw if not enabled) */
|
|
242
|
+
readonly testEnvironment: RemoteTestEnvironmentHandle;
|
|
243
|
+
/** Playwright handle (methods throw if not configured) */
|
|
244
|
+
readonly playwright: RemotePlaywrightHandle;
|
|
245
|
+
/**
|
|
246
|
+
* Execute code as ES module in the isolate.
|
|
247
|
+
* Supports top-level await.
|
|
248
|
+
* @param code - The code to execute
|
|
249
|
+
* @param filename - Optional filename for stack traces
|
|
250
|
+
*/
|
|
251
|
+
eval(code: string, filename?: string): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* @deprecated Use the new signature: eval(code: string, filename?: string)
|
|
254
|
+
*/
|
|
255
|
+
eval(code: string, options?: EvalOptions): Promise<void>;
|
|
104
256
|
/** Dispose the runtime */
|
|
105
257
|
dispose(): Promise<void>;
|
|
106
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* Remote test environment handle.
|
|
261
|
+
* All methods are async since they communicate over IPC.
|
|
262
|
+
*/
|
|
263
|
+
export interface RemoteTestEnvironmentHandle {
|
|
264
|
+
/** Run all registered tests and return results */
|
|
265
|
+
runTests(timeout?: number): Promise<RunResults>;
|
|
266
|
+
/** Check if any tests are registered */
|
|
267
|
+
hasTests(): Promise<boolean>;
|
|
268
|
+
/** Get count of registered tests */
|
|
269
|
+
getTestCount(): Promise<number>;
|
|
270
|
+
/** Reset test environment state */
|
|
271
|
+
reset(): Promise<void>;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Remote playwright handle - provides access to browser data collection.
|
|
275
|
+
* All methods are async since they communicate over IPC.
|
|
276
|
+
*/
|
|
277
|
+
export interface RemotePlaywrightHandle {
|
|
278
|
+
/** Get collected browser console logs and network data */
|
|
279
|
+
getCollectedData(): Promise<CollectedData>;
|
|
280
|
+
/** Clear collected data */
|
|
281
|
+
clearCollectedData(): Promise<void>;
|
|
282
|
+
}
|
|
107
283
|
/**
|
|
108
284
|
* Options for dispatching a request.
|
|
109
285
|
*/
|
|
@@ -111,54 +287,3 @@ export interface DispatchOptions {
|
|
|
111
287
|
/** Request timeout in ms */
|
|
112
288
|
timeout?: number;
|
|
113
289
|
}
|
|
114
|
-
/**
|
|
115
|
-
* Options for setting up Playwright.
|
|
116
|
-
*/
|
|
117
|
-
export interface PlaywrightSetupOptions {
|
|
118
|
-
/** Browser type to use */
|
|
119
|
-
browserType?: "chromium" | "firefox" | "webkit";
|
|
120
|
-
/** Run browser in headless mode */
|
|
121
|
-
headless?: boolean;
|
|
122
|
-
/** Base URL for navigation */
|
|
123
|
-
baseURL?: string;
|
|
124
|
-
/** Console log event handler */
|
|
125
|
-
onConsoleLog?: (log: {
|
|
126
|
-
level: string;
|
|
127
|
-
args: unknown[];
|
|
128
|
-
}) => void;
|
|
129
|
-
/** Network request event handler */
|
|
130
|
-
onNetworkRequest?: (request: {
|
|
131
|
-
url: string;
|
|
132
|
-
method: string;
|
|
133
|
-
headers: Record<string, string>;
|
|
134
|
-
timestamp: number;
|
|
135
|
-
}) => void;
|
|
136
|
-
/** Network response event handler */
|
|
137
|
-
onNetworkResponse?: (response: {
|
|
138
|
-
url: string;
|
|
139
|
-
status: number;
|
|
140
|
-
headers: Record<string, string>;
|
|
141
|
-
timestamp: number;
|
|
142
|
-
}) => void;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Handler for Playwright events streamed from daemon.
|
|
146
|
-
*/
|
|
147
|
-
export interface PlaywrightEventHandler {
|
|
148
|
-
onConsoleLog?: (log: {
|
|
149
|
-
level: string;
|
|
150
|
-
args: unknown[];
|
|
151
|
-
}) => void;
|
|
152
|
-
onNetworkRequest?: (request: {
|
|
153
|
-
url: string;
|
|
154
|
-
method: string;
|
|
155
|
-
headers: Record<string, string>;
|
|
156
|
-
timestamp: number;
|
|
157
|
-
}) => void;
|
|
158
|
-
onNetworkResponse?: (response: {
|
|
159
|
-
url: string;
|
|
160
|
-
status: number;
|
|
161
|
-
headers: Record<string, string>;
|
|
162
|
-
timestamp: number;
|
|
163
|
-
}) => void;
|
|
164
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ricsam/isolate-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"main": "./dist/cjs/index.cjs",
|
|
5
5
|
"types": "./dist/types/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -16,8 +16,17 @@
|
|
|
16
16
|
"typecheck": "tsc --noEmit"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"@ricsam/isolate-playwright": "*",
|
|
19
20
|
"@ricsam/isolate-protocol": "*"
|
|
20
21
|
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"playwright": ">=1.40.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependenciesMeta": {
|
|
26
|
+
"playwright": {
|
|
27
|
+
"optional": true
|
|
28
|
+
}
|
|
29
|
+
},
|
|
21
30
|
"author": "Richard Samuelsson",
|
|
22
31
|
"license": "MIT",
|
|
23
32
|
"repository": {
|