Skip to content

Commit 862d56a

Browse files
feat(experimental): implement ability to write test dependencies
1 parent 641a566 commit 862d56a

39 files changed

Lines changed: 3800 additions & 83 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
@@ -105,7 +105,7 @@
105105
"sizzle": "2.3.6",
106106
"socket.io": "4.7.5",
107107
"socket.io-client": "4.7.5",
108-
"source-map": "0.7.4",
108+
"source-map": "0.7.6",
109109
"strftime": "0.10.2",
110110
"strip-ansi": "6.0.1",
111111
"temp": "0.8.3",

src/browser/cdp/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
async getStyleSheetText(sessionId: CDPSessionId, styleSheetId: CDPStyleSheetId): Promise<{ text: string }> {
53+
return this._connection.request("CSS.getStyleSheetText", { sessionId, params: { styleSheetId } });
54+
}
55+
56+
/** @link https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-startPreciseCoverage */
57+
async startRuleUsageTracking(sessionId: CDPSessionId): Promise<number> {
58+
return this._connection.request("CSS.startRuleUsageTracking", { sessionId });
59+
}
60+
61+
/** @link https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-stopPreciseCoverage */
62+
async stopRuleUsageTracking(sessionId: CDPSessionId): Promise<StopRuleUsageTrackingResponse> {
63+
return this._connection.request("CSS.stopRuleUsageTracking", { sessionId });
64+
}
65+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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<GetScriptSourceResponse>("Debugger.getScriptSource", {
91+
sessionId,
92+
params: { scriptId },
93+
});
94+
}
95+
}

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: 13 additions & 7 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'. */
@@ -52,28 +52,34 @@ export class CDPProfiler extends CDPEventEmitter<ProfilerEvents> {
5252
}
5353

5454
/** @param sessionId result of "Target.attachToTarget" */
55+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Profiler/#method-disable */
5556
async disable(sessionId: CDPSessionId): Promise<void> {
5657
return this._connection.request("Profiler.disable", { sessionId });
5758
}
5859

5960
/** @param sessionId result of "Target.attachToTarget" */
61+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Profiler/#method-enable */
6062
async enable(sessionId: CDPSessionId): Promise<void> {
6163
return this._connection.request("Profiler.enable", { sessionId });
6264
}
6365

64-
async startPreciseCoverage(sessionId: CDPSessionId, params: StartPreciseCoverageRequest): Promise<number> {
65-
const res = await this._connection.request<StartPreciseCoverageResponse>("Profiler.startPreciseCoverage", {
66+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Profiler/#method-startPreciseCoverage */
67+
async startPreciseCoverage(
68+
sessionId: CDPSessionId,
69+
params: StartPreciseCoverageRequest,
70+
): Promise<{ timestamp: number }> {
71+
return this._connection.request<StartPreciseCoverageResponse>("Profiler.startPreciseCoverage", {
6672
sessionId,
6773
params,
6874
});
69-
70-
return res.timestamp;
7175
}
7276

77+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Profiler/#method-stopPreciseCoverage */
7378
async stopPreciseCoverage(sessionId: CDPSessionId): Promise<number> {
7479
return this._connection.request("Profiler.stopPreciseCoverage", { sessionId });
7580
}
7681

82+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Profiler/#method-takePreciseCoverage */
7783
async takePreciseCoverage(sessionId: CDPSessionId): Promise<TakePreciseCoverageResponse> {
7884
return this._connection.request("Profiler.takePreciseCoverage", { sessionId });
7985
}

src/browser/cdp/domains/runtime.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
/** @param sessionId result of "Target.attachToTarget" */
52+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Runtime/#method-evaluate */
53+
async evaluate<T>(sessionId: CDPSessionId, params: EvaluateRequest): Promise<EvaluateResponse<T>> {
54+
return this._connection.request<EvaluateResponse<T>>("Runtime.evaluate", { sessionId, params });
55+
}
56+
57+
/** @param sessionId result of "Target.attachToTarget" */
58+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Runtime/#method-enable */
59+
async enable(sessionId: CDPSessionId): Promise<void> {
60+
return this._connection.request("Runtime.enable", { sessionId });
61+
}
62+
63+
/** @param sessionId result of "Target.attachToTarget" */
64+
/** @link https://chromedevtools.github.io/devtools-protocol/1-3/Runtime/#method-disable */
65+
async disable(sessionId: CDPSessionId): Promise<void> {
66+
return this._connection.request("Runtime.disable", { sessionId });
67+
}
68+
}

0 commit comments

Comments
 (0)