@lambdatest/smartui-cli 4.0.2 → 4.0.4

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 +52 -43
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -822,7 +822,7 @@ var auth_default = (ctx) => {
822
822
  };
823
823
 
824
824
  // package.json
825
- var version = "4.0.2";
825
+ var version = "4.0.4";
826
826
  var package_default = {
827
827
  name: "@lambdatest/smartui-cli",
828
828
  version,
@@ -1512,7 +1512,7 @@ function processSnapshot(snapshot, ctx) {
1512
1512
  return __async(this, null, function* () {
1513
1513
  var _a;
1514
1514
  updateLogContext({ task: "discovery" });
1515
- ctx.log.debug(`Processing snapshot ${snapshot.name}`);
1515
+ ctx.log.debug(`Processing snapshot ${snapshot.name} ${snapshot.url}`);
1516
1516
  let launchOptions = { headless: true };
1517
1517
  let contextOptions = {
1518
1518
  javaScriptEnabled: ctx.config.cliEnableJavaScript,
@@ -1526,32 +1526,43 @@ function processSnapshot(snapshot, ctx) {
1526
1526
  }
1527
1527
  const context = yield ctx.browser.newContext(contextOptions);
1528
1528
  ctx.log.debug(`Browser context created with options ${JSON.stringify(contextOptions)}`);
1529
- const domainName = new URL(snapshot.url).hostname;
1530
- ctx.log.debug("Setting cookies in context for domain:", domainName);
1531
- const cookieArray = snapshot.dom.cookies.split("; ").map((cookie) => {
1532
- if (!cookie)
1533
- return null;
1534
- const [name, value] = cookie.split("=");
1535
- if (!name || !value)
1536
- return null;
1537
- return {
1538
- name: name.trim(),
1539
- value: value.trim(),
1540
- domain: domainName,
1541
- path: "/"
1542
- };
1543
- }).filter(Boolean);
1544
- if (cookieArray && Array.isArray(cookieArray) && cookieArray.length > 0) {
1545
- yield context.addCookies(cookieArray);
1546
- ctx.log.debug("Cookies added");
1547
- } else {
1548
- ctx.log.debug("No valid cookies to add");
1529
+ if (snapshot.dom.cookies) {
1530
+ const domainName = new URL(snapshot.url).hostname;
1531
+ ctx.log.debug(`Setting cookies for domain: ${domainName}`);
1532
+ const cookieArray = snapshot.dom.cookies.split("; ").map((cookie) => {
1533
+ if (!cookie)
1534
+ return null;
1535
+ const [name, value] = cookie.split("=");
1536
+ if (!name || !value)
1537
+ return null;
1538
+ return {
1539
+ name: name.trim(),
1540
+ value: value.trim(),
1541
+ domain: domainName,
1542
+ path: "/"
1543
+ };
1544
+ }).filter(Boolean);
1545
+ if (cookieArray.length > 0) {
1546
+ yield context.addCookies(cookieArray);
1547
+ } else {
1548
+ ctx.log.debug("No valid cookies to add");
1549
+ }
1549
1550
  }
1550
1551
  const page = yield context.newPage();
1551
1552
  let cache = {};
1553
+ if (snapshot.dom.resources.length) {
1554
+ for (let resource of snapshot.dom.resources) {
1555
+ let body = resource.mimetype == "text/css" ? Buffer.from(resource.content).toString("base64") : resource.content;
1556
+ cache[resource.url] = {
1557
+ body,
1558
+ type: resource.mimetype
1559
+ };
1560
+ }
1561
+ }
1552
1562
  yield page.route("**/*", (route, request) => __async(this, null, function* () {
1553
1563
  const requestUrl = request.url();
1554
1564
  const requestHostname = new URL(requestUrl).hostname;
1565
+ let requestOptions = { timeout: REQUEST_TIMEOUT };
1555
1566
  try {
1556
1567
  if (/\.(mp3|mp4|wav|ogg|webm)$/i.test(request.url())) {
1557
1568
  throw new Error("resource type mp3/mp4/wav/ogg/webm");
@@ -1559,18 +1570,30 @@ function processSnapshot(snapshot, ctx) {
1559
1570
  ctx.config.allowedHostnames.push(new URL(snapshot.url).hostname);
1560
1571
  if (ctx.config.enableJavaScript)
1561
1572
  ALLOWED_RESOURCES.push("script");
1562
- let requestOptions = {
1563
- timeout: REQUEST_TIMEOUT
1564
- };
1565
- if (requestUrl === snapshot.url && ctx.config.basicAuthorization) {
1573
+ if (ctx.config.basicAuthorization) {
1566
1574
  ctx.log.debug(`Adding basic authorization to the headers for root url`);
1567
1575
  let token = Buffer.from(`${ctx.config.basicAuthorization.username}:${ctx.config.basicAuthorization.password}`).toString("base64");
1568
1576
  requestOptions.headers = __spreadProps(__spreadValues({}, request.headers()), {
1569
1577
  Authorization: `Basic ${token}`
1570
1578
  });
1571
1579
  }
1572
- const response = yield page.request.fetch(request, { timeout: REQUEST_TIMEOUT });
1573
- const body = yield response.body();
1580
+ let response, body;
1581
+ if (requestUrl === snapshot.url) {
1582
+ response = {
1583
+ status: () => 200,
1584
+ headers: () => ({ "content-type": "text/html" })
1585
+ };
1586
+ body = snapshot.dom.html;
1587
+ } else if (cache[requestUrl]) {
1588
+ response = {
1589
+ status: () => 200,
1590
+ headers: () => ({ "content-type": cache[requestUrl].mimetype })
1591
+ };
1592
+ body = cache[requestUrl].body;
1593
+ } else {
1594
+ response = yield page.request.fetch(request, requestOptions);
1595
+ body = yield response.body();
1596
+ }
1574
1597
  if (!body) {
1575
1598
  ctx.log.debug(`Handling request ${requestUrl}
1576
1599
  - skipping no response`);
@@ -1697,7 +1720,6 @@ function processSnapshot(snapshot, ctx) {
1697
1720
  } catch (error) {
1698
1721
  ctx.log.debug(`Network idle failed due to ${error}`);
1699
1722
  }
1700
- yield new Promise((r) => setTimeout(r, 1e3));
1701
1723
  if (processedOptions.element) {
1702
1724
  let l = yield page.locator(processedOptions.element).all();
1703
1725
  if (l.length === 0) {
@@ -1729,15 +1751,6 @@ function processSnapshot(snapshot, ctx) {
1729
1751
  }
1730
1752
  }
1731
1753
  }
1732
- if (snapshot.dom.resources.length) {
1733
- for (let resource of snapshot.dom.resources) {
1734
- let body = resource.mimetype == "text/css" ? Buffer.from(resource.content).toString("base64") : resource.content;
1735
- cache[resource.url] = {
1736
- body,
1737
- type: resource.mimetype
1738
- };
1739
- }
1740
- }
1741
1754
  return {
1742
1755
  processedSnapshot: {
1743
1756
  name: snapshot.name,
@@ -2311,18 +2324,14 @@ var commander_default = program;
2311
2324
  let client = new httpClient(env_default());
2312
2325
  let log2 = logger_default;
2313
2326
  try {
2314
- let { data: { latestVersion, deprecated, additionalDescription, additionalDescriptionLatestVersion } } = yield client.checkUpdate(log2);
2327
+ let { data: { latestVersion, deprecated, additionalDescription } } = yield client.checkUpdate(log2);
2315
2328
  log2.info(`
2316
2329
  LambdaTest SmartUI CLI v${package_default.version}`);
2317
2330
  log2.info(chalk7__default.default.yellow(`${additionalDescription}`));
2318
2331
  if (deprecated) {
2319
2332
  log2.warn(`This version is deprecated. A new version ${latestVersion} is available!`);
2320
- log2.warn(`${additionalDescriptionLatestVersion}
2321
- `);
2322
2333
  } else if (package_default.version !== latestVersion) {
2323
2334
  log2.info(chalk7__default.default.green(`A new version ${latestVersion} is available!`));
2324
- log2.info(chalk7__default.default.red(`${additionalDescriptionLatestVersion}
2325
- `));
2326
2335
  } else
2327
2336
  log2.info(chalk7__default.default.gray("https://www.npmjs.com/package/@lambdatest/smartui-cli\n"));
2328
2337
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambdatest/smartui-cli",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
5
5
  "files": [
6
6
  "dist/**/*"