@lambdatest/smartui-cli 4.0.22 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.cjs +65 -9
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -638,6 +638,17 @@ var WebStaticConfigSchema = {
638
638
  minimum: 0,
639
639
  maximum: 3e4,
640
640
  errorMessage: "waitForTimeout must be > 0 and <= 30000"
641
+ },
642
+ execute: {
643
+ type: "object",
644
+ properties: {
645
+ afterNavigation: {
646
+ type: "string"
647
+ },
648
+ beforeSnapshot: {
649
+ type: "string"
650
+ }
651
+ }
641
652
  }
642
653
  },
643
654
  required: ["name", "url"],
@@ -1270,6 +1281,7 @@ var server_default = (ctx) => __async(void 0, null, function* () {
1270
1281
  throw new Error(validateSnapshot.errors[0].message);
1271
1282
  ctx.testType = testType;
1272
1283
  (_a = ctx.snapshotQueue) == null ? void 0 : _a.enqueue(snapshot);
1284
+ ctx.isSnapshotCaptured = true;
1273
1285
  replyCode = 200;
1274
1286
  replyBody = { data: { message: "success", warnings: [] } };
1275
1287
  } catch (error) {
@@ -1389,6 +1401,9 @@ var logger = winston.createLogger({
1389
1401
  case "warn":
1390
1402
  message = chalk__default.default.yellow(message);
1391
1403
  break;
1404
+ case "error":
1405
+ message = chalk__default.default.red(message);
1406
+ break;
1392
1407
  }
1393
1408
  return info.level === "info" ? message : `[${contextString}:${info.level}] ` + message;
1394
1409
  })
@@ -1451,7 +1466,7 @@ var auth_default = (ctx) => {
1451
1466
  };
1452
1467
 
1453
1468
  // package.json
1454
- var version = "4.0.22";
1469
+ var version = "4.1.1";
1455
1470
  var package_default = {
1456
1471
  name: "@lambdatest/smartui-cli",
1457
1472
  version,
@@ -1906,7 +1921,8 @@ var ctx_default = (options) => {
1906
1921
  },
1907
1922
  cliVersion: version,
1908
1923
  totalSnapshots: -1,
1909
- isStartExec: false
1924
+ isStartExec: false,
1925
+ isSnapshotCaptured: false
1910
1926
  };
1911
1927
  };
1912
1928
  function executeCommand(command7) {
@@ -2109,8 +2125,11 @@ var finalizeBuild_default = (ctx) => {
2109
2125
  ctx2.log.debug(`Closed browser`);
2110
2126
  yield (_b = ctx2.server) == null ? void 0 : _b.close();
2111
2127
  ctx2.log.debug(`Closed server`);
2112
- let resp = yield ctx2.client.getS3PreSignedURL(ctx2);
2113
- yield ctx2.client.uploadLogs(ctx2, resp.data.url);
2128
+ if (ctx2.isSnapshotCaptured) {
2129
+ ctx2.log.debug(`Log file to be uploaded`);
2130
+ let resp = yield ctx2.client.getS3PreSignedURL(ctx2);
2131
+ yield ctx2.client.uploadLogs(ctx2, resp.data.url);
2132
+ }
2114
2133
  fs6__default.default.unlinkSync(constants_default.LOG_FILE_PATH);
2115
2134
  ctx2.log.debug(`Log file deleted: ${constants_default.LOG_FILE_PATH}`);
2116
2135
  } catch (error) {
@@ -2910,8 +2929,12 @@ configWebFigma.name("config:create-figma-web").description("Create figma config
2910
2929
  createWebFigmaConfig(filepath);
2911
2930
  });
2912
2931
  });
