@lambdatest/smartui-cli 3.0.4 → 3.0.6
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.
- package/dist/index.cjs +60 -38
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7,7 +7,7 @@ var listr2 = require('listr2');
|
|
|
7
7
|
var chalk8 = require('chalk');
|
|
8
8
|
var path2 = require('path');
|
|
9
9
|
var fastify = require('fastify');
|
|
10
|
-
var
|
|
10
|
+
var fs5 = require('fs');
|
|
11
11
|
var test = require('@playwright/test');
|
|
12
12
|
var Ajv = require('ajv');
|
|
13
13
|
var addErrors = require('ajv-errors');
|
|
@@ -23,7 +23,7 @@ var which__default = /*#__PURE__*/_interopDefault(which);
|
|
|
23
23
|
var chalk8__default = /*#__PURE__*/_interopDefault(chalk8);
|
|
24
24
|
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
25
25
|
var fastify__default = /*#__PURE__*/_interopDefault(fastify);
|
|
26
|
-
var
|
|
26
|
+
var fs5__default = /*#__PURE__*/_interopDefault(fs5);
|
|
27
27
|
var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
28
28
|
var addErrors__default = /*#__PURE__*/_interopDefault(addErrors);
|
|
29
29
|
var FormData__default = /*#__PURE__*/_interopDefault(FormData);
|
|
@@ -304,8 +304,8 @@ var constants_default = {
|
|
|
304
304
|
|
|
305
305
|
// src/lib/utils.ts
|
|
306
306
|
function delDir(dir) {
|
|
307
|
-
if (
|
|
308
|
-
|
|
307
|
+
if (fs5__default.default.existsSync(dir)) {
|
|
308
|
+
fs5__default.default.rmSync(dir, { recursive: true });
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
311
|
function scrollToBottomAndBackToTop({
|
|
@@ -417,15 +417,20 @@ function getRenderViewports(ctx) {
|
|
|
417
417
|
...mobileRenderViewports[constants_default.MOBILE_OS_ANDROID]
|
|
418
418
|
];
|
|
419
419
|
}
|
|
420
|
-
var MAX_RESOURCE_SIZE =
|
|
420
|
+
var MAX_RESOURCE_SIZE = 10 * 1024 ** 2;
|
|
421
421
|
var ALLOWED_RESOURCES = ["document", "stylesheet", "image", "media", "font", "other"];
|
|
422
422
|
var ALLOWED_STATUSES = [200, 201];
|
|
423
423
|
var REQUEST_TIMEOUT = 1e4;
|
|
424
424
|
var MIN_VIEWPORT_HEIGHT = 1080;
|
|
425
425
|
var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function* () {
|
|
426
426
|
ctx.log.debug(`Processing snapshot ${snapshot.name}`);
|
|
427
|
-
if (!ctx.browser)
|
|
428
|
-
|
|
427
|
+
if (!ctx.browser) {
|
|
428
|
+
let launchOptions = { headless: true };
|
|
429
|
+
if (ctx.env.HTTP_PROXY || ctx.env.HTTPS_PROXY)
|
|
430
|
+
launchOptions.proxy = { server: ctx.env.HTTP_PROXY || ctx.env.HTTPS_PROXY };
|
|
431
|
+
ctx.browser = yield test.chromium.launch(launchOptions);
|
|
432
|
+
ctx.log.debug(`Chromium launched with options ${JSON.stringify(launchOptions)}`);
|
|
433
|
+
}
|
|
429
434
|
const context = yield ctx.browser.newContext({ userAgent: constants_default.CHROME_USER_AGENT });
|
|
430
435
|
const page = yield context.newPage();
|
|
431
436
|
let cache = {};
|
|
@@ -878,9 +883,9 @@ var validateSnapshot = ajv.compile(SnapshotSchema);
|
|
|
878
883
|
|
|
879
884
|
// src/lib/server.ts
|
|
880
885
|
var server_default = (ctx) => __async(void 0, null, function* () {
|
|
881
|
-
const server = fastify__default.default({ logger: false, bodyLimit: 1e7 });
|
|
886
|
+
const server = fastify__default.default({ logger: ctx.env.LT_SDK_DEBUG ? true : false, bodyLimit: 1e7 });
|
|
882
887
|
const opts = {};
|
|
883
|
-
const SMARTUI_DOM =
|
|
888
|
+
const SMARTUI_DOM = fs5.readFileSync(path2__default.default.resolve(__dirname, "dom-serializer.js"), "utf-8");
|
|
884
889
|
server.get("/healthcheck", opts, (_, reply) => {
|
|
885
890
|
reply.code(200).send({ cliVersion: ctx.cliVersion });
|
|
886
891
|
});
|
|
@@ -900,7 +905,7 @@ var server_default = (ctx) => __async(void 0, null, function* () {
|
|
|
900
905
|
return reply.code(500).send({ error: { message: error.message } });
|
|
901
906
|
}
|
|
902
907
|
}));
|
|
903
|
-
yield server.listen();
|
|
908
|
+
yield server.listen({ port: 49152 });
|
|
904
909
|
let { port } = server.addresses()[0];
|
|
905
910
|
process.env.SMARTUI_SERVER_ADDRESS = `http://localhost:${port}`;
|
|
906
911
|
process.env.CYPRESS_SMARTUI_SERVER_ADDRESS = `http://localhost:${port}`;
|
|
@@ -914,6 +919,9 @@ var env_default = () => {
|
|
|
914
919
|
SMARTUI_CLIENT_API_URL = "https://api.lambdatest.com/visualui/1.0",
|
|
915
920
|
LT_SDK_LOG_LEVEL,
|
|
916
921
|
LT_SDK_DEBUG,
|
|
922
|
+
SMARTUI_GIT_INFO_FILEPATH,
|
|
923
|
+
HTTP_PROXY,
|
|
924
|
+
HTTPS_PROXY,
|
|
917
925
|
GITHUB_ACTIONS
|
|
918
926
|
} = process.env;
|
|
919
927
|
return {
|
|
@@ -921,6 +929,9 @@ var env_default = () => {
|
|
|
921
929
|
SMARTUI_CLIENT_API_URL,
|
|
922
930
|
LT_SDK_LOG_LEVEL,
|
|
923
931
|
LT_SDK_DEBUG,
|
|
932
|
+
SMARTUI_GIT_INFO_FILEPATH,
|
|
933
|
+
HTTP_PROXY,
|
|
934
|
+
HTTPS_PROXY,
|
|
924
935
|
GITHUB_ACTIONS
|
|
925
936
|
};
|
|
926
937
|
};
|
|
@@ -954,7 +965,7 @@ var logger = winston.createLogger({
|
|
|
954
965
|
return info.level === "info" ? message : `[${contextString}:${info.level}] ` + message;
|
|
955
966
|
})
|
|
956
967
|
),
|
|
957
|
-
transports: [new winston.transports.Console()]
|
|
968
|
+
transports: [new winston.transports.Console(), new winston.transports.File({ filename: ".smartui.log" })]
|
|
958
969
|
});
|
|
959
970
|
var logger_default = logger;
|
|
960
971
|
|
|
@@ -998,7 +1009,7 @@ var auth_default = (ctx) => {
|
|
|
998
1009
|
};
|
|
999
1010
|
|
|
1000
1011
|
// package.json
|
|
1001
|
-
var version = "3.0.
|
|
1012
|
+
var version = "3.0.6";
|
|
1002
1013
|
var package_default = {
|
|
1003
1014
|
name: "@lambdatest/smartui-cli",
|
|
1004
1015
|
version,
|
|
@@ -1071,7 +1082,7 @@ var httpClient = class {
|
|
|
1071
1082
|
headers: error.response.headers,
|
|
1072
1083
|
body: error.response.data
|
|
1073
1084
|
})}`);
|
|
1074
|
-
throw new Error((_a = error.response.data.error) == null ? void 0 : _a.message);
|
|
1085
|
+
throw new Error(((_a = error.response.data.error) == null ? void 0 : _a.message) || error.response.data.message);
|
|
1075
1086
|
}
|
|
1076
1087
|
if (error.request) {
|
|
1077
1088
|
log.debug(`http request failed: ${error.toJSON()}`);
|
|
@@ -1124,7 +1135,7 @@ var httpClient = class {
|
|
|
1124
1135
|
}
|
|
1125
1136
|
uploadScreenshot({ id: buildId, name: buildName, baseline }, ssPath, ssName, browserName, viewport, log) {
|
|
1126
1137
|
browserName = browserName === constants_default.SAFARI ? constants_default.WEBKIT : browserName;
|
|
1127
|
-
const file =
|
|
1138
|
+
const file = fs5__default.default.readFileSync(ssPath);
|
|
1128
1139
|
const form = new FormData__default.default();
|
|
1129
1140
|
form.append("screenshot", file, { filename: `${ssName}.png`, contentType: "image/png" });
|
|
1130
1141
|
form.append("browser", browserName);
|
|
@@ -1170,7 +1181,7 @@ var ctx_default = (options) => {
|
|
|
1170
1181
|
let config = constants_default.DEFAULT_CONFIG;
|
|
1171
1182
|
try {
|
|
1172
1183
|
if (options.config) {
|
|
1173
|
-
config = JSON.parse(
|
|
1184
|
+
config = JSON.parse(fs5__default.default.readFileSync(options.config, "utf-8"));
|
|
1174
1185
|
if ((_a = config.web) == null ? void 0 : _a.resolutions) {
|
|
1175
1186
|
config.web.viewports = config.web.resolutions;
|
|
1176
1187
|
delete config.web.resolutions;
|
|
@@ -1250,26 +1261,37 @@ function isGitRepo() {
|
|
|
1250
1261
|
}
|
|
1251
1262
|
}
|
|
1252
1263
|
var git_default = (ctx) => {
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1264
|
+
if (ctx.env.SMARTUI_GIT_INFO_FILEPATH) {
|
|
1265
|
+
let gitInfo = JSON.parse(fs5__default.default.readFileSync(ctx.env.SMARTUI_GIT_INFO_FILEPATH, "utf-8"));
|
|
1266
|
+
return {
|
|
1267
|
+
branch: gitInfo.branch || "",
|
|
1268
|
+
commitId: gitInfo.commit_id.slice(0, 6) || "",
|
|
1269
|
+
commitMessage: gitInfo.commit_body || "",
|
|
1270
|
+
commitAuthor: gitInfo.commit_author || "",
|
|
1271
|
+
githubURL: ctx.env.GITHUB_ACTIONS ? `${constants_default.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${gitInfo.commit_id}` : ""
|
|
1272
|
+
};
|
|
1273
|
+
} else {
|
|
1274
|
+
const splitCharacter = "<##>";
|
|
1275
|
+
const prettyFormat = ["%h", "%H", "%s", "%f", "%b", "%at", "%ct", "%an", "%ae", "%cn", "%ce", "%N", ""];
|
|
1276
|
+
const command3 = 'git log -1 --pretty=format:"' + prettyFormat.join(splitCharacter) + '" && git rev-parse --abbrev-ref HEAD && git tag --contains HEAD';
|
|
1277
|
+
let res = executeCommand(command3).split(splitCharacter);
|
|
1278
|
+
var branchAndTags = res[res.length - 1].split("\n").filter((n) => n);
|
|
1279
|
+
var branch = branchAndTags[0];
|
|
1280
|
+
branchAndTags.slice(1);
|
|
1281
|
+
return {
|
|
1282
|
+
branch: branch || "",
|
|
1283
|
+
commitId: res[0] || "",
|
|
1284
|
+
commitMessage: res[2] || "",
|
|
1285
|
+
commitAuthor: res[7] || "",
|
|
1286
|
+
githubURL: ctx.env.GITHUB_ACTIONS ? `${constants_default.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${res[1]}` : ""
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1267
1289
|
};
|
|
1268
1290
|
var getGitInfo_default = (ctx) => {
|
|
1269
1291
|
return {
|
|
1270
1292
|
title: `Fetching git repo details`,
|
|
1271
1293
|
skip: (ctx2) => {
|
|
1272
|
-
return !isGitRepo() ? "[SKIPPED] Fetching git repo details; not a git repo" : "";
|
|
1294
|
+
return !isGitRepo() && !ctx2.env.SMARTUI_GIT_INFO_FILEPATH ? "[SKIPPED] Fetching git repo details; not a git repo" : "";
|
|
1273
1295
|
},
|
|
1274
1296
|
task: (ctx2, task) => __async(void 0, null, function* () {
|
|
1275
1297
|
try {
|
|
@@ -1415,13 +1437,13 @@ function createConfig(filepath) {
|
|
|
1415
1437
|
console.log("Error: Config file must have .json extension");
|
|
1416
1438
|
return;
|
|
1417
1439
|
}
|
|
1418
|
-
if (
|
|
1440
|
+
if (fs5__default.default.existsSync(filepath)) {
|
|
1419
1441
|
console.log(`Error: SmartUI Config already exists: ${filepath}`);
|
|
1420
1442
|
console.log(`To create a new file, please specify the file name like: 'smartui config:create .smartui-config.json'`);
|
|
1421
1443
|
return;
|
|
1422
1444
|
}
|
|
1423
|
-
|
|
1424
|
-
|
|
1445
|
+
fs5__default.default.mkdirSync(path2__default.default.dirname(filepath), { recursive: true });
|
|
1446
|
+
fs5__default.default.writeFileSync(filepath, JSON.stringify(constants_default.DEFAULT_CONFIG, null, 2) + "\n");
|
|
1425
1447
|
console.log(`Created SmartUI Config: ${filepath}`);
|
|
1426
1448
|
}
|
|
1427
1449
|
function createWebStaticConfig(filepath) {
|
|
@@ -1431,13 +1453,13 @@ function createWebStaticConfig(filepath) {
|
|
|
1431
1453
|
console.log("Error: Config file must have .json extension");
|
|
1432
1454
|
return;
|
|
1433
1455
|
}
|
|
1434
|
-
if (
|
|
1456
|
+
if (fs5__default.default.existsSync(filepath)) {
|
|
1435
1457
|
console.log(`Error: web-static config already exists: ${filepath}`);
|
|
1436
1458
|
console.log(`To create a new file, please specify the file name like: 'smartui config:create-web-static links.json'`);
|
|
1437
1459
|
return;
|
|
1438
1460
|
}
|
|
1439
|
-
|
|
1440
|
-
|
|
1461
|
+
fs5__default.default.mkdirSync(path2__default.default.dirname(filepath), { recursive: true });
|
|
1462
|
+
fs5__default.default.writeFileSync(filepath, JSON.stringify(constants_default.DEFAULT_WEB_STATIC_CONFIG, null, 2) + "\n");
|
|
1441
1463
|
console.log(`Created web-static config: ${filepath}`);
|
|
1442
1464
|
}
|
|
1443
1465
|
|
|
@@ -1595,12 +1617,12 @@ var command2 = new commander.Command();
|
|
|
1595
1617
|
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) {
|
|
1596
1618
|
return __async(this, null, function* () {
|
|
1597
1619
|
let ctx = ctx_default(command3.optsWithGlobals());
|
|
1598
|
-
if (!
|
|
1620
|
+
if (!fs5__default.default.existsSync(file)) {
|
|
1599
1621
|
console.log(`Error: Web Static Config file ${file} not found.`);
|
|
1600
1622
|
return;
|
|
1601
1623
|
}
|
|
1602
1624
|
try {
|
|
1603
|
-
ctx.webStaticConfig = JSON.parse(
|
|
1625
|
+
ctx.webStaticConfig = JSON.parse(fs5__default.default.readFileSync(file, "utf8"));
|
|
1604
1626
|
if (!validateWebStaticConfig(ctx.webStaticConfig))
|
|
1605
1627
|
throw new Error(validateWebStaticConfig.errors[0].message);
|
|
1606
1628
|
} catch (error) {
|