From 052d9caba70cb5c8d9e25cb7a747ae7b4041400d Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Thu, 29 Aug 2024 14:09:13 +0100 Subject: [PATCH] Linting and formatting fixes for test files (#2739) * Fix type issues * Remove for each loops * Fix no assignment in expression * Ignore testing delete rules * Strongly type paramaters --------- 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 | 35 ++++++++-------- test/docs-tests/gauge/tests/selectors.ts | 5 ++- 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 | 10 ++--- test/functional-tests/tests/dropDown.ts | 2 +- test/functional-tests/tests/hooks.ts | 4 +- test/functional-tests/tests/htmlElementAPI.ts | 30 ++++++------- test/functional-tests/tests/pageActions.ts | 14 +++---- test/functional-tests/tests/selectors.ts | 5 ++- test/functional-tests/tests/server.js | 5 ++- .../types-test-support/generate-types-test.js | 22 +++++----- test/unit-tests/$.test.js | 29 +++++++------ .../actions/pageActionChecks.test.js | 28 ++++++------- test/unit-tests/beforeunload.test.js | 3 +- test/unit-tests/browserLauncher.test.js | 1 + test/unit-tests/checkbox.test.js | 42 +++++-------------- 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 | 12 +++--- test/unit-tests/cookies.test.js | 2 +- test/unit-tests/dropDown.test.js | 10 ++--- test/unit-tests/elementSearch.test.js | 9 ++-- test/unit-tests/elements/checkBox.test.js | 31 +++++++------- test/unit-tests/elements/dropDown.test.js | 36 ++++++++-------- .../unit-tests/elements/elementHelper.test.js | 22 +++++----- test/unit-tests/elements/radioButton.test.js | 31 +++++++------- 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 | 11 +++-- 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 | 15 ++++--- test/unit-tests/radioButton.test.js | 14 +++---- test/unit-tests/range.test.js | 10 ++--- 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 | 37 ++++++++-------- test/unit-tests/timeField.test.js | 15 +++---- test/unit-tests/util.test.js | 15 ++++--- test/unit-tests/visibility.test.js | 4 +- test/unit-tests/write.test.js | 6 ++- 58 files changed, 329 insertions(+), 321 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..f58d86bf6 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, @@ -40,8 +40,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", @@ -63,7 +63,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); @@ -99,7 +99,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); } @@ -111,17 +111,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)); } @@ -169,7 +169,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 }); } @@ -179,7 +179,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 }); }); @@ -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/gauge/tests/selectors.ts b/test/docs-tests/gauge/tests/selectors.ts index 00b9068bc..587d9ea60 100644 --- a/test/docs-tests/gauge/tests/selectors.ts +++ b/test/docs-tests/gauge/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: Required for testing 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; } 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..bb68e4655 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 ") @@ -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/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..f70648b6e 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, @@ -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 }); }); @@ -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() @@ -278,15 +278,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/functional-tests/tests/pageActions.ts b/test/functional-tests/tests/pageActions.ts index 0cddc9175..c16b73813 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 { @@ -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); } 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; } 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/actions/pageActionChecks.test.js b/test/unit-tests/actions/pageActionChecks.test.js index 268a942ff..777e47bc7 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, @@ -86,10 +83,9 @@ describe("pageActionChecks", () => { retryTimeout: 10, }); }); - afterEach( - () => - (pageActionChecks = rewire("../../../lib/actions/pageActionChecks")), - ); + afterEach(() => { + pageActionChecks = rewire("../../../lib/actions/pageActionChecks"); + }); it("should call checkActionable with default checks if not given", async () => { const defaultChecks = [ pageActionChecks.checksMap.visible, 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/browserLauncher.test.js b/test/unit-tests/browserLauncher.test.js index 8fd90d768..afa03d12c 100644 --- a/test/unit-tests/browserLauncher.test.js +++ b/test/unit-tests/browserLauncher.test.js @@ -28,6 +28,7 @@ describe("OpenBrowser", () => { "--test-arg3", ]; expect(testArgs).to.include.members(expectedArgs); + // biome-ignore lint: Required for testing delete process.env.TAIKO_BROWSER_ARGS; }); }); diff --git a/test/unit-tests/checkbox.test.js b/test/unit-tests/checkbox.test.js index 116111f68..b5e63cf31 100644 --- a/test/unit-tests/checkbox.test.js +++ b/test/unit-tests/checkbox.test.js @@ -28,20 +28,20 @@ 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; let filePath; before(async () => { - const innerHtml = - `` + - " " + - "
" + - `checkboxWithInlineLabel` + - `hiddenCheckbox` + - "" + - "

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

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

someCheckBox`; filePath = createHtml(innerHtml, test_name); await openBrowser(openBrowserArgs); await goto(filePath); @@ -182,15 +160,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..ebb516fff 100644 --- a/test/unit-tests/config.test.js +++ b/test/unit-tests/config.test.js @@ -2,13 +2,15 @@ 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); }); afterEach(() => { config = rewire("../../lib/config"); + config.setConfig(originalConfig); }); describe("Test setConfig", () => { describe("For invalid config name", () => { @@ -84,10 +86,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); - }); + } }); }); @@ -310,8 +312,4 @@ describe("Config tests", () => { expect(actualOptions).to.deep.equal(exceptedOptions); }); }); - - afterEach(() => { - config.setConfig(originalConfig); - }); }); 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..cb247519d 100644 --- a/test/unit-tests/dropDown.test.js +++ b/test/unit-tests/dropDown.test.js @@ -98,7 +98,7 @@ describe(test_name, () => { `
@@ -334,15 +334,15 @@ describe(test_name, () => { it("should emit events", async () => { await evaluate(() => { document.raisedEvents = []; - var dropDown = document.getElementById("select-one"); - ["input", "change"].forEach((ev) => { + const dropDown = document.getElementById("select-one"); + for (const ev of ["input", "change"]) { dropDown.addEventListener(ev, () => document.raisedEvents.push(ev)); - }); + } }); 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..678c035e6 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"); @@ -68,6 +68,7 @@ describe("CheckBox", () => { afterEach(() => { CheckBox = rewire("../../../lib/elements/checkBox"); dispatchedEvent = null; + // biome-ignore lint: Required for testing delete Object.prototype.checked; }); diff --git a/test/unit-tests/elements/dropDown.test.js b/test/unit-tests/elements/dropDown.test.js index 89e0211cc..f2e9f27fa 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); @@ -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/elements/elementHelper.test.js b/test/unit-tests/elements/elementHelper.test.js index 8394f7aa5..021202239 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 = () => { @@ -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; }); diff --git a/test/unit-tests/elements/radioButton.test.js b/test/unit-tests/elements/radioButton.test.js index 66f810cb1..31324cec5 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); @@ -66,6 +66,7 @@ describe("RadioButton", () => { afterEach(() => { RadioButton = rewire("../../../lib/elements/radioButton"); dispatchedEvent = null; + // biome-ignore lint: Required for testing delete Object.prototype.checked; }); 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..47474de4f 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"], @@ -65,9 +68,9 @@ describe("Fetch Handler", () => { }, ], ]; - headersAndHost.forEach((headerAndHost) => { + for (const headerAndHost of headersAndHost) { fetchHandler.setHTTPHeaders(headerAndHost[0], headerAndHost[1]); - }); + } }); it("should set appropriate headers for a host", () => { headersAndHost.forEach((headerAndHost, index) => { 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..6c5e88870 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, }; @@ -21,6 +21,7 @@ describe("Plugins", () => { } describe("With ENV variable", () => { afterEach(() => { + // biome-ignore lint: Required for testing delete process.env.TAIKO_PLUGIN; }); it("should give plugin name from ENV variable", () => { @@ -40,7 +41,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 +108,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 +130,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) { @@ -209,8 +210,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 {}; } diff --git a/test/unit-tests/radioButton.test.js b/test/unit-tests/radioButton.test.js index 6b10b0559..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 = `