Skip to content

Commit

Permalink
Merge pull request #124 from pinanks/DOT-3550
Browse files Browse the repository at this point in the history
Release v4.0.3
  • Loading branch information
sushobhit-lt authored Sep 16, 2024
2 parents 8222a65 + fa997c2 commit bc1a5d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lambdatest/smartui-cli",
"version": "4.0.2",
"version": "4.0.3",
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
"files": [
"dist/**/*"
Expand Down
22 changes: 15 additions & 7 deletions src/lib/processSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
await page.route('**/*', async (route, request) => {
const requestUrl = request.url()
const requestHostname = new URL(requestUrl).hostname;
let requestOptions: Record<string, any> = { timeout: REQUEST_TIMEOUT }

try {
// abort audio/video media requests
Expand All @@ -136,11 +137,7 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
// handle discovery config
ctx.config.allowedHostnames.push(new URL(snapshot.url).hostname);
if (ctx.config.enableJavaScript) ALLOWED_RESOURCES.push('script');

let requestOptions: Record<string, any> = {
timeout: REQUEST_TIMEOUT
}
if (requestUrl === snapshot.url && ctx.config.basicAuthorization ) {
if (ctx.config.basicAuthorization) {
ctx.log.debug(`Adding basic authorization to the headers for root url`);
let token = Buffer.from(`${ctx.config.basicAuthorization.username}:${ctx.config.basicAuthorization.password}`).toString('base64');
requestOptions.headers = {
Expand All @@ -149,9 +146,20 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise<Record
};
}

const response = await page.request.fetch(request, { timeout: REQUEST_TIMEOUT });
const body = await response.body();
// get response
let response, body;
if (requestUrl === snapshot.url) {
response = {
status: () => 200,
headers: () => ({ 'content-type': 'text/html' })
}
body = snapshot.dom.html
} else {
response = await page.request.fetch(request, requestOptions);
body = await response.body();
}

// handle response
if (!body) {
ctx.log.debug(`Handling request ${requestUrl}\n - skipping no response`);
} else if (!body.length) {
Expand Down

0 comments on commit bc1a5d3

Please sign in to comment.