Skip to content

Commit 3689209

Browse files
Merge pull request #306 from LambdaTest/stage
Release 4.1.16
2 parents a3a2b3f + 14964f7 commit 3689209

File tree

9 files changed

+49
-8
lines changed

9 files changed

+49
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/smartui-cli",
3-
"version": "4.1.15",
3+
"version": "4.1.16",
44
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
55
"files": [
66
"dist/**/*"

src/commander/commander.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ program
2020
.option('--markBaseline', 'Mark this build baseline')
2121
.option('--baselineBranch <string>', 'Mark this build baseline')
2222
.option('--baselineBuild <string>', 'Mark this build baseline')
23+
.option('--githubURL <string>', 'GitHub URL including commitId')
2324
.addCommand(exec)
2425
.addCommand(capture)
2526
.addCommand(configWeb)

src/lib/ctx.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export default (options: Record<string, string>): Context => {
2626
try {
2727
if (options.config) {
2828
config = JSON.parse(fs.readFileSync(options.config, 'utf-8'));
29-
logger.debug(`Config file ${options.config} loaded: ${JSON.stringify(config, null, 2)}`);
29+
// TODO: Mask sensitive data of config file
30+
// logger.debug(`Config file ${options.config} loaded: ${JSON.stringify(config, null, 2)}`);
3031

3132
// resolutions supported for backward compatibility
3233
if (config.web?.resolutions) {
@@ -112,7 +113,8 @@ export default (options: Record<string, string>): Context => {
112113
ignoreHTTPSErrors: config.ignoreHTTPSErrors ?? false,
113114
skipBuildCreation: config.skipBuildCreation ?? false,
114115
tunnel: tunnelObj,
115-
userAgent: config.userAgent || ''
116+
userAgent: config.userAgent || '',
117+
requestHeaders: config.requestHeaders || {}
116118
},
117119
uploadFilePath: '',
118120
webStaticConfig: [],
@@ -148,7 +150,8 @@ export default (options: Record<string, string>): Context => {
148150
fetchResults: fetchResultObj,
149151
fetchResultsFileName: fetchResultsFileObj,
150152
baselineBranch: options.baselineBranch || '',
151-
baselineBuild: options.baselineBuild || ''
153+
baselineBuild: options.baselineBuild || '',
154+
githubURL : options.githubURL || ''
152155
},
153156
cliVersion: version,
154157
totalSnapshots: -1,

src/lib/git.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export default (ctx: Context): Git => {
3333
ctx.env.SMART_GIT = false
3434
}
3535
}
36+
let githubURL;
37+
if (ctx.options.githubURL && ctx.options.githubURL.startsWith('https://')) {
38+
githubURL = ctx.options.githubURL;
39+
}
3640
if (ctx.env.SMARTUI_GIT_INFO_FILEPATH) {
3741
let gitInfo = JSON.parse(fs.readFileSync(ctx.env.SMARTUI_GIT_INFO_FILEPATH, 'utf-8'));
3842

@@ -46,7 +50,7 @@ export default (ctx: Context): Git => {
4650
commitId: gitInfo.commit_id.slice(0,6) || '',
4751
commitMessage: gitInfo.commit_body || '',
4852
commitAuthor: gitInfo.commit_author || '',
49-
githubURL: (ctx.env.GITHUB_ACTIONS) ? `${constants.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${gitInfo.commit_id}` : '',
53+
githubURL: githubURL ? githubURL : (ctx.env.GITHUB_ACTIONS) ? `${constants.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${gitInfo.commit_id}` : '',
5054
baselineBranch: ctx.options.baselineBranch || ctx.env.BASELINE_BRANCH || ''
5155
}
5256
} else {
@@ -73,7 +77,7 @@ export default (ctx: Context): Git => {
7377
commitId: res[0] || '',
7478
commitMessage: res[2] || '',
7579
commitAuthor: res[7] || '',
76-
githubURL: (ctx.env.GITHUB_ACTIONS) ? `${constants.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${res[1]}` : '',
80+
githubURL: githubURL ? githubURL : (ctx.env.GITHUB_ACTIONS) ? `${constants.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${res[1]}` : '',
7781
baselineBranch: ctx.options.baselineBranch || ctx.env.BASELINE_BRANCH || ''
7882
};
7983
}

src/lib/processSnapshot.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export async function prepareSnapshot(snapshot: Snapshot, ctx: Context): Promise
1919
if (ctx.config.basicAuthorization) {
2020
processedOptions.basicAuthorization = ctx.config.basicAuthorization;
2121
}
22+
if (ctx.config.requestHeaders && Array.isArray(ctx.config.requestHeaders)) {
23+
processedOptions.requestHeaders = ctx.config.requestHeaders
24+
}
2225
ctx.config.allowedHostnames.push(new URL(snapshot.url).hostname);
2326
processedOptions.allowedHostnames = ctx.config.allowedHostnames;
2427
processedOptions.skipCapturedCookies = ctx.env.SMARTUI_DO_NOT_USE_CAPTURED_COOKIES;
@@ -181,6 +184,9 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
181184
};
182185

183186
let processedOptions: Record<string, any> = {};
187+
if (ctx.config.requestHeaders && Array.isArray(ctx.config.requestHeaders)) {
188+
processedOptions.requestHeaders = ctx.config.requestHeaders
189+
}
184190

185191
let globalViewport = ""
186192
let globalBrowser = constants.CHROME
@@ -266,6 +272,13 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
266272
let token = Buffer.from(`${ctx.config.basicAuthorization.username}:${ctx.config.basicAuthorization.password}`).toString('base64');
267273
requestOptions.headers.Authorization = `Basic ${token}`;
268274
}
275+
if (ctx.config.requestHeaders && Array.isArray(ctx.config.requestHeaders)) {
276+
ctx.config.requestHeaders.forEach((headerObj) => {
277+
Object.entries(headerObj).forEach(([key, value]) => {
278+
requestOptions.headers[key] = value;
279+
});
280+
});
281+
}
269282

270283
// get response
271284
let response, body;

src/lib/schemaValidation.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ const ConfigSchema = {
161161
errorMessage: {
162162
uniqueItems: "Invalid config; duplicates in allowedAssets"
163163
}
164-
165164
},
166165
basicAuthorization: {
167166
type: "object",
@@ -248,6 +247,18 @@ const ConfigSchema = {
248247
type: "string",
249248
errorMessage: "User Agent value must be a valid string"
250249
},
250+
requestHeaders: {
251+
type: "array",
252+
items: {
253+
type: "object",
254+
minProperties: 1,
255+
additionalProperties: { type: "string" }
256+
},
257+
uniqueItems: true,
258+
errorMessage: {
259+
uniqueItems: "Invalid config; duplicates in requestHeaders"
260+
}
261+
}
251262
},
252263
anyOf: [
253264
{ required: ["web"] },

src/lib/server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export default async (ctx: Context): Promise<FastifyInstance<Server, IncomingMes
6464
console.log(`Failed to fetch capabilities for sessionId ${sessionId}: ${error.message}`);
6565
}
6666
}
67+
68+
if (capsBuildId && capsBuildId !== '') {
69+
process.env.SMARTUI_BUILD_ID = capsBuildId;
70+
}
6771
}
6872

