forked from dcouple/Pane
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaywright.shared.ts
More file actions
34 lines (28 loc) · 858 Bytes
/
Copy pathplaywright.shared.ts
File metadata and controls
34 lines (28 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const DEFAULT_PLAYWRIGHT_PORT = 4521;
interface PlaywrightServerEnvironment {
[name: string]: string;
}
export function getPlaywrightPort(): number {
const rawPort = process.env.PLAYWRIGHT_PORT || process.env.VITE_PORT || process.env.PORT;
if (!rawPort) {
return DEFAULT_PLAYWRIGHT_PORT;
}
const port = Number.parseInt(rawPort, 10);
if (!Number.isInteger(port) || port <= 0 || port > 65535) {
throw new Error(`Invalid Playwright dev server port: ${rawPort}`);
}
return port;
}
export function getPlaywrightBaseURL(port = getPlaywrightPort()): string {
return `http://localhost:${port}`;
}
export function getPlaywrightServerEnv(
port = getPlaywrightPort(),
extraEnv: PlaywrightServerEnvironment = {},
): PlaywrightServerEnvironment {
return {
...extraEnv,
PORT: String(port),
VITE_PORT: String(port),
};
}