Skip to content

Commit 5284dcc

Browse files
authored
Merge branch 'stage' into ping_test
2 parents a05c7e7 + c7e74a2 commit 5284dcc

File tree

10 files changed

+78
-23
lines changed

10 files changed

+78
-23
lines changed

src/commander/capture.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ command
2020
.option('-F, --force', 'forcefully apply the specified parallel instances per browser')
2121
.option('--fetch-results [filename]', 'Fetch results and optionally specify an output file, e.g., <filename>.json')
2222
.option('--buildName <string>', 'Specify the build name')
23+
.option('--scheduled <string>', 'Specify the schedule ID')
2324
.option('--userName <string>', 'Specify the LT username')
2425
.option('--accessKey <string>', 'Specify the LT accesskey')
2526
.action(async function(file, _, command) {
@@ -38,7 +39,6 @@ command
3839
try {
3940
ctx.webStaticConfig = JSON.parse(fs.readFileSync(file, 'utf8'));
4041
if (!validateWebStaticConfig(ctx.webStaticConfig)){
41-
4242
ctx.log.debug(JSON.stringify(validateWebStaticConfig.errors, null, 2));
4343
// Iterate and add warning for "additionalProperties"
4444
validateWebStaticConfig.errors?.forEach(error => {
@@ -58,6 +58,7 @@ command
5858
}
5959
} catch (error: any) {
6060
ctx.log.error(`Invalid Web Static Config; ${error.message}`);
61+
process.exitCode = 1;
6162
return;
6263
}
6364
//Print Config here in debug mode
@@ -88,6 +89,7 @@ command
8889
} catch (error) {
8990
console.log('\nRefer docs: https://www.lambdatest.com/support/docs/smart-visual-regression-testing/');
9091
process.exitCode = 1;
92+
throw new Error();
9193
}
9294

9395
})

src/commander/exec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ command
2222
.option('-P, --port <number>', 'Port number for the server')
2323
.option('--fetch-results [filename]', 'Fetch results and optionally specify an output file, e.g., <filename>.json')
2424
.option('--buildName <string>', 'Specify the build name')
25+
.option('--scheduled <string>', 'Specify the schedule ID')
2526
.option('--userName <string>', 'Specify the LT username')
2627
.option('--accessKey <string>', 'Specify the LT accesskey')
2728
.action(async function(execCommand, _, command) {

src/lib/constants.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ export default {
360360

361361
FIGMA_API: 'https://api.figma.com/v1/',
362362
DEFAULT_FIGMA_CONFIG: {
363-
"depth": 2,
363+
"depth": 1,
364364
"figma_config": [
365365
{
366366
"figma_file_token": "token_for_first_figma_file",
@@ -381,7 +381,7 @@ export default {
381381
]
382382
},
383383
figma: {
384-
"depth": 2,
384+
"depth": 1,
385385
"configs": [
386386
{
387387
"figma_file_token": "<token>",
@@ -408,7 +408,7 @@ export default {
408408
}
409409
],
410410
figma: {
411-
"depth": 2,
411+
"depth": 1,
412412
"configs": [
413413
{
414414
"figma_file_token": "<token>",

src/lib/ctx.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Context, Env, WebConfig, MobileConfig, basicAuth, tunnelConfig } from '../types.js'
22
import constants from './constants.js'
33
import { version } from '../../package.json'
4-
import { validateConfig } from './schemaValidation.js'
4+
import { validateConfig, validateConfigForScheduled } from './schemaValidation.js'
55
import logger from './logger.js'
66
import getEnv from './env.js'
77
import httpClient from './httpClient.js'
@@ -23,6 +23,7 @@ export default (options: Record<string, string>): Context => {
2323
let fetchResultObj: boolean;
2424
let fetchResultsFileObj: string;
2525
let buildNameObj: string;
26+
let allowDuplicateSnapshotNames: boolean = false;
2627
try {
2728
if (options.config) {
2829
config = JSON.parse(fs.readFileSync(options.config, 'utf-8'));
@@ -35,9 +36,11 @@ export default (options: Record<string, string>): Context => {
3536
delete config.web.resolutions;
3637
}
3738

39+
let validateConfigFn = options.scheduled ? validateConfigForScheduled : validateConfig;
40+
3841
// validate config
39-
if (!validateConfig(config)) {
40-
throw new Error(validateConfig.errors[0].message);
42+
if (!validateConfigFn(config)) {
43+
throw new Error(validateConfigFn.errors[0].message);
4144
}
4245
} else {
4346
logger.info("## No config file provided. Using default config.");
@@ -70,7 +73,7 @@ export default (options: Record<string, string>): Context => {
7073
}
7174
} catch (error: any) {
7275
console.log(`[smartui] Error: ${error.message}`);
73-
process.exit();
76+
process.exit(1);
7477
}
7578

7679
if (config.web) {
@@ -85,10 +88,13 @@ export default (options: Record<string, string>): Context => {
8588
}
8689
}
8790
if (config.basicAuthorization) {
88-
basicAuthObj = config.basicAuthorization
91+
basicAuthObj = config.basicAuthorization;
8992
}
9093
if (config.tunnel) {
91-
tunnelObj = config.tunnel
94+
tunnelObj = config.tunnel;
95+
}
96+
if (config.allowDuplicateSnapshotNames) {
97+
allowDuplicateSnapshotNames = true;
9298
}
9399

94100
return {
@@ -114,7 +120,8 @@ export default (options: Record<string, string>): Context => {
114120
skipBuildCreation: config.skipBuildCreation ?? false,
115121
tunnel: tunnelObj,
116122
userAgent: config.userAgent || '',
117-
requestHeaders: config.requestHeaders || {}
123+
requestHeaders: config.requestHeaders || {},
124+
allowDuplicateSnapshotNames: allowDuplicateSnapshotNames,
118125
},
119126
uploadFilePath: '',
120127
webStaticConfig: [],
@@ -142,6 +149,7 @@ export default (options: Record<string, string>): Context => {
142149
force: options.force ? true : false,
143150
markBaseline: options.markBaseline ? true : false,
144151
buildName: options.buildName || '',
152+
scheduled: options.scheduled || '',
145153
port: port,
146154
ignoreResolutions: resolutionOff,
147155
fileExtension: extensionFiles,

src/lib/httpClient.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export default class httpClient {
202202
}
203203
}
204204

205-
createBuild(git: Git, config: any, log: Logger, buildName: string, isStartExec: boolean, smartGit: boolean, markBaseline: boolean, baselineBuild: string) {
205+
createBuild(git: Git, config: any, log: Logger, buildName: string, isStartExec: boolean, smartGit: boolean, markBaseline: boolean, baselineBuild: string, scheduled?: string) {
206206
return this.request({
207207
url: '/build',
208208
method: 'POST',
@@ -214,7 +214,8 @@ export default class httpClient {
214214
packageVersion: pkgJSON.version,
215215
smartGit,
216216
markBaseline,
217-
baselineBuild
217+
baselineBuild,
218+
scheduled
218219
}
219220
}, log)
220221
}

src/lib/schemaValidation.ts

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ const ConfigSchema = {
258258
errorMessage: {
259259
uniqueItems: "Invalid config; duplicates in requestHeaders"
260260
}
261+
},
262+
allowDuplicateSnapshotNames: {
263+
type: "boolean",
264+
errorMessage: "Invalid config; allowDuplicateSnapshotNames must be true/false"
261265
}
262266
},
263267
anyOf: [
@@ -508,8 +512,8 @@ const FigmaDesignConfigSchema: JSONSchemaType<FigmaDesignConfig> = {
508512
properties: {
509513
depth: {
510514
type: "integer",
511-
minimum: 2,
512-
errorMessage: "Depth must be an integer and greater than 1"
515+
minimum: 1,
516+
errorMessage: "Depth must be an integer and greater than 0"
513517
},
514518
figma_config: {
515519
type: "array",
@@ -582,8 +586,8 @@ const FigmaWebConfigSchema: JSONSchemaType<Object> = {
582586
"properties": {
583587
depth: {
584588
type: "integer",
585-
minimum: 2,
586-
errorMessage: "Depth must be an integer and greater than 1"
589+
minimum: 1,
590+
errorMessage: "Depth must be an integer and greater than 0"
587591
},
588592
"configs": {
589593
"type": "array",
@@ -698,8 +702,8 @@ const FigmaAppConfigSchema: JSONSchemaType<Object> = {
698702
"properties": {
699703
depth: {
700704
type: "integer",
701-
minimum: 2,
702-
errorMessage: "Depth must be an integer and greater than 1"
705+
minimum: 1,
706+
errorMessage: "Depth must be an integer and greater than 0"
703707
},
704708
"configs": {
705709
"type": "array",
@@ -759,4 +763,41 @@ export const validateWebStaticConfig = ajv.compile(WebStaticConfigSchema);
759763
export const validateSnapshot = ajv.compile(SnapshotSchema);
760764
export const validateFigmaDesignConfig = ajv.compile(FigmaDesignConfigSchema);
761765
export const validateWebFigmaConfig = ajv.compile(FigmaWebConfigSchema);
762-
export const validateAppFigmaConfig = ajv.compile(FigmaAppConfigSchema);
766+
export const validateAppFigmaConfig = ajv.compile(FigmaAppConfigSchema);
767+
768+
export const validateConfigForScheduled = (config: any) => {
769+
validateConfigForScheduled.errors = null;
770+
771+
772+
if (!validateConfig(config)) {
773+
774+
let errors = validateConfig.errors || [];
775+
776+
errors = errors.filter(error => {
777+
const message = error.message || '';
778+
return !message.includes('max unique viewports allowed - 5')
779+
});
780+
781+
if (config.web && config.web.viewports && Array.isArray(config.web.viewports)) {
782+
if (config.web.viewports.length > 8) {
783+
errors.push({
784+
message: "Invalid config; max unique viewports allowed - 8 (scheduled build)",
785+
keyword: "maxItems",
786+
instancePath: "/web/viewports",
787+
schemaPath: "#/properties/web/properties/viewports/maxItems"
788+
} as any);
789+
}
790+
}
791+
792+
// If there are any errors remaining, set them and return false
793+
if (errors.length > 0) {
794+
validateConfigForScheduled.errors = errors;
795+
return false;
796+
}
797+
}
798+
799+
return true;
800+
};
801+
802+
// Initialize the errors property
803+
validateConfigForScheduled.errors = null;

src/lib/snapshotQueue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export default class Queue {
276276
this.ctx.log.info(`Processing Snapshot: ${snapshot?.name}`);
277277
}
278278

279-
if (!this.ctx.config.delayedUpload && snapshot && snapshot.name && this.snapshotNames.includes(snapshot.name)) {
279+
if (!this.ctx.config.delayedUpload && snapshot && snapshot.name && this.snapshotNames.includes(snapshot.name) && !this.ctx.config.allowDuplicateSnapshotNames) {
280280
drop = true;
281281
this.ctx.log.info(`Skipping duplicate SmartUI snapshot '${snapshot.name}'. To capture duplicate screenshots, please set the 'delayedUpload' configuration as true in your config file.`);
282282
}

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);
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);
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);
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);
1616
if (resp && resp.data && resp.data.buildId) {
1717
ctx.build = {
1818
id: resp.data.buildId,

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface Context {
3636
tunnel: tunnelConfig | undefined;
3737
userAgent?: string;
3838
requestHeaders?: Array<Record<string, string>>;
39+
allowDuplicateSnapshotNames?: boolean;
3940
};
4041
uploadFilePath: string;
4142
webStaticConfig: WebStaticConfig;
@@ -54,6 +55,7 @@ export interface Context {
5455
force?: boolean,
5556
markBaseline?: boolean,
5657
buildName?: string,
58+
scheduled?: string,
5759
port?: number,
5860
ignoreResolutions?: boolean,
5961
fileExtension?: Array<string>,

0 commit comments

Comments
 (0)