@lambdatest/smartui-cli 3.0.8 → 3.0.9

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 +38 -14
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -437,14 +437,19 @@ var REQUEST_TIMEOUT = 1e4;
437
437
  var MIN_VIEWPORT_HEIGHT = 1080;
438
438
  var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function* () {
439
439
  ctx.log.debug(`Processing snapshot ${snapshot.name}`);
440
+ let launchOptions = { headless: true };
441
+ let contextOptions = {
442
+ javaScriptEnabled: ctx.config.enableJavaScript,
443
+ userAgent: constants_default.CHROME_USER_AGENT
444
+ };
440
445
  if (!ctx.browser) {
441
- let launchOptions = { headless: true };
442
446
  if (ctx.env.HTTP_PROXY || ctx.env.HTTPS_PROXY)
443
447
  launchOptions.proxy = { server: ctx.env.HTTP_PROXY || ctx.env.HTTPS_PROXY };
444
448
  ctx.browser = yield test.chromium.launch(launchOptions);
445
449
  ctx.log.debug(`Chromium launched with options ${JSON.stringify(launchOptions)}`);
446
450
  }
447
- const context = yield ctx.browser.newContext({ userAgent: constants_default.CHROME_USER_AGENT });
451
+ const context = yield ctx.browser.newContext(contextOptions);
452
+ ctx.log.debug(`Browser context created with options ${JSON.stringify(contextOptions)}`);
448
453
  const page = yield context.newPage();
449
454
  let cache = {};
450
455
  yield page.route("**/*", (route, request) => __async(void 0, null, function* () {
@@ -560,14 +565,19 @@ var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function*
560
565
  yield page.setViewportSize({ width: viewport.width, height: viewport.height || MIN_VIEWPORT_HEIGHT });
561
566
  ctx.log.debug(`Page resized to ${viewport.width}x${viewport.height || MIN_VIEWPORT_HEIGHT}`);
562
567
  if (!navigated) {
563
- yield page.goto(snapshot.url, { waitUntil: "domcontentloaded" });
564
- yield new Promise((r) => setTimeout(r, 1250));
565
- if (ctx.config.waitForTimeout)
566
- yield page.waitForTimeout(ctx.config.waitForTimeout);
567
- navigated = true;
568
- ctx.log.debug(`Navigated to ${snapshot.url}`);
568
+ try {
569
+ yield page.goto(snapshot.url, { waitUntil: "domcontentloaded" });
570
+ yield new Promise((r) => setTimeout(r, 1250));
571
+ if (ctx.config.waitForTimeout)
572
+ yield page.waitForTimeout(ctx.config.waitForTimeout);
573
+ navigated = true;
574
+ ctx.log.debug(`Navigated to ${snapshot.url}`);
575
+ } catch (error) {
576
+ ctx.log.debug(`Navigation to discovery page failed; ${error}`);
577
+ throw new Error(error.message);
578
+ }
569
579
  }
570
- if (fullPage)
580
+ if (ctx.config.enableJavaScript && fullPage)
571
581
  yield page.evaluate(scrollToBottomAndBackToTop);
572
582
  try {
573
583
  yield page.waitForLoadState("networkidle", { timeout: 5e3 });
@@ -606,8 +616,6 @@ var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function*
606
616
  }
607
617
  }
608
618
  }
609
- yield page.close();
610
- yield context.close();
611
619
  if (snapshot.dom.resources.length) {
612
620
  for (let resource of snapshot.dom.resources) {
613
621
  cache[resource.url] = {
@@ -953,6 +961,8 @@ var server_default = (ctx) => __async(void 0, null, function* () {
953
961
  reply.code(200).send({ data: { dom: SMARTUI_DOM } });
954
962
  });
955
963
  server.post("/snapshot", opts, (request, reply) => __async(void 0, null, function* () {
964
+ let replyCode;
965
+ let replyBody;
956
966
  try {
957
967
  let { snapshot, testType } = request.body;
958
968
  if (!validateSnapshot(snapshot))
@@ -960,10 +970,24 @@ var server_default = (ctx) => __async(void 0, null, function* () {
960
970
  let { processedSnapshot, warnings } = yield processSnapshot_default(snapshot, ctx);
961
971
  yield ctx.client.uploadSnapshot(ctx.build.id, processedSnapshot, testType, ctx.log);
962
972
  ctx.totalSnapshots++;
963
- reply.code(200).send({ data: { message: "success", warnings } });
973
+ replyCode = 200;
974
+ replyBody = { data: { message: "success", warnings } };
964
975
  } catch (error) {
965
- return reply.code(500).send({ error: { message: error.message } });
976
+ ctx.log.debug(`snapshot failed; ${error}`);
977
+ replyCode = 500;
978
+ replyBody = { error: { message: error.message } };
979
+ }
980
+ if (ctx.browser) {
981
+ for (let context of ctx.browser.contexts()) {
982
+ for (let page of context.pages()) {
983
+ yield page.close();
984
+ ctx.log.debug(`Closed browser page`);
985
+ }
986
+ yield context.close();
987
+ ctx.log.debug(`Closed browser context`);
988
+ }
966
989
  }
990
+ return reply.code(replyCode).send(replyBody);
967
991
  }));
968
992
  yield server.listen({ port: 49152 });
969
993
  let { port } = server.addresses()[0];
@@ -1075,7 +1099,7 @@ var auth_default = (ctx) => {
1075
1099
  };
1076
1100
 
1077
1101
  // package.json
1078
- var version = "3.0.8";
1102
+ var version = "3.0.9";
1079
1103
  var package_default = {
1080
1104
  name: "@lambdatest/smartui-cli",
1081
1105
  version,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambdatest/smartui-cli",
3
- "version": "3.0.8",
3
+ "version": "3.0.9",
4
4
  "description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
5
5
  "files": [
6
6
  "dist/**/*"