Skip to content

Commit 3cd139a

Browse files
authored
🤖 Merge PR DefinitelyTyped#73713 fix(selenium-webdriver): add jsdoc, export things properly by @hkleungai
1 parent 332844d commit 3cd139a

File tree

2 files changed

+55
-40
lines changed

2 files changed

+55
-40
lines changed
Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,71 @@
11
import { RemoteValue } from "./remoteValue";
22

3-
interface Source {
3+
export interface ScriptSource {
44
realm: string;
55
context?: string;
66
}
77

8+
/**
9+
* Represents a message received through a channel.
10+
* Described in https://w3c.github.io/webdriver-bidi/#event-script-message.
11+
*/
812
declare class Message {
913
private _channel: string;
1014
private _data: RemoteValue;
1115
private _source: Source;
1216

17+
/**
18+
* Creates a new Message instance.
19+
* @param channel - The channel through which the message is received.
20+
* @param data - The data contained in the message.
21+
* @param source - The source of the message.
22+
*/
1323
constructor(
1424
channel: string,
1525
data: RemoteValue,
1626
source: Source,
1727
);
1828

29+
/**
30+
* Gets the channel through which the message is received.
31+
* @returns The channel.
32+
*/
1933
get channel(): string;
2034

35+
/**
36+
* Gets the data contained in the message.
37+
* @returns The data.
38+
*/
2139
get data(): RemoteValue;
2240

41+
/**
42+
* Gets the source of the message.
43+
* @returns The source.
44+
*/
2345
get source(): Source;
2446
}
2547

26-
declare class source {
48+
/**
49+
* Represents a source object.
50+
* Described in https://w3c.github.io/webdriver-bidi/#type-script-Source.
51+
*/
52+
declare class Source {
2753
private _browsingContextId: string | null;
2854
private _realmId: string;
2955

30-
constructor(
31-
source: Source,
32-
);
56+
constructor(source: ScriptSource);
3357

58+
/**
59+
* Get the browsing context ID.
60+
* @returns The browsing context ID.
61+
*/
3462
get browsingContextId(): string | null;
3563

64+
/**
65+
* Get the realm ID.
66+
* @returns The realm ID.
67+
*/
3668
get realmId(): string;
3769
}
70+
71+
export { Message, Source };
Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,39 @@
11
import { RemoteValue } from "selenium-webdriver/bidi/remoteValue";
2-
import { Message, Source, source as SourceClass } from "selenium-webdriver/bidi/scriptTypes";
2+
import { Message, ScriptSource, Source } from "selenium-webdriver/bidi/scriptTypes";
33

44
function testMessageClass() {
5-
const source: Source = {
5+
const scriptSource: ScriptSource = {
66
realm: "testRealm",
77
context: "testContext",
88
};
99

10+
const source = new Source(scriptSource);
11+
1012
const remoteValue: RemoteValue = {
1113
type: "string",
1214
value: "testValue",
1315
};
1416

1517
const message = new Message("testChannel", remoteValue, source);
1618

17-
if (message.channel !== "testChannel") {
18-
console.error("Failed: Message channel does not match expected value");
19-
} else {
20-
console.log("Passed: Message channel matches expected value");
21-
}
22-
23-
if (message.data !== remoteValue) {
24-
console.error("Failed: Message data does not match expected value");
25-
} else {
26-
console.log("Passed: Message data matches expected value");
27-
}
28-
29-
if (message.source !== source) {
30-
console.error("Failed: Message source does not match expected value");
31-
} else {
32-
console.log("Passed: Message source matches expected value");
33-
}
19+
// $ExpectType string
20+
message.channel;
21+
// $ExpectType RemoteValue
22+
message.data;
23+
// $ExpectType Source
24+
message.source;
3425
}
3526

3627
function testSourceClass() {
37-
const sourceInstance: Source = {
28+
const scriptSource: ScriptSource = {
3829
realm: "testRealm",
3930
context: "testContext",
4031
};
4132

42-
const sourceObj = new SourceClass(sourceInstance);
43-
44-
if (sourceObj.browsingContextId !== null) {
45-
console.error("Failed: browsingContextId should be null");
46-
} else {
47-
console.log("Passed: browsingContextId is null as expected");
48-
}
33+
const source = new Source(scriptSource);
4934

50-
if (sourceObj.realmId !== "testRealm") {
51-
console.error("Failed: realmId does not match expected value");
52-
} else {
53-
console.log("Passed: realmId matches expected value");
54-
}
35+
// $ExpectType string | null
36+
source.browsingContextId;
37+
// $ExpectType string
38+
source.realmId;
5539
}
56-
57-
testSourceClass();
58-
testMessageClass();

0 commit comments

Comments
 (0)