@lambdatest/smartui-cli 4.1.24 → 4.1.26

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 +286 -24
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -775,6 +775,10 @@ var ConfigSchema = {
775
775
  allowDuplicateSnapshotNames: {
776
776
  type: "boolean",
777
777
  errorMessage: "Invalid config; allowDuplicateSnapshotNames must be true/false"
778
+ },
779
+ useLambdaInternal: {
780
+ type: "boolean",
781
+ errorMessage: "Invalid config; useLambdaInternal must be true/false"
778
782
  }
779
783
  },
780
784
  anyOf: [
@@ -1008,6 +1012,18 @@ var SnapshotSchema = {
1008
1012
  sessionId: {
1009
1013
  type: "string",
1010
1014
  errorMessage: "Invalid snapshot options; sessionId must be a string"
1015
+ },
1016
+ contextId: {
1017
+ type: "string",
1018
+ errorMessage: "Invalid snapshot options; contextId must be a string"
1019
+ },
1020
+ sync: {
1021
+ type: "boolean",
1022
+ errorMessage: "Invalid snapshot options; sync must be a boolean"
1023
+ },
1024
+ timeout: {
1025
+ type: "number",
1026
+ errorMessage: "Invalid snapshot options; timeout must be a number"
1011
1027
  }
1012
1028
  },
1013
1029
  additionalProperties: false
@@ -1670,8 +1686,39 @@ function stopTunnelHelper(ctx) {
1670
1686
  ctx.log.debug("Tunnel is Stopped ? " + status);
1671
1687
  });
1672
1688
  }
1689
+ function calculateVariantCount(config) {
1690
+ let variantCount = 0;
1691
+ if (config.web) {
1692
+ const browsers = config.web.browsers || [];
1693
+ const viewports = config.web.viewports || [];
1694
+ variantCount += browsers.length * viewports.length;
1695
+ }
1696
+ if (config.mobile) {
1697
+ const devices = config.mobile.devices || [];
1698
+ variantCount += devices.length;
1699
+ }
1700
+ return variantCount;
1701
+ }
1702
+ function calculateVariantCountFromSnapshot(snapshot, globalConfig) {
1703
+ var _a, _b;
1704
+ let variantCount = 0;
1705
+ if ((_a = snapshot.options) == null ? void 0 : _a.web) {
1706
+ const browsers = snapshot.options.web.browsers || [];
1707
+ const viewports = snapshot.options.web.viewports || [];
1708
+ variantCount += browsers.length * viewports.length;
1709
+ }
1710
+ if ((_b = snapshot.options) == null ? void 0 : _b.mobile) {
1711
+ const devices = snapshot.options.mobile.devices || [];
1712
+ variantCount += devices.length;
1713
+ }
1714
+ if (variantCount === 0 && globalConfig) {
1715
+ variantCount = calculateVariantCount(globalConfig);
1716
+ }
1717
+ return variantCount;
1718
+ }
1673
1719
 
1674
1720
  // src/lib/server.ts
