Skip to content

Commit

Permalink
Merge pull request #51 from pinanks/DOT-2923-new
Browse files Browse the repository at this point in the history
Release v2.0.7
  • Loading branch information
sushobhit-lt authored Feb 20, 2024
2 parents 1076b0a + 124ab01 commit e1f4628
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 34 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": "2.0.6",
"version": "2.0.7",
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
"files": [
"dist/**/*"
Expand Down
13 changes: 6 additions & 7 deletions src/lib/schemaValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ const ajv = new Ajv({ allErrors: true });
ajv.addFormat('web-url', {
type: 'string',
validate: (url: string) => {
const urlPattern = new RegExp('^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
return urlPattern.test(url.trim());
try {
new URL(url.trim());
return true;
} catch (error) {
return false;
}
}
});
addErrors(ajv);
Expand Down
6 changes: 1 addition & 5 deletions src/lib/screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ export async function captureScreenshots(ctx: Context, screenshots: WebStaticCon
let screenshotId = screenshot.name.toLowerCase().replace(/\s/g, '-');

const page = await context.newPage();
if(screenshot.url){
screenshot.url = screenshot.url.trim();
screenshot.url = ensureHttps(screenshot.url)
}
await page.goto(screenshot.url, pageOptions);
await page.goto(screenshot.url.trim(), pageOptions);


for (let k = 0; k < totalViewports; k++) {
Expand Down
21 changes: 0 additions & 21 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
import fs from 'fs';

const HTTP_SCHEME = 'https:';
const HTTP_SCHEME_PREFIX = 'https://';
const WWW = 'www.';

export function delDir(dir: string): void {
if (fs.existsSync(dir)) {
fs.rmSync(dir, { recursive: true });
}
}

// Function to ensure URL uses HTTPS scheme
export function ensureHttps(urlString: string) {
try {
if (urlString && urlString.startsWith(WWW)) {
urlString = HTTP_SCHEME_PREFIX + urlString
}
let url = new URL(urlString);
if (url.protocol !== HTTP_SCHEME) {
url.protocol = HTTP_SCHEME;
}
return url.toString();
} catch (error) {
console.error('Invalid URL: '+urlString, error);
return null;
}
}

export function scrollToBottomAndBackToTop({
frequency = 100,
timing = 8,
Expand Down

0 comments on commit e1f4628

Please sign in to comment.