@lambdatest/smartui-cli 4.0.6 → 4.0.7
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 +443 -66
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -536,6 +536,10 @@ var ConfigSchema = {
|
|
|
536
536
|
errorMessage: "Invalid config; password is mandatory"
|
|
537
537
|
}
|
|
538
538
|
}
|
|
539
|
+
},
|
|
540
|
+
delayedUpload: {
|
|
541
|
+
type: "boolean",
|
|
542
|
+
errorMessage: "Invalid config; delayedUpload must be true/false"
|
|
539
543
|
}
|
|
540
544
|
},
|
|
541
545
|
anyOf: [
|
|
@@ -672,6 +676,64 @@ var SnapshotSchema = {
|
|
|
672
676
|
errorMessage: "Invalid snapshot options; selectDOM xpath array must have unique and non-empty items"
|
|
673
677
|
}
|
|
674
678
|
}
|
|
679
|
+
},
|
|
680
|
+
web: {
|
|
681
|
+
type: "object",
|
|
682
|
+
properties: {
|
|
683
|
+
browsers: {
|
|
684
|
+
type: "array",
|
|
685
|
+
items: {
|
|
686
|
+
type: "string",
|
|
687
|
+
enum: [constants_default.CHROME, constants_default.FIREFOX, constants_default.SAFARI, constants_default.EDGE],
|
|
688
|
+
minLength: 1
|
|
689
|
+
},
|
|
690
|
+
uniqueItems: true,
|
|
691
|
+
errorMessage: `Invalid snapshot options; allowed browsers - ${constants_default.CHROME}, ${constants_default.FIREFOX}, ${constants_default.SAFARI}, ${constants_default.EDGE}`
|
|
692
|
+
},
|
|
693
|
+
viewports: {
|
|
694
|
+
type: "array",
|
|
695
|
+
items: {
|
|
696
|
+
type: "array",
|
|
697
|
+
items: {
|
|
698
|
+
type: "number",
|
|
699
|
+
minimum: 1
|
|
700
|
+
},
|
|
701
|
+
minItems: 1,
|
|
702
|
+
maxItems: 2,
|
|
703
|
+
errorMessage: "Invalid snapshot options; each viewport array must contain either a single width or a width and height tuple with positive values."
|
|
704
|
+
},
|
|
705
|
+
uniqueItems: true,
|
|
706
|
+
errorMessage: "Invalid snapshot options; viewports must be an array of unique arrays."
|
|
707
|
+
}
|
|
708
|
+
},
|
|
709
|
+
required: ["viewports"],
|
|
710
|
+
errorMessage: "Invalid snapshot options; web must include viewports property."
|
|
711
|
+
},
|
|
712
|
+
mobile: {
|
|
713
|
+
type: "object",
|
|
714
|
+
properties: {
|
|
715
|
+
devices: {
|
|
716
|
+
type: "array",
|
|
717
|
+
items: {
|
|
718
|
+
type: "string",
|
|
719
|
+
enum: Object.keys(constants_default.SUPPORTED_MOBILE_DEVICES),
|
|
720
|
+
minLength: 1
|
|
721
|
+
},
|
|
722
|
+
uniqueItems: true,
|
|
723
|
+
errorMessage: "Invalid snapshot options; devices must be an array of unique supported mobile devices."
|
|
724
|
+
},
|
|
725
|
+
fullPage: {
|
|
726
|
+
type: "boolean",
|
|
727
|
+
errorMessage: "Invalid snapshot options; fullPage must be a boolean."
|
|
728
|
+
},
|
|
729
|
+
orientation: {
|
|
730
|
+
type: "string",
|
|
731
|
+
enum: [constants_default.MOBILE_ORIENTATION_PORTRAIT, constants_default.MOBILE_ORIENTATION_LANDSCAPE],
|
|
732
|
+
errorMessage: "Invalid snapshot options; orientation must be either 'portrait' or 'landscape'."
|
|
733
|
+
}
|
|
734
|
+
},
|
|
735
|
+
required: ["devices"],
|
|
736
|
+
errorMessage: "Invalid snapshot options; mobile must include devices property."
|
|
675
737
|
}
|
|
676
738
|
},
|
|
677
739
|
additionalProperties: false
|
|
@@ -884,7 +946,7 @@ var auth_default = (ctx) => {
|
|
|
884
946
|
};
|
|
885
947
|
|
|
886
948
|
// package.json
|
|
887
|
-
var version = "4.0.
|
|
949
|
+
var version = "4.0.7";
|
|
888
950
|
var package_default = {
|
|
889
951
|
name: "@lambdatest/smartui-cli",
|
|
890
952
|
version,
|
|
@@ -1096,7 +1158,7 @@ var httpClient = class {
|
|
|
1096
1158
|
}
|
|
1097
1159
|
};
|
|
1098
1160
|
var ctx_default = (options) => {
|
|
1099
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1161
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1100
1162
|
let env = env_default();
|
|
1101
1163
|
let webConfig;
|
|
1102
1164
|
let mobileConfig;
|
|
@@ -1159,7 +1221,8 @@ var ctx_default = (options) => {
|
|
|
1159
1221
|
scrollTime: config.scrollTime || constants_default.DEFAULT_SCROLL_TIME,
|
|
1160
1222
|
allowedHostnames: config.allowedHostnames || [],
|
|
1161
1223
|
basicAuthorization: basicAuthObj,
|
|
1162
|
-
smartIgnore: (_f = config.smartIgnore) != null ? _f : false
|
|
1224
|
+
smartIgnore: (_f = config.smartIgnore) != null ? _f : false,
|
|
1225
|
+
delayedUpload: (_g = config.delayedUpload) != null ? _g : false
|
|
1163
1226
|
},
|
|
1164
1227
|
uploadFilePath: "",
|
|
1165
1228
|
webStaticConfig: [],
|
|
@@ -1327,13 +1390,17 @@ var processSnapshot_default = (ctx) => {
|
|
|
1327
1390
|
return {
|
|
1328
1391
|
title: `Processing snapshots`,
|
|
1329
1392
|
task: (ctx2, task) => __async(void 0, null, function* () {
|
|
1330
|
-
var _a;
|
|
1393
|
+
var _a, _b;
|
|
1331
1394
|
try {
|
|
1395
|
+
if (ctx2.config.delayedUpload) {
|
|
1396
|
+
ctx2.log.debug("started after processing because of delayedUpload");
|
|
1397
|
+
(_a = ctx2.snapshotQueue) == null ? void 0 : _a.startProcessingfunc();
|
|
1398
|
+
}
|
|
1332
1399
|
yield new Promise((resolve) => {
|
|
1333
1400
|
let output2 = "";
|
|
1334
1401
|
const intervalId = setInterval(() => {
|
|
1335
|
-
var _a2,
|
|
1336
|
-
if (((_a2 = ctx2.snapshotQueue) == null ? void 0 : _a2.isEmpty()) && !((
|
|
1402
|
+
var _a2, _b2, _c;
|
|
1403
|
+
if (((_a2 = ctx2.snapshotQueue) == null ? void 0 : _a2.isEmpty()) && !((_b2 = ctx2.snapshotQueue) == null ? void 0 : _b2.isProcessing())) {
|
|
1337
1404
|
clearInterval(intervalId);
|
|
1338
1405
|
resolve();
|
|
1339
1406
|
} else {
|
|
@@ -1342,7 +1409,7 @@ var processSnapshot_default = (ctx) => {
|
|
|
1342
1409
|
}, 500);
|
|
1343
1410
|
});
|
|
1344
1411
|
let output = "";
|
|
1345
|
-
for (let snapshot of (
|
|
1412
|
+
for (let snapshot of (_b = ctx2.snapshotQueue) == null ? void 0 : _b.getProcessedSnapshots()) {
|
|
1346
1413
|
if (snapshot.error)
|
|
1347
1414
|
output += `${chalk7__default.default.red("\u2717")} ${chalk7__default.default.gray(`${snapshot.name}
|
|
1348
1415
|
[error] ${snapshot.error}`)}
|
|
@@ -1478,6 +1545,28 @@ function getWebRenderViewports(ctx) {
|
|
|
1478
1545
|
}
|
|
1479
1546
|
return webRenderViewports;
|
|
1480
1547
|
}
|
|
1548
|
+
function getWebRenderViewportsForOptions(options) {
|
|
1549
|
+
let webRenderViewports = [];
|
|
1550
|
+
if (options.web && Array.isArray(options.web.viewports)) {
|
|
1551
|
+
for (const viewport of options.web.viewports) {
|
|
1552
|
+
if (Array.isArray(viewport) && viewport.length > 0) {
|
|
1553
|
+
let viewportObj = {
|
|
1554
|
+
width: viewport[0]
|
|
1555
|
+
};
|
|
1556
|
+
if (viewport.length > 1) {
|
|
1557
|
+
viewportObj.height = viewport[1];
|
|
1558
|
+
}
|
|
1559
|
+
webRenderViewports.push({
|
|
1560
|
+
viewport: viewportObj,
|
|
1561
|
+
viewportString: `${viewport[0]}${viewport[1] ? "x" + viewport[1] : ""}`,
|
|
1562
|
+
fullPage: viewport.length === 1,
|
|
1563
|
+
device: false
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
return webRenderViewports;
|
|
1569
|
+
}
|
|
1481
1570
|
function getMobileRenderViewports(ctx) {
|
|
1482
1571
|
var _a;
|
|
1483
1572
|
let mobileRenderViewports = {};
|
|
@@ -1499,6 +1588,34 @@ function getMobileRenderViewports(ctx) {
|
|
|
1499
1588
|
}
|
|
1500
1589
|
return mobileRenderViewports;
|
|
1501
1590
|
}
|
|
1591
|
+
function getMobileRenderViewportsForOptions(options) {
|
|
1592
|
+
var _a;
|
|
1593
|
+
let mobileRenderViewports = {};
|
|
1594
|
+
mobileRenderViewports[constants_default.MOBILE_OS_IOS] = [];
|
|
1595
|
+
mobileRenderViewports[constants_default.MOBILE_OS_ANDROID] = [];
|
|
1596
|
+
if (options.mobile) {
|
|
1597
|
+
for (const device of options.mobile.devices) {
|
|
1598
|
+
let os = constants_default.SUPPORTED_MOBILE_DEVICES[device].os;
|
|
1599
|
+
let { width, height } = constants_default.SUPPORTED_MOBILE_DEVICES[device].viewport;
|
|
1600
|
+
let orientation = options.mobile.orientation || constants_default.MOBILE_ORIENTATION_PORTRAIT;
|
|
1601
|
+
let portrait = orientation === constants_default.MOBILE_ORIENTATION_PORTRAIT;
|
|
1602
|
+
let fullPage;
|
|
1603
|
+
if (options.mobile.fullPage === void 0 || options.mobile.fullPage) {
|
|
1604
|
+
fullPage = true;
|
|
1605
|
+
} else {
|
|
1606
|
+
fullPage = false;
|
|
1607
|
+
}
|
|
1608
|
+
(_a = mobileRenderViewports[os]) == null ? void 0 : _a.push({
|
|
1609
|
+
viewport: { width: portrait ? width : height, height: portrait ? height : width },
|
|
1610
|
+
viewportString: `${device} (${orientation})`,
|
|
1611
|
+
fullPage,
|
|
1612
|
+
device: true,
|
|
1613
|
+
os
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
return mobileRenderViewports;
|
|
1618
|
+
}
|
|
1502
1619
|
function getRenderViewports(ctx) {
|
|
1503
1620
|
let mobileRenderViewports = getMobileRenderViewports(ctx);
|
|
1504
1621
|
let webRenderViewports = getWebRenderViewports(ctx);
|
|
@@ -1508,69 +1625,20 @@ function getRenderViewports(ctx) {
|
|
|
1508
1625
|
...mobileRenderViewports[constants_default.MOBILE_OS_ANDROID]
|
|
1509
1626
|
];
|
|
1510
1627
|
}
|
|
1628
|
+
function getRenderViewportsForOptions(options) {
|
|
1629
|
+
let mobileRenderViewports = getMobileRenderViewportsForOptions(options);
|
|
1630
|
+
let webRenderViewports = getWebRenderViewportsForOptions(options);
|
|
1631
|
+
return [
|
|
1632
|
+
...webRenderViewports,
|
|
1633
|
+
...mobileRenderViewports[constants_default.MOBILE_OS_IOS],
|
|
1634
|
+
...mobileRenderViewports[constants_default.MOBILE_OS_ANDROID]
|
|
1635
|
+
];
|
|
1636
|
+
}
|
|
1511
1637
|
var MAX_RESOURCE_SIZE = 15 * 1024 ** 2;
|
|
1512
1638
|
var ALLOWED_RESOURCES = ["document", "stylesheet", "image", "media", "font", "other"];
|
|
1513
1639
|
var ALLOWED_STATUSES = [200, 201];
|
|
1514
1640
|
var REQUEST_TIMEOUT = 1e4;
|
|
1515
1641
|
var MIN_VIEWPORT_HEIGHT = 1080;
|
|
1516
|
-
var Queue = class {
|
|
1517
|
-
constructor(ctx) {
|
|
1518
|
-
this.snapshots = [];
|
|
1519
|
-
this.processedSnapshots = [];
|
|
1520
|
-
this.processing = false;
|
|
1521
|
-
this.processingSnapshot = "";
|
|
1522
|
-
this.ctx = ctx;
|
|
1523
|
-
}
|
|
1524
|
-
enqueue(item) {
|
|
1525
|
-
this.snapshots.push(item);
|
|
1526
|
-
if (!this.processing) {
|
|
1527
|
-
this.processing = true;
|
|
1528
|
-
this.processNext();
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
processNext() {
|
|
1532
|
-
return __async(this, null, function* () {
|
|
1533
|
-
if (!this.isEmpty()) {
|
|
1534
|
-
const snapshot = this.snapshots.shift();
|
|
1535
|
-
try {
|
|
1536
|
-
this.processingSnapshot = snapshot == null ? void 0 : snapshot.name;
|
|
1537
|
-
let { processedSnapshot, warnings } = yield processSnapshot(snapshot, this.ctx);
|
|
1538
|
-
yield this.ctx.client.uploadSnapshot(this.ctx, processedSnapshot);
|
|
1539
|
-
this.ctx.totalSnapshots++;
|
|
1540
|
-
this.processedSnapshots.push({ name: snapshot.name, warnings });
|
|
1541
|
-
} catch (error) {
|
|
1542
|
-
this.ctx.log.debug(`snapshot failed; ${error}`);
|
|
1543
|
-
this.processedSnapshots.push({ name: snapshot.name, error: error.message });
|
|
1544
|
-
}
|
|
1545
|
-
if (this.ctx.browser) {
|
|
1546
|
-
for (let context of this.ctx.browser.contexts()) {
|
|
1547
|
-
for (let page of context.pages()) {
|
|
1548
|
-
yield page.close();
|
|
1549
|
-
this.ctx.log.debug(`Closed browser page for snapshot ${snapshot.name}`);
|
|
1550
|
-
}
|
|
1551
|
-
yield context.close();
|
|
1552
|
-
this.ctx.log.debug(`Closed browser context for snapshot ${snapshot.name}`);
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
this.processNext();
|
|
1556
|
-
} else {
|
|
1557
|
-
this.processing = false;
|
|
1558
|
-
}
|
|
1559
|
-
});
|
|
1560
|
-
}
|
|
1561
|
-
isProcessing() {
|
|
1562
|
-
return this.processing;
|
|
1563
|
-
}
|
|
1564
|
-
getProcessingSnapshot() {
|
|
1565
|
-
return this.processingSnapshot;
|
|
1566
|
-
}
|
|
1567
|
-
getProcessedSnapshots() {
|
|
1568
|
-
return this.processedSnapshots;
|
|
1569
|
-
}
|
|
1570
|
-
isEmpty() {
|
|
1571
|
-
return this.snapshots && this.snapshots.length ? false : true;
|
|
1572
|
-
}
|
|
1573
|
-
};
|
|
1574
1642
|
function processSnapshot(snapshot, ctx) {
|
|
1575
1643
|
return __async(this, null, function* () {
|
|
1576
1644
|
var _a;
|
|
@@ -1719,6 +1787,33 @@ function processSnapshot(snapshot, ctx) {
|
|
|
1719
1787
|
return true;
|
|
1720
1788
|
return false;
|
|
1721
1789
|
};
|
|
1790
|
+
if (options.web && Object.keys(options.web).length) {
|
|
1791
|
+
processedOptions.web = {};
|
|
1792
|
+
if (options.web.viewports && options.web.viewports.length > 0) {
|
|
1793
|
+
processedOptions.web.viewports = options.web.viewports.filter(
|
|
1794
|
+
(viewport) => Array.isArray(viewport) && viewport.length > 0
|
|
1795
|
+
);
|
|
1796
|
+
}
|
|
1797
|
+
if (options.web.browsers && options.web.browsers.length > 0) {
|
|
1798
|
+
processedOptions.web.browsers = options.web.browsers;
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
if (options.mobile && Object.keys(options.mobile).length) {
|
|
1802
|
+
processedOptions.mobile = {};
|
|
1803
|
+
if (options.mobile.devices && options.mobile.devices.length > 0) {
|
|
1804
|
+
processedOptions.mobile.devices = options.mobile.devices;
|
|
1805
|
+
}
|
|
1806
|
+
if (options.mobile.hasOwnProperty("fullPage") && typeof options.mobile.fullPage === "boolean") {
|
|
1807
|
+
processedOptions.mobile.fullPage = options.mobile.fullPage;
|
|
1808
|
+
} else {
|
|
1809
|
+
processedOptions.mobile.fullPage = true;
|
|
1810
|
+
}
|
|
1811
|
+
if (options.mobile.hasOwnProperty("orientation") && (options.mobile.orientation === constants_default.MOBILE_ORIENTATION_PORTRAIT || options.mobile.orientation === constants_default.MOBILE_ORIENTATION_LANDSCAPE)) {
|
|
1812
|
+
processedOptions.mobile.orientation = options.mobile.orientation;
|
|
1813
|
+
} else {
|
|
1814
|
+
processedOptions.mobile.orientation = constants_default.MOBILE_ORIENTATION_PORTRAIT;
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1722
1817
|
if (options.element && Object.keys(options.element).length) {
|
|
1723
1818
|
if (options.element.id)
|
|
1724
1819
|
processedOptions.element = "#" + options.element.id;
|
|
@@ -1758,7 +1853,12 @@ function processSnapshot(snapshot, ctx) {
|
|
|
1758
1853
|
}
|
|
1759
1854
|
let navigated = false;
|
|
1760
1855
|
let previousDeviceType = null;
|
|
1761
|
-
let renderViewports
|
|
1856
|
+
let renderViewports;
|
|
1857
|
+
if (snapshot.options && snapshot.options.web || snapshot.options && snapshot.options.mobile) {
|
|
1858
|
+
renderViewports = getRenderViewportsForOptions(snapshot.options);
|
|
1859
|
+
} else {
|
|
1860
|
+
renderViewports = getRenderViewports(ctx);
|
|
1861
|
+
}
|
|
1762
1862
|
for (const { viewport, viewportString, fullPage, device } of renderViewports) {
|
|
1763
1863
|
if (previousDeviceType !== null && previousDeviceType !== device) {
|
|
1764
1864
|
navigated = false;
|
|
@@ -1817,6 +1917,7 @@ function processSnapshot(snapshot, ctx) {
|
|
|
1817
1917
|
});
|
|
1818
1918
|
}
|
|
1819
1919
|
}
|
|
1920
|
+
ctx.log.debug(`Processed options: ${JSON.stringify(processedOptions)}`);
|
|
1820
1921
|
}
|
|
1821
1922
|
return {
|
|
1822
1923
|
processedSnapshot: {
|
|
@@ -1831,6 +1932,282 @@ function processSnapshot(snapshot, ctx) {
|
|
|
1831
1932
|
});
|
|
1832
1933
|
}
|
|
1833
1934
|
|
|
1935
|
+
// src/lib/snapshotQueue.ts
|
|
1936
|
+
var Queue = class {
|
|
1937
|
+
constructor(ctx) {
|
|
1938
|
+
this.snapshots = [];
|
|
1939
|
+
this.processedSnapshots = [];
|
|
1940
|
+
this.processing = false;
|
|
1941
|
+
this.processingSnapshot = "";
|
|
1942
|
+
this.snapshotNames = [];
|
|
1943
|
+
this.variants = [];
|
|
1944
|
+
this.ctx = ctx;
|
|
1945
|
+
}
|
|
1946
|
+
enqueue(item) {
|
|
1947
|
+
this.snapshots.push(item);
|
|
1948
|
+
if (!this.ctx.config.delayedUpload) {
|
|
1949
|
+
if (!this.processing) {
|
|
1950
|
+
this.processing = true;
|
|
1951
|
+
this.processNext();
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
startProcessingfunc() {
|
|
1956
|
+
if (!this.processing) {
|
|
1957
|
+
this.processing = true;
|
|
1958
|
+
this.processNext();
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
processGenerateVariants(snapshot) {
|
|
1962
|
+
if (snapshot.options) {
|
|
1963
|
+
if (snapshot.options.web) {
|
|
1964
|
+
this.generateWebVariants(snapshot, snapshot.options.web);
|
|
1965
|
+
}
|
|
1966
|
+
if (snapshot.options.mobile) {
|
|
1967
|
+
this.generateMobileVariants(snapshot, snapshot.options.mobile);
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
if (!snapshot.options || snapshot.options && !snapshot.options.web && !snapshot.options.mobile) {
|
|
1971
|
+
this.generateVariants(snapshot, this.ctx.config);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
generateVariants(snapshot, config) {
|
|
1975
|
+
if (config.web) {
|
|
1976
|
+
const browsers = config.web.browsers || [];
|
|
1977
|
+
const viewports = config.web.viewports || [];
|
|
1978
|
+
for (const browser of browsers) {
|
|
1979
|
+
for (const viewport of viewports) {
|
|
1980
|
+
const width = viewport.width;
|
|
1981
|
+
const height = viewport.height || 0;
|
|
1982
|
+
const variant = `${snapshot.name}_${browser}_viewport[${width}]_viewport[${height}]`;
|
|
1983
|
+
this.variants.push(variant);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
if (config.mobile) {
|
|
1988
|
+
const devices = config.mobile.devices || [];
|
|
1989
|
+
const orientation = config.mobile.orientation || constants_default.MOBILE_ORIENTATION_PORTRAIT;
|
|
1990
|
+
for (const device of devices) {
|
|
1991
|
+
const variant = `${snapshot.name}_${device}_${orientation}`;
|
|
1992
|
+
this.variants.push(variant);
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
generateWebVariants(snapshot, webConfig) {
|
|
1997
|
+
var _a, _b, _c;
|
|
1998
|
+
const browsers = (_c = (_b = webConfig.browsers) != null ? _b : (_a = this.ctx.config.web) == null ? void 0 : _a.browsers) != null ? _c : [constants_default.CHROME, constants_default.EDGE, constants_default.FIREFOX, constants_default.SAFARI];
|
|
1999
|
+
const viewports = webConfig.viewports || [];
|
|
2000
|
+
for (const browser of browsers) {
|
|
2001
|
+
for (const viewport of viewports) {
|
|
2002
|
+
const width = viewport[0];
|
|
2003
|
+
const height = viewport[1] || 0;
|
|
2004
|
+
const variant = `${snapshot.name}_${browser}_viewport[${width}]_viewport[${height}]`;
|
|
2005
|
+
this.variants.push(variant);
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
generateMobileVariants(snapshot, mobileConfig) {
|
|
2010
|
+
var _a, _b, _c;
|
|
2011
|
+
const devices = mobileConfig.devices || [];
|
|
2012
|
+
const orientation = (_c = (_b = mobileConfig.orientation) != null ? _b : (_a = this.ctx.config.mobile) == null ? void 0 : _a.orientation) != null ? _c : constants_default.MOBILE_ORIENTATION_PORTRAIT;
|
|
2013
|
+
for (const device of devices) {
|
|
2014
|
+
const variant = `${snapshot.name}_${device}_${orientation}`;
|
|
2015
|
+
this.variants.push(variant);
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
filterExistingVariants(snapshot, config) {
|
|
2019
|
+
let drop = true;
|
|
2020
|
+
if (snapshot.options && snapshot.options.web) {
|
|
2021
|
+
const webDrop = this.filterWebVariants(snapshot, snapshot.options.web);
|
|
2022
|
+
if (!webDrop)
|
|
2023
|
+
drop = false;
|
|
2024
|
+
}
|
|
2025
|
+
if (snapshot.options && snapshot.options.mobile) {
|
|
2026
|
+
const mobileDrop = this.filterMobileVariants(snapshot, snapshot.options.mobile);
|
|
2027
|
+
if (!mobileDrop)
|
|
2028
|
+
drop = false;
|
|
2029
|
+
}
|
|
2030
|
+
if (!snapshot.options || snapshot.options && !snapshot.options.web && !snapshot.options.mobile) {
|
|
2031
|
+
const configDrop = this.filterVariants(snapshot, config);
|
|
2032
|
+
if (!configDrop)
|
|
2033
|
+
drop = false;
|
|
2034
|
+
}
|
|
2035
|
+
return drop;
|
|
2036
|
+
}
|
|
2037
|
+
filterVariants(snapshot, config) {
|
|
2038
|
+
var _a;
|
|
2039
|
+
let allVariantsDropped = true;
|
|
2040
|
+
if (config.web) {
|
|
2041
|
+
const browsers = config.web.browsers || [];
|
|
2042
|
+
const viewports = config.web.viewports || [];
|
|
2043
|
+
for (const browser of browsers) {
|
|
2044
|
+
for (const viewport of viewports) {
|
|
2045
|
+
const width = viewport.width;
|
|
2046
|
+
const height = viewport.height || 0;
|
|
2047
|
+
const variant = `${snapshot.name}_${browser}_viewport[${width}]_viewport[${height}]`;
|
|
2048
|
+
if (!this.variants.includes(variant)) {
|
|
2049
|
+
allVariantsDropped = false;
|
|
2050
|
+
if (!snapshot.options)
|
|
2051
|
+
snapshot.options = {};
|
|
2052
|
+
if (!snapshot.options.web)
|
|
2053
|
+
snapshot.options.web = { browsers: [], viewports: [] };
|
|
2054
|
+
if (!snapshot.options.web.browsers.includes(browser)) {
|
|
2055
|
+
snapshot.options.web.browsers.push(browser);
|
|
2056
|
+
}
|
|
2057
|
+
const viewportExists = snapshot.options.web.viewports.some(
|
|
2058
|
+
(existingViewport) => existingViewport[0] === width && (existingViewport.length < 2 || existingViewport[1] === height)
|
|
2059
|
+
);
|
|
2060
|
+
if (!viewportExists) {
|
|
2061
|
+
if (height > 0) {
|
|
2062
|
+
snapshot.options.web.viewports.push([width, height]);
|
|
2063
|
+
} else {
|
|
2064
|
+
snapshot.options.web.viewports.push([width]);
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
if (config.mobile) {
|
|
2072
|
+
const devices = config.mobile.devices || [];
|
|
2073
|
+
const orientation = config.mobile.orientation || constants_default.MOBILE_ORIENTATION_PORTRAIT;
|
|
2074
|
+
const fullPage = (_a = config.mobile.fullPage) != null ? _a : true;
|
|
2075
|
+
for (const device of devices) {
|
|
2076
|
+
const variant = `${snapshot.name}_${device}_${orientation}`;
|
|
2077
|
+
if (!this.variants.includes(variant)) {
|
|
2078
|
+
allVariantsDropped = false;
|
|
2079
|
+
if (!snapshot.options)
|
|
2080
|
+
snapshot.options = {};
|
|
2081
|
+
if (!snapshot.options.mobile)
|
|
2082
|
+
snapshot.options.mobile = { devices: [], orientation: constants_default.MOBILE_ORIENTATION_PORTRAIT, fullPage };
|
|
2083
|
+
if (!snapshot.options.mobile.devices.includes(device)) {
|
|
2084
|
+
snapshot.options.mobile.devices.push(device);
|
|
2085
|
+
}
|
|
2086
|
+
snapshot.options.mobile.orientation = orientation;
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
return allVariantsDropped;
|
|
2091
|
+
}
|
|
2092
|
+
filterWebVariants(snapshot, webConfig) {
|
|
2093
|
+
var _a, _b, _c;
|
|
2094
|
+
const browsers = (_c = (_b = webConfig.browsers) != null ? _b : (_a = this.ctx.config.web) == null ? void 0 : _a.browsers) != null ? _c : [constants_default.CHROME, constants_default.EDGE, constants_default.FIREFOX, constants_default.SAFARI];
|
|
2095
|
+
const viewports = webConfig.viewports || [];
|
|
2096
|
+
let allVariantsDropped = true;
|
|
2097
|
+
if (!snapshot.options) {
|
|
2098
|
+
snapshot.options = {};
|
|
2099
|
+
}
|
|
2100
|
+
snapshot.options.web = { browsers: [], viewports: [] };
|
|
2101
|
+
for (const browser of browsers) {
|
|
2102
|
+
for (const viewport of viewports) {
|
|
2103
|
+
const width = viewport[0];
|
|
2104
|
+
const height = viewport[1] || 0;
|
|
2105
|
+
const variant = `${snapshot.name}_${browser}_viewport[${width}]_viewport[${height}]`;
|
|
2106
|
+
if (!this.variants.includes(variant)) {
|
|
2107
|
+
allVariantsDropped = false;
|
|
2108
|
+
if (!snapshot.options.web.browsers.includes(browser)) {
|
|
2109
|
+
snapshot.options.web.browsers.push(browser);
|
|
2110
|
+
}
|
|
2111
|
+
const viewportExists = snapshot.options.web.viewports.some(
|
|
2112
|
+
(existingViewport) => existingViewport[0] === width && (existingViewport.length < 2 || existingViewport[1] === height)
|
|
2113
|
+
);
|
|
2114
|
+
if (!viewportExists) {
|
|
2115
|
+
if (height > 0) {
|
|
2116
|
+
snapshot.options.web.viewports.push([width, height]);
|
|
2117
|
+
} else {
|
|
2118
|
+
snapshot.options.web.viewports.push([width]);
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
return allVariantsDropped;
|
|
2125
|
+
}
|
|
2126
|
+
filterMobileVariants(snapshot, mobileConfig) {
|
|
2127
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2128
|
+
if (!snapshot.options) {
|
|
2129
|
+
snapshot.options = {};
|
|
2130
|
+
}
|
|
2131
|
+
const devices = mobileConfig.devices || [];
|
|
2132
|
+
const orientation = (_c = (_b = mobileConfig.orientation) != null ? _b : (_a = this.ctx.config.mobile) == null ? void 0 : _a.orientation) != null ? _c : constants_default.MOBILE_ORIENTATION_PORTRAIT;
|
|
2133
|
+
const fullPage = (_f = (_e = mobileConfig.fullPage) != null ? _e : (_d = this.ctx.config.mobile) == null ? void 0 : _d.fullPage) != null ? _f : true;
|
|
2134
|
+
let allVariantsDropped = true;
|
|
2135
|
+
snapshot.options.mobile = { devices: [], orientation: constants_default.MOBILE_ORIENTATION_PORTRAIT, fullPage };
|
|
2136
|
+
for (const device of devices) {
|
|
2137
|
+
const variant = `${snapshot.name}_${device}_${orientation}`;
|
|
2138
|
+
if (!this.variants.includes(variant)) {
|
|
2139
|
+
allVariantsDropped = false;
|
|
2140
|
+
snapshot.options.mobile.devices.push(device);
|
|
2141
|
+
snapshot.options.mobile.orientation = orientation;
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
return allVariantsDropped;
|
|
2145
|
+
}
|
|
2146
|
+
processNext() {
|
|
2147
|
+
return __async(this, null, function* () {
|
|
2148
|
+
if (!this.isEmpty()) {
|
|
2149
|
+
let snapshot;
|
|
2150
|
+
if (this.ctx.config.delayedUpload) {
|
|
2151
|
+
snapshot = this.snapshots.pop();
|
|
2152
|
+
} else {
|
|
2153
|
+
snapshot = this.snapshots.shift();
|
|
2154
|
+
}
|
|
2155
|
+
try {
|
|
2156
|
+
this.processingSnapshot = snapshot == null ? void 0 : snapshot.name;
|
|
2157
|
+
let drop = false;
|
|
2158
|
+
if (!this.ctx.config.delayedUpload && snapshot && snapshot.name && this.snapshotNames.includes(snapshot.name)) {
|
|
2159
|
+
drop = true;
|
|
2160
|
+
this.ctx.log.info(`Skipping duplicate SmartUI snapshot '${snapshot.name}'. To capture duplicate screenshots, please set the 'delayedUploads' configuration as true in your config file.`);
|
|
2161
|
+
}
|
|
2162
|
+
if (this.ctx.config.delayedUpload && snapshot && snapshot.name && this.snapshotNames.includes(snapshot.name)) {
|
|
2163
|
+
drop = this.filterExistingVariants(snapshot, this.ctx.config);
|
|
2164
|
+
}
|
|
2165
|
+
if (snapshot && snapshot.name && !this.snapshotNames.includes(snapshot.name) && !drop) {
|
|
2166
|
+
this.snapshotNames.push(snapshot.name);
|
|
2167
|
+
}
|
|
2168
|
+
if (this.ctx.config.delayedUpload && snapshot && !drop) {
|
|
2169
|
+
this.processGenerateVariants(snapshot);
|
|
2170
|
+
}
|
|
2171
|
+
if (!drop) {
|
|
2172
|
+
let { processedSnapshot, warnings } = yield processSnapshot(snapshot, this.ctx);
|
|
2173
|
+
yield this.ctx.client.uploadSnapshot(this.ctx, processedSnapshot);
|
|
2174
|
+
this.ctx.totalSnapshots++;
|
|
2175
|
+
this.processedSnapshots.push({ name: snapshot.name, warnings });
|
|
2176
|
+
}
|
|
2177
|
+
} catch (error) {
|
|
2178
|
+
this.ctx.log.debug(`snapshot failed; ${error}`);
|
|
2179
|
+
this.processedSnapshots.push({ name: snapshot.name, error: error.message });
|
|
2180
|
+
}
|
|
2181
|
+
if (this.ctx.browser) {
|
|
2182
|
+
for (let context of this.ctx.browser.contexts()) {
|
|
2183
|
+
for (let page of context.pages()) {
|
|
2184
|
+
yield page.close();
|
|
2185
|
+
this.ctx.log.debug(`Closed browser page for snapshot ${snapshot.name}`);
|
|
2186
|
+
}
|
|
2187
|
+
yield context.close();
|
|
2188
|
+
this.ctx.log.debug(`Closed browser context for snapshot ${snapshot.name}`);
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
this.processNext();
|
|
2192
|
+
} else {
|
|
2193
|
+
this.processing = false;
|
|
2194
|
+
}
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
isProcessing() {
|
|
2198
|
+
return this.processing;
|
|
2199
|
+
}
|
|
2200
|
+
getProcessingSnapshot() {
|
|
2201
|
+
return this.processingSnapshot;
|
|
2202
|
+
}
|
|
2203
|
+
getProcessedSnapshots() {
|
|
2204
|
+
return this.processedSnapshots;
|
|
2205
|
+
}
|
|
2206
|
+
isEmpty() {
|
|
2207
|
+
return this.snapshots && this.snapshots.length ? false : true;
|
|
2208
|
+
}
|
|
2209
|
+
};
|
|
2210
|
+
|
|
1834
2211
|
// src/commander/exec.ts
|
|
1835
2212
|
var command = new commander.Command();
|
|
1836
2213
|
command.name("exec").description("Run test commands around SmartUI").argument("<command...>", "Command supplied for running tests").option("-P, --port <number>", "Port number for the server").action(function(execCommand, _, command5) {
|