2913
- function captureScreenshotsForConfig(_0, _1, _2, _3, _4) {
2914
- return __async(this, arguments, function* (ctx, browsers, { name, url, waitForTimeout }, browserName, renderViewports) {
2932
+ function captureScreenshotsForConfig(ctx, browsers, urlConfig, browserName, renderViewports) {
2933
+ return __async(this, null, function* () {
2934
+ ctx.log.debug(`*** urlConfig ${JSON.stringify(urlConfig)}`);
2935
+ let { name, url, waitForTimeout, execute } = urlConfig;
2936
+ let afterNavigationScript = execute == null ? void 0 : execute.afterNavigation;
2937
+ let beforeSnapshotScript = execute == null ? void 0 : execute.beforeSnapshot;
2915
2938
  let pageOptions = { waitUntil: process.env.SMARTUI_PAGE_WAIT_UNTIL_EVENT || "load", timeout: ctx.config.waitForPageRender || constants_default.DEFAULT_PAGE_LOAD_TIMEOUT };
2916
2939
  let ssId = name.toLowerCase().replace(/\s/g, "_");
2917
2940
  let context;
@@ -2930,12 +2953,14 @@ function captureScreenshotsForConfig(_0, _1, _2, _3, _4) {
2930
2953
  context = yield browser == null ? void 0 : browser.newContext(contextOptions);
2931
2954
  page = yield context == null ? void 0 : context.newPage();
2932
2955
  yield page == null ? void 0 : page.goto(url.trim(), pageOptions);
2956
+ yield executeDocumentScripts(ctx, page, "afterNavigation", afterNavigationScript);
2933
2957
  for (let { viewport, viewportString, fullPage } of renderViewports) {
2934
2958
  let ssPath = `screenshots/${ssId}/${`${browserName}-${viewport.width}x${viewport.height}`}-${ssId}.png`;
2935
2959
  yield page == null ? void 0 : page.setViewportSize({ width: viewport.width, height: viewport.height || constants_default.MIN_VIEWPORT_HEIGHT });
2936
2960
  if (fullPage)
2937
2961
  yield page == null ? void 0 : page.evaluate(scrollToBottomAndBackToTop);
2938
2962
  yield page == null ? void 0 : page.waitForTimeout(waitForTimeout || 0);
2963
+ yield executeDocumentScripts(ctx, page, "beforeSnapshot", beforeSnapshotScript);
2939
2964
  yield page == null ? void 0 : page.screenshot({ path: ssPath, fullPage });
2940
2965
  yield ctx.client.uploadScreenshot(ctx.build, ssPath, name, browserName, viewportString, ctx.log);
2941
2966
  }
@@ -3012,7 +3037,7 @@ function captureScreenshots(ctx) {
3012
3037
  ctx.task.output = output;
3013
3038
  capturedScreenshots++;
3014
3039
  } catch (error) {
3015
- ctx.log.debug(`screenshot capture failed for ${JSON.stringify(staticConfig)}; error: ${error}`);
3040
+ ctx.log.debug(`captureScreenshots failed for ${JSON.stringify(staticConfig)}; error: ${error}`);
3016
3041
  output += `${chalk__default.default.gray(staticConfig.name)} ${chalk__default.default.red("\u2717")}
3017
3042
  `;
3018
3043
  ctx.task.output = output;
@@ -3207,6 +3232,23 @@ function processChunk(ctx, urlConfig) {
3207
3232
  return { capturedScreenshots, finalOutput };
3208
3233
  });
3209
3234
  }
3235
+ function executeDocumentScripts(ctx, page, actionType, script) {
3236
+ return __async(this, null, function* () {
3237
+ try {
3238
+ if (!page) {
3239
+ throw new Error("Page instance not available");
3240
+ }
3241
+ if (script !== "") {
3242
+ yield page.evaluate((script2) => {
3243
+ new Function(script2)();
3244
+ }, script);
3245
+ }
3246
+ } catch (error) {
3247
+ ctx.log.error(`Error executing script for action ${actionType}: `, error);
3248
+ throw error;
3249
+ }
3250
+ });
3251
+ }
3210
3252
  var captureScreenshots_default = (ctx) => {
3211
3253
  return {
3212
3254
  title: "Capturing screenshots",
@@ -3244,20 +3286,32 @@ var captureScreenshots_default = (ctx) => {
3244
3286
  var command2 = new commander.Command();
3245
3287
  command2.name("capture").description("Capture screenshots of static sites").argument("<file>", "Web static config file").option("-C, --parallel [number]", "Specify the number of instances per browser", parseInt).option("-F, --force", "forcefully apply the specified parallel instances per browser").option("--fetch-results [filename]", "Fetch results and optionally specify an output file, e.g., <filename>.json").option("--buildName <string>", "Specify the build name").action(function(file, _, command7) {
3246
3288
  return __async(this, null, function* () {
3289
+ var _a, _b;
3247
3290
  const options = command7.optsWithGlobals();
3248
3291
  if (options.buildName === "") {
3249
3292
  console.log(`Error: The '--buildName' option cannot be an empty string.`);
3250
3293
  process.exit(1);
3251
3294
  }
3252
3295
  let ctx = ctx_default(command7.optsWithGlobals());
3296
+ ctx.isSnapshotCaptured = true;
3253
3297
  if (!fs6__default.default.existsSync(file)) {
3254
3298
  ctx.log.error(`Web Static Config file ${file} not found.`);
3255
3299
  return;
3256
3300
  }
3257
3301
  try {
3258
3302
  ctx.webStaticConfig = JSON.parse(fs6__default.default.readFileSync(file, "utf8"));
3259
- if (!validateWebStaticConfig(ctx.webStaticConfig))
3260
- throw new Error(validateWebStaticConfig.errors[0].message);
3303
+ if (!validateWebStaticConfig(ctx.webStaticConfig)) {
3304
+ ctx.log.debug(JSON.stringify(validateWebStaticConfig.errors, null, 2));
3305
+ (_a = validateWebStaticConfig.errors) == null ? void 0 : _a.forEach((error) => {
3306
+ if (error.keyword === "additionalProperties") {
3307
+ ctx.log.warn(`Additional property "${error.params.additionalProperty}" is not allowed.`);
3308
+ } else {
3309
+ const validationError = error.message;
3310
+ throw new Error(validationError || "Invalid Web Static config found in file : " + file);
3311
+ }
3312
+ });
3313
+ throw new Error((_b = validateWebStaticConfig.errors[0]) == null ? void 0 : _b.message);
3314
+ }
3261
3315
  if (ctx.webStaticConfig && ctx.webStaticConfig.length === 0) {
3262
3316
  ctx.log.error(`No URLs found in the specified config file -> ${file}`);
3263
3317
  return;
@@ -3331,6 +3385,7 @@ command3.name("upload").description("Upload screenshots from given directory").a
3331
3385
  process.exit(1);
3332
3386
  }
3333
3387
  let ctx = ctx_default(command7.optsWithGlobals());
3388
+ ctx.isSnapshotCaptured = true;
3334
3389
  if (!fs6__default.default.existsSync(directory)) {
3335
3390
  console.log(`Error: The provided directory ${directory} not found.`);
3336
3391
  return;
@@ -3529,6 +3584,7 @@ uploadFigma.name("upload-figma").description("Capture screenshots of static site
3529
3584
  return __async(this, null, function* () {
3530
3585
  var _a, _b;
3531
3586
  let ctx = ctx_default(command7.optsWithGlobals());
3587
+ ctx.isSnapshotCaptured = true;
3532
3588
  if (!fs6__default.default.existsSync(file)) {
3533
3589
  console.log(`Error: Figma Config file ${file} not found.`);
3534
3590
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambdatest/smartui-cli",
3
- "version": "4.0.22",
3
+ "version": "4.1.1",
4
4
  "description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
5
5
  "files": [
6
6
  "dist/**/*"