From feba91a9d9e1aa2b4e9022561397a291b05d552e Mon Sep 17 00:00:00 2001 From: DudaGod Date: Tue, 19 Dec 2023 12:06:37 +0300 Subject: [PATCH] fix: typings --- src/browser/commands/scrollIntoView.ts | 4 +--- src/browser/types.ts | 20 ++++++++++++++++++++ src/config/types.ts | 8 ++++++++ src/types/index.ts | 2 +- src/utils/worker-process.ts | 4 +++- typings/global.d.ts | 5 +++++ 6 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/browser/commands/scrollIntoView.ts b/src/browser/commands/scrollIntoView.ts index 389c39326..7146de881 100644 --- a/src/browser/commands/scrollIntoView.ts +++ b/src/browser/commands/scrollIntoView.ts @@ -1,6 +1,4 @@ -type Browser = { - publicAPI: WebdriverIO.Browser; -}; +import type { Browser } from "../types"; // TODO: remove after fix https://github.com/webdriverio/webdriverio/issues/9620 export = async (browser: Browser): Promise => { diff --git a/src/browser/types.ts b/src/browser/types.ts index 36b5ff8b1..d7e220e36 100644 --- a/src/browser/types.ts +++ b/src/browser/types.ts @@ -1,4 +1,6 @@ import type { AssertViewCommand, AssertViewElementCommand } from "./commands/types"; +import type { BrowserConfig } from "./../config/browser-config"; +import type { AssertViewResult, RunnerTest, RunnerHook } from "../types"; export interface BrowserMeta { pid: number; @@ -6,6 +8,13 @@ export interface BrowserMeta { [name: string]: unknown; } +export interface Browser { + publicAPI: WebdriverIO.Browser; + config: BrowserConfig; + state: Record; + applyState: (state: Record) => void; +} + declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace WebdriverIO { @@ -70,6 +79,17 @@ declare global { * @returns {Promise} value, returned by `stepCb` */ runStep(stepName: string, stepCb: () => Promise | unknown): Promise; + + // TODO: describe executionContext more precisely + executionContext: (RunnerTest | RunnerHook) & { + hermioneCtx: { + assertViewResults: Array; + }; + ctx: { + browser: WebdriverIO.Browser; + currentTest: RunnerTest; + }; + }; } interface Element { diff --git a/src/config/types.ts b/src/config/types.ts index b8fdbb863..98cf39c12 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -120,6 +120,14 @@ export interface CommonConfig { system: SystemConfig; headless: boolean | null; isolation: boolean; + + openAndWaitOpts: { + timeout?: number; + waitNetworkIdle: boolean; + waitNetworkIdleTimeout: number; + failOnNetworkError: boolean; + ignoreNetworkErrorsPatterns: Array; + }; } export interface SetsConfig { diff --git a/src/types/index.ts b/src/types/index.ts index aa4e2f1bc..64047126b 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -14,7 +14,7 @@ import { WorkerProcess } from "../utils/worker-process"; import { BaseHermione } from "../base-hermione"; import { CoordBounds, LooksSameOptions } from "looks-same"; -export { Suite as RunnerSuite, Test as RunnerTest } from "mocha"; +export { Suite as RunnerSuite, Test as RunnerTest, Hook as RunnerHook } from "mocha"; export type { Browser as WdioBrowser } from "webdriverio"; diff --git a/src/utils/worker-process.ts b/src/utils/worker-process.ts index eda7b2264..f66724b54 100644 --- a/src/utils/worker-process.ts +++ b/src/utils/worker-process.ts @@ -1,5 +1,7 @@ import { ChildProcess } from "child_process"; +type Serializable = string | object | number | boolean | bigint; + export class WorkerProcess { protected process: ChildProcess; @@ -11,7 +13,7 @@ export class WorkerProcess { this.process = process; } - send(message: unknown): boolean { + send(message: Serializable): boolean { if (!this.process.connected) { return false; } diff --git a/typings/global.d.ts b/typings/global.d.ts index 05161856b..6fe5974d2 100644 --- a/typings/global.d.ts +++ b/typings/global.d.ts @@ -28,3 +28,8 @@ interface SuiteDefinition { only: (title: string, fn: (this: Mocha.Suite) => void) => Mocha.Suite; skip: (title: string, fn: (this: Mocha.Suite) => void) => Mocha.Suite; } + +declare namespace globalThis { + // eslint-disable-next-line no-var + var expect: ExpectWebdriverIO.Expect; +}