Skip to content

Commit cc65292

Browse files
committed
Merge branch 'stage' of github.com:LambdaTest/smartui-cli into DOT-6255
2 parents 6d4c388 + d13b7b7 commit cc65292

File tree

7 files changed

+71
-15
lines changed

7 files changed

+71
-15
lines changed

src/lib/ctx.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ export default (options: Record<string, string>): Context => {
3939
delete config.web.resolutions;
4040
}
4141

42+
if(config.approvalThreshold && config.rejectionThreshold) {
43+
if(config.rejectionThreshold <= config.approvalThreshold) {
44+
throw new Error('Invalid config; rejectionThreshold must be greater than approvalThreshold');
45+
}
46+
}
47+
4248
let validateConfigFn = options.scheduled ? validateConfigForScheduled : validateConfig;
4349

4450
// validate config
@@ -142,6 +148,8 @@ export default (options: Record<string, string>): Context => {
142148
useLambdaInternal: useLambdaInternal,
143149
useExtendedViewport: useExtendedViewport,
144150
loadDomContent: loadDomContent,
151+
approvalThreshold: config.approvalThreshold,
152+
rejectionThreshold: config.rejectionThreshold,
145153
},
146154
uploadFilePath: '',
147155
webStaticConfig: [],

src/lib/httpClient.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -345,24 +345,33 @@ export default class httpClient {
345345
}, ctx.log)
346346
}
347347

348-
processSnapshot(ctx: Context, snapshot: ProcessedSnapshot, snapshotUuid: string, discoveryErrors: DiscoveryErrors, variantCount: number, sync: boolean = false) {
348+
processSnapshot(ctx: Context, snapshot: ProcessedSnapshot, snapshotUuid: string, discoveryErrors: DiscoveryErrors, variantCount: number, sync: boolean = false, approvalThreshold: number| undefined, rejectionThreshold: number| undefined) {
349+
const requestData: any = {
350+
name: snapshot.name,
351+
url: snapshot.url,
352+
snapshotUuid: snapshotUuid,
353+
variantCount: variantCount,
354+
test: {
355+
type: ctx.testType,
356+
source: 'cli'
357+
},
358+
discoveryErrors: discoveryErrors,
359+
doRemoteDiscovery: snapshot.options.doRemoteDiscovery,
360+
sync: sync
361+
};
362+
363+
if (approvalThreshold !== undefined) {
364+
requestData.approvalThreshold = approvalThreshold;
365+
}
366+
if (rejectionThreshold !== undefined) {
367+
requestData.rejectionThreshold = rejectionThreshold;
368+
}
369+
349370
return this.request({
350371
url: `/build/${ctx.build.id}/snapshot`,
351372
method: 'POST',
352373
headers: { 'Content-Type': 'application/json' },
353-
data: {
354-
name: snapshot.name,
355-
url: snapshot.url,
356-
snapshotUuid: snapshotUuid,
357-
variantCount: variantCount,
358-
test: {
359-
type: ctx.testType,
360-
source: 'cli'
361-
},
362-
doRemoteDiscovery: snapshot.options.doRemoteDiscovery,
363-
discoveryErrors: discoveryErrors,
364-
sync: sync
365-
}
374+
data: requestData
366375
}, ctx.log)
367376
}
368377

src/lib/schemaValidation.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,18 @@ const ConfigSchema = {
279279
loadDomContent: {
280280
type: "boolean",
281281
errorMessage: "Invalid config; loadDomContent must be true/false"
282+
},
283+
approvalThreshold: {
284+
type: "number",
285+
minimum: 0,
286+
maximum: 100,
287+
errorMessage: "Invalid config; approvalThreshold must be a number"
288+
},
289+
rejectionThreshold: {
290+
type: "number",
291+
minimum: 0,
292+
maximum: 100,
293+
errorMessage: "Invalid config; rejectionThreshold must be a number"
282294
}
283295
},
284296
anyOf: [
@@ -542,6 +554,18 @@ const SnapshotSchema: JSONSchemaType<Snapshot> = {
542554
useExtendedViewport: {
543555
type: "boolean",
544556
errorMessage: "Invalid snapshot options; useExtendedViewport must be a boolean"
557+
},
558+
approvalThreshold: {
559+
type: "number",
560+
minimum: 0,
561+
maximum: 100,
562+
errorMessage: "Invalid snapshot options; approvalThreshold must be a number between 0 and 100"
563+
},
564+
rejectionThreshold: {
565+
type: "number",
566+
minimum: 0,
567+
maximum: 100,
568+
errorMessage: "Invalid snapshot options; rejectionThreshold must be a number between 0 and 100"
545569
}
546570
},
547571
additionalProperties: false

src/lib/server.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export default async (ctx: Context): Promise<FastifyInstance<Server, IncomingMes
3737
try {
3838
let { snapshot, testType } = request.body;
3939
if (!validateSnapshot(snapshot)) throw new Error(validateSnapshot.errors[0].message);
40+
41+
if(snapshot?.options?.approvalThreshold !== undefined && snapshot?.options?.rejectionThreshold !== undefined) {
42+
if(snapshot?.options?.rejectionThreshold <= snapshot?.options?.approvalThreshold) {
43+
throw new Error(`Invalid snapshot options; rejectionThreshold (${snapshot.options.rejectionThreshold}) must be greater than approvalThreshold (${snapshot.options.approvalThreshold})`);
44+
}
45+
}
4046

4147
// Fetch sessionId from snapshot options if present
4248
const sessionId = snapshot?.options?.sessionId;

src/lib/snapshotQueue.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,9 @@ export default class Queue {
427427
}
428428
this.processNext();
429429
} else {
430-
await this.ctx.client.processSnapshot(this.ctx, processedSnapshot, snapshotUuid, discoveryErrors,calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config),snapshot?.options?.sync);
430+
let approvalThreshold = snapshot?.options?.approvalThreshold || this.ctx.config.approvalThreshold;
431+
let rejectionThreshold = snapshot?.options?.rejectionThreshold || this.ctx.config.rejectionThreshold;
432+
await this.ctx.client.processSnapshot(this.ctx, processedSnapshot, snapshotUuid, discoveryErrors,calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config),snapshot?.options?.sync, approvalThreshold, rejectionThreshold);
431433
if(snapshot?.options?.contextId && this.ctx.contextToSnapshotMap?.has(snapshot.options.contextId)){
432434
this.ctx.contextToSnapshotMap.set(snapshot.options.contextId, 1);
433435
}

src/tasks/processSnapshot.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
3636
}
3737
task.output = output;
3838
task.title = 'Processed snapshots'
39+
if(ctx.snapshotQueue?.getProcessedSnapshots()?.length === 0){
40+
task.title = 'No snapshots processed';
41+
}
3942
} catch (error: any) {
4043
ctx.log.debug(error);
4144
task.output = chalk.gray(error.message);

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export interface Context {
4040
useLambdaInternal?: boolean;
4141
useExtendedViewport?: boolean;
4242
loadDomContent?: boolean;
43+
approvalThreshold?: number;
44+
rejectionThreshold?: number;
4345
};
4446
uploadFilePath: string;
4547
webStaticConfig: WebStaticConfig;
@@ -158,6 +160,8 @@ export interface Snapshot {
158160
sync?: boolean;
159161
contextId?: string;
160162
useExtendedViewport?: boolean;
163+
approvalThreshold?: number;
164+
rejectionThreshold?: number;
161165
}
162166
}
163167

0 commit comments

Comments
 (0)