@lambdatest/smartui-cli 3.0.8 → 3.0.10

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 +53 -20
  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 } };
966
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
+ }
989
+ }
990
+ return reply.code(replyCode).send(replyBody);
967
991
  }));
968
992
  yield server.listen({ port: 49152 });
969
993
  let { port } = server.addresses()[0];
@@ -985,7 +1009,9 @@ var env_default = () => {
985
1009
  GITHUB_ACTIONS,
986
1010
  FIGMA_TOKEN,
987
1011
  LT_USERNAME,
988
- LT_ACCESS_KEY
1012
+ LT_ACCESS_KEY,
1013
+ BASELINE_BRANCH,
1014
+ CURRENT_BRANCH
989
1015
  } = process.env;
990
1016
  return {
991
1017
  PROJECT_TOKEN,
@@ -998,7 +1024,9 @@ var env_default = () => {
998
1024
  GITHUB_ACTIONS,
999
1025
  FIGMA_TOKEN,
1000
1026
  LT_USERNAME,
1001
- LT_ACCESS_KEY
1027
+ LT_ACCESS_KEY,
1028
+ BASELINE_BRANCH,
1029
+ CURRENT_BRANCH
1002
1030
  };
1003
1031
  };
1004
1032
  var logContext = { task: "smartui-cli" };
@@ -1075,7 +1103,7 @@ var auth_default = (ctx) => {
1075
1103
  };
1076
1104
 
1077
1105
  // package.json
1078
- var version = "3.0.8";
1106
+ var version = "3.0.10";
1079
1107
  var package_default = {
1080
1108
  name: "@lambdatest/smartui-cli",
1081
1109
  version,
@@ -1351,11 +1379,12 @@ var git_default = (ctx) => {
1351
1379
  if (ctx.env.SMARTUI_GIT_INFO_FILEPATH) {
1352
1380
  let gitInfo = JSON.parse(fs5__default.default.readFileSync(ctx.env.SMARTUI_GIT_INFO_FILEPATH, "utf-8"));
1353
1381
  return {
1354
- branch: gitInfo.branch || "",
1382
+ branch: ctx.env.CURRENT_BRANCH || gitInfo.branch || "",
1355
1383
  commitId: gitInfo.commit_id.slice(0, 6) || "",
1356
1384
  commitMessage: gitInfo.commit_body || "",
1357
1385
  commitAuthor: gitInfo.commit_author || "",
1358
- githubURL: ctx.env.GITHUB_ACTIONS ? `${constants_default.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${gitInfo.commit_id}` : ""
1386
+ githubURL: ctx.env.GITHUB_ACTIONS ? `${constants_default.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${gitInfo.commit_id}` : "",
1387
+ baselineBranch: ctx.env.BASELINE_BRANCH || ""
1359
1388
  };
1360
1389
  } else {
1361
1390
  const splitCharacter = "<##>";
@@ -1363,14 +1392,15 @@ var git_default = (ctx) => {
1363
1392
  const command4 = 'git log -1 --pretty=format:"' + prettyFormat.join(splitCharacter) + '" && git rev-parse --abbrev-ref HEAD && git tag --contains HEAD';
1364
1393
  let res = executeCommand(command4).split(splitCharacter);
1365
1394
  var branchAndTags = res[res.length - 1].split("\n").filter((n) => n);
1366
- var branch = branchAndTags[0];
1395
+ var branch = ctx.env.CURRENT_BRANCH || branchAndTags[0];
1367
1396
  branchAndTags.slice(1);
1368
1397
  return {
1369
1398
  branch: branch || "",
1370
1399
  commitId: res[0] || "",
1371
1400
  commitMessage: res[2] || "",
1372
1401
  commitAuthor: res[7] || "",
1373
- githubURL: ctx.env.GITHUB_ACTIONS ? `${constants_default.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${res[1]}` : ""
1402
+ githubURL: ctx.env.GITHUB_ACTIONS ? `${constants_default.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${res[1]}` : "",
1403
+ baselineBranch: ctx.env.BASELINE_BRANCH || ""
1374
1404
  };
1375
1405
  }
1376
1406
  };
@@ -1381,6 +1411,9 @@ var getGitInfo_default = (ctx) => {
1381
1411
  return !isGitRepo() && !ctx2.env.SMARTUI_GIT_INFO_FILEPATH ? "[SKIPPED] Fetching git repo details; not a git repo" : "";
1382
1412
  },
1383
1413
  task: (ctx2, task) => __async(void 0, null, function* () {
1414
+ if (ctx2.env.CURRENT_BRANCH && ctx2.env.CURRENT_BRANCH.trim() === "") {
1415
+ throw new Error("Error: The environment variable CURRENT_BRANCH cannot be empty.");
1416
+ }
1384
1417
  try {
1385
1418
  ctx2.git = git_default(ctx2);
1386
1419
  task.output = chalk8__default.default.gray(`branch: ${ctx2.git.branch}, commit: ${ctx2.git.commitId}, author: ${ctx2.git.commitAuthor}`);
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.10",
4
4
  "description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
5
5
  "files": [
6
6
  "dist/**/*"