Skip to content

Commit 598f7b1

Browse files
authored
Merge pull request #267 from LambdaTest/stage
Release PR Version: 4.1.7-beta.3
2 parents a349c79 + ec8ce85 commit 598f7b1

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/smartui-cli",
3-
"version": "4.1.7-beta.2",
3+
"version": "4.1.7-beta.3",
44
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
55
"files": [
66
"dist/**/*"

src/lib/ctx.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export default (options: Record<string, string>): Context => {
9393
cliEnableJavaScript: config.cliEnableJavaScript ?? true,
9494
scrollTime: config.scrollTime || constants.DEFAULT_SCROLL_TIME,
9595
allowedHostnames: config.allowedHostnames || [],
96+
allowedAssets: config.allowedAssets || [],
9697
basicAuthorization: basicAuthObj,
9798
smartIgnore: config.smartIgnore ?? false,
9899
delayedUpload: config.delayedUpload ?? false,

src/lib/processSnapshot.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,41 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
387387
ctx.log.debug(`Network idle failed due to ${error}`);
388388
}
389389

390+
if (ctx.config.allowedAssets && ctx.config.allowedAssets.length) {
391+
for (let assetUrl of ctx.config.allowedAssets) {
392+
if (!cache[assetUrl]) {
393+
ctx.log.debug(`Fetching asset ${assetUrl} from allowedAssets array`);
394+
try {
395+
const response = await page.request.fetch(assetUrl, {
396+
timeout: 25000,
397+
headers: {
398+
...constants.REQUEST_HEADERS
399+
}
400+
});
401+
402+
const body = await response.body();
403+
404+
if (body && body.length) {
405+
ctx.log.debug(`Caching asset ${assetUrl}`);
406+
cache[assetUrl] = {
407+
body: body.toString('base64'),
408+
type: response.headers()['content-type']
409+
};
410+
} else {
411+
ctx.log.debug(`Asset ${assetUrl} returned empty or invalid body`);
412+
}
413+
} catch (error) {
414+
if (error && error.message) {
415+
ctx.log.debug(`Error fetching asset with error message ${assetUrl}: ${error.message}`);
416+
}
417+
ctx.log.debug(`Error fetching asset ${assetUrl}: ${JSON.stringify(error)}`);
418+
}
419+
} else {
420+
ctx.log.debug(`Asset ${assetUrl} already cached`);
421+
}
422+
}
423+
}
424+
390425
// snapshot options
391426
if (processedOptions.element) {
392427
let l = await page.locator(processedOptions.element).all()

src/lib/schemaValidation.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ const ConfigSchema = {
147147
uniqueItems: "Invalid config; duplicates in allowedHostnames"
148148
}
149149

150+
},
151+
allowedAssets: {
152+
type: "array",
153+
items: {
154+
type: "string",
155+
minLength: 1,
156+
errorMessage: {
157+
minLength: "Invalid config; allowedAssets cannot be empty"
158+
}
159+
},
160+
uniqueItems: true,
161+
errorMessage: {
162+
uniqueItems: "Invalid config; duplicates in allowedAssets"
163+
}
164+
150165
},
151166
basicAuthorization: {
152167
type: "object",

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface Context {
2525
cliEnableJavaScript: boolean;
2626
scrollTime: number;
2727
allowedHostnames: Array<string>;
28+
allowedAssets: Array<string>;
2829
basicAuthorization: basicAuth | undefined;
2930
smartIgnore: boolean;
3031
delayedUpload: boolean;

0 commit comments

Comments
 (0)