Skip to content

Commit 1c563c8

Browse files
authored
Merge pull request #252 from parthlambdatest/Dot-4847
Release Version: 4.1.5
2 parents b50bae1 + 3c3e34c commit 1c563c8

8 files changed

+108
-8
lines changed

package.json

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

src/lib/ctx.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ export default (options: Record<string, string>): Context => {
9898
delayedUpload: config.delayedUpload ?? false,
9999
useGlobalCache: config.useGlobalCache ?? false,
100100
ignoreHTTPSErrors: config.ignoreHTTPSErrors ?? false,
101-
skipBuildCreation: config.skipBuildCreation ?? false
101+
skipBuildCreation: config.skipBuildCreation ?? false,
102+
tunnel: config.tunnel ?? false,
103+
tunnelName: config.tunnelName || ''
102104
},
103105
uploadFilePath: '',
104106
webStaticConfig: [],
@@ -116,6 +118,11 @@ export default (options: Record<string, string>): Context => {
116118
url: ''
117119
},
118120
args: {},
121+
tunnelDetails: {
122+
tunnelPort: -1,
123+
tunnelHost: '',
124+
tunnelName: ''
125+
},
119126
options: {
120127
parallel: parallelObj,
121128
force: options.force ? true : false,

src/lib/httpClient.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ export default class httpClient {
102102
headers: resp.headers,
103103
body: resp.data
104104
})}`)
105-
return resp.data;
105+
if (resp.data !== ""){
106+
return resp.data;
107+
} else {
108+
return resp;
109+
}
106110
} else {
107111
log.debug(`empty response: ${JSON.stringify(resp)}`)
108112
return {};
@@ -155,7 +159,8 @@ export default class httpClient {
155159
git,
156160
config,
157161
buildName,
158-
isStartExec
162+
isStartExec,
163+
packageVersion: pkgJSON.version
159164
}
160165
}, log)
161166
}
@@ -169,6 +174,17 @@ export default class httpClient {
169174
}, log);
170175
}
171176

177+
getTunnelDetails(tunnelName: string, log: Logger) {
178+
return this.request({
179+
url: '/tunnel',
180+
method: 'POST',
181+
data: {
182+
tunnelName: tunnelName
183+
}
184+
}, log)
185+
}
186+
187+
172188
ping(buildId: string, log: Logger) {
173189
return this.request({
174190
url: '/build/ping',

src/lib/processSnapshot.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,15 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
306306
}
307307
}
308308

309-
// process for every viewport
309+
if (ctx.config.tunnel) {
310+
if (ctx.tunnelDetails && ctx.tunnelDetails.tunnelPort != -1 && ctx.tunnelDetails.tunnelHost != '') {
311+
const tunnelAddress = `http://${ctx.tunnelDetails.tunnelHost}:${ctx.tunnelDetails.tunnelPort}`;
312+
processedOptions.tunnelAddress = tunnelAddress;
313+
ctx.log.debug(`Tunnel address added to processedOptions: ${tunnelAddress}`);
314+
}
315+
}
316+
317+
// process for every viewport
310318
let navigated: boolean = false;
311319
let previousDeviceType: string | null = null;
312320

@@ -354,7 +362,19 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
354362
ctx.log.debug(`Navigated to ${snapshot.url}`);
355363
} catch (error: any) {
356364
ctx.log.debug(`Navigation to discovery page failed; ${error}`)
357-
throw new Error(error.message)
365+
if (error && error.name && error.name === 'TimeoutError') {
366+
ctx.log.debug(`Payload uploaded tough navigation to discovery page failed; ${error}`)
367+
return {
368+
processedSnapshot: {
369+
name: snapshot.name,
370+
url: snapshot.url,
371+
dom: Buffer.from(snapshot.dom.html).toString('base64'),
372+
resources: cache,
373+
options: processedOptions
374+
},
375+
warnings: [...optionWarnings, ...snapshot.dom.warnings]
376+
};
377+
}
358378
}
359379

360380
}

src/lib/schemaValidation.ts

