Skip to content

Commit db6f13c

Browse files
feat(experimental): implement ability to write test dependencies
1 parent d47e39f commit db6f13c

38 files changed

Lines changed: 3783 additions & 64 deletions

package-lock.json

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"sizzle": "2.3.6",
105105
"socket.io": "4.7.5",
106106
"socket.io-client": "4.7.5",
107-
"source-map": "0.7.4",
107+
"source-map": "0.7.6",
108108
"strftime": "0.10.2",
109109
"strip-ansi": "6.0.1",
110110
"temp": "0.8.3",

src/browser/cdp/connection.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class CDPConnection {
178178
this._pingHealthCheckStart();
179179

180180
const onPing = (): void => result.pong();
181-
const _onMessage = (data: RawData): void => this._onMessage(data);
181+
const onMessage = (data: RawData): void => this._onMessage(data);
182182
const onError = (err: Error): void => {
183183
if (result === this._wsConnection) {
184184
this._closeWsConnection(
@@ -190,11 +190,11 @@ export class CDPConnection {
190190
};
191191

192192
result.on("ping", onPing);
193-
result.on("message", _onMessage);
193+
result.on("message", onMessage);
194194
result.on("error", onError);
195195
result.once("close", () => {
196196
result.off("ping", onPing);
197-
result.off("message", _onMessage);
197+
result.off("message", onMessage);
198198
result.off("error", onError);
199199
if (result === this._wsConnection) {
200200
this._closeWsConnection(
@@ -388,7 +388,7 @@ export class CDPConnection {
388388
}
389389

390390
/** @description Performs high-level CDP request with retries and timeouts */
391-
async request<T>(
391+
async request<T = void>(
392392
method: CDPRequest["method"],
393393
{ params, sessionId }: Omit<CDPRequest, "id" | "method"> = {},
394394
): Promise<T> {

src/browser/cdp/domains/css.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { CDPConnection } from "../connection";
2+
import { CDPEventEmitter } from "../emitter";
3+
import type { CDPCSSStyleSheetHeader, CDPSessionId, CDPStyleSheetId } from "../types";
4+
5+
interface StopRuleUsageTrackingResponse {
6+
ruleUsage: Array<{
7+
styleSheetId: CDPStyleSheetId;
8+
startOffset: number;
9+
endOffset: number;
10+
used: boolean;
11+
}>;
12+
}
13+
14+
export interface CssEvents {
15+
fontsUpdated: {
16+
font: Record<string, unknown>;
17+
};
18+
mediaQueryResultChanged: Record<string, never>;
19+
styleSheetAdded: {
20+
header: CDPCSSStyleSheetHeader;
21+
};
22+
styleSheetChanged: {
23+
styleSheetId: CDPStyleSheetId;
24+
};
25+
styleSheetRemoved: {
26+
styleSheetId: CDPStyleSheetId;
27+
};
28+
}
29+
30+
/** @link https://chromedevtools.github.io/devtools-protocol/tot/CSS/ */
31+
export class CDPCss extends CDPEventEmitter<CssEvents> {
32+
private readonly _connection: CDPConnection;
33+
34+
public constructor(connection: CDPConnection) {
35+
super();
36+
37+
this._connection = connection;
38+
}
39+
40+
/** @param sessionId result of "Target.attachToTarget" */
41+
/** @link https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-enable */
42+
async enable(sessionId: CDPSessionId): Promise<void> {
43+
return this._connection.request("CSS.enable", { sessionId });
44+
}
45+
46+
/** @param sessionId result of "Target.attachToTarget" */
47+
/** @link https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-disable */
48+
async disable(sessionId: CDPSessionId): Promise<void> {
49+
return this._connection.request("CSS.disable", { sessionId });
50+
}
51+
52+
/** @link https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-getStyleSheetText */
53+
async getStyleSheetText(sessionId: CDPSessionId, styleSheetId: CDPStyleSheetId): Promise<{ text: string }> {
54+
return this._connection.request("CSS.getStyleSheetText", { sessionId, params: { styleSheetId } });
55+
}
56+
57+
/** @link https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-startRuleUsageTracking */
58+
async startRuleUsageTracking(sessionId: CDPSessionId): Promise<void> {
59+
return this._connection.request("CSS.startRuleUsageTracking", { sessionId });
60+
}
61+
62+
/** @link https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-stopRuleUsageTracking */
63+
async stopRuleUsageTracking(sessionId: CDPSessionId): Promise<StopRuleUsageTrackingResponse> {
64+
return this._connection.request("CSS.stopRuleUsageTracking", { sessionId });
65+
}
66+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { CDPConnection } from "../connection";
2+
import { CDPEventEmitter } from "../emitter";
3+
import type {
4+
CDPDebuggerCallFrame,
5+
CDPDebuggerPausedReason,
6+
CDPExecutionContextId,
7+
CDPRuntimeScriptId,
8+
CDPRuntimeStackTrace,
9+
CDPSessionId,
10+
} from "../types";
11+
12+
interface ScriptData {
13+
scriptId: CDPRuntimeScriptId;
14+
/** URL or name of the script parsed (if any). */
15+
url: string;
16+
/** Line offset of the script within the resource with given URL (for script tags). */
17+
startLine: number;
18+
/** Column offset of the script within the resource with given URL. */
19+
startColumn: number;
20+
/** Last line of the script. */
21+
endLine: number;
22+
/** Length of the last line of the script. */
23+
endColumn: number;
24+
executionContextId: CDPExecutionContextId;
25+
/** Content hash of the script, SHA-256. */
26+
hash: string;
27+
/** For Wasm modules, the content of the build_id custom section. For JavaScript the debugId magic comment. */
28+
buildId: string;
29+
/** Embedder-specific auxiliary data likely matching {isDefault: boolean, type: 'default'|'isolated'|'worker', frameId: string} */
30+
executionContextAuxData?: Record<string, unknown>;
31+
sourceMapURL?: string;
32+
/** True, if this script has sourceURL. */
33+
hasSourceURL?: boolean;
34+
/** True, if this script is ES6 module. */
35+
isModule?: boolean;
36+
/** This script length. */
37+
length?: number;
38+
}
39+
40+
interface GetScriptSourceResponse {
41+
/** Script source (empty in case of Wasm bytecode). */
42+
scriptSource: string;
43+
/** Wasm bytecode. (Encoded as a base64 string when passed over JSON) */
44+
bytecode?: string;
45+
}
46+
47+
export interface DebuggerEvents {
48+
paused: {
49+
callFrames: CDPDebuggerCallFrame;
50+
/** Location of console.profileEnd(). */
51+
reason: CDPDebuggerPausedReason;
52+
/** Object containing break-specific auxiliary properties. */
53+
data?: Record<string, unknown>;
54+
asyncStackTrace?: CDPRuntimeStackTrace;
55+
};
56+
resumed: Record<never, unknown>;
57+
scriptFailedToParse: ScriptData;
58+
scriptParsed: ScriptData;
59+
}
60+
61+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Debugger/ */
62+
export class CDPDebugger extends CDPEventEmitter<DebuggerEvents> {
63+
private readonly _connection: CDPConnection;
64+
65+
public constructor(connection: CDPConnection) {
66+
super();
67+
68+
this._connection = connection;
69+
}
70+
71+
/** @param sessionId result of "Target.attachToTarget" */
72+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Debugger/#method-disable */
73+
async disable(sessionId: CDPSessionId): Promise<void> {
74+
return this._connection.request("Debugger.disable", { sessionId });
75+
}
76+
77+
/** @param sessionId result of "Target.attachToTarget" */
78+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Debugger/#method-enable */
79+
async enable(sessionId: CDPSessionId): Promise<void> {
80+
return this._connection.request("Debugger.enable", { sessionId });
81+
}
82+
83+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Debugger/#method-resume */
84+
async resume(sessionId: CDPSessionId, terminateOnResume?: boolean): Promise<void> {
85+
return this._connection.request("Debugger.resume", { sessionId, params: { terminateOnResume } });
86+
}
87+
88+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Debugger/#method-getScriptSource */
89+
async getScriptSource(sessionId: CDPSessionId, scriptId: CDPRuntimeScriptId): Promise<GetScriptSourceResponse> {
90+
return this._connection.request("Debugger.getScriptSource", { sessionId, params: { scriptId }});
91+
}
92+
}

src/browser/cdp/domains/dom.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { CDPConnection } from "../connection";
2+
import { CDPEventEmitter } from "../emitter";
3+
import type { CDPSessionId } from "../types";
4+
5+
export interface DomEvents {
6+
attributeModified: Record<string, unknown>;
7+
attributeRemoved: Record<string, unknown>;
8+
characterDataModified: Record<string, unknown>;
9+
childNodeCountUpdated: Record<string, unknown>;
10+
childNodeInserted: Record<string, unknown>;
11+
childNodeRemoved: Record<string, unknown>;
12+
documentUpdated: Record<string, unknown>;
13+
setChildNodes: Record<string, unknown>;
14+
}
15+
16+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Dom/ */
17+
export class CDPDom extends CDPEventEmitter<DomEvents> {
18+
private readonly _connection: CDPConnection;
19+
20+
public constructor(connection: CDPConnection) {
21+
super();
22+
23+
this._connection = connection;
24+
}
25+
26+
/** @param sessionId result of "Target.attachToTarget" */
27+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/DOM/#method-enable */
28+
async enable(sessionId: CDPSessionId): Promise<void> {
29+
return this._connection.request("DOM.enable", { sessionId });
30+
}
31+
32+
/** @param sessionId result of "Target.attachToTarget" */
33+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/DOM/#method-disable */
34+
async disable(sessionId: CDPSessionId): Promise<void> {
35+
return this._connection.request("DOM.disable", { sessionId });
36+
}
37+
}
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { CDPConnection } from "./connection";
2-
import { CDPEventEmitter } from "./emitter";
3-
import type { CDPDebuggerLocation, CDPSessionId, CDPScriptCoverage, CDPProfile } from "./types";
1+
import { CDPConnection } from "../connection";
2+
import { CDPEventEmitter } from "../emitter";
3+
import type { CDPDebuggerLocation, CDPSessionId, CDPScriptCoverage, CDPProfile } from "../types";
44

55
interface StartPreciseCoverageRequest {
66
/** Collect accurate call counts beyond simple 'covered' or 'not covered'. */
@@ -72,10 +72,7 @@ export class CDPProfiler extends CDPEventEmitter<ProfilerEvents> {
7272
sessionId: CDPSessionId,
7373
params: StartPreciseCoverageRequest,
7474
): Promise<StartPreciseCoverageResponse> {
75-
return this._connection.request<StartPreciseCoverageResponse>("Profiler.startPreciseCoverage", {
76-
sessionId,
77-
params,
78-
});
75+
return this._connection.request("Profiler.startPreciseCoverage", { sessionId, params });
7976
}
8077

8178
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Profiler/#method-stopPreciseCoverage */
@@ -85,6 +82,6 @@ export class CDPProfiler extends CDPEventEmitter<ProfilerEvents> {
8582

8683
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Profiler/#method-takePreciseCoverage */
8784
async takePreciseCoverage(sessionId: CDPSessionId): Promise<TakePreciseCoverageResponse> {
88-
return this._connection.request<TakePreciseCoverageResponse>("Profiler.takePreciseCoverage", { sessionId });
85+
return this._connection.request("Profiler.takePreciseCoverage", { sessionId });
8986
}
9087
}

src/browser/cdp/domains/runtime.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { CDPConnection } from "../connection";
2+
import { CDPEventEmitter } from "../emitter";
3+
import type { CDPExecutionContextId, CDPRuntimeRemoteObject, CDPSessionId } from "../types";
4+
5+
interface EvaluateRequest {
6+
/** Expression to evaluate. */
7+
expression: string;
8+
/** Symbolic group name that can be used to release multiple objects. */
9+
objectGroup?: string;
10+
/** Determines whether Command Line API should be available during the evaluation. */
11+
includeCommandLineAPI?: boolean;
12+
/** In silent mode exceptions thrown during evaluation are not reported and do not pause execution. Overrides setPauseOnException state. */
13+
silent?: boolean;
14+
/** Specifies in which execution context to perform evaluation. If the parameter is omitted the evaluation will be performed in the context of the inspected page. This is mutually exclusive with uniqueContextId, which offers an alternative way to identify the execution context that is more reliable in a multi-process environment. */
15+
contextId?: CDPExecutionContextId;
16+
/** Whether the result is expected to be a JSON object that should be sent by value. */
17+
returnByValue?: boolean;
18+
/** Whether execution should be treated as initiated by user in the UI. */
19+
userGesture?: boolean;
20+
/** Whether execution should await for resulting value and return once awaited promise is resolved. */
21+
awaitPromise?: boolean;
22+
}
23+
24+
interface EvaluateResponse<T> {
25+
/** Evaluation result. */
26+
result: CDPRuntimeRemoteObject<T>;
27+
/** Exception details. */
28+
exceptionDetails?: Record<string, unknown>;
29+
}
30+
31+
export interface RuntimeEvents {
32+
consoleAPICalled: Record<string, unknown>;
33+
exceptionRevoked: Record<string, unknown>;
34+
exceptionThrown: Record<string, unknown>;
35+
executionContextCreated: Record<string, unknown>;
36+
executionContextDestroyed: Record<string, unknown>;
37+
executionContextsCleared: Record<string, unknown>;
38+
inspectRequested: Record<string, unknown>;
39+
}
40+
41+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Runtime/ */
42+
export class CDPRuntime extends CDPEventEmitter<RuntimeEvents> {
43+
private readonly _connection: CDPConnection;
44+
45+
public constructor(connection: CDPConnection) {
46+
super();
47+
48+
this._connection = connection;
49+
}
50+
51+
/**
52+
* @param sessionId result of "Target.attachToTarget"
53+
* @link https://chromedevtools.github.io/devtools-protocol/1-3/Runtime/#method-evaluate
54+
*/
55+
async evaluate<T>(sessionId: CDPSessionId, params: EvaluateRequest): Promise<EvaluateResponse<T>> {
56+
return this._connection.request("Runtime.evaluate", { sessionId, params });
57+
}
58+
59+
/**
60+
* @param sessionId result of "Target.attachToTarget"
61+
* @link https://chromedevtools.github.io/devtools-protocol/1-3/Runtime/#method-enable
62+
*/
63+
async enable(sessionId: CDPSessionId): Promise<void> {
64+
return this._connection.request("Runtime.enable", { sessionId });
65+
}
66+
67+
/**
68+
* @param sessionId result of "Target.attachToTarget"
69+
* @link https://chromedevtools.github.io/devtools-protocol/1-3/Runtime/#method-disable
70+
*/
71+
async disable(sessionId: CDPSessionId): Promise<void> {
72+
return this._connection.request("Runtime.disable", { sessionId });
73+
}
74+
}

0 commit comments

Comments
 (0)