-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathconfigUtils.ts
More file actions
144 lines (123 loc) · 4.17 KB
/
Copy pathconfigUtils.ts
File metadata and controls
144 lines (123 loc) · 4.17 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { ValidatedEnvironment } from "../common/device-validator.js";
import { BrowserStackConfig } from "../../../lib/types.js";
import { getBrowserStackAuth } from "../../../lib/get-auth.js";
export function generateBrowserStackYMLInstructions(
config: {
validatedEnvironments?: ValidatedEnvironment[];
platforms?: string[];
enablePercy?: boolean;
projectName: string;
},
browserStackConfig: BrowserStackConfig,
): string {
const enablePercy = config.enablePercy || false;
const projectName = config.projectName || "BrowserStack Automate Build";
// Get credentials from config
const authString = getBrowserStackAuth(browserStackConfig);
const [username] = authString.split(":");
// Generate platform configurations using the utility function
const platformConfigs = generatePlatformConfigs(config);
const stepTitle =
"Create a browserstack.yml file in the project root with your validated device configurations:If already exists, update it with the following content for devices and project details.";
const buildName = `${projectName}-Build`;
let ymlContent = `
# ======================
# BrowserStack Reporting
# ======================
userName: ${username}
accessKey: "<your BrowserStack access key>"
# TODO: Replace these sample values with your actual project details
projectName: ${projectName}
buildName: ${buildName}
# =======================================
# Platforms (Browsers / Devices to test)
# =======================================`;
ymlContent += `
# Platforms object contains all the browser / device combinations you want to test on.
platforms:
${platformConfigs}`;
ymlContent += `
# =======================
# Parallels per Platform
# =======================
# The number of parallel threads to be used for each platform set.
# BrowserStack's SDK runner will select the best strategy based on the configured value
# The number of parallel threads to be used for each platform set.
parallelsPerPlatform: 1
# =================
# Local Testing
# =================
# Set to true to test local
browserstackLocal: true
# ===================
# Debugging features
# ===================
debug: true # Visual logs, text logs, etc.
testObservability: true # For Test Observability`;
if (enablePercy) {
ymlContent += `
# =====================
# Percy Visual Testing
# =====================
# Set percy to true to enable visual testing.
# Set percyCaptureMode to 'manual' to control when screenshots are taken.
percy: true
percyCaptureMode: manual`;
}
return `
---STEP---
${stepTitle}
\`\`\`yaml${ymlContent}
\`\`\`
\n`;
}
function generatePlatformConfigs(config: {
validatedEnvironments?: ValidatedEnvironment[];
platforms?: string[];
}): string {
if (config.validatedEnvironments && config.validatedEnvironments.length > 0) {
// Generate platforms array from validated environments
const platforms = config.validatedEnvironments.map((env) => {
if (env.platform === "windows" || env.platform === "macos") {
// Desktop configuration
return {
os: env.platform === "windows" ? "Windows" : "OS X",
osVersion: env.osVersion,
browserName: env.browser,
browserVersion: env.browserVersion || "latest",
};
} else {
// Mobile configuration (android/ios)
return {
deviceName: env.deviceName,
osVersion: env.osVersion,
browserName: env.browser,
};
}
});
// Convert platforms to YAML format
return platforms
.map((platform) => {
if (platform.deviceName) {
// Mobile platform
return ` - deviceName: "${platform.deviceName}"
osVersion: "${platform.osVersion}"
browserName: ${platform.browserName}`;
} else {
// Desktop platform
return ` - os: ${platform.os}
osVersion: "${platform.osVersion}"
browserName: ${platform.browserName}
browserVersion: ${platform.browserVersion}`;
}
})
.join("\n");
} else if (config.platforms && config.platforms.length > 0) {
// Fallback to default platforms configuration
return ` - os: Windows
osVersion: 11
browserName: chrome
browserVersion: latest`;
}
return "";
}