+8
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ const ConfigSchema = {
173173
type: "boolean",
174174
errorMessage: "Invalid config; skipBuildCreation must be true/false"
175175
},
176+
tunnel: {
177+
type: "boolean",
178+
errorMessage: "Invalid config; tunnel must be true/false"
179+
},
180+
tunnelName: {
181+
type: "string",
182+
errorMessage: "Invalid config; tunnelName must be string"
183+
},
176184
},
177185
anyOf: [
178186
{ required: ["web"] },

src/lib/snapshotQueue.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,24 @@ export default class Queue {
357357
const presignedResponse = await this.ctx.client.getS3PresignedURLForSnapshotUpload(this.ctx, processedSnapshot.name, snapshotUuid);
358358
const uploadUrl = presignedResponse.data.url;
359359

360-
await this.ctx.client.uploadSnapshotToS3(this.ctx, uploadUrl, processedSnapshot)
361-
await this.ctx.client.processSnapshot(this.ctx, processedSnapshot, snapshotUuid, discoveryErrors);
360+
let snapshotUploadResponse = await this.ctx.client.uploadSnapshotToS3(this.ctx, uploadUrl, processedSnapshot);
361+
if (!snapshotUploadResponse || Object.keys(snapshotUploadResponse).length === 0) {
362+
this.ctx.log.debug(`snapshot failed; Unable to upload dom to S3`);
363+
this.processedSnapshots.push({ name: snapshot?.name, error: `snapshot failed; Unable to upload dom to S3` });
364+
if (this.ctx.browser) {
365+
for (let context of this.ctx.browser.contexts()) {
366+
for (let page of context.pages()) {
367+
await page.close();
368+
this.ctx.log.debug(`Closed browser page for snapshot ${snapshot.name}`);
369+
}
370+
await context.close();
371+
this.ctx.log.debug(`Closed browser context for snapshot ${snapshot.name}`);
372+
}
373+
}
374+
this.processNext();
375+
} else {
376+
await this.ctx.client.processSnapshot(this.ctx, processedSnapshot, snapshotUuid, discoveryErrors);
377+
}
362378
} else {
363379
await this.ctx.client.uploadSnapshot(this.ctx, processedSnapshot, discoveryErrors);
364380
}

src/tasks/createBuildExec.ts

+26
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,38 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
1919
baseline: resp.data.baseline,
2020
useKafkaFlow: resp.data.useKafkaFlow || false,
2121
}
22+
if (ctx.build.id === '') {
23+
ctx.log.debug('Build creation failed: Build ID is empty');
24+
task.output = chalk.red('Build creation failed: Build ID is empty');
25+
throw new Error('SmartUI build creation failed');
26+
}
2227
task.output = chalk.gray(`build id: ${resp.data.buildId}`);
2328
task.title = 'SmartUI build created'
2429
} else {
2530
task.output = chalk.gray(`Empty PROJECT_TOKEN and PROJECT_NAME. Skipping Creation of Build!`)
2631
task.title = 'Skipped SmartUI build creation'
2732
}
33+
34+
if (ctx.config.tunnel) {
35+
let tunnelResp = await ctx.client.getTunnelDetails(ctx.config.tunnelName, ctx.log);
36+
ctx.log.debug(`Tunnel Response: ${JSON.stringify(tunnelResp)}`)
37+
if (tunnelResp && tunnelResp.data && tunnelResp.data.host && tunnelResp.data.port && tunnelResp.data.tunnel_name) {
38+
ctx.tunnelDetails = {
39+
tunnelHost: tunnelResp.data.host,
40+
tunnelPort: tunnelResp.data.port,
41+
tunnelName: tunnelResp.data.tunnel_name
42+
}
43+
ctx.log.debug(`Tunnel Details: ${JSON.stringify(ctx.tunnelDetails)}`)
44+
} else if (tunnelResp && tunnelResp.error) {
45+
if (tunnelResp.error.message) {
46+
if (tunnelResp.error.code && tunnelResp.error.code === 400) {
47+
ctx.log.warn(tunnelResp.error.message)
48+
} else {
49+
ctx.log.warn(`Error while fetch tunnel details; Either tunnel is not running or tunnel parameters are different`)
50+
}
51+
}
52+
}
53+
}
2854
} catch (error: any) {
2955
ctx.log.debug(error);
3056
task.output = chalk.gray(error.message);

src/types.ts

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export interface Context {
3232
figma?: FigmaWebConfig;
3333
ignoreHTTPSErrors : boolean;
3434
skipBuildCreation?: boolean;
35+
tunnel?: boolean;
36+
tunnelName?: string;
3537
};
3638
uploadFilePath: string;
3739
webStaticConfig: WebStaticConfig;
@@ -40,6 +42,11 @@ export interface Context {
4042
args: {
4143
execCommand?: Array<string>
4244
}
45+
tunnelDetails: {
46+
tunnelPort: number;
47+
tunnelHost: string;
48+
tunnelName: string;
49+
}
4350
options: {
4451
parallel?: number,
4552
force?: boolean,

0 commit comments

Comments
 (0)