Skip to content

Commit 771ed4d

Browse files
Merge branch 'stage' into prod
2 parents 982cee5 + e726054 commit 771ed4d

File tree

7 files changed

+68
-3
lines changed

7 files changed

+68
-3
lines changed

src/dom/dom-serializer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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/httpClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default class httpClient {
8888

8989
async request(config: AxiosRequestConfig, log: Logger): Promise<Record<string, any>> {
9090
log.debug(`http request: ${config.method} ${config.url}`);
91-
if (config && config.data && !config.data.name) {
91+
if (config && config.data && !config.data.name && !config.data.snapshot) {
9292
log.debug(config.data);
9393
}
9494
if (config && config.data && config.data.snapshotUuid) {
@@ -477,6 +477,7 @@ export default class httpClient {
477477
}
478478

479479
processWebFigma(requestBody: any, log: Logger) {
480+
requestBody.packageVersion = pkgJSON.version;
480481
return this.request({
481482
url: "figma-web/upload",
482483
method: "POST",

src/lib/processSnapshot.ts

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

420+
if (ctx.config.allowedAssets && ctx.config.allowedAssets.length) {
421+
for (let assetUrl of ctx.config.allowedAssets) {
422+
if (!cache[assetUrl]) {
423+
ctx.log.debug(`Fetching asset ${assetUrl} from allowedAssets array`);
424+
try {
425+
const response = await page.request.fetch(assetUrl, {
426+
timeout: 25000,
427+
headers: {
428+
...constants.REQUEST_HEADERS
429+
}
430+
});
431+
432+
const body = await response.body();
433+
434+
if (body && body.length) {
435+
ctx.log.debug(`Caching asset ${assetUrl}`);
436+
cache[assetUrl] = {
437+
body: body.toString('base64'),
438+
type: response.headers()['content-type']
439+
};
440+
} else {
441+
ctx.log.debug(`Asset ${assetUrl} returned empty or invalid body`);
442+
}
443+
} catch (error) {
444+
if (error && error.message) {
445+
ctx.log.debug(`Error fetching asset with error message ${assetUrl}: ${error.message}`);
446+
}
447+
ctx.log.debug(`Error fetching asset ${assetUrl}: ${JSON.stringify(error)}`);
448+
}
449+
} else {
450+
ctx.log.debug(`Asset ${assetUrl} already cached`);
451+
}
452+
}
453+
}
454+
420455
// snapshot options
421456
if (processedOptions.element) {
422457
let l = await page.locator(processedOptions.element).all()
@@ -506,6 +541,18 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
506541
discoveryErrors.timestamp = new Date().toISOString();
507542
// ctx.log.warn(discoveryErrors);
508543
}
544+
545+
if (ctx.config.useGlobalCache) {
546+
const keys = globalCache.keys();
547+
keys.forEach((key) => {
548+
if (!(key in cache)) {
549+
const globalCacheData = globalCache.get(key);
550+
if (globalCacheData) {
551+
cache[key] = globalCacheData;
552+
}
553+
}
554+
});
555+
}
509556
return {
510557
processedSnapshot: {
511558
name: snapshot.name,

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/lib/screenshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function captureScreenshotsForConfig(
2121
let beforeSnapshotScript = execute?.beforeSnapshot;
2222
let waitUntilEvent = pageEvent || process.env.SMARTUI_PAGE_WAIT_UNTIL_EVENT || 'load';
2323

24-
let pageOptions = { waitUntil: waitUntilEvent, timeout: ctx.config.waitForPageRender || constants.DEFAULT_PAGE_LOAD_TIMEOUT };
24+
let pageOptions = { waitUntil: waitUntilEvent, timeout: ctx.config.waitForPageRender || constants.DEFAULT_PAGE_LOAD_TIMEOUT};
2525
ctx.log.debug(`url: ${url} pageOptions: ${JSON.stringify(pageOptions)}`);
2626
let ssId = name.toLowerCase().replace(/\s/g, '_');
2727
let context: BrowserContext;

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)