1721
+ var uploadDomToS3ViaEnv = process.env.USE_LAMBDA_INTERNAL || false;
1675
1722
  var server_default = (ctx) => __async(void 0, null, function* () {
1676
1723
  const server = fastify__default.default({
1677
1724
  logger: {
@@ -1691,7 +1738,7 @@ var server_default = (ctx) => __async(void 0, null, function* () {
1691
1738
  reply.code(200).send({ data: { dom: SMARTUI_DOM } });
1692
1739
  });
1693
1740
  server.post("/snapshot", opts, (request, reply) => __async(void 0, null, function* () {
1694
- var _a, _b, _c;
1741
+ var _a, _b, _c, _d, _e;
1695
1742
  let replyCode;
1696
1743
  let replyBody;
1697
1744
  try {
@@ -1700,8 +1747,9 @@ var server_default = (ctx) => __async(void 0, null, function* () {
1700
1747
  throw new Error(validateSnapshot.errors[0].message);
1701
1748
  const sessionId = (_a = snapshot == null ? void 0 : snapshot.options) == null ? void 0 : _a.sessionId;
1702
1749
  let capsBuildId = "";
1750
+ const contextId = (_b = snapshot == null ? void 0 : snapshot.options) == null ? void 0 : _b.contextId;
1703
1751
  if (sessionId) {
1704
- if ((_b = ctx.sessionCapabilitiesMap) == null ? void 0 : _b.has(sessionId)) {
1752
+ if ((_c = ctx.sessionCapabilitiesMap) == null ? void 0 : _c.has(sessionId)) {
1705
1753
  const cachedCapabilities = ctx.sessionCapabilitiesMap.get(sessionId);
1706
1754
  capsBuildId = (cachedCapabilities == null ? void 0 : cachedCapabilities.buildId) || "";
1707
1755
  } else {
@@ -1724,7 +1772,19 @@ var server_default = (ctx) => __async(void 0, null, function* () {
1724
1772
  }
1725
1773
  }
1726
1774
  ctx.testType = testType;
1727
- (_c = ctx.snapshotQueue) == null ? void 0 : _c.enqueue(snapshot);
1775
+ if (contextId && !ctx.contextToSnapshotMap) {
1776
+ ctx.contextToSnapshotMap = /* @__PURE__ */ new Map();
1777
+ ctx.log.debug(`Initialized empty context mapping map for contextId: ${contextId}`);
1778
+ }
1779
+ if (contextId && ctx.contextToSnapshotMap) {
1780
+ ctx.contextToSnapshotMap.set(contextId, 0);
1781
+ ctx.log.debug(`Marking contextId as captured and added to queue: ${contextId}`);
1782
+ }
1783
+ if (contextId) {
1784
+ (_d = ctx.snapshotQueue) == null ? void 0 : _d.enqueueFront(snapshot);
1785
+ } else {
1786
+ (_e = ctx.snapshotQueue) == null ? void 0 : _e.enqueue(snapshot);
1787
+ }
1728
1788
  ctx.isSnapshotCaptured = true;
1729
1789
  replyCode = 200;
1730
1790
  replyBody = { data: { message: "success", warnings: [] } };
@@ -1736,7 +1796,7 @@ var server_default = (ctx) => __async(void 0, null, function* () {
1736
1796
  return reply.code(replyCode).send(replyBody);
1737
1797
  }));
1738
1798
  server.post("/stop", opts, (_, reply) => __async(void 0, null, function* () {
1739
- var _a, _b;
1799
+ var _a, _b, _c;
1740
1800
  let replyCode;
1741
1801
  let replyBody;
1742
1802
  try {
@@ -1758,8 +1818,15 @@ var server_default = (ctx) => __async(void 0, null, function* () {
1758
1818
  if (ctx.server) {
1759
1819
  ctx.server.close();
1760
1820
  }
1761
- let resp = yield ctx.client.getS3PreSignedURL(ctx);
1762
- yield ctx.client.uploadLogs(ctx, resp.data.url);
1821
+ let uploadCLILogsToS3 = ((_c = ctx == null ? void 0 : ctx.config) == null ? void 0 : _c.useLambdaInternal) || uploadDomToS3ViaEnv;
1822
+ if (!uploadCLILogsToS3) {
1823
+ ctx.log.debug(`Log file to be uploaded`);
1824
+ let resp = yield ctx.client.getS3PreSignedURL(ctx);
1825
+ yield ctx.client.uploadLogs(ctx, resp.data.url);
1826
+ } else {
1827
+ ctx.log.debug(`Log file to be uploaded via LSRS`);
1828
+ let resp = ctx.client.sendCliLogsToLSRS(ctx);
1829
+ }
1763
1830
  if (pingIntervalId !== null) {
1764
1831
  clearInterval(pingIntervalId);
1765
1832
  ctx.log.debug("Ping polling stopped immediately.");
@@ -1777,6 +1844,93 @@ var server_default = (ctx) => __async(void 0, null, function* () {
1777
1844
  server.get("/ping", opts, (_, reply) => {
1778
1845
  reply.code(200).send({ status: "Server is running", version: ctx.cliVersion });
1779
1846
  });
1847
+ server.get("/snapshot/status", opts, (request, reply) => __async(void 0, null, function* () {
1848
+ var _a;
1849
+ let replyCode;
1850
+ let replyBody;
1851
+ try {
1852
+ ctx.log.debug(`request.query : ${JSON.stringify(request.query)}`);
1853
+ const { contextId, pollTimeout, snapshotName } = request.query;
1854
+ if (!contextId || !snapshotName) {
1855
+ throw new Error("contextId and snapshotName are required parameters");
1856
+ }
1857
+ const timeoutDuration = pollTimeout * 1e3 || 3e4;
1858
+ if ((_a = ctx.contextToSnapshotMap) == null ? void 0 : _a.has(contextId)) {
1859
+ let contextStatus = ctx.contextToSnapshotMap.get(contextId);
1860
+ while (contextStatus == 0) {
1861
+ yield new Promise((resolve) => setTimeout(resolve, 5e3));
1862
+ contextStatus = ctx.contextToSnapshotMap.get(contextId);
1863
+ }
1864
+ if (contextStatus == 2) {
1865
+ throw new Error("Snapshot Failed");
1866
+ }
1867
+ ctx.log.debug("Snapshot uploaded successfully");
1868
+ let lastExternalResponse = null;
1869
+ const startTime = Date.now();
1870
+ while (true) {
1871
+ try {
1872
+ const externalResponse = yield ctx.client.getSnapshotStatus(
1873
+ snapshotName,
1874
+ contextId,
1875
+ ctx
1876
+ );
1877
+ lastExternalResponse = externalResponse;
1878
+ if (externalResponse.statusCode === 200) {
1879
+ replyCode = 200;
1880
+ replyBody = externalResponse.data;
1881
+ return reply.code(replyCode).send(replyBody);
1882
+ } else if (externalResponse.statusCode === 202) {
1883
+ replyBody = externalResponse.data;
1884
+ ctx.log.debug(`External API attempt: Still processing, Pending Screenshots ${externalResponse.snapshotCount}`);
1885
+ yield new Promise((resolve) => setTimeout(resolve, 5e3));
1886
+ } else if (externalResponse.statusCode === 404) {
1887
+ ctx.log.debug(`Snapshot still processing, not uploaded`);
1888
+ yield new Promise((resolve) => setTimeout(resolve, 5e3));
1889
+ } else {
1890
+ ctx.log.debug(`Unexpected response from external API: ${JSON.stringify(externalResponse)}`);
1891
+ replyCode = 500;
1892
+ replyBody = {
1893
+ error: {
1894
+ message: `Unexpected response from external API: ${externalResponse.statusCode}`,
1895
+ externalApiStatus: externalResponse.statusCode
1896
+ }
1897
+ };
1898
+ return reply.code(replyCode).send(replyBody);
1899
+ }
1900
+ ctx.log.debug(`timeoutDuration: ${timeoutDuration}`);
1901
+ ctx.log.debug(`Time passed: ${Date.now() - startTime}`);
1902
+ if (Date.now() - startTime > timeoutDuration) {
1903
+ replyCode = 202;
1904
+ replyBody = {
1905
+ data: {
1906
+ message: "Request timed out-> Snapshot still processing"
1907
+ }
1908
+ };
1909
+ return reply.code(replyCode).send(replyBody);
1910
+ }
1911
+ } catch (externalApiError) {
1912
+ ctx.log.debug(`External API call failed: ${externalApiError.message}`);
1913
+ replyCode = 500;
1914
+ replyBody = {
1915
+ error: {
1916
+ message: `External API call failed: ${externalApiError.message}`
1917
+ }
1918
+ };
1919
+ return reply.code(replyCode).send(replyBody);
1920
+ }
1921
+ }
1922
+ } else {
1923
+ replyCode = 404;
1924
+ replyBody = { error: { message: `No snapshot found for contextId: ${contextId}` } };
1925
+ return reply.code(replyCode).send(replyBody);
1926
+ }
1927
+ } catch (error) {
1928
+ ctx.log.debug(`snapshot status failed; ${error}`);
1929
+ replyCode = 500;
1930
+ replyBody = { error: { message: error.message } };
1931
+ return reply.code(replyCode).send(replyBody);
1932
+ }
1933
+ }));
1780
1934
  yield server.listen({ port: ctx.options.port });
1781
1935
  let { port } = server.addresses()[0];
1782
1936
  process.env.SMARTUI_SERVER_ADDRESS = `http://localhost:${port}`;
@@ -1923,7 +2077,7 @@ var authExec_default = (ctx) => {
1923
2077
  };
1924
2078
 
1925
2079
  // package.json
1926
- var version = "4.1.24";
2080
+ var version = "4.1.26";
1927
2081
  var package_default = {
1928
2082
  name: "@lambdatest/smartui-cli",
1929
2083
  version,
@@ -2043,10 +2197,10 @@ var httpClient = class {
2043
2197
  request(config, log2) {
2044
2198
  return __async(this, null, function* () {
2045
2199
  log2.debug(`http request: ${config.method} ${config.url}`);
2046
- if (config && config.data && !config.data.name && !config.data.snapshot) {
2200
+ if (config && config.data && !config.data.skipLogging && !config.data.name && !config.data.snapshot) {
2047
2201
  log2.debug(config.data);
2048
2202
  }
2049
- if (config && config.data && config.data.snapshotUuid) {
2203
+ if (config && config.data && !config.data.skipLogging && config.data.snapshotUuid) {
2050
2204
  log2.debug(config.data);
2051
2205
  }
2052
2206
  return this.axiosInstance.request(config).then((resp) => {
@@ -2264,7 +2418,7 @@ var httpClient = class {
2264
2418
  }
2265
2419
  }, ctx.log);
2266
2420
  }
2267
- processSnapshot(ctx, snapshot, snapshotUuid, discoveryErrors) {
2421
+ processSnapshot(ctx, snapshot, snapshotUuid, discoveryErrors, variantCount, sync = false) {
2268
2422
  return this.request({
2269
2423
  url: `/build/${ctx.build.id}/snapshot`,
2270
2424
  method: "POST",
@@ -2273,12 +2427,14 @@ var httpClient = class {
2273
2427
  name: snapshot.name,
2274
2428
  url: snapshot.url,
2275
2429
  snapshotUuid,
2430
+ variantCount,
2276
2431
  test: {
2277
2432
  type: ctx.testType,
2278
2433
  source: "cli"
2279
2434
  },
2280
2435
  doRemoteDiscovery: snapshot.options.doRemoteDiscovery,
2281
- discoveryErrors
2436
+ discoveryErrors,
2437
+ sync
2282
2438
  }
2283
2439
  }, ctx.log);
2284
2440
  }
@@ -2419,6 +2575,36 @@ var httpClient = class {
2419
2575
  }
2420
2576
  }, ctx.log);
2421
2577
  }
2578
+ sendDomToLSRS(ctx, snapshot, snapshotUuid) {
2579
+ return this.request({
2580
+ url: `/upload/dom`,
2581
+ method: "POST",
2582
+ data: {
2583
+ buildId: ctx.build.id,
2584
+ snapshotName: snapshot.name,
2585
+ snapshotUuid,
2586
+ domContent: snapshot,
2587
+ skipLogging: true
2588
+ }
2589
+ }, ctx.log);
2590
+ }
2591
+ sendDomToLSRSForCaps(ctx, snapshot, snapshotUuid, capsBuildId, capsProjectToken) {
2592
+ return this.request({
2593
+ url: `/upload/dom`,
2594
+ method: "POST",
2595
+ headers: {
2596
+ "Content-Type": "application/json",
2597
+ projectToken: capsProjectToken !== "" ? capsProjectToken : this.projectToken
2598
+ },
2599
+ data: {
2600
+ buildId: capsBuildId,
2601
+ snapshotName: snapshot.name,
2602
+ snapshotUuid,
2603
+ domContent: snapshot,
2604
+ skipLogging: true
2605
+ }
2606
+ }, ctx.log);
2607
+ }
2422
2608
  uploadLogs(ctx, uploadURL) {
2423
2609
  const fileStream = fs5__default.default.createReadStream(constants_default.LOG_FILE_PATH);
2424
2610
  const { size } = fs5__default.default.statSync(constants_default.LOG_FILE_PATH);
@@ -2436,6 +2622,18 @@ var httpClient = class {
2436
2622
  // prevent axios from limiting the content size
2437
2623
  }, ctx.log);
2438
2624
  }
2625
+ sendCliLogsToLSRS(ctx) {
2626
+ const logContent = fs5__default.default.readFileSync(constants_default.LOG_FILE_PATH, "utf-8");
2627
+ return this.request({
2628
+ url: `/upload/logs`,
2629
+ method: "POST",
2630
+ data: {
2631
+ buildId: ctx.build.id,
2632
+ logContent,
2633
+ skipLogging: true
2634
+ }
2635
+ }, ctx.log);
2636
+ }
2439
2637
  uploadSnapshotToS3(ctx, uploadURL, snapshot) {
2440
2638
  return this.request({
2441
2639
  url: uploadURL,
@@ -2500,6 +2698,15 @@ var httpClient = class {
2500
2698
  data: requestData
2501
2699
  }, ctx.log);
2502
2700
  }
2701
+ getSnapshotStatus(snapshotName, snapshotUuid, ctx) {
2702
+ return this.request({
2703
+ url: `/snapshot/status?buildId=${ctx.build.id}&snapshotName=${snapshotName}&snapshotUUID=${snapshotUuid}`,
2704
+ method: "GET",
2705
+ headers: {
2706
+ "Content-Type": "application/json"
2707
+ }
2708
+ }, ctx.log);
2709
+ }
2503
2710
  };
2504
2711
  var ctx_default = (options) => {
2505
2712
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
@@ -2519,6 +2726,7 @@ var ctx_default = (options) => {
2519
2726
  let fetchResultsFileObj;
2520
2727
  let buildNameObj;
2521
2728
  let allowDuplicateSnapshotNames = false;
2729
+ let useLambdaInternal = false;
2522
2730
  try {
2523
2731
  if (options.config) {
2524
2732
  config = JSON.parse(fs5__default.default.readFileSync(options.config, "utf-8"));
@@ -2583,6 +2791,12 @@ var ctx_default = (options) => {
2583
2791
  if (config.allowDuplicateSnapshotNames) {
2584
2792
  allowDuplicateSnapshotNames = true;
2585
2793
  }
2794
+ if (config.useLambdaInternal) {
2795
+ useLambdaInternal = true;
2796
+ }
2797
+ if (config.waitForPageRender && config.waitForPageRender < 3e4) {
2798
+ config.waitForPageRender = 3e4;
2799
+ }
2586
2800
  return {
2587
2801
  env,
2588
2802
  log: logger_default,
@@ -2607,7 +2821,8 @@ var ctx_default = (options) => {
2607
2821
  tunnel: tunnelObj,
2608
2822
  userAgent: config.userAgent || "",
2609
2823
  requestHeaders: config.requestHeaders || {},
2610
- allowDuplicateSnapshotNames
2824
+ allowDuplicateSnapshotNames,
2825
+ useLambdaInternal
2611
2826
  },
2612
2827
  uploadFilePath: "",
2613
2828
  webStaticConfig: [],
@@ -2927,6 +3142,7 @@ ${snapshot.warnings.length ? chalk__default.default.gray(`[warning] ${snapshot.w
2927
3142
  rendererOptions: { persistentOutput: true }
2928
3143
  };
2929
3144
  };
3145
+ var uploadDomToS3ViaEnv2 = process.env.USE_LAMBDA_INTERNAL || false;
2930
3146
  var finalizeBuild_default = (ctx) => {
2931
3147
  return {
2932
3148
  title: `Finalizing build`,
@@ -2991,9 +3207,15 @@ var finalizeBuild_default = (ctx) => {
2991
3207
  yield (_b = ctx2.server) == null ? void 0 : _b.close();
2992
3208
  ctx2.log.debug(`Closed server`);
2993
3209
  if (ctx2.isSnapshotCaptured) {
2994
- ctx2.log.debug(`Log file to be uploaded`);
2995
- let resp = yield ctx2.client.getS3PreSignedURL(ctx2);
2996
- yield ctx2.client.uploadLogs(ctx2, resp.data.url);
3210
+ let uploadCLILogsToS3 = ctx2.config.useLambdaInternal || uploadDomToS3ViaEnv2;
3211
+ if (!uploadCLILogsToS3) {
3212
+ ctx2.log.debug(`Log file to be uploaded`);
3213
+ let resp = yield ctx2.client.getS3PreSignedURL(ctx2);
3214
+ yield ctx2.client.uploadLogs(ctx2, resp.data.url);
3215
+ } else {
3216
+ ctx2.log.debug(`Log file to be uploaded via LSRS`);
3217
+ let resp = ctx2.client.sendCliLogsToLSRS(ctx2);
3218
+ }
2997
3219
  }
2998
3220
  } catch (error) {
2999
3221
  ctx2.log.debug(error);
@@ -3657,6 +3879,7 @@ function processSnapshot(snapshot, ctx) {
3657
3879
  };
3658
3880
  });
3659
3881
  }
3882
+ var uploadDomToS3ViaEnv3 = process.env.USE_LAMBDA_INTERNAL || false;
3660
3883
  var Queue = class {
3661
3884
  constructor(ctx) {
3662
3885
  this.snapshots = [];
@@ -3676,6 +3899,15 @@ var Queue = class {
3676
3899
  }
3677
3900
  }
3678
3901
  }
3902
+ enqueueFront(item) {
3903
+ this.snapshots.unshift(item);
3904
+ if (!this.ctx.config.delayedUpload) {
3905
+ if (!this.processing) {
3906
+ this.processing = true;
3907
+ this.processNext();
3908
+ }
3909
+ }
3910
+ }
3679
3911
  startProcessingfunc() {
3680
3912
  if (!this.processing) {
3681
3913
  this.processing = true;
@@ -3869,7 +4101,7 @@ var Queue = class {
3869
4101
  }
3870
4102
  processNext() {
3871
4103
  return __async(this, null, function* () {
3872
- var _a, _b, _c, _d;
4104
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
3873
4105
  if (!this.isEmpty()) {
3874
4106
  let snapshot;
3875
4107
  if (this.ctx.config.delayedUpload) {
@@ -3925,11 +4157,19 @@ var Queue = class {
3925
4157
  discoveryErrors = result.discoveryErrors;
3926
4158
  }
3927
4159
  if (useCapsBuildId) {
4160
+ this.ctx.log.info(`Using cached buildId: ${capsBuildId}`);
3928
4161
  if (useKafkaFlowCaps) {
3929
4162
  const snapshotUuid = uuid.v4();
3930
- const presignedResponse = yield this.ctx.client.getS3PresignedURLForSnapshotUploadCaps(this.ctx, processedSnapshot.name, snapshotUuid, capsBuildId, capsProjectToken);
3931
- const uploadUrl = presignedResponse.data.url;
3932
- yield this.ctx.client.uploadSnapshotToS3Caps(this.ctx, uploadUrl, processedSnapshot, capsProjectToken);
4163
+ let uploadDomToS3 = this.ctx.config.useLambdaInternal || uploadDomToS3ViaEnv3;
4164
+ if (!uploadDomToS3) {
4165
+ this.ctx.log.debug(`Uploading dom to S3 for snapshot using presigned URL for CAPS`);
4166
+ const presignedResponse = yield this.ctx.client.getS3PresignedURLForSnapshotUploadCaps(this.ctx, processedSnapshot.name, snapshotUuid, capsBuildId, capsProjectToken);
4167
+ const uploadUrl = presignedResponse.data.url;
4168
+ yield this.ctx.client.uploadSnapshotToS3Caps(this.ctx, uploadUrl, processedSnapshot, capsProjectToken);
4169
+ } else {
4170
+ this.ctx.log.debug(`Uploading dom to S3 for snapshot using LSRS`);
4171
+ yield this.ctx.client.sendDomToLSRSForCaps(this.ctx, processedSnapshot, snapshotUuid, capsBuildId, capsProjectToken);
4172
+ }
3933
4173
  yield this.ctx.client.processSnapshotCaps(this.ctx, processedSnapshot, snapshotUuid, capsBuildId, capsProjectToken, discoveryErrors);
3934
4174
  } else {
3935
4175
  yield this.ctx.client.uploadSnapshotForCaps(this.ctx, processedSnapshot, capsBuildId, capsProjectToken, discoveryErrors);
@@ -3962,10 +4202,21 @@ var Queue = class {
3962
4202
  }
3963
4203
  }
3964
4204
  if (this.ctx.build && this.ctx.build.useKafkaFlow) {
3965
- const snapshotUuid = uuid.v4();
3966
- const presignedResponse = yield this.ctx.client.getS3PresignedURLForSnapshotUpload(this.ctx, processedSnapshot.name, snapshotUuid);
3967
- const uploadUrl = presignedResponse.data.url;
3968
- let snapshotUploadResponse = yield this.ctx.client.uploadSnapshotToS3(this.ctx, uploadUrl, processedSnapshot);
4205
+ let snapshotUuid = uuid.v4();
4206
+ let snapshotUploadResponse;
4207
+ if (((_e = snapshot == null ? void 0 : snapshot.options) == null ? void 0 : _e.contextId) && ((_f = this.ctx.contextToSnapshotMap) == null ? void 0 : _f.has(snapshot.options.contextId))) {
4208
+ snapshotUuid = snapshot.options.contextId;
4209
+ }
4210
+ let uploadDomToS3 = this.ctx.config.useLambdaInternal || uploadDomToS3ViaEnv3;
4211
+ if (!uploadDomToS3) {
4212
+ this.ctx.log.debug(`Uploading dom to S3 for snapshot using presigned URL`);
4213
+ const presignedResponse = yield this.ctx.client.getS3PresignedURLForSnapshotUpload(this.ctx, processedSnapshot.name, snapshotUuid);
4214
+ const uploadUrl = presignedResponse.data.url;
4215
+ snapshotUploadResponse = yield this.ctx.client.uploadSnapshotToS3(this.ctx, uploadUrl, processedSnapshot);
4216
+ } else {
4217
+ this.ctx.log.debug(`Uploading dom to S3 for snapshot using LSRS`);
4218
+ snapshotUploadResponse = yield this.ctx.client.sendDomToLSRS(this.ctx, processedSnapshot, snapshotUuid);
4219
+ }
3969
4220
  if (!snapshotUploadResponse || Object.keys(snapshotUploadResponse).length === 0) {
3970
4221
  this.ctx.log.debug(`snapshot failed; Unable to upload dom to S3`);
3971
4222
  this.processedSnapshots.push({ name: snapshot == null ? void 0 : snapshot.name, error: `snapshot failed; Unable to upload dom to S3` });
@@ -3979,11 +4230,19 @@ var Queue = class {
3979
4230
  this.ctx.log.debug(`Closed browser context for snapshot ${snapshot.name}`);
3980
4231
  }
3981
4232
  }
4233
+ if ((_g = snapshot == null ? void 0 : snapshot.options) == null ? void 0 : _g.contextId) {
4234
+ (_i = this.ctx.contextToSnapshotMap) == null ? void 0 : _i.set((_h = snapshot == null ? void 0 : snapshot.options) == null ? void 0 : _h.contextId, 2);
4235
+ }
3982
4236
  this.processNext();
3983
4237
  } else {
3984
- yield this.ctx.client.processSnapshot(this.ctx, processedSnapshot, snapshotUuid, discoveryErrors);
4238
+ yield this.ctx.client.processSnapshot(this.ctx, processedSnapshot, snapshotUuid, discoveryErrors, calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config), (_j = snapshot == null ? void 0 : snapshot.options) == null ? void 0 : _j.sync);
4239
+ if (((_k = snapshot == null ? void 0 : snapshot.options) == null ? void 0 : _k.contextId) && ((_l = this.ctx.contextToSnapshotMap) == null ? void 0 : _l.has(snapshot.options.contextId))) {
4240
+ this.ctx.contextToSnapshotMap.set(snapshot.options.contextId, 1);
4241
+ }
4242
+ this.ctx.log.debug(`ContextId: ${(_m = snapshot == null ? void 0 : snapshot.options) == null ? void 0 : _m.contextId} status set to uploaded`);
3985
4243
  }
3986
4244
  } else {
4245
+ this.ctx.log.info(`Uploading snapshot to S3`);
3987
4246
  yield this.ctx.client.uploadSnapshot(this.ctx, processedSnapshot, discoveryErrors);
3988
4247
  }
3989
4248
  this.ctx.totalSnapshots++;
@@ -3993,6 +4252,9 @@ var Queue = class {
3993
4252
  } catch (error) {
3994
4253
  this.ctx.log.debug(`snapshot failed; ${error}`);
3995
4254
  this.processedSnapshots.push({ name: snapshot == null ? void 0 : snapshot.name, error: error.message });
4255
+ if (((_n = snapshot == null ? void 0 : snapshot.options) == null ? void 0 : _n.contextId) && this.ctx.contextToSnapshotMap) {
4256
+ this.ctx.contextToSnapshotMap.set(snapshot.options.contextId, 2);
4257
+ }
3996
4258
  }
3997
4259
  if (this.ctx.browser) {
3998
4260
  for (let context of this.ctx.browser.contexts()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambdatest/smartui-cli",
3
- "version": "4.1.24",
3
+ "version": "4.1.26",
4
4
  "description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
5
5
  "files": [
6
6
  "dist/**/*"