@lambdatest/smartui-cli 3.0.0 → 3.0.2

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 +160 -105
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -4,7 +4,7 @@
4
4
  var commander = require('commander');
5
5
  var which = require('which');
6
6
  var listr2 = require('listr2');
7
- var chalk = require('chalk');
7
+ var chalk8 = require('chalk');
8
8
  var path2 = require('path');
9
9
  var fastify = require('fastify');
10
10
  var fs4 = require('fs');
@@ -20,7 +20,7 @@ var spawn = require('cross-spawn');
20
20
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
21
21
 
22
22
  var which__default = /*#__PURE__*/_interopDefault(which);
23
- var chalk__default = /*#__PURE__*/_interopDefault(chalk);
23
+ var chalk8__default = /*#__PURE__*/_interopDefault(chalk8);
24
24
  var path2__default = /*#__PURE__*/_interopDefault(path2);
25
25
  var fastify__default = /*#__PURE__*/_interopDefault(fastify);
26
26
  var fs4__default = /*#__PURE__*/_interopDefault(fs4);
@@ -113,7 +113,7 @@ var constants_default = {
113
113
  FIREFOX: "firefox",
114
114
  EDGE: "edge",
115
115
  EDGE_CHANNEL: "msedge",
116
- PW_WEBKIT: "webkit",
116
+ WEBKIT: "webkit",
117
117
  // viewports
118
118
  MIN_VIEWPORT_HEIGHT: 1080,
119
119
  // mobile
@@ -369,31 +369,53 @@ function closeBrowsers(browsers) {
369
369
  yield (_a = browsers[browserName]) == null ? void 0 : _a.close();
370
370
  });
371
371
  }
