@lambdatest/smartui-cli 2.0.5 → 2.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 +124 -34
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -69,7 +69,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
69
69
|
var MIN_VIEWPORT_HEIGHT = 1080;
|
|
70
70
|
var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function* () {
|
|
71
71
|
let options = snapshot.options;
|
|
72
|
-
let
|
|
72
|
+
let optionWarnings = /* @__PURE__ */ new Set();
|
|
73
73
|
let processedOptions = {};
|
|
74
74
|
if (options && Object.keys(options).length !== 0) {
|
|
75
75
|
ctx.log.debug(`Processing options: ${JSON.stringify(options)}`);
|
|
@@ -115,7 +115,7 @@ var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function*
|
|
|
115
115
|
for (const selector of selectors) {
|
|
116
116
|
let l = yield page.locator(selector).all();
|
|
117
117
|
if (l.length === 0) {
|
|
118
|
-
|
|
118
|
+
optionWarnings.add(`For snapshot ${snapshot.name}, no element found for selector ${selector}`);
|
|
119
119
|
continue;
|
|
120
120
|
}
|
|
121
121
|
locators.push(...l);
|
|
@@ -135,7 +135,6 @@ var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function*
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
warnings.push(...snapshot.dom.warnings);
|
|
139
138
|
return {
|
|
140
139
|
processedSnapshot: {
|
|
141
140
|
name: snapshot.name,
|
|
@@ -143,7 +142,7 @@ var processSnapshot_default = (snapshot, ctx) => __async(void 0, null, function*
|
|
|
143
142
|
dom: Buffer.from(snapshot.dom.html).toString("base64"),
|
|
144
143
|
options: processedOptions
|
|
145
144
|
},
|
|
146
|
-
warnings
|
|
145
|
+
warnings: [...optionWarnings, ...snapshot.dom.warnings]
|
|
147
146
|
};
|
|
148
147
|
});
|
|
149
148
|
var ajv = new Ajv__default.default({ allErrors: true });
|
|
@@ -322,7 +321,7 @@ var SnapshotSchema = {
|
|
|
322
321
|
additionalProperties: false
|
|
323
322
|
}
|
|
324
323
|
},
|
|
325
|
-
required: ["name", "url", "dom"
|
|
324
|
+
required: ["name", "url", "dom"],
|
|
326
325
|
additionalProperties: false,
|
|
327
326
|
errorMessage: "Invalid snapshot"
|
|
328
327
|
};
|
|
@@ -354,7 +353,7 @@ var server_default = (ctx) => __async(void 0, null, function* () {
|
|
|
354
353
|
return reply.code(500).send({ error: { message: error.message } });
|
|
355
354
|
}
|
|
356
355
|
}));
|
|
357
|
-
yield server.listen(
|
|
356
|
+
yield server.listen();
|
|
358
357
|
let { port } = server.addresses()[0];
|
|
359
358
|
process.env.SMARTUI_SERVER_ADDRESS = `http://localhost:${port}`;
|
|
360
359
|
return server;
|
|
@@ -365,42 +364,47 @@ var env_default = () => {
|
|
|
365
364
|
const {
|
|
366
365
|
PROJECT_TOKEN = "",
|
|
367
366
|
SMARTUI_CLIENT_API_URL = "https://api.lambdatest.com/visualui/1.0",
|
|
368
|
-
|
|
369
|
-
|
|
367
|
+
LT_SDK_LOG_LEVEL,
|
|
368
|
+
LT_SDK_DEBUG
|
|
370
369
|
} = process.env;
|
|
371
370
|
return {
|
|
372
371
|
PROJECT_TOKEN,
|
|
373
372
|
SMARTUI_CLIENT_API_URL,
|
|
374
|
-
|
|
375
|
-
|
|
373
|
+
LT_SDK_LOG_LEVEL,
|
|
374
|
+
LT_SDK_DEBUG
|
|
376
375
|
};
|
|
377
376
|
};
|
|
378
|
-
|
|
379
|
-
// src/lib/logger.ts
|
|
380
|
-
var logContext = {};
|
|
377
|
+
var logContext = { task: "smartui-cli" };
|
|
381
378
|
function updateLogContext(newContext) {
|
|
382
379
|
logContext = __spreadValues(__spreadValues({}, logContext), newContext);
|
|
383
380
|
}
|
|
384
381
|
var logLevel = () => {
|
|
385
382
|
let env = env_default();
|
|
386
|
-
let debug = env.
|
|
387
|
-
return debug || env.
|
|
383
|
+
let debug = env.LT_SDK_DEBUG === "true" ? "debug" : void 0;
|
|
384
|
+
return debug || env.LT_SDK_LOG_LEVEL || "info";
|
|
388
385
|
};
|
|
389
386
|
var logger = winston.createLogger({
|
|
390
387
|
level: logLevel(),
|
|
391
388
|
format: winston.format.combine(
|
|
392
389
|
winston.format.timestamp(),
|
|
393
390
|
winston.format.printf((info) => {
|
|
394
|
-
let contextString;
|
|
395
|
-
|
|
396
|
-
|
|
391
|
+
let contextString = Object.values(logContext).join(" | ");
|
|
392
|
+
let message = typeof info.message === "object" ? JSON.stringify(info.message) : info.message;
|
|
393
|
+
switch (info.level) {
|
|
394
|
+
case "debug":
|
|
395
|
+
message = chalk__default.default.blue(message);
|
|
396
|
+
break;
|
|
397
|
+
case "warn":
|
|
398
|
+
message = chalk__default.default.yellow(message);
|
|
399
|
+
break;
|
|
400
|
+
case "error":
|
|
401
|
+
message = chalk__default.default.red(message);
|
|
402
|
+
break;
|
|
397
403
|
}
|
|
398
|
-
|
|
399
|
-
message += info.message === "object" ? JSON.stringify(info.message) : info.message;
|
|
400
|
-
return message;
|
|
404
|
+
return info.level === "info" ? message : `[${contextString}:${info.level}] ` + message;
|
|
401
405
|
})
|
|
402
406
|
),
|
|
403
|
-
transports: [new winston.transports.
|
|
407
|
+
transports: [new winston.transports.Console()]
|
|
404
408
|
});
|
|
405
409
|
var logger_default = logger;
|
|
406
410
|
|
|
@@ -416,9 +420,8 @@ var startServer_default = (ctx) => {
|
|
|
416
420
|
task.output = chalk__default.default.gray(`listening on port ${(_a = ctx2.server.addresses()[0]) == null ? void 0 : _a.port}`);
|
|
417
421
|
task.title = "SmartUI started";
|
|
418
422
|
} catch (error) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}
|
|
423
|
+
ctx2.log.debug(error);
|
|
424
|
+
task.output = chalk__default.default.gray(error.message);
|
|
422
425
|
throw new Error("SmartUI server setup failed");
|
|
423
426
|
}
|
|
424
427
|
}),
|
|
@@ -435,7 +438,7 @@ var auth_default = (ctx) => {
|
|
|
435
438
|
task.output = chalk__default.default.gray(`using project token '******#${ctx2.env.PROJECT_TOKEN.split("#").pop()}'`);
|
|
436
439
|
task.title = "Authenticated with SmartUI";
|
|
437
440
|
} catch (error) {
|
|
438
|
-
ctx2.log.debug(error
|
|
441
|
+
ctx2.log.debug(error);
|
|
439
442
|
task.output = chalk__default.default.gray(error.message);
|
|
440
443
|
throw new Error("Authentication failed");
|
|
441
444
|
}
|
|
@@ -504,7 +507,54 @@ function createWebStaticConfig(filepath) {
|
|
|
504
507
|
}
|
|
505
508
|
|
|
506
509
|
// package.json
|
|
507
|
-
var version = "2.0.
|
|
510
|
+
var version = "2.0.6";
|
|
511
|
+
var package_default = {
|
|
512
|
+
name: "@lambdatest/smartui-cli",
|
|
513
|
+
version,
|
|
514
|
+
description: "A command line interface (CLI) to run SmartUI tests on LambdaTest",
|
|
515
|
+
files: [
|
|
516
|
+
"dist/**/*"
|
|
517
|
+
],
|
|
518
|
+
scripts: {
|
|
519
|
+
build: "tsup",
|
|
520
|
+
release: "pnpm run build && pnpm publish --access public --no-git-checks"
|
|
521
|
+
},
|
|
522
|
+
bin: {
|
|
523
|
+
smartui: "./dist/index.cjs"
|
|
524
|
+
},
|
|
525
|
+
type: "module",
|
|
526
|
+
keywords: [
|
|
527
|
+
"lambdatest",
|
|
528
|
+
"smartui",
|
|
529
|
+
"cli"
|
|
530
|
+
],
|
|
531
|
+
author: "LambdaTest <keys@lambdatest.com>",
|
|
532
|
+
license: "MIT",
|
|
533
|
+
dependencies: {
|
|
534
|
+
"@playwright/browser-chromium": "^1.40.1",
|
|
535
|
+
"@playwright/browser-firefox": "^1.40.1",
|
|
536
|
+
"@playwright/browser-webkit": "^1.40.1",
|
|
537
|
+
"@playwright/test": "^1.40.1",
|
|
538
|
+
"@types/cross-spawn": "^6.0.4",
|
|
539
|
+
"@types/node": "^20.8.9",
|
|
540
|
+
"@types/which": "^3.0.2",
|
|
541
|
+
ajv: "^8.12.0",
|
|
542
|
+
"ajv-errors": "^3.0.0",
|
|
543
|
+
axios: "^1.6.0",
|
|
544
|
+
chalk: "^4.1.2",
|
|
545
|
+
commander: "^11.1.0",
|
|
546
|
+
"cross-spawn": "^7.0.3",
|
|
547
|
+
fastify: "^4.24.3",
|
|
548
|
+
"form-data": "^4.0.0",
|
|
549
|
+
listr2: "^7.0.1",
|
|
550
|
+
tsup: "^7.2.0",
|
|
551
|
+
which: "^4.0.0",
|
|
552
|
+
winston: "^3.10.0"
|
|
553
|
+
},
|
|
554
|
+
devDependencies: {
|
|
555
|
+
typescript: "^5.3.2"
|
|
556
|
+
}
|
|
557
|
+
};
|
|
508
558
|
var HTTP_SCHEME = "https:";
|
|
509
559
|
var HTTP_SCHEME_PREFIX = "https://";
|
|
510
560
|
var WWW = "www.";
|
|
@@ -575,11 +625,18 @@ var httpClient = class {
|
|
|
575
625
|
return resp.data;
|
|
576
626
|
}).catch((error) => {
|
|
577
627
|
if (error.response) {
|
|
628
|
+
log.debug(`http response: ${JSON.stringify({
|
|
629
|
+
status: error.response.status,
|
|
630
|
+
headers: error.response.headers,
|
|
631
|
+
body: error.response.data
|
|
632
|
+
})}`);
|
|
578
633
|
throw new Error(JSON.stringify(error.response.data));
|
|
579
634
|
}
|
|
580
635
|
if (error.request) {
|
|
636
|
+
log.debug(`http request failed: ${error.toJSON()}`);
|
|
581
637
|
throw new Error(error.toJSON().message);
|
|
582
638
|
}
|
|
639
|
+
log.debug(`http request failed: ${error.message}`);
|
|
583
640
|
throw new Error(error.message);
|
|
584
641
|
});
|
|
585
642
|
});
|
|
@@ -664,6 +721,17 @@ var httpClient = class {
|
|
|
664
721
|
throw new Error(error.message);
|
|
665
722
|
});
|
|
666
723
|
}
|
|
724
|
+
checkUpdate(log) {
|
|
725
|
+
return this.request({
|
|
726
|
+
url: `/packageinfo`,
|
|
727
|
+
method: "GET",
|
|
728
|
+
headers: { "Content-Type": "application/json" },
|
|
729
|
+
params: {
|
|
730
|
+
packageName: package_default.name,
|
|
731
|
+
packageVersion: package_default.version
|
|
732
|
+
}
|
|
733
|
+
}, log);
|
|
734
|
+
}
|
|
667
735
|
};
|
|
668
736
|
var ctx_default = (options) => {
|
|
669
737
|
let env = env_default();
|
|
@@ -762,6 +830,7 @@ var getGitInfo_default = (ctx) => {
|
|
|
762
830
|
task.output = chalk__default.default.gray(`branch: ${ctx2.git.branch}, commit: ${ctx2.git.commitId}, author: ${ctx2.git.commitAuthor}`);
|
|
763
831
|
task.title = "Fetched git information";
|
|
764
832
|
} catch (error) {
|
|
833
|
+
ctx2.log.debug(error);
|
|
765
834
|
task.output = chalk__default.default.gray(`${error.message}`);
|
|
766
835
|
throw new Error("Error fetching git repo details");
|
|
767
836
|
}
|
|
@@ -786,6 +855,7 @@ var createBuild_default = (ctx) => {
|
|
|
786
855
|
task.output = chalk__default.default.gray(`build id: ${resp.data.buildId}`);
|
|
787
856
|
task.title = "SmartUI build created";
|
|
788
857
|
} catch (error) {
|
|
858
|
+
ctx2.log.debug(error);
|
|
789
859
|
task.output = chalk__default.default.gray(JSON.parse(error.message).message);
|
|
790
860
|
throw new Error("SmartUI build creation failed");
|
|
791
861
|
}
|
|
@@ -839,9 +909,9 @@ var finalizeBuild_default = (ctx) => {
|
|
|
839
909
|
task.output = chalk__default.default.gray(`build url: ${ctx2.build.url}`);
|
|
840
910
|
task.title = "Finalized build";
|
|
841
911
|
} catch (error) {
|
|
842
|
-
ctx2.log.debug(error
|
|
912
|
+
ctx2.log.debug(error);
|
|
843
913
|
task.output = chalk__default.default.gray(error.message);
|
|
844
|
-
throw new Error("Finalize build
|
|
914
|
+
throw new Error("Finalize build failed");
|
|
845
915
|
}
|
|
846
916
|
}),
|
|
847
917
|
rendererOptions: { persistentOutput: true }
|
|
@@ -855,7 +925,7 @@ command.name("exec").description("Run test commands around SmartUI").argument("<
|
|
|
855
925
|
var _a, _b;
|
|
856
926
|
let ctx = ctx_default(command3.optsWithGlobals());
|
|
857
927
|
if (!which__default.default.sync(execCommand[0], { nothrow: true })) {
|
|
858
|
-
|
|
928
|
+
ctx.log.error(`Error: Command not found "${execCommand[0]}"`);
|
|
859
929
|
return;
|
|
860
930
|
}
|
|
861
931
|
ctx.args.execCommand = execCommand;
|
|
@@ -883,7 +953,7 @@ command.name("exec").description("Run test commands around SmartUI").argument("<
|
|
|
883
953
|
try {
|
|
884
954
|
yield tasks.run(ctx);
|
|
885
955
|
} catch (error) {
|
|
886
|
-
|
|
956
|
+
ctx.log.info("\nRefer docs: https://www.lambdatest.com/support/docs/smart-visual-regression-testing/");
|
|
887
957
|
} finally {
|
|
888
958
|
yield (_a = ctx.server) == null ? void 0 : _a.close();
|
|
889
959
|
yield (_b = ctx.browser) == null ? void 0 : _b.close();
|
|
@@ -1044,6 +1114,26 @@ var capture_default = command2;
|
|
|
1044
1114
|
var program = new commander.Command();
|
|
1045
1115
|
program.name("smartui").description("CLI to help you run your SmartUI tests on LambdaTest platform").version(`v${version}`).option("-c --config <filepath>", "Config file path").addCommand(exec_default2).addCommand(capture_default).addCommand(configWeb).addCommand(configStatic);
|
|
1046
1116
|
var commander_default = program;
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1117
|
+
(function() {
|
|
1118
|
+
return __async(this, null, function* () {
|
|
1119
|
+
let client = new httpClient(env_default());
|
|
1120
|
+
let log = logger_default;
|
|
1121
|
+
try {
|
|
1122
|
+
log.info(`
|
|
1123
|
+
LambdaTest SmartUI CLI v${package_default.version}`);
|
|
1124
|
+
let { data: { latestVersion, deprecated } } = yield client.checkUpdate(log);
|
|
1125
|
+
if (deprecated)
|
|
1126
|
+
log.warn(`This version is deprecated. A new version ${latestVersion} is available!
|
|
1127
|
+
`);
|
|
1128
|
+
else if (package_default.version !== latestVersion)
|
|
1129
|
+
log.info(chalk__default.default.gray(`A new version ${latestVersion} is available!
|
|
1130
|
+
`));
|
|
1131
|
+
else
|
|
1132
|
+
log.info(chalk__default.default.gray("https://www.npmjs.com/package/@lambdatest/smartui-cli\n"));
|
|
1133
|
+
} catch (error) {
|
|
1134
|
+
log.debug(error);
|
|
1135
|
+
log.info(chalk__default.default.gray("https://www.npmjs.com/package/@lambdatest/smartui-cli\n"));
|
|
1136
|
+
}
|
|
1137
|
+
commander_default.parse();
|
|
1138
|
+
});
|
|
1139
|
+
})();
|