Skip to content

Commit 212db9e

Browse files
authored
feat(vscode): defined DartFrogApplication (#932)
1 parent b1f5e1a commit 212db9e

File tree

3 files changed

+249
-0
lines changed

3 files changed

+249
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* Represents the metadata associated to a Dart Frog application.
3+
*/
4+
export class DartFrogApplication {
5+
constructor(projectPath: string, port: number, vmServicePort: number) {
6+
this.projectPath = projectPath;
7+
this.port = port;
8+
this.vmServicePort = vmServicePort;
9+
}
10+
11+
/**
12+
* The root path to the application's project directory.
13+
*/
14+
public readonly projectPath: string;
15+
16+
/**
17+
* The port on which the application is listening.
18+
*/
19+
public readonly port: number;
20+
21+
/**
22+
* The port on which the VM service is listening.
23+
*/
24+
public readonly vmServicePort: number;
25+
26+
private _id: string | undefined;
27+
28+
/**
29+
* The application's unique identifier.
30+
*
31+
* The application's unique identifier is generated by the Dart Frog daemon
32+
* upon starting the application.
33+
*
34+
* It is undefined until the application has been started by the Dart Frog
35+
* daemon, and in turn, has been assigned such identifier.
36+
*/
37+
public get id(): string | undefined {
38+
return this._id;
39+
}
40+
41+
/**
42+
* Sets the application's unique identifier.
43+
*
44+
* This method should only be called once, when the application is started and
45+
* has been assigned an identifier by the Dart Frog daemon.
46+
*
47+
* If the application already has an identifier, this method will do nothing.
48+
*/
49+
public set id(value: string) {
50+
if (this._id) {
51+
return;
52+
}
53+
54+
this._id = value;
55+
}
56+
57+
private _vmServiceUri: string | undefined;
58+
59+
/**
60+
* The URI of the VM service.
61+
*
62+
* This is used to attach to the debug session.
63+
*
64+
* It is undefined until the application has been started by the Dart Frog
65+
* daemon, and in turn, has been assigned such URI.
66+
*/
67+
public get vmServiceUri(): string | undefined {
68+
return this._vmServiceUri;
69+
}
70+
71+
/**
72+
* Sets the URI of the VM service.
73+
*
74+
* This method should only be called once, when the application is started and
75+
* has been assigned a VM service URI by the Dart Frog daemon.
76+
*
77+
* If the application already has a VM service URI, this method will do
78+
* nothing.
79+
*/
80+
public set vmServiceUri(value: string) {
81+
if (this._vmServiceUri) {
82+
return;
83+
}
84+
85+
this._vmServiceUri = value;
86+
}
87+
88+
private _address: string | undefined;
89+
90+
/**
91+
* The HTTP address of the Dart Frog application.
92+
*
93+
* This is used to launch the application in the browser.
94+
*
95+
* It is undefined until the application has been started by the Dart Frog
96+
* daemon, and in turn, has been assigned such address.
97+
*/
98+
public get address(): string | undefined {
99+
return this._address;
100+
}
101+
102+
/**
103+
* Sets the HTTP address of the Dart Frog application.
104+
*
105+
* This method should only be called once, when the application is started and
106+
* has been assigned an address by the Dart Frog daemon.
107+
*
108+
* If the application already has an address, this method will do nothing.
109+
*/
110+
public set address(value: string) {
111+
if (this._address) {
112+
return;
113+
}
114+
115+
this._address = value;
116+
}
117+
}

extensions/vscode/src/daemon/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./protocol";
22
export * from "./dart-frog-daemon";
3+
export * from "./dart-frog-application";
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import * as assert from "assert";
2+
import { DartFrogApplication } from "../../../daemon";
3+
4+
suite("DartFrogApplication", () => {
5+
const projectPath = "/path/to/project";
6+
const port = 8080;
7+
const vmServicePort = 8081;
8+
9+
test("constructor sets properties", () => {
10+
const application = new DartFrogApplication(
11+
projectPath,
12+
port,
13+
vmServicePort
14+
);
15+
16+
assert.equal(application.projectPath, projectPath);
17+
assert.equal(application.port, port);
18+
assert.equal(application.vmServicePort, vmServicePort);
19+
});
20+
21+
suite("id", () => {
22+
test("is undefined by default", () => {
23+
const application = new DartFrogApplication(
24+
projectPath,
25+
port,
26+
vmServicePort
27+
);
28+
29+
assert.equal(application.id, undefined);
30+
});
31+
32+
test("can be set", () => {
33+
const application = new DartFrogApplication(
34+
projectPath,
35+
port,
36+
vmServicePort
37+
);
38+
39+
application.id = "1";
40+
41+
assert.equal(application.id, "1");
42+
});
43+
44+
test("cannot be set more than once", () => {
45+
const application = new DartFrogApplication(
46+
projectPath,
47+
port,
48+
vmServicePort
49+
);
50+
51+
application.id = "1";
52+
application.id = "2";
53+
54+
assert.equal(application.id, "1");
55+
});
56+
});
57+
58+
suite("vmServiceUri", () => {
59+
test("is undefined by default", () => {
60+
const application = new DartFrogApplication(
61+
projectPath,
62+
port,
63+
vmServicePort
64+
);
65+
66+
assert.equal(application.vmServiceUri, undefined);
67+
});
68+
69+
test("can be set", () => {
70+
const application = new DartFrogApplication(
71+
projectPath,
72+
port,
73+
vmServicePort
74+
);
75+
76+
application.vmServiceUri = "http://localhost:8081";
77+
78+
assert.equal(application.vmServiceUri, "http://localhost:8081");
79+
});
80+
81+
test("cannot be set more than once", () => {
82+
const application = new DartFrogApplication(
83+
projectPath,
84+
port,
85+
vmServicePort
86+
);
87+
88+
application.vmServiceUri = "http://localhost:8081";
89+
application.vmServiceUri = "http://localhost:8082";
90+
91+
assert.equal(application.vmServiceUri, "http://localhost:8081");
92+
});
93+
});
94+
95+
suite("address", () => {
96+
test("is undefined by default", () => {
97+
const application = new DartFrogApplication(
98+
projectPath,
99+
port,
100+
vmServicePort
101+
);
102+
103+
assert.equal(application.address, undefined);
104+
});
105+
106+
test("can be set", () => {
107+
const application = new DartFrogApplication(
108+
projectPath,
109+
port,
110+
vmServicePort
111+
);
112+
113+
application.address = "http://localhost:8080";
114+
115+
assert.equal(application.address, "http://localhost:8080");
116+
});
117+
118+
test("cannot be set more than once", () => {
119+
const application = new DartFrogApplication(
120+
projectPath,
121+
port,
122+
vmServicePort
123+
);
124+
125+
application.address = "http://localhost:8080";
126+
application.address = "http://localhost:8081";
127+
128+
assert.equal(application.address, "http://localhost:8080");
129+
});
130+
});
131+
});

0 commit comments

Comments
 (0)