From 85ab64fd92672c9c15bde9e1557552a9911f8a22 Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Wed, 28 Aug 2024 13:52:01 +0100 Subject: [PATCH 1/9] Default test lint fixes Signed-off-by: Zabil Cheriya Maliackal --- biome.jsonc | 1 - test/docs-tests/gauge/tests/assert.ts | 2 +- test/docs-tests/gauge/tests/hooks.ts | 4 +- test/docs-tests/gauge/tests/htmlElementAPI.ts | 17 ++++---- test/docs-tests/prepare.js | 6 +-- test/functional-tests/tests/alert.ts | 2 +- test/functional-tests/tests/assert.ts | 2 +- test/functional-tests/tests/browserAction.ts | 4 +- test/functional-tests/tests/dropDown.ts | 2 +- test/functional-tests/tests/hooks.ts | 4 +- test/functional-tests/tests/htmlElementAPI.ts | 8 ++-- test/functional-tests/tests/pageActions.ts | 6 +-- test/functional-tests/tests/server.js | 5 ++- .../types-test-support/generate-types-test.js | 22 +++++----- test/unit-tests/$.test.js | 29 +++++++------ test/unit-tests/beforeunload.test.js | 3 +- test/unit-tests/checkbox.test.js | 41 ++++--------------- test/unit-tests/clearIntercept.test.js | 5 ++- test/unit-tests/clientProxy.test.js | 2 +- test/unit-tests/closeTab.test.js | 6 ++- test/unit-tests/config.test.js | 3 +- test/unit-tests/cookies.test.js | 2 +- test/unit-tests/dropDown.test.js | 4 +- test/unit-tests/elementSearch.test.js | 9 ++-- test/unit-tests/elements/checkBox.test.js | 30 +++++++------- test/unit-tests/elements/dropDown.test.js | 24 +++++------ .../unit-tests/elements/elementHelper.test.js | 16 ++++---- test/unit-tests/elements/radioButton.test.js | 30 +++++++------- test/unit-tests/filefield.test.js | 2 +- test/unit-tests/goBack.test.js | 4 +- test/unit-tests/goto.test.js | 16 ++++---- test/unit-tests/handlers/domHandler.test.js | 6 +-- test/unit-tests/handlers/fetchHandler.test.js | 7 +++- test/unit-tests/handlers/inputHandler.test.js | 4 +- .../handlers/networkHandler.test.js | 5 ++- test/unit-tests/handlers/pageHandler.test.js | 2 +- .../unit-tests/handlers/targetHandler.test.js | 4 +- test/unit-tests/helper.test.js | 3 +- test/unit-tests/incognito.test.js | 3 +- test/unit-tests/intercept.test.js | 12 +++--- test/unit-tests/openBrowser.test.js | 4 +- test/unit-tests/openTab.test.js | 11 +++-- test/unit-tests/plugins.test.js | 12 +++--- test/unit-tests/radioButton.test.js | 4 +- test/unit-tests/range.test.js | 6 +-- test/unit-tests/screenshot.test.js | 4 +- test/unit-tests/switchTo.test.js | 3 +- test/unit-tests/taiko-test.js | 7 ++-- test/unit-tests/test-util.js | 15 +++---- test/unit-tests/textBox.test.js | 22 +++++----- test/unit-tests/timeField.test.js | 14 +++---- test/unit-tests/util.test.js | 15 ++++--- test/unit-tests/visibility.test.js | 4 +- test/unit-tests/write.test.js | 6 ++- 54 files changed, 243 insertions(+), 241 deletions(-) diff --git a/biome.jsonc b/biome.jsonc index d83a11215..bf68869d1 100644 --- a/biome.jsonc +++ b/biome.jsonc @@ -9,7 +9,6 @@ "reports", ".gauge", "examples", - "test", ".local-chromium", "types", "lib/api.json" diff --git a/test/docs-tests/gauge/tests/assert.ts b/test/docs-tests/gauge/tests/assert.ts index 4ccab7db2..fa1e61616 100644 --- a/test/docs-tests/gauge/tests/assert.ts +++ b/test/docs-tests/gauge/tests/assert.ts @@ -1,4 +1,4 @@ -const assert = require("assert"); +const assert = require("node:assert"); import { Step, type Table } from "gauge-ts"; import { below, evaluate, text, textBox, title, toLeftOf } from "taiko"; import { getElements } from "./selectors"; diff --git a/test/docs-tests/gauge/tests/hooks.ts b/test/docs-tests/gauge/tests/hooks.ts index 9f71aaf1b..7ba33a0a6 100644 --- a/test/docs-tests/gauge/tests/hooks.ts +++ b/test/docs-tests/gauge/tests/hooks.ts @@ -1,4 +1,4 @@ -import { basename, join } from "path"; +import { basename, join } from "node:path"; import { AfterScenario, AfterSuite, @@ -26,7 +26,7 @@ export default class Hooks { @CustomScreenshotWriter() public async takeScreenshot(): Promise { const fileName = join( - process.env["gauge_screenshots_dir"], + process.env.gauge_screenshots_dir, `screenshot${Date.now()}.png`, ); await screenshot({ path: fileName }); diff --git a/test/docs-tests/gauge/tests/htmlElementAPI.ts b/test/docs-tests/gauge/tests/htmlElementAPI.ts index a37ea47c9..d23cffc02 100644 --- a/test/docs-tests/gauge/tests/htmlElementAPI.ts +++ b/test/docs-tests/gauge/tests/htmlElementAPI.ts @@ -1,5 +1,5 @@ -import assert = require("assert"); -import _path = require("path"); +import assert = require("node:assert"); +import _path = require("node:path"); import { $, type DialogHandler, @@ -188,15 +188,14 @@ export default class HtmlElementAPI { @Step("Navigate to relative path ") public async navigateToPath(relativePath: string) { const absolutePath = _path.resolve(relativePath); - await goto("file:///" + absolutePath); + await goto(`file:///${absolutePath}`); } @Step("Navigate to relative API reference page for ") public async navigateToApiRefPage(functionName: string) { - const relativePath = - "../tmp/docs/_site/api/" + functionName + "/index.html"; + const relativePath = `../tmp/docs/_site/api/${functionName}/index.html`; const absolutePath = _path.resolve(relativePath); - await goto("file:///" + absolutePath); + await goto(`file:///${absolutePath}`); } @ContinueOnFailure() @@ -259,15 +258,15 @@ export default class HtmlElementAPI { } @Step("Navigate to relative path with timeout ms") - public async navigateToPathWithTimeout(path: string, timeout: any) { + public async navigateToPathWithTimeout(path: string, timeout: number) { const absolutePath = _path.resolve(path); - await goto("file:///" + absolutePath, { + await goto(`file:///${absolutePath}`, { navigationTimeout: timeout, }); } @Step("Navigate to with timeout ms") - public async navigateToURLWithTimeout(url: string, timeout: any) { + public async navigateToURLWithTimeout(url: string, timeout: number) { await goto(url, { navigationTimeout: timeout }); } diff --git a/test/docs-tests/prepare.js b/test/docs-tests/prepare.js index 84aacd3d9..e4f724756 100644 --- a/test/docs-tests/prepare.js +++ b/test/docs-tests/prepare.js @@ -2,9 +2,9 @@ const chai = require("chai"); // const expect = chai.expect; const chaiAsPromised = require("chai-as-promised"); chai.use(chaiAsPromised); -const fs = require("fs"); -const util = require("util"); -const path = require("path"); +const fs = require("node:fs"); +const util = require("node:util"); +const path = require("node:path"); const { jsDocToJson } = require("../../lib/documentation"); const _ncp = require("ncp").ncp; _ncp.limit = 16; diff --git a/test/functional-tests/tests/alert.ts b/test/functional-tests/tests/alert.ts index 9821d1ba7..3dd57dfb7 100644 --- a/test/functional-tests/tests/alert.ts +++ b/test/functional-tests/tests/alert.ts @@ -1,7 +1,7 @@ // eslint-disable-next-line no-unused-vars import { type DataStore, DataStoreFactory, Step } from "gauge-ts"; import { accept, alert, prompt } from "taiko"; -const assert = require("assert"); +const assert = require("node:assert"); const scenarioStore: DataStore = DataStoreFactory.getSpecDataStore(); export default class Alert { diff --git a/test/functional-tests/tests/assert.ts b/test/functional-tests/tests/assert.ts index 226acf3fa..1a32b969e 100644 --- a/test/functional-tests/tests/assert.ts +++ b/test/functional-tests/tests/assert.ts @@ -1,4 +1,4 @@ -const assert = require("assert"); +const assert = require("node:assert"); import { Step, type Table } from "gauge-ts"; import { evaluate, text, textBox, title, toLeftOf } from "taiko"; import { getElements } from "./selectors"; diff --git a/test/functional-tests/tests/browserAction.ts b/test/functional-tests/tests/browserAction.ts index c4c161aad..a567f792f 100644 --- a/test/functional-tests/tests/browserAction.ts +++ b/test/functional-tests/tests/browserAction.ts @@ -15,7 +15,7 @@ import { setLocation, switchTo, } from "taiko"; -const assert = require("assert"); +const assert = require("node:assert"); const cwd = process.cwd(); export default class Assert { @@ -80,7 +80,7 @@ export default class Assert { @Step("Navigate to file with relative Path ") public async navigateToFileWithRelativePath(filePath: string) { - await goto("file:///" + cwd + filePath); + await goto(`file:///${cwd}${filePath}`); } @Step("Override browser permission with for site ") diff --git a/test/functional-tests/tests/dropDown.ts b/test/functional-tests/tests/dropDown.ts index 3a652a9ea..eb7c6af1e 100644 --- a/test/functional-tests/tests/dropDown.ts +++ b/test/functional-tests/tests/dropDown.ts @@ -1,4 +1,4 @@ -const assert = require("assert"); +const assert = require("node:assert"); import { getElements } from "./selectors"; import { Step, type Table } from "gauge-ts"; diff --git a/test/functional-tests/tests/hooks.ts b/test/functional-tests/tests/hooks.ts index 304162956..337dee684 100644 --- a/test/functional-tests/tests/hooks.ts +++ b/test/functional-tests/tests/hooks.ts @@ -1,4 +1,4 @@ -import { basename, join } from "path"; +import { basename, join } from "node:path"; import { AfterScenario, AfterSuite, @@ -37,7 +37,7 @@ export default class Hooks { @CustomScreenshotWriter() public async takeScreenshot(): Promise { const fileName = join( - process.env["gauge_screenshots_dir"], + process.env.gauge_screenshots_dir, `screenshot${Date.now()}.png`, ); await screenshot({ path: fileName }); diff --git a/test/functional-tests/tests/htmlElementAPI.ts b/test/functional-tests/tests/htmlElementAPI.ts index 669b29e76..81ab1ecbf 100644 --- a/test/functional-tests/tests/htmlElementAPI.ts +++ b/test/functional-tests/tests/htmlElementAPI.ts @@ -1,5 +1,5 @@ -import assert = require("assert"); -import _path = require("path"); +import assert = require("node:assert"); +import _path = require("node:path"); import { $, type DialogHandler, @@ -215,7 +215,7 @@ export default class HtmlElementAPI { @Step("Navigate to relative path ") public async navigateToPath(relativePath: string) { const absolutePath = _path.resolve(relativePath); - await goto("file:///" + absolutePath); + await goto(`file:///${absolutePath}`); } @ContinueOnFailure() @@ -280,7 +280,7 @@ export default class HtmlElementAPI { @Step("Navigate to relative path with timeout ms") public async navigateToPathWithTimeout(path: string, timeout: any) { const absolutePath = _path.resolve(path); - await goto("file:///" + absolutePath, { + await goto(`file:///${absolutePath}`, { navigationTimeout: timeout, }); } diff --git a/test/functional-tests/tests/pageActions.ts b/test/functional-tests/tests/pageActions.ts index 0cddc9175..ff3b077ca 100644 --- a/test/functional-tests/tests/pageActions.ts +++ b/test/functional-tests/tests/pageActions.ts @@ -1,5 +1,5 @@ import { getElements } from "./selectors"; -const assert = require("assert"); +const assert = require("node:assert"); import { $, type SearchElement, @@ -16,7 +16,7 @@ import { tap, toLeftOf, } from "taiko"; -const URL = require("url").URL; +const URL = require("node:url").URL; import { Step, type Table, type TableRow } from "gauge-ts"; export default class PageActions { @@ -88,7 +88,7 @@ export default class PageActions { @Step("Assert tap on screen") public async assertTapOnScreen() { - function getResult(): void {} + function getResult(): void { } const touch = await evaluate(() => getResult()); assert.deepEqual(touch, ["Touchstart: 0", "Touchend: 0"]); } diff --git a/test/functional-tests/tests/server.js b/test/functional-tests/tests/server.js index 7479fcb4d..1ce5b7fb6 100644 --- a/test/functional-tests/tests/server.js +++ b/test/functional-tests/tests/server.js @@ -1,9 +1,10 @@ const app = require("the-internet-express"); const express = require("express"); -const path = require("path"); +const path = require("node:path"); const fileApp = express(); -let ieServer, filesServer; +let ieServer; +let filesServer; fileApp.use("/", express.static(path.join(__dirname, "../specs/data"))); diff --git a/test/types-test-support/generate-types-test.js b/test/types-test-support/generate-types-test.js index 8aeabee25..1794fb58a 100644 --- a/test/types-test-support/generate-types-test.js +++ b/test/types-test-support/generate-types-test.js @@ -1,8 +1,8 @@ const taiko = require("../../lib/taiko"); const config = require("../../lib/config"); -const fs = require("fs"); -const path = require("path"); -const util = require("util"); +const fs = require("node:fs"); +const path = require("node:path"); +const util = require("node:util"); (async () => { /** @@ -47,7 +47,9 @@ const util = require("util"); (item) => item !== "emitter" && item !== "metadata", ); let result = ""; - funcs.sort().forEach(async (item) => (result += `taiko.${item};\n`)); + for (const item of funcs.sort()) { + result += `taiko.${item};\n`; + } result += "\n"; return result; } @@ -71,16 +73,12 @@ const util = require("util"); return str.charAt(0).toUpperCase() + str.slice(1); } const simpleName = typeName.replace(/\./, ""); - const functionName = "get" + firstToUpper(simpleName); - const constName = "c" + firstToUpper(simpleName); + const functionName = `get${firstToUpper(simpleName)}`; + const constName = `c${firstToUpper(simpleName)}`; return { functionName, constName }; } const { functionName, constName } = createNamesFromType(); - const result = - `export function ${functionName}(){\n` + - `const ${constName}: ${typeName} = ${JSON.stringify(literal)};\n` + - `return ${constName};\n` + - "}\n\n"; + const result = `export function ${functionName}(){\nconst ${constName}: ${typeName} = ${JSON.stringify(literal)};\nreturn ${constName};\n}\n\n`; return result; } return ( @@ -94,4 +92,4 @@ const util = require("util"); } } return await genTypeTestForTaiko(); -})().then((filePath) => console.log("Generated " + filePath)); +})().then((filePath) => console.log(`Generated ${filePath}`)); diff --git a/test/unit-tests/$.test.js b/test/unit-tests/$.test.js index b3d2f2bfa..f6d4adaa7 100644 --- a/test/unit-tests/$.test.js +++ b/test/unit-tests/$.test.js @@ -71,30 +71,33 @@ describe(test_name, () => { it("should construct elementWrapper from function returning Node", async () => { expect( await $(() => { - return document.querySelector('#foo'); + return document.querySelector("#foo"); }).exists(), ).to.be.true; }); it("should construct elementWrapper from function returning NodeList", async () => { expect( await $(() => { - return document.querySelectorAll('#foo'); + return document.querySelectorAll("#foo"); }).exists(), ).to.be.true; }); - it('should accept args to be passed to query function as an option', async () => { - expect(await $((selector) => document.querySelector(selector), { args: '#foo' }).exists()).to - .be.true; + it("should accept args to be passed to query function as an option", async () => { + expect( + await $((selector) => document.querySelector(selector), { + args: "#foo", + }).exists(), + ).to.be.true; }); it("should throw an error if the query function does not return a node or nodeList", async () => { - await expect($(() => { }).exists()).to.be.eventually.rejectedWith( + await expect($(() => {}).exists()).to.be.eventually.rejectedWith( "Query function should return a DOM Node or DOM NodeList", ); }); }); - describe('text with xpath', () => { - it('should find text with xpath', async () => { + describe("text with xpath", () => { + it("should find text with xpath", async () => { expect(await $("//*[text()='taiko']").exists()).to.be.true; }); @@ -104,11 +107,11 @@ describe(test_name, () => { ); }); - it('test text() with xpath', async () => { - expect(await $("//*[text()='taiko']").text()).to.be.eql('taiko'); + it("test text() with xpath", async () => { + expect(await $("//*[text()='taiko']").text()).to.be.eql("taiko"); }); - it('should return true for non hidden element when isVisible fn is called', async () => { + it("should return true for non hidden element when isVisible fn is called", async () => { expect(await $("//*[text()='taiko']").isVisible()).to.be.true; }); @@ -117,8 +120,8 @@ describe(test_name, () => { .rejected; }); - it('should return false for hidden element when isVisible fn is called on text', async () => { - expect(await $('#hidden').isVisible()).to.be.false; + it("should return false for hidden element when isVisible fn is called on text", async () => { + expect(await $("#hidden").isVisible()).to.be.false; }); }); diff --git a/test/unit-tests/beforeunload.test.js b/test/unit-tests/beforeunload.test.js index a9b500a35..d32e0fe4f 100644 --- a/test/unit-tests/beforeunload.test.js +++ b/test/unit-tests/beforeunload.test.js @@ -17,7 +17,8 @@ const { createHtml, removeFile, openBrowserArgs } = require("./test-util"); const test_name = "beforeunload"; describe(test_name, () => { - let filePath, filePath1; + let filePath; + let filePath1; let called = false; before(async () => { const innerHtml = ` diff --git a/test/unit-tests/checkbox.test.js b/test/unit-tests/checkbox.test.js index 116111f68..924d7cf6d 100644 --- a/test/unit-tests/checkbox.test.js +++ b/test/unit-tests/checkbox.test.js @@ -34,14 +34,13 @@ const inputTypeCaseSensitive = { let filePath; before(async () => { - const innerHtml = - `` + - " " + - "
" + - `checkboxWithInlineLabel` + - `hiddenCheckbox` + - "" + - "

" + - `` + - '' + - "

" + - '' + - "
" + - '' + - `someCheckBox` + - ""; +
checkboxWithInlineLabelhiddenCheckbox

someCheckBox`; filePath = createHtml(innerHtml, test_name); await openBrowser(openBrowserArgs); await goto(filePath); @@ -182,15 +159,15 @@ const inputTypeCaseSensitive = { it("should emit events", async () => { await evaluate(() => { document.raisedEvents = []; - var dropDown = document.getElementById("checkboxWithLabelFor"); - ["input", "change", "click"].forEach((ev) => { + const dropDown = document.getElementById("checkboxWithLabelFor"); + for (const ev of ["input", "change", "click"]) { dropDown.addEventListener(ev, () => document.raisedEvents.push(ev)); - }); + } }); await checkBox("checkboxWithLabelFor").check(); - var events = await evaluate(() => document.raisedEvents); + const events = await evaluate(() => document.raisedEvents); expect(events).to.eql(["change", "input", "click"]); }); }); diff --git a/test/unit-tests/clearIntercept.test.js b/test/unit-tests/clearIntercept.test.js index 6277bea8e..cdc7e55ea 100644 --- a/test/unit-tests/clearIntercept.test.js +++ b/test/unit-tests/clearIntercept.test.js @@ -1,9 +1,10 @@ const expect = require("chai").expect; -const { EventEmitter } = require("events"); +const { EventEmitter } = require("node:events"); const rewire = require("rewire"); describe("clearIntercept", () => { - let validateEmitterEvent, taiko; + let validateEmitterEvent; + let taiko; before(() => { taiko = rewire("../../lib/taiko"); }); diff --git a/test/unit-tests/clientProxy.test.js b/test/unit-tests/clientProxy.test.js index c5690d725..03f7b5af0 100644 --- a/test/unit-tests/clientProxy.test.js +++ b/test/unit-tests/clientProxy.test.js @@ -1,6 +1,6 @@ const chai = require("chai"); const expect = chai.expect; -const util = require("util"); +const util = require("node:util"); const { openBrowser, closeBrowser, client } = require("../../lib/taiko"); const { openBrowserArgs } = require("./test-util"); diff --git a/test/unit-tests/closeTab.test.js b/test/unit-tests/closeTab.test.js index d0179e047..c44ef2d8b 100644 --- a/test/unit-tests/closeTab.test.js +++ b/test/unit-tests/closeTab.test.js @@ -1,5 +1,5 @@ const expect = require("chai").expect; -const { EventEmitter } = require("events"); +const { EventEmitter } = require("node:events"); const rewire = require("rewire"); describe("closeTab", () => { @@ -10,7 +10,9 @@ describe("closeTab", () => { let _isMatchRegex = false; const _isMatchTarget = false; - let currentTarget, taiko, targetHandler; + let currentTarget; + let taiko; + let targetHandler; const descEmmitter = new EventEmitter(); const validateEmitterEvent = (event, expectedText) => diff --git a/test/unit-tests/config.test.js b/test/unit-tests/config.test.js index b7a92e108..7df698990 100644 --- a/test/unit-tests/config.test.js +++ b/test/unit-tests/config.test.js @@ -2,7 +2,8 @@ const expect = require("chai").expect; const rewire = require("rewire"); describe("Config tests", () => { - let config, originalConfig; + let config; + let originalConfig; beforeEach(() => { config = rewire("../../lib/config"); Object.assign({}, config.defaultConfig); diff --git a/test/unit-tests/cookies.test.js b/test/unit-tests/cookies.test.js index 383475f4b..b8793baab 100644 --- a/test/unit-tests/cookies.test.js +++ b/test/unit-tests/cookies.test.js @@ -33,7 +33,7 @@ describe(test_name, () => { const cookieName = "MySetCookie"; await expect( taiko.setCookie(cookieName, "Foo", { url: "file:///foo.html" }), - ).to.eventually.be.rejectedWith("Unable to set " + cookieName + " cookie"); + ).to.eventually.be.rejectedWith(`Unable to set ${cookieName} cookie`); }); it("setCookie should set successfully", async () => { diff --git a/test/unit-tests/dropDown.test.js b/test/unit-tests/dropDown.test.js index 8d52b0429..dec0cc966 100644 --- a/test/unit-tests/dropDown.test.js +++ b/test/unit-tests/dropDown.test.js @@ -334,7 +334,7 @@ describe(test_name, () => { it("should emit events", async () => { await evaluate(() => { document.raisedEvents = []; - var dropDown = document.getElementById("select-one"); + const dropDown = document.getElementById("select-one"); ["input", "change"].forEach((ev) => { dropDown.addEventListener(ev, () => document.raisedEvents.push(ev)); }); @@ -342,7 +342,7 @@ describe(test_name, () => { await dropDown("One").select("Hot Beverages"); - var events = await evaluate(() => document.raisedEvents); + const events = await evaluate(() => document.raisedEvents); expect(events).to.eql(["change", "input"]); }); }); diff --git a/test/unit-tests/elementSearch.test.js b/test/unit-tests/elementSearch.test.js index 537ab6769..d9d19b246 100644 --- a/test/unit-tests/elementSearch.test.js +++ b/test/unit-tests/elementSearch.test.js @@ -4,7 +4,9 @@ class DomRects {} const TEXT_NODE = 3; describe("Element Search", () => { - let Element, elementSearch, getIfExists; + let Element; + let elementSearch; + let getIfExists; before(() => { Element = rewire("../../lib/elements/element"); @@ -18,7 +20,8 @@ describe("Element Search", () => { }); describe("getIfExists", () => { - let findElementCallCount, originalWaitUntil; + let findElementCallCount; + let originalWaitUntil; const findElement = async () => { findElementCallCount++; return [{ id: 23 }]; @@ -47,7 +50,7 @@ describe("Element Search", () => { it("should try to find element after wait on unsuccessful finding", async () => { const findElement = async () => { findElementCallCount++; - const elements = findElementCallCount == 2 ? [{ id: 23 }] : []; + const elements = findElementCallCount === 2 ? [{ id: 23 }] : []; return elements; }; const elements = await getIfExists(findElement, "Element description")( diff --git a/test/unit-tests/elements/checkBox.test.js b/test/unit-tests/elements/checkBox.test.js index 958eb0bed..072b76f20 100644 --- a/test/unit-tests/elements/checkBox.test.js +++ b/test/unit-tests/elements/checkBox.test.js @@ -9,21 +9,21 @@ class Event { } describe("CheckBox", () => { - let nodes, - CheckBox, - dispatchedEvent = null, - runtimeHandler = { - async runtimeCallFunctionOn(predicate, contextId, options) { - return { - result: { - value: predicate.call(nodes[options.objectId], options.arg), - }, - }; - }, - async runtimeEvaluate(exp, executionContextId, opt = {}) { - return true; - }, - }; + let nodes; + let CheckBox; + let dispatchedEvent = null; + const runtimeHandler = { + async runtimeCallFunctionOn(predicate, contextId, options) { + return { + result: { + value: predicate.call(nodes[options.objectId], options.arg), + }, + }; + }, + async runtimeEvaluate(exp, executionContextId, opt = {}) { + return true; + }, + }; beforeEach(() => { CheckBox = rewire("../../../lib/elements/checkBox"); diff --git a/test/unit-tests/elements/dropDown.test.js b/test/unit-tests/elements/dropDown.test.js index 89e0211cc..9182e4dd6 100644 --- a/test/unit-tests/elements/dropDown.test.js +++ b/test/unit-tests/elements/dropDown.test.js @@ -10,18 +10,18 @@ class Event { } describe("DropDown", () => { - let nodes, - DropDown, - dispatchedEvents, - runtimeHandler = { - async runtimeCallFunctionOn(predicate, contextId, options) { - return { - result: { - value: predicate.call(nodes[options.objectId], options.arg), - }, - }; - }, - }; + let nodes; + let DropDown; + let dispatchedEvents; + const runtimeHandler = { + async runtimeCallFunctionOn(predicate, contextId, options) { + return { + result: { + value: predicate.call(nodes[options.objectId], options.arg), + }, + }; + }, + }; beforeEach(() => { DropDown = rewire("../../../lib/elements/dropDown"); DropDown.__set__("Event", Event); diff --git a/test/unit-tests/elements/elementHelper.test.js b/test/unit-tests/elements/elementHelper.test.js index 8394f7aa5..5477373ca 100644 --- a/test/unit-tests/elements/elementHelper.test.js +++ b/test/unit-tests/elements/elementHelper.test.js @@ -5,14 +5,14 @@ const Element = require("../../../lib/elements/element"); const { setConfig } = require("../../../lib/config"); describe("elementHelper", () => { - let boxModel, - highlightQuadArgs, - hideHighlightCalled, - warningMessage, - getBoxModelCalled, - actualConsole, - elemHelper, - highlightQuadCalled; + let boxModel; + let highlightQuadArgs; + let hideHighlightCalled; + let warningMessage; + let getBoxModelCalled; + let actualConsole; + let elemHelper; + let highlightQuadCalled; function createElement(id, isVisible) { const elem = new Element(id, ""); elem.isVisible = () => { diff --git a/test/unit-tests/elements/radioButton.test.js b/test/unit-tests/elements/radioButton.test.js index 66f810cb1..6f2223307 100644 --- a/test/unit-tests/elements/radioButton.test.js +++ b/test/unit-tests/elements/radioButton.test.js @@ -9,21 +9,21 @@ class Event { } describe("RadioButton", () => { - let nodes, - RadioButton, - dispatchedEvent = null, - runtimeHandler = { - async runtimeCallFunctionOn(predicate, contextId, options) { - return { - result: { - value: predicate.call(nodes[options.objectId], options.arg), - }, - }; - }, - async runtimeEvaluate(exp, executionContextId, opt = {}) { - return true; - }, - }; + let nodes; + let RadioButton; + let dispatchedEvent = null; + const runtimeHandler = { + async runtimeCallFunctionOn(predicate, contextId, options) { + return { + result: { + value: predicate.call(nodes[options.objectId], options.arg), + }, + }; + }, + async runtimeEvaluate(exp, executionContextId, opt = {}) { + return true; + }, + }; beforeEach(() => { RadioButton = rewire("../../../lib/elements/radioButton"); RadioButton.__set__("Event", Event); diff --git a/test/unit-tests/filefield.test.js b/test/unit-tests/filefield.test.js index 4e08c7b85..42c181711 100644 --- a/test/unit-tests/filefield.test.js +++ b/test/unit-tests/filefield.test.js @@ -19,7 +19,7 @@ const { openBrowserArgs, resetConfig, } = require("./test-util"); -const path = require("path"); +const path = require("node:path"); const test_name = "fileField"; describe(test_name, () => { diff --git a/test/unit-tests/goBack.test.js b/test/unit-tests/goBack.test.js index 4491dab3b..d9b23e1ee 100644 --- a/test/unit-tests/goBack.test.js +++ b/test/unit-tests/goBack.test.js @@ -5,8 +5,8 @@ const test_name = "goBack"; describe(test_name, () => { let taiko; - let actualHistoryEntryId, - actualOptions = null; + let actualHistoryEntryId; + let actualOptions = null; before(async () => { const mockWrapper = async (options, cb) => { diff --git a/test/unit-tests/goto.test.js b/test/unit-tests/goto.test.js index 5525fc3f4..f80b697df 100644 --- a/test/unit-tests/goto.test.js +++ b/test/unit-tests/goto.test.js @@ -3,12 +3,12 @@ const expect = require("chai").expect; const test_name = "Goto"; describe(test_name, () => { - let actualHeader, - actualDomain, - actualUrl, - actualOptions, - taiko, - validateCalled = false; + let actualHeader; + let actualDomain; + let actualUrl; + let actualOptions; + let taiko; + let validateCalled = false; before(() => { taiko = rewire("../../lib/taiko"); @@ -78,7 +78,7 @@ describe(test_name, () => { it("should add protocol http:// if not given", async () => { const urlWithoutProtocol = "example.com"; - const expectedUrl = "http://" + urlWithoutProtocol; + const expectedUrl = `http://${urlWithoutProtocol}`; await taiko.goto(urlWithoutProtocol); expect(actualUrl).to.equal(expectedUrl); }); @@ -92,7 +92,7 @@ describe(test_name, () => { it("should add protocol http:// for url with port specified", async () => { const urlWithPort = "localhost:8080"; - const expectedUrl = "http://" + urlWithPort; + const expectedUrl = `http://${urlWithPort}`; await taiko.goto(urlWithPort); expect(actualUrl).to.equal(expectedUrl); }); diff --git a/test/unit-tests/handlers/domHandler.test.js b/test/unit-tests/handlers/domHandler.test.js index e88067917..a3d1cecee 100644 --- a/test/unit-tests/handlers/domHandler.test.js +++ b/test/unit-tests/handlers/domHandler.test.js @@ -2,8 +2,8 @@ const rewire = require("rewire"); const expect = require("chai").expect; describe("domHandler", () => { - let calledWith = {}, - domHandler; + let calledWith = {}; + let domHandler; before(() => { domHandler = rewire("../../../lib/handlers/domHandler"); @@ -11,7 +11,7 @@ describe("domHandler", () => { domHandler.__set__("dom", { getContentQuads: async (param) => { calledWith = param; - if (param.objectId == 1) { + if (param.objectId === 1) { return { quads: [[0, 1, 2, 3, 4, 5, 6, 7]] }; } return { quads: [[8, 9, 10, 11, 12, 13, 14, 15]] }; diff --git a/test/unit-tests/handlers/fetchHandler.test.js b/test/unit-tests/handlers/fetchHandler.test.js index ea7887625..e4425a27e 100644 --- a/test/unit-tests/handlers/fetchHandler.test.js +++ b/test/unit-tests/handlers/fetchHandler.test.js @@ -5,7 +5,9 @@ const chaiAsPromissed = require("chai-as-promised"); chai.use(chaiAsPromissed); describe("Fetch Handler", () => { - let requestInterceptor, continueInterceptedRequestOptions, fetchHandler; + let requestInterceptor; + let continueInterceptedRequestOptions; + let fetchHandler; before(() => { fetchHandler = rewire("../../../lib/handlers/fetchHandler"); @@ -38,7 +40,8 @@ describe("Fetch Handler", () => { }); describe("http headers", () => { - let headersAndHost, expectedHeaders; + let headersAndHost; + let expectedHeaders; before(() => { headersAndHost = [ [{ header1: "header1 value" }, "https://example.com"], diff --git a/test/unit-tests/handlers/inputHandler.test.js b/test/unit-tests/handlers/inputHandler.test.js index 83031672a..8b46f1600 100644 --- a/test/unit-tests/handlers/inputHandler.test.js +++ b/test/unit-tests/handlers/inputHandler.test.js @@ -2,8 +2,8 @@ const rewire = require("rewire"); const expect = require("chai").expect; describe("inputHandler", () => { - let calledWith = [], - inputHandler; + let calledWith = []; + let inputHandler; before(() => { inputHandler = rewire("../../../lib/handlers/inputHandler"); diff --git a/test/unit-tests/handlers/networkHandler.test.js b/test/unit-tests/handlers/networkHandler.test.js index e3e00e5e2..9e764fb99 100644 --- a/test/unit-tests/handlers/networkHandler.test.js +++ b/test/unit-tests/handlers/networkHandler.test.js @@ -6,11 +6,12 @@ chai.use(chaiAsPromissed); const test_name = "Network Handler"; describe(test_name, () => { - let actualNetworkCondition, networkHandler; + let actualNetworkCondition; + let networkHandler; before(() => { networkHandler = rewire("../../../lib/handlers/networkHandler"); - delete process.env.TAIKO_EMULATE_NETWORK; + process.env.TAIKO_EMULATE_NETWORK = undefined; const network = { requestWillBeSent: () => {}, loadingFinished: () => {}, diff --git a/test/unit-tests/handlers/pageHandler.test.js b/test/unit-tests/handlers/pageHandler.test.js index 1ef17a30b..c8e1c56eb 100644 --- a/test/unit-tests/handlers/pageHandler.test.js +++ b/test/unit-tests/handlers/pageHandler.test.js @@ -1,5 +1,5 @@ const rewire = require("rewire"); -const EventEmitter = require("events").EventEmitter; +const EventEmitter = require("node:events").EventEmitter; const expect = require("chai").expect; describe("pageHandler", () => { diff --git a/test/unit-tests/handlers/targetHandler.test.js b/test/unit-tests/handlers/targetHandler.test.js index b28beb793..4ae638223 100644 --- a/test/unit-tests/handlers/targetHandler.test.js +++ b/test/unit-tests/handlers/targetHandler.test.js @@ -3,8 +3,8 @@ const rewire = require("rewire"); describe("TargetHandler", () => { describe(".getCriTargets", () => { - let _targets = [], - targetHandler; + let _targets = []; + let targetHandler; before(() => { targetHandler = rewire("../../../lib/handlers/targetHandler"); diff --git a/test/unit-tests/helper.test.js b/test/unit-tests/helper.test.js index 9dbe8d05d..b4e688d87 100644 --- a/test/unit-tests/helper.test.js +++ b/test/unit-tests/helper.test.js @@ -6,7 +6,8 @@ const { waitUntil } = require("../../lib/helper"); describe("Helper", () => { describe("waitUntil", () => { - let callCount, maxCallCOunt; + let callCount; + let maxCallCOunt; const condition = async () => { if (callCount === maxCallCOunt) { return true; diff --git a/test/unit-tests/incognito.test.js b/test/unit-tests/incognito.test.js index cfc5a7d5b..37ebedd71 100644 --- a/test/unit-tests/incognito.test.js +++ b/test/unit-tests/incognito.test.js @@ -18,7 +18,8 @@ const { openBrowserArgs, resetConfig } = require("./test-util"); const { createHtml, removeFile } = require("./test-util"); describe("Browser Context", () => { - let url1, url2; + let url1; + let url2; before(async () => { await openBrowser(openBrowserArgs); setConfig({ diff --git a/test/unit-tests/intercept.test.js b/test/unit-tests/intercept.test.js index 73e408ba8..f104cb7fe 100644 --- a/test/unit-tests/intercept.test.js +++ b/test/unit-tests/intercept.test.js @@ -159,7 +159,7 @@ describe(test_name, () => { }); it("intercepts requestUrl", async () => { - for (var i = 0; i < count + 1; i++) { + for (let i = 0; i < count + 1; i++) { fetchHandler.handleInterceptor({ requestId: "requestId", request: { @@ -169,13 +169,13 @@ describe(test_name, () => { resourceType: "Document", isNavigationRequest: true, }); - var result = count === i ? undefined : "http://www.gauge.org"; + const result = count === i ? undefined : "http://www.gauge.org"; expect(actualOption.url).to.equal(result); } }); it("maintains count amidst interleaving matched requests", async () => { - for (var i = 0; i < count + 1; i++) { + for (let i = 0; i < count + 1; i++) { fetchHandler.handleInterceptor({ requestId: "otherRequestId", request: { @@ -194,7 +194,7 @@ describe(test_name, () => { resourceType: "Document", isNavigationRequest: true, }); - var result = count === i ? undefined : "http://www.gauge.org"; + const result = count === i ? undefined : "http://www.gauge.org"; expect(actualOption.url).to.equal(result); } }); @@ -205,7 +205,7 @@ describe(test_name, () => { requestUrl: "www.google.com", action: "www.gauge.org", }); - var result = fetchHandler.resetInterceptor("www.google.com"); + const result = fetchHandler.resetInterceptor("www.google.com"); fetchHandler.handleInterceptor({ requestId: "requestId", request: { @@ -219,7 +219,7 @@ describe(test_name, () => { expect(result).to.equal(true); }); it("reset intercept returns false if intercept does not exist for the requestUrl", async () => { - var result = fetchHandler.resetInterceptor("www.google.com"); + const result = fetchHandler.resetInterceptor("www.google.com"); expect(result).to.equal(false); }); it("reset interceptors should set interceptors empty array and userEnabledIntercept false", async () => { diff --git a/test/unit-tests/openBrowser.test.js b/test/unit-tests/openBrowser.test.js index b70c82101..1c29bb3fa 100644 --- a/test/unit-tests/openBrowser.test.js +++ b/test/unit-tests/openBrowser.test.js @@ -4,7 +4,9 @@ const rewire = require("rewire"); const { openBrowserArgs } = require("./test-util"); describe("OpenBrowser", () => { - let taiko, openBrowser, closeBrowser; + let taiko; + let openBrowser; + let closeBrowser; before(() => { taiko = rewire("../../lib/taiko"); openBrowser = taiko.openBrowser; diff --git a/test/unit-tests/openTab.test.js b/test/unit-tests/openTab.test.js index 5a21d68f6..c5395dac6 100644 --- a/test/unit-tests/openTab.test.js +++ b/test/unit-tests/openTab.test.js @@ -1,10 +1,13 @@ const expect = require("chai").expect; -const { EventEmitter } = require("events"); +const { EventEmitter } = require("node:events"); const rewire = require("rewire"); -const { fail } = require("assert"); +const { fail } = require("node:assert"); describe("openTab", () => { - let actualTarget, actualOptions, actualUrl, taiko; + let actualTarget; + let actualOptions; + let actualUrl; + let taiko; const target = "TARGET"; before(async () => { @@ -73,7 +76,7 @@ describe("openTab", () => { it("should add protocol http:// if not given", async () => { const expectedUrl = "gauge.org"; await taiko.openTab(expectedUrl); - expect(actualUrl).to.equal("http://" + expectedUrl); + expect(actualUrl).to.equal(`http://${expectedUrl}`); }); it("should call doActionAwaitingNavigation with default options if options not given", async () => { diff --git a/test/unit-tests/plugins.test.js b/test/unit-tests/plugins.test.js index a2084de61..1444228b9 100644 --- a/test/unit-tests/plugins.test.js +++ b/test/unit-tests/plugins.test.js @@ -1,7 +1,7 @@ const expect = require("chai").expect; const rewire = require("rewire"); -const path = require("path"); -const os = require("os"); +const path = require("node:path"); +const os = require("node:os"); describe("Plugins", () => { let PLUGINS; @@ -13,7 +13,7 @@ describe("Plugins", () => { }); describe("GetPlugins", () => { function mockReadFileSyncWith(content) { - var fsMock = { + const fsMock = { readFileSync: () => content, existsSync: () => true, }; @@ -40,7 +40,7 @@ describe("Plugins", () => { describe("Get plugins from package.json", () => { it("should give empty array if there is no package.json", () => { - var fsMock = { + const fsMock = { existsSync: () => false, }; PLUGINS.__set__("fs", fsMock); @@ -107,7 +107,7 @@ describe("Plugins", () => { it("should let plugins register to available hooks", () => { const expectedResult = "Value from hook"; PLUGINS.registerHooks({ preConnectionHook: () => expectedResult }); - const actualResult = PLUGINS.pluginHooks["preConnectionHook"](); + const actualResult = PLUGINS.pluginHooks.preConnectionHook(); expect(actualResult).to.equal(expectedResult); }); it("should throw error if plugins try to register unavailable hook", () => { @@ -129,7 +129,7 @@ describe("Plugins", () => { const simlinkedPath = path.join(tmpDir, "taiko-plugin-simlinked-path"); const globalPluginPath = path.join(tmpDir, "global", "taiko-plugin-path"); const localPluginPath = path.join(tmpDir, "local", "taiko-plugin-path"); - var fsMock = { + const fsMock = { existsSync: () => true, readdirSync: (path) => { if (path === globalPluginPath) { diff --git a/test/unit-tests/radioButton.test.js b/test/unit-tests/radioButton.test.js index 6b10b0559..0c25a5ab5 100644 --- a/test/unit-tests/radioButton.test.js +++ b/test/unit-tests/radioButton.test.js @@ -165,13 +165,13 @@ describe(test_name, () => { it("test select() triggers events", async () => { await evaluate(() => { document.raisedEvents = []; - var dropDown = document.getElementById("radioButtonWithLabelFor"); + const dropDown = document.getElementById("radioButtonWithLabelFor"); ["input", "change", "click"].forEach((ev) => { dropDown.addEventListener(ev, () => document.raisedEvents.push(ev)); }); }); await radioButton("radioButtonWithLabelFor").select(); - var events = await evaluate(() => document.raisedEvents); + const events = await evaluate(() => document.raisedEvents); expect(events).to.eql(["change", "input", "click"]); }); diff --git a/test/unit-tests/range.test.js b/test/unit-tests/range.test.js index bd94145de..f9d73c0aa 100644 --- a/test/unit-tests/range.test.js +++ b/test/unit-tests/range.test.js @@ -1,6 +1,6 @@ const chai = require("chai"); const expect = chai.expect; -var sinon = require("sinon"); +const sinon = require("sinon"); const { descEvent } = require("../../lib/eventBus"); const chaiAsPromised = require("chai-as-promised"); chai.use(chaiAsPromised); @@ -197,7 +197,7 @@ describe("Range test", () => { it("should emit events", async () => { await evaluate(() => { document.raisedEvents = []; - var range = document.getElementById("range-2"); + const range = document.getElementById("range-2"); ["input", "change"].forEach((ev) => { range.addEventListener(ev, () => document.raisedEvents.push(ev)); }); @@ -205,7 +205,7 @@ describe("Range test", () => { await range({ id: "range-2" }).select(110); - var events = await evaluate(() => document.raisedEvents); + const events = await evaluate(() => document.raisedEvents); expect(events).to.eql(["change", "input"]); }); diff --git a/test/unit-tests/screenshot.test.js b/test/unit-tests/screenshot.test.js index 001abcebf..71f68e729 100644 --- a/test/unit-tests/screenshot.test.js +++ b/test/unit-tests/screenshot.test.js @@ -15,8 +15,8 @@ const { openBrowserArgs, resetConfig, } = require("./test-util"); -const path = require("path"); -const fs = require("fs"); +const path = require("node:path"); +const fs = require("node:fs"); const test_name = "screenshot"; describe(test_name, () => { diff --git a/test/unit-tests/switchTo.test.js b/test/unit-tests/switchTo.test.js index 18de420ba..cb70bfa47 100644 --- a/test/unit-tests/switchTo.test.js +++ b/test/unit-tests/switchTo.test.js @@ -6,7 +6,8 @@ const rewire = require("rewire"); chai.use(chaiAsPromised); describe("switchTo", () => { - let argument, taiko; + let argument; + let taiko; let registeredTarget; before(async () => { diff --git a/test/unit-tests/taiko-test.js b/test/unit-tests/taiko-test.js index d784b6004..18289dfc1 100644 --- a/test/unit-tests/taiko-test.js +++ b/test/unit-tests/taiko-test.js @@ -1,6 +1,6 @@ -const assert = require("assert"); +const assert = require("node:assert"); const taiko = require("../../lib/taiko"); -const util = require("util"); +const util = require("node:util"); const { removeQuotes, symbols } = require("../../lib/util"); (() => { @@ -10,8 +10,7 @@ const { removeQuotes, symbols } = require("../../lib/util"); .apply(["metadata"], Object.values(taiko.metadata)) .filter((item) => item !== "repl"); assert.deepEqual(allFuncs.sort(), funcsInMetadata.sort()); - const description = - symbols.pass + "All the exported functions are present in metadata"; + const description = `${symbols.pass}All the exported functions are present in metadata`; console.log( removeQuotes(util.inspect(description, { colors: true }), description), ); diff --git a/test/unit-tests/test-util.js b/test/unit-tests/test-util.js index c189afd30..d3eec6c53 100644 --- a/test/unit-tests/test-util.js +++ b/test/unit-tests/test-util.js @@ -1,6 +1,6 @@ -const path = require("path"); -const { writeFileSync, unlinkSync, existsSync } = require("fs"); -const { pathToFileURL, fileURLToPath } = require("url"); +const path = require("node:path"); +const { writeFileSync, unlinkSync, existsSync } = require("node:fs"); +const { pathToFileURL, fileURLToPath } = require("node:url"); const { setConfig } = require("../../lib/taiko"); module.exports.createHtml = (innerHtml, testName) => { @@ -9,7 +9,7 @@ module.exports.createHtml = (innerHtml, testName) => { "test", "unit-tests", "data", - testName + ".html", + `${testName}.html`, ); const content = ` @@ -27,12 +27,13 @@ module.exports.createHtml = (innerHtml, testName) => { }; module.exports.removeFile = (filePath) => { + let _filePath = filePath; try { - filePath = fileURLToPath(filePath); + _filePath = fileURLToPath(filePath); } catch (e) { } finally { - if (existsSync(filePath)) { - unlinkSync(filePath); + if (existsSync(_filePath)) { + unlinkSync(_filePath); } } }; diff --git a/test/unit-tests/textBox.test.js b/test/unit-tests/textBox.test.js index 3aed00926..3d41851d0 100644 --- a/test/unit-tests/textBox.test.js +++ b/test/unit-tests/textBox.test.js @@ -382,7 +382,7 @@ describe(test_name, () => { }); }); - var inputTypes = [ + const inputTypes = [ { type: "text", name: "inputType-text", @@ -418,16 +418,16 @@ describe(test_name, () => { function toInputTypeCaseSensitive(inputType) { const type = inputType.type.toUpperCase(); - const name = "inputType-" + type; + const name = `inputType-${type}`; return Object.assign({}, inputType, { type: type, name: name }); } - var inputTypesCaseSensitive = inputTypes.map(toInputTypeCaseSensitive); + const inputTypesCaseSensitive = inputTypes.map(toInputTypeCaseSensitive); - var inputTypesToTest = inputTypes.concat(inputTypesCaseSensitive); + const inputTypesToTest = inputTypes.concat(inputTypesCaseSensitive); inputTypesToTest.forEach((inputType) => { - describe("input with type " + inputType.type, () => { + describe(`input with type ${inputType.type}`, () => { let filePath; before(async () => { const innerHtml = ` @@ -529,7 +529,7 @@ describe(test_name, () => { it("test exists()", async () => { expect( await textBox({ - id: inputType.name + "WithLabelFor", + id: `${inputType.name}WithLabelFor`, }).exists(), ).to.be.true; }); @@ -537,7 +537,7 @@ describe(test_name, () => { it("test value()", async () => { expect( await textBox({ - id: inputType.name + "WithLabelFor", + id: `${inputType.name}WithLabelFor`, }).value(), ).to.equal(inputType.testValue); }); @@ -545,7 +545,7 @@ describe(test_name, () => { it("test description", async () => { expect( textBox({ - id: inputType.name + "WithLabelFor", + id: `${inputType.name}WithLabelFor`, }).description, ).to.be.eql(`TextBox[id="inputType-${inputType.type}WithLabelFor"]`); }); @@ -702,7 +702,7 @@ describe(test_name, () => { it("test exists()", async () => { expect( await textBox({ - id: inputTypeName + "WithLabelFor", + id: `${inputTypeName}WithLabelFor`, }).exists(), ).to.be.true; }); @@ -710,7 +710,7 @@ describe(test_name, () => { it("test value()", async () => { expect( await textBox({ - id: inputTypeName + "WithLabelFor", + id: `${inputTypeName}WithLabelFor`, }).value(), ).to.equal(inputValue); }); @@ -718,7 +718,7 @@ describe(test_name, () => { it("test description", async () => { expect( textBox({ - id: inputTypeName + "WithLabelFor", + id: `${inputTypeName}WithLabelFor`, }).description, ).to.be.eql('TextBox[id="input-without-typeWithLabelFor"]'); }); diff --git a/test/unit-tests/timeField.test.js b/test/unit-tests/timeField.test.js index 1d3d6f95b..8921e4976 100644 --- a/test/unit-tests/timeField.test.js +++ b/test/unit-tests/timeField.test.js @@ -48,7 +48,7 @@ describe(test_name, () => { return date; }; - var inputTypes = [ + const inputTypes = [ { type: "date", name: "inputType-date", @@ -107,7 +107,7 @@ describe(test_name, () => { ]; inputTypes.forEach((inputType) => { - describe("input with type " + inputType.type, () => { + describe(`input with type ${inputType.type}`, () => { let filePath; before(async () => { const innerHtml = ` @@ -263,7 +263,7 @@ describe(test_name, () => { it("test exists()", async () => { expect( await timeField({ - id: inputType.name + "WithLabelFor", + id: `${inputType.name}WithLabelFor`, }).exists(), ).to.be.true; }); @@ -271,19 +271,19 @@ describe(test_name, () => { it("test value()", async () => { expect( await timeField({ - id: inputType.name + "WithLabelFor", + id: `${inputType.name}WithLabelFor`, }).value(), ).to.equal(inputType.testDefaultValue); }); it("test select()", async () => { await timeField({ - id: inputType.name + "WithLabelFor", + id: `${inputType.name}WithLabelFor`, }).select(inputType.testValue); expect( await timeField({ - id: inputType.name + "WithLabelFor", + id: `${inputType.name}WithLabelFor`, }).value(), ).to.equal(inputType.testActualValue); }); @@ -291,7 +291,7 @@ describe(test_name, () => { it("test description", async () => { expect( timeField({ - id: inputType.name + "WithLabelFor", + id: `${inputType.name}WithLabelFor`, }).description, ).to.be.eql( `TimeField[id="inputType-${inputType.type}WithLabelFor"]`, diff --git a/test/unit-tests/util.test.js b/test/unit-tests/util.test.js index 77367acee..7a9451943 100644 --- a/test/unit-tests/util.test.js +++ b/test/unit-tests/util.test.js @@ -1,11 +1,14 @@ const chai = require("chai"); -const path = require("path"); +const path = require("node:path"); const rewire = require("rewire"); const expect = chai.expect; const test_name = "util"; describe(test_name, () => { - let util, trimCharLeft, escapeHtml, taikoInstallationLocation; + let util; + let trimCharLeft; + let escapeHtml; + let taikoInstallationLocation; before(() => { util = rewire("../../lib/util"); trimCharLeft = util.trimCharLeft; @@ -42,10 +45,10 @@ describe(test_name, () => { }); describe("taikoInstallationLocation", () => { - let packageJSONExists = true, - packageJSONData, - globalPath, - localPath; + let packageJSONExists = true; + let packageJSONData; + let globalPath; + let localPath; before(() => { globalPath = path.join("path", "to", "taiko-global", "installation"); localPath = path.join("path", "to", "taiko-local", "installation"); diff --git a/test/unit-tests/visibility.test.js b/test/unit-tests/visibility.test.js index 04b4c3102..65852a94b 100644 --- a/test/unit-tests/visibility.test.js +++ b/test/unit-tests/visibility.test.js @@ -1,5 +1,5 @@ -const path = require("path"); -const { pathToFileURL } = require("url"); +const path = require("node:path"); +const { pathToFileURL } = require("node:url"); const { goto, openBrowser, diff --git a/test/unit-tests/write.test.js b/test/unit-tests/write.test.js index 23cb337d9..26e31fd55 100644 --- a/test/unit-tests/write.test.js +++ b/test/unit-tests/write.test.js @@ -1,7 +1,7 @@ const chai = require("chai"); const chaiAsPromised = require("chai-as-promised"); const rewire = require("rewire"); -const EventEmitter = require("events").EventEmitter; +const EventEmitter = require("node:events").EventEmitter; chai.use(chaiAsPromised); const expect = chai.expect; const { @@ -181,7 +181,9 @@ describe(test_name, () => { // separated from the rest because taiko needs to get rewired describe("write with hideText option", () => { - let filePath, actualEmmiter, taiko; + let filePath; + let actualEmmiter; + let taiko; const emitter = new EventEmitter(); const validateEmitterEvent = (event, expectedText) => From 3e08aac86b28100b8600e2878ebf9c57529f4f96 Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Wed, 28 Aug 2024 14:18:16 +0100 Subject: [PATCH 2/9] Fix type issues Signed-off-by: Zabil Cheriya Maliackal --- test/functional-tests/tests/browserAction.ts | 6 ++--- test/functional-tests/tests/htmlElementAPI.ts | 22 +++++++++---------- test/functional-tests/tests/pageActions.ts | 12 +++++----- test/functional-tests/tests/selectors.ts | 5 +++-- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/test/functional-tests/tests/browserAction.ts b/test/functional-tests/tests/browserAction.ts index a567f792f..bb68e4655 100644 --- a/test/functional-tests/tests/browserAction.ts +++ b/test/functional-tests/tests/browserAction.ts @@ -98,7 +98,7 @@ export default class Assert { @Step("Assert location longitude as and latitude as ") public async function(longitude: string, latitude: string) { - const geolocation: any = await evaluate( + const geolocation = (await evaluate( () => new Promise((resolve) => navigator.geolocation.getCurrentPosition((position) => { @@ -108,7 +108,7 @@ export default class Assert { }); }), ), - ); + )) as { latitude: number; longitude: number }; assert.equal(geolocation.longitude, Number.parseFloat(longitude)); assert.equal(geolocation.latitude, Number.parseFloat(latitude)); } @@ -119,7 +119,7 @@ export default class Assert { } @Step("Assert width is and height is ") - public async assertWidthAndHeight(width: any, height: any) { + public async assertWidthAndHeight(width: number, height: number) { const innerWidth = await evaluate(() => window.innerWidth); const innerHeight = await evaluate(() => window.innerHeight); assert.equal(innerWidth, width); diff --git a/test/functional-tests/tests/htmlElementAPI.ts b/test/functional-tests/tests/htmlElementAPI.ts index 81ab1ecbf..f70648b6e 100644 --- a/test/functional-tests/tests/htmlElementAPI.ts +++ b/test/functional-tests/tests/htmlElementAPI.ts @@ -41,8 +41,8 @@ export default class HtmlElementAPI { @Step("Navigate to with basic auth and ") public async navigateWithBasicAuth( url: string, - username: any, - password: any, + username: string, + password: string, ) { const encodedCredentials = Buffer.from(`${username}:${password}`).toString( "base64", @@ -64,7 +64,7 @@ export default class HtmlElementAPI { public async selectDropDownValue( value: string | number, dropDownName: string, - fieldValue: any, + fieldValue: string, ) { const box = dropDown(dropDownName); await box.select(value); @@ -119,7 +119,7 @@ export default class HtmlElementAPI { } @Step("Get value of Text Box ") - public async getTextboxValue(text: any, textBoxName: string) { + public async getTextboxValue(text: string, textBoxName: string) { const field = textBox(textBoxName); assert.equal(await field.value(), text); } @@ -131,17 +131,17 @@ export default class HtmlElementAPI { } @Step("Write into Text Box ") - public async writeInto(text: string, textBoxName: any) { + public async writeInto(text: string, textBoxName: string) { await write(text, into(textBoxName)); } @Step("Write into TextBox with name ") - public async writeWithName(text: string, textBoxName: any) { + public async writeWithName(text: string, textBoxName: string) { await write(text, into(textBox({ name: textBoxName }))); } @Step("Write to Text Box ") - public async writeTo(text: string, textBoxName: any) { + public async writeTo(text: string, textBoxName: string) { await write(text, to(textBoxName)); } @@ -189,7 +189,7 @@ export default class HtmlElementAPI { } @Step("Respond to with ") - public async interceptResponse(url: string, responseBody: any) { + public async interceptResponse(url: string, responseBody: string) { await intercept(url, { body: responseBody }); } @@ -199,7 +199,7 @@ export default class HtmlElementAPI { } @Step("Intercept and continue with postData ") - public async interceptRequest(url: string, mockData: any) { + public async interceptRequest(url: string, mockData: string) { await intercept(url, (request) => { request.continue({ postData: mockData }); }); @@ -278,7 +278,7 @@ export default class HtmlElementAPI { } @Step("Navigate to relative path with timeout ms") - public async navigateToPathWithTimeout(path: string, timeout: any) { + public async navigateToPathWithTimeout(path: string, timeout: number) { const absolutePath = _path.resolve(path); await goto(`file:///${absolutePath}`, { navigationTimeout: timeout, @@ -286,7 +286,7 @@ export default class HtmlElementAPI { } @Step("Navigate to with timeout ms") - public async navigateToURLWithTimeout(url: string, timeout: any) { + public async navigateToURLWithTimeout(url: string, timeout: number) { await goto(url, { navigationTimeout: timeout }); } diff --git a/test/functional-tests/tests/pageActions.ts b/test/functional-tests/tests/pageActions.ts index ff3b077ca..c16b73813 100644 --- a/test/functional-tests/tests/pageActions.ts +++ b/test/functional-tests/tests/pageActions.ts @@ -55,28 +55,28 @@ export default class PageActions { public async dragSourceToDirection(source: string, directionTable: Table) { const direction = {}; - directionTable.getTableRows().forEach((row: TableRow) => { + for (const row of directionTable.getTableRows()) { direction[row.getCellValues()[0]] = Number.parseInt( row.getCellValues()[1], ); - }); + } await dragAndDrop($(source), direction); } @Step("Assert url host is ") - public async assertUrlOfHost(hostName: any) { + public async assertUrlOfHost(hostName: string) { const url = await currentURL(); assert.equal(new URL(url).hostname, hostName); } @Step("Assert page navigated back ") - public async assertPageNavigatedBack(hostName: any) { + public async assertPageNavigatedBack(hostName: string) { const url = await currentURL(); assert.equal(new URL(url).hostname, hostName); } @Step("Assert page navigated to ") - public async assertPageNavigatedToTarget(target: any) { + public async assertPageNavigatedToTarget(target: string) { const url = await currentURL(); assert.equal(new URL(url).pathname, target); } @@ -88,7 +88,7 @@ export default class PageActions { @Step("Assert tap on screen") public async assertTapOnScreen() { - function getResult(): void { } + function getResult(): void {} const touch = await evaluate(() => getResult()); assert.deepEqual(touch, ["Touchstart: 0", "Touchend: 0"]); } diff --git a/test/functional-tests/tests/selectors.ts b/test/functional-tests/tests/selectors.ts index 00b9068bc..8be4537fc 100644 --- a/test/functional-tests/tests/selectors.ts +++ b/test/functional-tests/tests/selectors.ts @@ -3,6 +3,7 @@ import { $, button, link, text, textBox } from "taiko"; function getElementWithSelector(element: string, selector: string) { let selectedElement = null; + // biome-ignore lint/suspicious/noImplicitAnyLet: let is used here to allow reassignment let selectedItem; try { selectedItem = JSON.parse(selector); @@ -32,10 +33,10 @@ function getElementWithSelector(element: string, selector: string) { export function getElements(table: Table) { const referenceElements = []; const headers = table.getColumnNames(); - table.getTableRows().forEach((row) => { + for (const row of table.getTableRows()) { referenceElements.push( getElementWithSelector(row.getCell(headers[0]), row.getCell(headers[1])), ); - }); + } return referenceElements; } From ea6711afd8a23d4740094ed01a7ec121b69fe3f7 Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Wed, 28 Aug 2024 14:24:03 +0100 Subject: [PATCH 3/9] Remove for each loops Signed-off-by: Zabil Cheriya Maliackal --- test/docs-tests/gauge/tests/selectors.ts | 4 ++-- test/unit-tests/checkbox.test.js | 1 + test/unit-tests/config.test.js | 4 ++-- test/unit-tests/dropDown.test.js | 6 +++--- test/unit-tests/elements/dropDown.test.js | 12 ++++++------ test/unit-tests/range.test.js | 4 ++-- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/test/docs-tests/gauge/tests/selectors.ts b/test/docs-tests/gauge/tests/selectors.ts index 00b9068bc..bcb165016 100644 --- a/test/docs-tests/gauge/tests/selectors.ts +++ b/test/docs-tests/gauge/tests/selectors.ts @@ -32,10 +32,10 @@ function getElementWithSelector(element: string, selector: string) { export function getElements(table: Table) { const referenceElements = []; const headers = table.getColumnNames(); - table.getTableRows().forEach((row) => { + for (const row of table.getTableRows()) { referenceElements.push( getElementWithSelector(row.getCell(headers[0]), row.getCell(headers[1])), ); - }); + } return referenceElements; } diff --git a/test/unit-tests/checkbox.test.js b/test/unit-tests/checkbox.test.js index 924d7cf6d..b5e63cf31 100644 --- a/test/unit-tests/checkbox.test.js +++ b/test/unit-tests/checkbox.test.js @@ -28,6 +28,7 @@ const inputTypeCaseSensitive = { testDescription: `${test_name} case insensitive selector`, }; +// biome-ignore lint/complexity/noForEach: No impact [inputType, inputTypeCaseSensitive].forEach((inputType) => describe(inputType.testDescription, () => { const type = inputType.type; diff --git a/test/unit-tests/config.test.js b/test/unit-tests/config.test.js index 7df698990..5a2c454b3 100644 --- a/test/unit-tests/config.test.js +++ b/test/unit-tests/config.test.js @@ -85,10 +85,10 @@ describe("Config tests", () => { it("should return the specified config", () => { const allowedConfig = Object.keys(config.defaultConfig); - allowedConfig.forEach((optionName) => { + for (const optionName of allowedConfig) { const optionValue = config.getConfig(optionName); expect(config.defaultConfig[optionName]).to.equal(optionValue); - }); + } }); }); diff --git a/test/unit-tests/dropDown.test.js b/test/unit-tests/dropDown.test.js index dec0cc966..cb247519d 100644 --- a/test/unit-tests/dropDown.test.js +++ b/test/unit-tests/dropDown.test.js @@ -98,7 +98,7 @@ describe(test_name, () => { `
@@ -335,9 +335,9 @@ describe(test_name, () => { await evaluate(() => { document.raisedEvents = []; const dropDown = document.getElementById("select-one"); - ["input", "change"].forEach((ev) => { + for (const ev of ["input", "change"]) { dropDown.addEventListener(ev, () => document.raisedEvents.push(ev)); - }); + } }); await dropDown("One").select("Hot Beverages"); diff --git a/test/unit-tests/elements/dropDown.test.js b/test/unit-tests/elements/dropDown.test.js index 9182e4dd6..f2e9f27fa 100644 --- a/test/unit-tests/elements/dropDown.test.js +++ b/test/unit-tests/elements/dropDown.test.js @@ -110,12 +110,12 @@ describe("DropDown", () => { await dropDown.select({ index: 2 }); expect(nodes[objectId].selectedIndex).to.be.equal(2); - dispatchedEvents.forEach((e) => { + for (const e of dispatchedEvents) { expect(e instanceof Event).to.be.true; expect(e.options).to.be.deep.equal({ bubbles: true, }); - }); + } expect(dispatchedEvents.map((x) => x.name)).to.eql(["change", "input"]); }); @@ -126,12 +126,12 @@ describe("DropDown", () => { await dropDown.select("26 value 2"); expect(nodes[objectId].selectedIndex).to.be.equal(2); - dispatchedEvents.forEach((e) => { + for (const e of dispatchedEvents) { expect(e instanceof Event).to.be.true; expect(e.options).to.be.deep.equal({ bubbles: true, }); - }); + } expect(dispatchedEvents.map((x) => x.name)).to.eql(["change", "input"]); }); @@ -142,12 +142,12 @@ describe("DropDown", () => { await dropDown.select("27 text 2"); expect(nodes[objectId].selectedIndex).to.be.equal(2); - dispatchedEvents.forEach((e) => { + for (const e of dispatchedEvents) { expect(e instanceof Event).to.be.true; expect(e.options).to.be.deep.equal({ bubbles: true, }); - }); + } expect(dispatchedEvents.map((x) => x.name)).to.eql(["change", "input"]); }); }); diff --git a/test/unit-tests/range.test.js b/test/unit-tests/range.test.js index f9d73c0aa..273ba0f74 100644 --- a/test/unit-tests/range.test.js +++ b/test/unit-tests/range.test.js @@ -198,9 +198,9 @@ describe("Range test", () => { await evaluate(() => { document.raisedEvents = []; const range = document.getElementById("range-2"); - ["input", "change"].forEach((ev) => { + for (const ev of ["input", "change"]) { range.addEventListener(ev, () => document.raisedEvents.push(ev)); - }); + } }); await range({ id: "range-2" }).select(110); From 34490e030480fe77e7838778fffad64ab3be9757 Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Wed, 28 Aug 2024 14:45:06 +0100 Subject: [PATCH 4/9] Fix no assignment in expression Signed-off-by: Zabil Cheriya Maliackal --- .../actions/pageActionChecks.test.js | 21 ++++++++----------- .../unit-tests/elements/elementHelper.test.js | 6 ++++-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/test/unit-tests/actions/pageActionChecks.test.js b/test/unit-tests/actions/pageActionChecks.test.js index 268a942ff..d87062a98 100644 --- a/test/unit-tests/actions/pageActionChecks.test.js +++ b/test/unit-tests/actions/pageActionChecks.test.js @@ -14,10 +14,9 @@ describe("pageActionChecks", () => { retryTimeout: 0, }); }); - afterEach( - () => - (pageActionChecks = rewire("../../../lib/actions/pageActionChecks")), - ); + afterEach(() => { + pageActionChecks = rewire("../../../lib/actions/pageActionChecks"); + }); it("should call elements isVisible method and return result", async () => { const elem = { isVisible: () => true }; const result = await pageActionChecks.__get__("checkVisible")(elem); @@ -31,10 +30,9 @@ describe("pageActionChecks", () => { retryTimeout: 0, }); }); - afterEach( - () => - (pageActionChecks = rewire("../../../lib/actions/pageActionChecks")), - ); + afterEach(() => { + pageActionChecks = rewire("../../../lib/actions/pageActionChecks"); + }); it("should call elements isDisabled method and return not of result", async () => { const elem = { isDisabled: () => false }; const result = await pageActionChecks.__get__("checkNotDisabled")(elem); @@ -48,10 +46,9 @@ describe("pageActionChecks", () => { retryTimeout: 0, }); }); - afterEach( - () => - (pageActionChecks = rewire("../../../lib/actions/pageActionChecks")), - ); + afterEach(() => { + pageActionChecks = rewire("../../../lib/actions/pageActionChecks"); + }); it("should check all given checks and return false if anyone is false", async () => { const checks = [ pageActionChecks.checksMap.visible, diff --git a/test/unit-tests/elements/elementHelper.test.js b/test/unit-tests/elements/elementHelper.test.js index 5477373ca..021202239 100644 --- a/test/unit-tests/elements/elementHelper.test.js +++ b/test/unit-tests/elements/elementHelper.test.js @@ -47,14 +47,16 @@ describe("elementHelper", () => { }); actualConsole = console; elemHelper.__set__("console", { - warn: (warning) => (warningMessage = warning), + warn: (warning) => { + warningMessage = warning; + }, }); setConfig({ highlightOnAction: true }); }); afterEach(() => { elemHelper = rewire("../../../lib/elements/elementHelper"); - // eslint-disable-next-line no-global-assign + // biome-ignore lint/suspicious/noGlobalAssign: Required for testing console = actualConsole; }); From 0f9a5e38224a4636bbadc83e286e2d7690f2a84b Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Wed, 28 Aug 2024 14:50:37 +0100 Subject: [PATCH 5/9] Ignore lint suggestion Signed-off-by: Zabil Cheriya Maliackal --- test/unit-tests/plugins.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unit-tests/plugins.test.js b/test/unit-tests/plugins.test.js index 1444228b9..6c4c64105 100644 --- a/test/unit-tests/plugins.test.js +++ b/test/unit-tests/plugins.test.js @@ -209,8 +209,10 @@ describe("Plugins", () => { ].includes(plugin) ) { return { capability: ["subcommands"] }; + // biome-ignore lint/style/noUselessElse: Needed for logic } else if (plugin === "taiko-plugin2") { return { capability: [] }; + // biome-ignore lint/style/noUselessElse: Needed for logic } else { return {}; } From 10813da91f3f0016d141fedaae14951b13aaf8e9 Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Wed, 28 Aug 2024 14:53:16 +0100 Subject: [PATCH 6/9] For loop lint Signed-off-by: Zabil Cheriya Maliackal --- test/unit-tests/radioButton.test.js | 10 +++++----- test/unit-tests/textBox.test.js | 15 ++++++++------- test/unit-tests/timeField.test.js | 1 + 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/test/unit-tests/radioButton.test.js b/test/unit-tests/radioButton.test.js index 0c25a5ab5..9358d628f 100644 --- a/test/unit-tests/radioButton.test.js +++ b/test/unit-tests/radioButton.test.js @@ -26,12 +26,12 @@ describe(test_name, () => { before(async () => { const innerHtml = `