6973
ctx.testType = testType;

src/tasks/getGitInfo.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
1616
try {
1717
ctx.git = getGitInfo(ctx);
1818
task.output = chalk.gray(`branch: ${ctx.git.branch}, commit: ${ctx.git.commitId}, author: ${ctx.git.commitAuthor}`);
19+
if (ctx.git.githubURL && ctx.git.githubURL !== '') {
20+
task.output += chalk.gray(`, githubURL: ${ctx.git.githubURL}`);
21+
}
1922
task.title = 'Fetched git information'
2023
} catch (error: any) {
2124
ctx.log.debug(error);

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface Context {
3535
skipBuildCreation?: boolean;
3636
tunnel: tunnelConfig | undefined;
3737
userAgent?: string;
38+
requestHeaders?: Array<Record<string, string>>;
3839
};
3940
uploadFilePath: string;
4041
webStaticConfig: WebStaticConfig;
@@ -61,7 +62,8 @@ export interface Context {
6162
fetchResults?: boolean,
6263
fetchResultsFileName?: string,
6364
baselineBranch?: string,
64-
baselineBuild?: string
65+
baselineBuild?: string,
66+
githubURL?: string
6567
}
6668
cliVersion: string;
6769
totalSnapshots: number;

0 commit comments

Comments
 (0)