Skip to content

Commit 85c0c7e

Browse files
authored
Merge pull request #347 from LambdaTest/stage
Release PR Version `4.1.28` Exit code throwing at end of cli process
2 parents 8492879 + e857b89 commit 85c0c7e

File tree

7 files changed

+24
-11
lines changed

7 files changed

+24
-11
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.27",
3+
"version": "4.1.28",
44
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
55
"files": [
66
"dist/**/*"

src/lib/httpClient.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ export default class httpClient {
142142
const response = await this.request({
143143
url: '/token/verify',
144144
method: 'GET',
145+
headers:{
146+
userName : env.LT_USERNAME,
147+
accessKey: env.LT_ACCESS_KEY
148+
}
145149
}, log);
146150
if (response && response.projectToken) {
147151
this.projectToken = response.projectToken;
@@ -157,8 +161,8 @@ export default class httpClient {
157161

158162
async authExec(ctx: Context, log: Logger, env: Env): Promise<{ authResult: number, orgId: number, userId: number }> {
159163
let authResult = 1;
160-
let userName = '';
161-
let passWord = '';
164+
let userName = ctx.env.LT_USERNAME;
165+
let passWord = ctx.env.LT_ACCESS_KEY;
162166
if (ctx.config.tunnel) {
163167
if (ctx.config.tunnel?.user && ctx.config.tunnel?.key) {
164168
userName = ctx.config.tunnel.user
@@ -202,10 +206,14 @@ export default class httpClient {
202206
}
203207
}
204208

205-
createBuild(git: Git, config: any, log: Logger, buildName: string, isStartExec: boolean, smartGit: boolean, markBaseline: boolean, baselineBuild: string, scheduled?: string) {
209+
createBuild(git: Git, config: any, log: Logger, buildName: string, isStartExec: boolean, smartGit: boolean, markBaseline: boolean, baselineBuild: string, scheduled?: string,userName?: string,accessKey?: string) {
206210
return this.request({
207211
url: '/build',
208212
method: 'POST',
213+
headers:{
214+
userName,
215+
accessKey
216+
},
209217
data: {
210218
git,
211219
config,
@@ -390,7 +398,7 @@ export default class httpClient {
390398

391399
uploadScreenshot(
392400
{ id: buildId, name: buildName, baseline }: Build,
393-
ssPath: string, ssName: string, browserName: string, viewport: string, log: Logger
401+
ssPath: string, ssName: string, browserName: string, viewport: string, url: string = '', log: Logger
394402
) {
395403
browserName = browserName === constants.SAFARI ? constants.WEBKIT : browserName;
396404
const file = fs.readFileSync(ssPath);
@@ -402,6 +410,7 @@ export default class httpClient {
402410
form.append('buildName', buildName);
403411
form.append('screenshotName', ssName);
404412
form.append('baseline', baseline.toString());
413+
form.append('pageUrl',url)
405414

406415
return this.axiosInstance.request({
407416
url: `/screenshot`,

src/lib/screenshot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async function captureScreenshotsForConfig(
5757

5858
await page?.screenshot({ path: ssPath, fullPage });
5959

60-
await ctx.client.uploadScreenshot(ctx.build, ssPath, name, browserName, viewportString, ctx.log);
60+
await ctx.client.uploadScreenshot(ctx.build, ssPath, name, browserName, viewportString, url, ctx.log);
6161
}
6262
} catch (error) {
6363
throw new Error(`captureScreenshotsForConfig failed for browser ${browserName}; error: ${error}`);
@@ -253,7 +253,7 @@ export async function uploadScreenshots(ctx: Context): Promise<void> {
253253
}
254254
}
255255

256-
await ctx.client.uploadScreenshot(ctx.build, filePath, ssId, 'default', viewport, ctx.log);
256+
await ctx.client.uploadScreenshot(ctx.build, filePath, ssId, 'default', viewport,"", ctx.log);
257257
ctx.log.info(`${filePath} : uploaded successfully`)
258258
noOfScreenshots++;
259259
} else {

src/tasks/createBuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
1010
updateLogContext({task: 'createBuild'});
1111

1212
try {
13-
let resp = await ctx.client.createBuild(ctx.git, ctx.config, ctx.log, ctx.build.name, ctx.isStartExec, ctx.env.SMART_GIT, ctx.options.markBaseline, ctx.options.baselineBuild, ctx.options.scheduled);
13+
let resp = await ctx.client.createBuild(ctx.git, ctx.config, ctx.log, ctx.build.name, ctx.isStartExec, ctx.env.SMART_GIT, ctx.options.markBaseline, ctx.options.baselineBuild, ctx.options.scheduled,ctx.env.LT_USERNAME,ctx.env.LT_ACCESS_KEY);
1414
if (resp && resp.data && resp.data.buildId) {
1515
ctx.build = {
1616
id: resp.data.buildId,

src/tasks/createBuildExec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
1212

1313
try {
1414
if (ctx.authenticatedInitially && !ctx.config.skipBuildCreation) {
15-
let resp = await ctx.client.createBuild(ctx.git, ctx.config, ctx.log, ctx.build.name, ctx.isStartExec, ctx.env.SMART_GIT, ctx.options.markBaseline, ctx.options.baselineBuild, ctx.options.scheduled);
15+
let resp = await ctx.client.createBuild(ctx.git, ctx.config, ctx.log, ctx.build.name, ctx.isStartExec, ctx.env.SMART_GIT, ctx.options.markBaseline, ctx.options.baselineBuild, ctx.options.scheduled,ctx.env.LT_USERNAME,ctx.env.LT_ACCESS_KEY);
1616
if (resp && resp.data && resp.data.buildId) {
1717
ctx.build = {
1818
id: resp.data.buildId,

src/tasks/exec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
3939
if (code !== null) {
4040
task.title = `Execution of '${ctx.args.execCommand?.join(' ')}' completed; exited with code ${code}`;
4141
if (code !== 0) {
42-
reject();
4342
process.exitCode = code
4443
}
4544
} else if (signal !== null) {

src/tasks/finalizeBuild.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
4949
} else {
5050
is_baseline = false;
5151
}
52-
console.log(`start polling was called at finalize build for buildId: ${buildId}`)
5352
startPolling(ctx, buildId, is_baseline, capabilities.projectToken);
5453
await new Promise(resolve => setTimeout(resolve, 7000));
5554
ctx.fetchResultsForBuild.push(buildId);
@@ -87,6 +86,12 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
8786
let resp = ctx.client.sendCliLogsToLSRS(ctx);
8887
}
8988
}
89+
if (process.exitCode && process.exitCode !== 0) {
90+
ctx.log.error(`Exiting process with code ${process.exitCode}`);
91+
task.output = chalk.gray(`Exiting process with code ${process.exitCode}`);
92+
task.title = 'Build finalized with errors';
93+
throw new Error(`Process exited with code ${process.exitCode}`);
94+
}
9095
} catch (error: any) {
9196
ctx.log.debug(error);
9297
}

0 commit comments

Comments
 (0)