372
- function getRenderViewports(ctx) {
373
- let renderViewports = [];
372
+ function getWebRenderViewports(ctx) {
373
+ let webRenderViewports = [];
374
374
  if (ctx.config.web) {
375
375
  for (const viewport of ctx.config.web.viewports) {
376
- renderViewports.push({
376
+ webRenderViewports.push({
377
377
  viewport,
378
378
  viewportString: `${viewport.width}${viewport.height ? "x" + viewport.height : ""}`,
379
- fullPage: viewport.height ? false : true
379
+ fullPage: viewport.height ? false : true,
380
+ device: false
380
381
  });
381
382
  }
382
383
  }
384
+ return webRenderViewports;
385
+ }
386
+ function getMobileRenderViewports(ctx) {
387
+ var _a;
388
+ let mobileRenderViewports = {};
389
+ mobileRenderViewports[constants_default.MOBILE_OS_IOS] = [];
390
+ mobileRenderViewports[constants_default.MOBILE_OS_ANDROID] = [];
383
391
  if (ctx.config.mobile) {
384
392
  for (const device of ctx.config.mobile.devices) {
385
- renderViewports.push({
386
- viewport: constants_default.SUPPORTED_MOBILE_DEVICES[device].viewport,
393
+ let os = constants_default.SUPPORTED_MOBILE_DEVICES[device].os;
394
+ let { width, height } = constants_default.SUPPORTED_MOBILE_DEVICES[device].viewport;
395
+ let portrait = ctx.config.mobile.orientation === constants_default.MOBILE_ORIENTATION_PORTRAIT ? true : false;
396
+ (_a = mobileRenderViewports[os]) == null ? void 0 : _a.push({
397
+ viewport: { width: portrait ? width : height, height: portrait ? height : width },
387
398
  viewportString: `${device} (${ctx.config.mobile.orientation})`,
388
- fullPage: ctx.config.mobile.fullPage
399
+ fullPage: ctx.config.mobile.fullPage,
400
+ device: true,
401
+ os
389
402
  });
390
403
  }
391
404
  }
392
- return renderViewports;
405
+ return mobileRenderViewports;
406
+ }
407
+ function getRenderViewports(ctx) {
408
+ let mobileRenderViewports = getMobileRenderViewports(ctx);
409
+ return [
410
+ ...getWebRenderViewports(ctx),
411
+ ...mobileRenderViewports[constants_default.MOBILE_OS_IOS],
412
+ ...mobileRenderViewports[constants_default.MOBILE_OS_ANDROID]
413
+ ];
393
414
  }
394
415
  var MAX_RESOURCE_SIZE = 5 * 1024 ** 2;
395
416
  var ALLOWED_RESOURCES = ["document", "stylesheet", "image", "media", "font", "other"];
396
417
  var ALLOWED_STATUSES = [200, 201];
418
+ var REQUEST_TIMEOUT = 1e4;
397
419
  var MIN_VIEWPORT_HEIGHT = 1080;
398
420
  var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function* () {
399
421
  ctx.log.debug(`Processing snapshot ${snapshot.name}`);
@@ -409,7 +431,7 @@ var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function*
409
431
  ctx.config.allowedHostnames.push(new URL(snapshot.url).hostname);
410
432
  if (ctx.config.enableJavaScript)
411
433
  ALLOWED_RESOURCES.push("script");
412
- const response = yield page.request.fetch(request);
434
+ const response = yield page.request.fetch(request, { timeout: REQUEST_TIMEOUT });
413
435
  const body = yield response.body();
414
436
  if (!body) {
415
437
  ctx.log.debug(`Handling request ${requestUrl}
@@ -897,13 +919,13 @@ var logger = winston.createLogger({
897
919
  let message = typeof info.message === "object" ? JSON.stringify(info.message) : info.message;
898
920
  switch (info.level) {
899
921
  case "debug":
900
- message = chalk__default.default.blue(message);
922
+ message = chalk8__default.default.blue(message);
901
923
  break;
902
924
  case "warn":
903
- message = chalk__default.default.yellow(message);
925
+ message = chalk8__default.default.yellow(message);
904
926
  break;
905
927
  case "error":
906
- message = chalk__default.default.red(message);
928
+ message = chalk8__default.default.red(message);
907
929
  break;
908
930
  }
909
931
  return info.level === "info" ? message : `[${contextString}:${info.level}] ` + message;
@@ -922,11 +944,11 @@ var startServer_default = (ctx) => {
922
944
  updateLogContext({ task: "startServer" });
923
945
  try {
924
946
  ctx2.server = yield server_default(ctx2);
925
- task.output = chalk__default.default.gray(`listening on port ${(_a = ctx2.server.addresses()[0]) == null ? void 0 : _a.port}`);
947
+ task.output = chalk8__default.default.gray(`listening on port ${(_a = ctx2.server.addresses()[0]) == null ? void 0 : _a.port}`);
926
948
  task.title = "SmartUI started";
927
949
  } catch (error) {
928
950
  ctx2.log.debug(error);
929
- task.output = chalk__default.default.gray(error.message);
951
+ task.output = chalk8__default.default.gray(error.message);
930
952
  throw new Error("SmartUI server setup failed");
931
953
  }
932
954
  }),
@@ -940,11 +962,11 @@ var auth_default = (ctx) => {
940
962
  updateLogContext({ task: "auth" });
941
963
  try {
942
964
  yield ctx2.client.auth(ctx2.log);
943
- task.output = chalk__default.default.gray(`using project token '******#${ctx2.env.PROJECT_TOKEN.split("#").pop()}'`);
965
+ task.output = chalk8__default.default.gray(`using project token '******#${ctx2.env.PROJECT_TOKEN.split("#").pop()}'`);
944
966
  task.title = "Authenticated with SmartUI";
945
967
  } catch (error) {
946
968
  ctx2.log.debug(error);
947
- task.output = chalk__default.default.gray(error.message);
969
+ task.output = chalk8__default.default.gray(error.message);
948
970
  throw new Error("Authentication failed");
949
971
  }
950
972
  }),
@@ -953,7 +975,7 @@ var auth_default = (ctx) => {
953
975
  };
954
976
 
955
977
  // package.json
956
- var version = "3.0.0";
978
+ var version = "3.0.2";
957
979
  var package_default = {
958
980
  name: "@lambdatest/smartui-cli",
959
981
  version,
@@ -1019,13 +1041,14 @@ var httpClient = class {
1019
1041
  })}`);
1020
1042
  return resp.data;
1021
1043
  }).catch((error) => {
1044
+ var _a;
1022
1045
  if (error.response) {
1023
1046
  log.debug(`http response: ${JSON.stringify({
1024
1047
  status: error.response.status,
1025
1048
  headers: error.response.headers,
1026
1049
  body: error.response.data
1027
1050
  })}`);
1028
- throw new Error(error.response.data.error.message);
1051
+ throw new Error((_a = error.response.data.error) == null ? void 0 : _a.message);
1029
1052
  }
1030
1053
  if (error.request) {
1031
1054
  log.debug(`http request failed: ${error.toJSON()}`);
@@ -1077,6 +1100,7 @@ var httpClient = class {
1077
1100
  }, log);
1078
1101
  }
1079
1102
  uploadScreenshot({ id: buildId, name: buildName, baseline }, ssPath, ssName, browserName, viewport, log) {
1103
+ browserName = browserName === constants_default.SAFARI ? constants_default.WEBKIT : browserName;
1080
1104
  const file = fs4__default.default.readFileSync(ssPath);
1081
1105
  const form = new FormData__default.default();
1082
1106
  form.append("screenshot", file, { filename: `${ssName}.png`, contentType: "image/png" });
@@ -1172,10 +1196,12 @@ var ctx_default = (options) => {
1172
1196
  id: "",
1173
1197
  name: "",
1174
1198
  baseline: false,
1175
- url: "",
1176
- projectId: ""
1199
+ url: ""
1177
1200
  },
1178
1201
  args: {},
1202
+ options: {
1203
+ parallel: options.parallel ? true : false
1204
+ },
1179
1205
  cliVersion: version,
1180
1206
  totalSnapshots: -1
1181
1207
  };
@@ -1225,11 +1251,11 @@ var getGitInfo_default = (ctx) => {
1225
1251
  task: (ctx2, task) => __async(void 0, null, function* () {
1226
1252
  try {
1227
1253
  ctx2.git = git_default(ctx2);
1228
- task.output = chalk__default.default.gray(`branch: ${ctx2.git.branch}, commit: ${ctx2.git.commitId}, author: ${ctx2.git.commitAuthor}`);
1254
+ task.output = chalk8__default.default.gray(`branch: ${ctx2.git.branch}, commit: ${ctx2.git.commitId}, author: ${ctx2.git.commitAuthor}`);
1229
1255
  task.title = "Fetched git information";
1230
1256
  } catch (error) {
1231
1257
  ctx2.log.debug(error);
1232
- task.output = chalk__default.default.gray(`${error.message}`);
1258
+ task.output = chalk8__default.default.gray(`${error.message}`);
1233
1259
  throw new Error("Error fetching git repo details");
1234
1260
  }
1235
1261
  }),
@@ -1249,11 +1275,11 @@ var createBuild_default = (ctx) => {
1249
1275
  url: resp.data.buildURL,
1250
1276
  baseline: resp.data.baseline
1251
1277
  };
1252
- task.output = chalk__default.default.gray(`build id: ${resp.data.buildId}`);
1278
+ task.output = chalk8__default.default.gray(`build id: ${resp.data.buildId}`);
1253
1279
  task.title = "SmartUI build created";
1254
1280
  } catch (error) {
1255
1281
  ctx2.log.debug(error);
1256
- task.output = chalk__default.default.gray(JSON.parse(error.message).message);
1282
+ task.output = chalk8__default.default.gray(error.message);
1257
1283
  throw new Error("SmartUI build creation failed");
1258
1284
  }
1259
1285
  }),
@@ -1272,13 +1298,13 @@ var exec_default = (ctx) => {
1272
1298
  let totalOutput = "";
1273
1299
  const output = listr2.createWritable((chunk) => {
1274
1300
  totalOutput += chunk;
1275
- task.output = chalk__default.default.gray(totalOutput);
1301
+ task.output = chalk8__default.default.gray(totalOutput);
1276
1302
  });
1277
1303
  (_b = childProcess.stdout) == null ? void 0 : _b.pipe(output);
1278
1304
  (_c = childProcess.stderr) == null ? void 0 : _c.pipe(output);
1279
1305
  childProcess.on("error", (error) => {
1280
1306
  var _a3;
1281
- task.output = chalk__default.default.gray(`error: ${error.message}`);
1307
+ task.output = chalk8__default.default.gray(`error: ${error.message}`);
1282
1308
  throw new Error(`Execution of '${(_a3 = ctx2.args.execCommand) == null ? void 0 : _a3.join(" ")}' failed`);
1283
1309
  });
1284
1310
  childProcess.on("close", (code, signal) => __async(void 0, null, function* () {
@@ -1304,11 +1330,11 @@ var finalizeBuild_default = (ctx) => {
1304
1330
  try {
1305
1331
  yield new Promise((resolve) => setTimeout(resolve, 2e3));
1306
1332
  yield ctx2.client.finalizeBuild(ctx2.build.id, ctx2.totalSnapshots, ctx2.log);
1307
- task.output = chalk__default.default.gray(`build url: ${ctx2.build.url}`);
1333
+ task.output = chalk8__default.default.gray(`build url: ${ctx2.build.url}`);
1308
1334
  task.title = "Finalized build";
1309
1335
  } catch (error) {
1310
1336
  ctx2.log.debug(error);
1311
- task.output = chalk__default.default.gray(error.message);
1337
+ task.output = chalk8__default.default.gray(error.message);
1312
1338
  throw new Error("Finalize build failed");
1313
1339
  }
1314
1340
  }),
@@ -1405,83 +1431,108 @@ configStatic.name("config:create-web-static").description("Create Web Static con
1405
1431
  createWebStaticConfig(filepath);
1406
1432
  });
1407
1433
  });
1434
+ function captureScreenshotsForConfig(_0, _1, _2, _3, _4) {
1435
+ return __async(this, arguments, function* (ctx, browsers, { name, url, waitForTimeout }, browserName, renderViewports) {
1436
+ let pageOptions = { waitUntil: process.env.SMARTUI_PAGE_WAIT_UNTIL_EVENT || "load" };
1437
+ let ssId = name.toLowerCase().replace(/\s/g, "_");
1438
+ let context;
1439
+ let page;
1440
+ try {
1441
+ const browser = browsers[browserName];
1442
+ context = yield browser == null ? void 0 : browser.newContext();
1443
+ page = yield context == null ? void 0 : context.newPage();
1444
+ yield page == null ? void 0 : page.goto(url.trim(), pageOptions);
1445
+ for (let { viewport, viewportString, fullPage } of renderViewports) {
1446
+ let ssPath = `screenshots/${ssId}/${`${browserName}-${viewport.width}x${viewport.height}`}-${ssId}.png`;
1447
+ yield page == null ? void 0 : page.setViewportSize({ width: viewport.width, height: viewport.height || constants_default.MIN_VIEWPORT_HEIGHT });
1448
+ if (fullPage)
1449
+ yield page == null ? void 0 : page.evaluate(scrollToBottomAndBackToTop);
1450
+ yield page == null ? void 0 : page.waitForTimeout(waitForTimeout || 0);
1451
+ yield page == null ? void 0 : page.screenshot({ path: ssPath, fullPage });
1452
+ yield ctx.client.uploadScreenshot(ctx.build, ssPath, name, browserName, viewportString, ctx.log);
1453
+ }
1454
+ } catch (error) {
1455
+ throw new Error(`captureScreenshotsForConfig failed for browser ${browserName}; error: ${error}`);
1456
+ } finally {
1457
+ yield page == null ? void 0 : page.close();
1458
+ yield context == null ? void 0 : context.close();
1459
+ }
1460
+ });
1461
+ }
1462
+ function captureScreenshotsAsync(ctx, staticConfig, browsers) {
1463
+ return __async(this, null, function* () {
1464
+ let capturePromises = [];
1465
+ if (ctx.config.web) {
1466
+ for (let browserName of ctx.config.web.browsers) {
1467
+ let webRenderViewports = getWebRenderViewports(ctx);
1468
+ capturePromises.push(captureScreenshotsForConfig(ctx, browsers, staticConfig, browserName, webRenderViewports));
1469
+ }
1470
+ }
1471
+ if (ctx.config.mobile) {
1472
+ let mobileRenderViewports = getMobileRenderViewports(ctx);
1473
+ if (mobileRenderViewports[constants_default.MOBILE_OS_IOS].length) {
1474
+ capturePromises.push(captureScreenshotsForConfig(ctx, browsers, staticConfig, constants_default.SAFARI, mobileRenderViewports[constants_default.MOBILE_OS_IOS]));
1475
+ }
1476
+ if (mobileRenderViewports[constants_default.MOBILE_OS_ANDROID].length) {
1477
+ capturePromises.push(captureScreenshotsForConfig(ctx, browsers, staticConfig, constants_default.CHROME, mobileRenderViewports[constants_default.MOBILE_OS_ANDROID]));
1478
+ }
1479
+ }
1480
+ return Promise.all(capturePromises);
1481
+ });
1482
+ }
1483
+ function captureScreenshotsSync(ctx, staticConfig, browsers) {
1484
+ return __async(this, null, function* () {
1485
+ if (ctx.config.web) {
1486
+ for (let browserName of ctx.config.web.browsers) {
1487
+ let webRenderViewports = getWebRenderViewports(ctx);
1488
+ yield captureScreenshotsForConfig(ctx, browsers, staticConfig, browserName, webRenderViewports);
1489
+ }
1490
+ }
1491
+ if (ctx.config.mobile) {
1492
+ let mobileRenderViewports = getMobileRenderViewports(ctx);
1493
+ if (mobileRenderViewports[constants_default.MOBILE_OS_IOS].length) {
1494
+ yield captureScreenshotsForConfig(ctx, browsers, staticConfig, constants_default.SAFARI, mobileRenderViewports[constants_default.MOBILE_OS_IOS]);
1495
+ }
1496
+ if (mobileRenderViewports[constants_default.MOBILE_OS_ANDROID].length) {
1497
+ yield captureScreenshotsForConfig(ctx, browsers, staticConfig, constants_default.CHROME, mobileRenderViewports[constants_default.MOBILE_OS_ANDROID]);
1498
+ }
1499
+ }
1500
+ });
1501
+ }
1408
1502
  function captureScreenshots(ctx) {
1409
1503
  return __async(this, null, function* () {
1410
- var _a, _b, _c, _d, _e, _f, _g, _h;
1411
1504
  delDir("screenshots");
1412
1505
  let browsers = {};
1413
1506
  let capturedScreenshots = 0;
1414
- let pageOptions = { waitUntil: process.env.SMARTUI_PAGE_WAIT_UNTIL_EVENT || "load" };
1415
- let totalScreenshots = ctx.webStaticConfig.length * ((((_b = (_a = ctx.config.web) == null ? void 0 : _a.browsers) == null ? void 0 : _b.length) * ((_d = (_c = ctx.config.web) == null ? void 0 : _c.viewports) == null ? void 0 : _d.length) || 0) + (((_f = (_e = ctx.config.mobile) == null ? void 0 : _e.devices) == null ? void 0 : _f.length) || 0));
1507
+ let output = "";
1416
1508
  try {
1417
1509
  browsers = yield launchBrowsers(ctx);
1418
- for (let staticConfig of ctx.webStaticConfig) {
1419
- let screenshotId = staticConfig.name.toLowerCase().replace(/\s/g, "_");
1420
- if (ctx.config.web) {
1421
- for (let browserName of ctx.config.web.browsers) {
1422
- const browser = browsers[browserName];
1423
- const context = yield browser.newContext();
1424
- const page = yield context.newPage();
1425
- yield page.goto(staticConfig.url.trim(), pageOptions);
1426
- for (let { width, height } of ctx.config.web.viewports) {
1427
- let ssPath = `screenshots/${screenshotId}/${browserName}-${width}x${height}-${screenshotId}.png`;
1428
- yield page.setViewportSize({ width, height: height || constants_default.MIN_VIEWPORT_HEIGHT });
1429
- if (height === 0)
1430
- yield page.evaluate(scrollToBottomAndBackToTop);
1431
- yield page.waitForTimeout(staticConfig.waitForTimeout || 0);
1432
- yield page.screenshot({ path: ssPath, fullPage: height ? false : true });
1433
- browserName = browserName === constants_default.SAFARI ? constants_default.PW_WEBKIT : browserName;
1434
- yield ctx.client.uploadScreenshot(ctx.build, ssPath, staticConfig.name, browserName, `${width}${height ? `x${height}` : ``}`, ctx.log);
1435
- capturedScreenshots++;
1436
- ctx.task.output = chalk__default.default.gray(`screenshots captured: ${capturedScreenshots}/${totalScreenshots}`);
1437
- }
1438
- yield page.close();
1439
- yield context.close();
1440
- }
1441
- }
1442
- if (ctx.config.mobile) {
1443
- let contextChrome = yield (_g = browsers[constants_default.CHROME]) == null ? void 0 : _g.newContext();
1444
- let contextSafari = yield (_h = browsers[constants_default.SAFARI]) == null ? void 0 : _h.newContext();
1445
- let pageChrome = yield contextChrome == null ? void 0 : contextChrome.newPage();
1446
- let pageSafari = yield contextSafari == null ? void 0 : contextSafari.newPage();
1447
- yield pageChrome == null ? void 0 : pageChrome.goto(staticConfig.url.trim(), pageOptions);
1448
- yield pageSafari == null ? void 0 : pageSafari.goto(staticConfig.url.trim(), pageOptions);
1449
- for (let device of ctx.config.mobile.devices) {
1450
- let ssPath = `screenshots/${screenshotId}/${device.replace(/\s/g, "_")}_${screenshotId}.png`;
1451
- let { width, height } = constants_default.SUPPORTED_MOBILE_DEVICES[device].viewport;
1452
- let portrait = ctx.config.mobile.orientation === constants_default.MOBILE_ORIENTATION_PORTRAIT ? true : false;
1453
- if (constants_default.SUPPORTED_MOBILE_DEVICES[device].os === constants_default.MOBILE_OS_ANDROID) {
1454
- yield pageChrome == null ? void 0 : pageChrome.setViewportSize({ width: portrait ? width : height, height: portrait ? height : width });
1455
- if (ctx.config.mobile.fullPage)
1456
- yield pageChrome == null ? void 0 : pageChrome.evaluate(scrollToBottomAndBackToTop);
1457
- yield pageChrome == null ? void 0 : pageChrome.waitForTimeout(staticConfig.waitForTimeout || 0);
1458
- yield pageChrome == null ? void 0 : pageChrome.screenshot({ path: ssPath, fullPage: ctx.config.mobile.fullPage });
1459
- yield ctx.client.uploadScreenshot(ctx.build, ssPath, staticConfig.name, constants_default.CHROME, `${device} (${ctx.config.mobile.orientation})`, ctx.log);
1460
- } else {
1461
- yield pageSafari == null ? void 0 : pageSafari.setViewportSize({ width: portrait ? width : height, height: portrait ? height : width });
1462
- if (ctx.config.mobile.fullPage)
1463
- yield pageChrome == null ? void 0 : pageChrome.evaluate(scrollToBottomAndBackToTop);
1464
- yield pageSafari == null ? void 0 : pageSafari.waitForTimeout(staticConfig.waitForTimeout || 0);
1465
- yield pageSafari == null ? void 0 : pageSafari.screenshot({ path: ssPath, fullPage: ctx.config.mobile.fullPage });
1466
- yield ctx.client.uploadScreenshot(ctx.build, ssPath, staticConfig.name, constants_default.PW_WEBKIT, `${device} (${ctx.config.mobile.orientation})`, ctx.log);
1467
- }
1468
- capturedScreenshots++;
1469
- ctx.task.output = chalk__default.default.gray(`screenshots captured: ${capturedScreenshots}/${totalScreenshots}`);
1470
- }
1471
- yield pageChrome == null ? void 0 : pageChrome.close();
1472
- yield pageSafari == null ? void 0 : pageSafari.close();
1473
- yield contextChrome == null ? void 0 : contextChrome.close();
1474
- yield contextSafari == null ? void 0 : contextSafari.close();
1475
- }
1476
- }
1477
- yield closeBrowsers(browsers);
1478
- delDir("screenshots");
1479
1510
  } catch (error) {
1480
1511
  yield closeBrowsers(browsers);
1481
- delDir("screenshots");
1482
- throw error;
1512
+ ctx.log.debug(error);
1513
+ throw new Error(`Failed launching browsers`);
1514
+ }
1515
+ for (let staticConfig of ctx.webStaticConfig) {
1516
+ try {
1517
+ if (ctx.options.parallel)
1518
+ yield captureScreenshotsAsync(ctx, staticConfig, browsers);
1519
+ else
1520
+ yield captureScreenshotsSync(ctx, staticConfig, browsers);
1521
+ delDir(`screenshots/${staticConfig.name.toLowerCase().replace(/\s/g, "_")}`);
1522
+ output += `${chalk8__default.default.gray(staticConfig.name)} ${chalk8__default.default.green("\u2713")}
1523
+ `;
1524
+ ctx.task.output = output;
1525
+ capturedScreenshots++;
1526
+ } catch (error) {
1527
+ ctx.log.debug(`screenshot capture failed for ${JSON.stringify(staticConfig)}; error: ${error}`);
1528
+ output += `${chalk8__default.default.gray(staticConfig.name)} ${chalk8__default.default.red("\u2717")}
1529
+ `;
1530
+ ctx.task.output = output;
1531
+ }
1483
1532
  }
1484
- return capturedScreenshots;
1533
+ yield closeBrowsers(browsers);
1534
+ delDir("screenshots");
1535
+ return { capturedScreenshots, output };
1485
1536
  });
1486
1537
  }
1487
1538
  var captureScreenshots_default = (ctx) => {
@@ -1490,11 +1541,15 @@ var captureScreenshots_default = (ctx) => {
1490
1541
  task: (ctx2, task) => __async(void 0, null, function* () {
1491
1542
  try {
1492
1543
  ctx2.task = task;
1493
- let totalScreenshots = yield captureScreenshots(ctx2);
1544
+ updateLogContext({ task: "capture" });
1545
+ let { capturedScreenshots, output } = yield captureScreenshots(ctx2);
1546
+ if (capturedScreenshots != ctx2.webStaticConfig.length) {
1547
+ throw new Error(output);
1548
+ }
1494
1549
  task.title = "Screenshots captured successfully";
1495
- task.output = chalk__default.default.gray(`total screenshots: ${totalScreenshots}`);
1496
1550
  } catch (error) {
1497
- task.output = chalk__default.default.gray(`${error.message}`);
1551
+ ctx2.log.debug(error);
1552
+ task.output = chalk8__default.default.gray(`${error.message}`);
1498
1553
  throw new Error("Capturing screenshots failed");
1499
1554
  }
1500
1555
  }),
@@ -1505,7 +1560,7 @@ var captureScreenshots_default = (ctx) => {
1505
1560
 
1506
1561
  // src/commander/capture.ts
1507
1562
  var command2 = new commander.Command();
1508
- command2.name("capture").description("Capture screenshots of static sites").argument("<file>", "Web static config file").action(function(file, _, command3) {
1563
+ command2.name("capture").description("Capture screenshots of static sites").argument("<file>", "Web static config file").option("--parallel", "Capture parallely on all browsers").action(function(file, _, command3) {
1509
1564
  return __async(this, null, function* () {
1510
1565
  let ctx = ctx_default(command3.optsWithGlobals());
1511
1566
  if (!fs4__default.default.existsSync(file)) {
@@ -1564,13 +1619,13 @@ LambdaTest SmartUI CLI v${package_default.version}`);
1564
1619
  log.warn(`This version is deprecated. A new version ${latestVersion} is available!
1565
1620
  `);
1566
1621
  else if (package_default.version !== latestVersion)
1567
- log.info(chalk__default.default.gray(`A new version ${latestVersion} is available!
1622
+ log.info(chalk8__default.default.gray(`A new version ${latestVersion} is available!
1568
1623
  `));
1569
1624
  else
1570
- log.info(chalk__default.default.gray("https://www.npmjs.com/package/@lambdatest/smartui-cli\n"));
1625
+ log.info(chalk8__default.default.gray("https://www.npmjs.com/package/@lambdatest/smartui-cli\n"));
1571
1626
  } catch (error) {
1572
1627
  log.debug(error);
1573
- log.info(chalk__default.default.gray("https://www.npmjs.com/package/@lambdatest/smartui-cli\n"));
1628
+ log.info(chalk8__default.default.gray("https://www.npmjs.com/package/@lambdatest/smartui-cli\n"));
1574
1629
  }
1575
1630
  commander_default.parse();
1576
1631
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambdatest/smartui-cli",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
5
5
  "files": [
6
6
  "dist/**/*"