diff --git a/lib/config.js b/lib/config.js index 3d3f4977a..50aace226 100644 --- a/lib/config.js +++ b/lib/config.js @@ -14,14 +14,14 @@ const defaultConfig = { : false, criConnectionRetries: process.env.TAIKO_CRI_CONNECTION_RETRIES || 50, firefox: - (process.env.TAIKO_BROWSER_PATH?.toLowerCase().includes("firefox")) || - false, - highlightOnAction: - process.env.TAIKO_BROWSER_PATH?.toLowerCase().includes("firefox") - ? false - : process.env.TAIKO_HIGHLIGHT_ON_ACTION - ? process.env.TAIKO_HIGHLIGHT_ON_ACTION.toLowerCase() === "true" - : true, + process.env.TAIKO_BROWSER_PATH?.toLowerCase().includes("firefox") || false, + highlightOnAction: process.env.TAIKO_BROWSER_PATH?.toLowerCase().includes( + "firefox", + ) + ? false + : process.env.TAIKO_HIGHLIGHT_ON_ACTION + ? process.env.TAIKO_HIGHLIGHT_ON_ACTION.toLowerCase() === "true" + : true, blockAlignment: "nearest", inlineAlignment: "nearest", useHostName: false, @@ -33,7 +33,7 @@ const setConfig = (options) => { if (typeof defaultConfig[key] !== typeof options[key]) { throw new Error( `Invalid value for ${key}. Expected ${typeof defaultConfig[ - key + key ]} received ${typeof options[key]}`, ); } diff --git a/lib/elementSearch.js b/lib/elementSearch.js index 3dfbe6955..ad5c0fe98 100644 --- a/lib/elementSearch.js +++ b/lib/elementSearch.js @@ -76,8 +76,8 @@ function match(text, options = {}, ...args) { nodeFilter, ); - const exactMatches = [], - containsMatches = []; + const exactMatches = []; + const containsMatches = []; function checkIfRegexMatch(text, searchText, exactMatch) { return exactMatch @@ -141,7 +141,8 @@ function match(text, options = {}, ...args) { ) { exactMatches.push(node); continue; - } else if ( + } + if ( // Contains match of values and types !args.exactMatch && (checkIfRegexMatch(node.value, searchText, false) || @@ -218,16 +219,16 @@ const $$ = async (selector) => { const $$xpath = async (selector) => { logQuery(`xpath - ${selector}`); - var xpathFunc = (selector) => { - var result = []; - var nodesSnapshot = document.evaluate( + const xpathFunc = (selector) => { + const result = []; + const nodesSnapshot = document.evaluate( selector, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null, ); - for (var i = 0; i < nodesSnapshot.snapshotLength; i++) { + for (let i = 0; i < nodesSnapshot.snapshotLength; i++) { result.push(nodesSnapshot.snapshotItem(i)); } return result; @@ -284,9 +285,11 @@ const findElements = async (selector, tag) => { const elements = await (async () => { if (isString(selector)) { return match(selector).elements(tag); - } else if (isSelector(selector)) { + } + if (isSelector(selector)) { return selector.elements(); - } else if (isElement(selector)) { + } + if (isElement(selector)) { return [selector]; } return null; diff --git a/lib/eventBus.js b/lib/eventBus.js index 0758ce0b0..2b69260b9 100644 --- a/lib/eventBus.js +++ b/lib/eventBus.js @@ -1,5 +1,5 @@ -const EventEmitter = require("events"); -const util = require("util"); +const EventEmitter = require("node:events"); +const util = require("node:util"); const { removeQuotes, symbols } = require("../lib/util"); const eventHandler = new EventEmitter(); diff --git a/lib/helper.js b/lib/helper.js index 2c7b238a2..7907de36e 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -18,8 +18,8 @@ * Few modifications are done on the file. */ -const fs = require("fs"); -const path = require("path"); +const fs = require("node:fs"); +const path = require("node:path"); let projectRoot = null; const descEvent = require("./eventBus").descEvent; @@ -96,7 +96,7 @@ const isStrictObject = (obj) => (obj.constructor === Object || obj.constructor.name === "Object"); function wait(time) { - var promise = new Promise((resolve) => + const promise = new Promise((resolve) => setTimeout(() => { resolve(); }, time), @@ -116,8 +116,8 @@ const commandlineArgs = () => { }; const sleep = (milliseconds) => { - var start = new Date().getTime(); - for (var i = 0; i < 1e7; i++) { + const start = new Date().getTime(); + for (let i = 0; i < 1e7; i++) { if (new Date().getTime() - start > milliseconds) { break; } @@ -128,7 +128,7 @@ const waitUntil = async (condition, retryInterval, retryTimeout, message) => { if (!retryTimeout) { return; } - var start = new Date().getTime(); + const start = new Date().getTime(); while (true) { let actualError; try { @@ -154,20 +154,18 @@ const waitUntil = async (condition, retryInterval, retryTimeout, message) => { }; const xpath = (s) => - `concat(${ - s - .match(/[^'"]+|['"]/g) - .map((part) => { - if (part === "'") { - return '"\'"'; - } - if (part === '"') { - return "'\"'"; - } - return "'" + part + "'"; - }) - .join(",") + ', ""' - })`; + `concat(${`${s + .match(/[^'"]+|['"]/g) + .map((part) => { + if (part === "'") { + return '"\'"'; + } + if (part === '"') { + return "'\"'"; + } + return `'${part}'`; + }) + .join(",")}, ""`})`; const handleUrlRedirection = (url) => { if (url.substr(-1) === "/") { diff --git a/lib/install.js b/lib/install.js index 2b781ab48..87db8b74d 100644 --- a/lib/install.js +++ b/lib/install.js @@ -31,7 +31,7 @@ let lastDownloadedBytes = 0; * @return {!Promise} */ function onSuccess(localRevisions) { - console.log("Chromium downloaded to " + revisionInfo.folderPath); + console.log(`Chromium downloaded to ${revisionInfo.folderPath}`); localRevisions = localRevisions.filter( (revision) => revision !== revisionInfo.revision, ); diff --git a/lib/plugins.js b/lib/plugins.js index f8e38a5bd..4ba4e7e79 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -1,6 +1,6 @@ -const fs = require("fs"); -const childProcess = require("child_process"); -const path = require("path"); +const fs = require("node:fs"); +const childProcess = require("node:child_process"); +const path = require("node:path"); const pluginHooks = { preConnectionHook: (target, options) => { @@ -91,9 +91,7 @@ function filterExecutablePlugin(plugins, pluginsPath) { return plugins .filter((npmModule) => { const packageJson = getPackageJsonForPlugin(pluginsPath, npmModule); - return ( - packageJson.capability && packageJson.capability.includes("subcommands") - ); + return packageJson.capability?.includes("subcommands"); }) .reduce((plugins, plugin) => { plugins[plugin.replace(/^taiko-/, "")] = path.join(pluginsPath, plugin); diff --git a/lib/proximityElementSearch.js b/lib/proximityElementSearch.js index 799ba6cd2..7a7a72ab5 100644 --- a/lib/proximityElementSearch.js +++ b/lib/proximityElementSearch.js @@ -55,8 +55,8 @@ class RelativeSearchElement { } async validNodes(objectId) { - let matchingNode, - minDiff = Number.POSITIVE_INFINITY; + let matchingNode; + let minDiff = Number.POSITIVE_INFINITY; this.calculatedRects = this.calculatedRects.length ? this.calculatedRects : await this.findProximityElementRects(); diff --git a/lib/repl/repl.js b/lib/repl/repl.js index 17c9a2ea6..7030eb94b 100644 --- a/lib/repl/repl.js +++ b/lib/repl/repl.js @@ -351,7 +351,8 @@ function displayUsageFor(name) { if (e.returns) { e.returns.map((e) => { console.log( - `Returns: ${type(e.type)} ${e.description.type ? desc(e.description) : e.description + `Returns: ${type(e.type)} ${ + e.description.type ? desc(e.description) : e.description }${EOL}`, ); }); @@ -442,9 +443,10 @@ const params = (p) => { return p .map( (p) => - `* ${param(p)}${p.properties - ? p.properties.map((p) => ` * ${param(p)}`).join("") - : "" + `* ${param(p)}${ + p.properties + ? p.properties.map((p) => ` * ${param(p)}`).join("") + : "" }`, ) .join(""); diff --git a/lib/util.js b/lib/util.js index 31fcc15b8..a055ab7d3 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,9 +1,9 @@ -const isWin = require("os").platform() === "win32"; -const Module = require("module"); -const nodeURL = require("url"); -const path = require("path"); -const { spawnSync } = require("child_process"); -const { readFileSync, existsSync, realpathSync } = require("fs"); +const isWin = require("node:os").platform() === "win32"; +const Module = require("node:module"); +const nodeURL = require("node:url"); +const path = require("node:path"); +const { spawnSync } = require("node:child_process"); +const { readFileSync, existsSync, realpathSync } = require("node:fs"); module.exports.removeQuotes = (textWithQuotes, textWithoutQuotes) => { return textWithQuotes @@ -21,12 +21,12 @@ module.exports.isTaikoRunner = (path) => { try { if (!path.includes("taiko.js")) { const link = realpathSync(path); - return link && link.includes("taiko.js"); + return link?.includes("taiko.js"); } - return path && path.includes("taiko.js"); + return path?.includes("taiko.js"); } catch (e) { return Module._nodeModulePaths("taiko").some( - (val) => path === val + ".bin/taiko", + (val) => path === `${val}.bin/taiko`, ); } }; @@ -58,7 +58,7 @@ module.exports.isSameUrl = (url1, url2) => { }; module.exports.escapeHtml = (str) => { - var chars = { + const chars = { "&": "&", "<": "<", ">": ">", @@ -78,7 +78,7 @@ module.exports.taikoInstallationLocation = () => { } let installLocation = ""; const jsonData = JSON.parse(readFileSync(packageJSONFilePath, "utf-8")); - if (jsonData.dependencies && jsonData.dependencies.taiko) { + if (jsonData.dependencies?.taiko) { installLocation = path.join( spawnSync("npm", ["root"]).output[1].toString().trim(), "taiko",