Skip to content

Commit

Permalink
fix: "assertView", "moveCursorTo", "executionContext" and "currentTes…
Browse files Browse the repository at this point in the history
…t" types
  • Loading branch information
DudaGod committed May 29, 2024
1 parent 473d9b6 commit eecbe23
Show file tree
Hide file tree
Showing 23 changed files with 356 additions and 318 deletions.
6 changes: 5 additions & 1 deletion src/browser/commands/moveCursorTo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ChainablePromiseElement } from "webdriverio";
import type { Browser } from "../types";

type MoveToOptions = {
Expand All @@ -6,7 +7,10 @@ type MoveToOptions = {
};

// As of now, we can't export type of the command function directly. See: https://github.com/webdriverio/webdriverio/issues/12527
export type MoveCursorToCommand = (this: WebdriverIO.Element, options: MoveToOptions) => Promise<void>;
export type MoveCursorToCommand = (
this: WebdriverIO.Element | ChainablePromiseElement<WebdriverIO.Element>,
options: MoveToOptions,
) => Promise<void>;

const makeMoveCursorToCommand = (session: WebdriverIO.Browser) =>
async function (this: WebdriverIO.Element, { xOffset = 0, yOffset = 0 }: MoveToOptions = {}): Promise<void> {
Expand Down
4 changes: 3 additions & 1 deletion src/browser/commands/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AssertViewOptsConfig } from "../../config/types";
import { ChainablePromiseElement } from "webdriverio";

export interface AssertViewOpts extends Partial<AssertViewOptsConfig> {
/**
Expand Down Expand Up @@ -87,8 +88,9 @@ export type AssertViewCommand = (
selectors: string | string[],
opts?: AssertViewOpts,
) => Promise<void>;

export type AssertViewElementCommand = (
this: WebdriverIO.Element,
this: WebdriverIO.Element | ChainablePromiseElement<WebdriverIO.Element>,
state: string,
opts?: AssertViewOpts,
) => Promise<void>;
8 changes: 4 additions & 4 deletions src/browser/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { EventEmitter } from "events";
import type { AssertViewCommand, AssertViewElementCommand } from "./commands/types";
import type { BrowserConfig } from "./../config/browser-config";
import type { AssertViewResult, RunnerTest, RunnerHook } from "../types";
import type { AssertViewResult } from "../types";
import { MoveCursorToCommand } from "./commands/moveCursorTo";
import { OpenAndWaitCommand } from "./commands/openAndWait";
import { Test, Hook } from "../test-reader/test-object";

export interface BrowserMeta {
pid: number;
Expand Down Expand Up @@ -120,14 +121,13 @@ declare global {
*/
runStep<T = unknown>(this: WebdriverIO.Browser, stepName: string, stepCb: () => Promise<T> | T): Promise<T>;

// TODO: describe executionContext more precisely
executionContext: (RunnerTest | RunnerHook) & {
executionContext: (Test | Hook) & {
hermioneCtx: {
assertViewResults: Array<AssertViewResult>;
};
ctx: {
browser: WebdriverIO.Browser;
currentTest: RunnerTest;
currentTest: Test;
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type GroupName = Exclude<keyof StatsResult, "total" | "perBrowser">;
type StatEvent = {
group: GroupName;
id: string;
browserId: string;
browserId?: string;
};

export class Stats {
Expand Down
8 changes: 4 additions & 4 deletions src/test-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class TestCollection {
this.#specs = _.mapValues(specs, _.clone);
}

getRootSuite(browserId: string): RootSuite {
getRootSuite(browserId: string): RootSuite | null {
const test = this.#originalSpecs[browserId][0];
return test && test.parent && this.#getRoot(test.parent);
}
Expand All @@ -37,7 +37,7 @@ export class TestCollection {
}

#getRoot(suite: Suite): RootSuite {
return suite.root ? (suite as RootSuite) : this.#getRoot(suite.parent);
return suite.root ? (suite as RootSuite) : this.#getRoot(suite.parent!);
}

getBrowsers(): string[] {
Expand Down Expand Up @@ -99,7 +99,7 @@ export class TestCollection {
}
}

eachTestByVersions(browserId: string, cb: (test: Test, browserId: string, browserVersion: string) => void): void {
eachTestByVersions(browserId: string, cb: (test: Test, browserId: string, browserVersion?: string) => void): void {
const groups = _.groupBy(this.#specs[browserId], "browserVersion");
const versions = Object.keys(groups);
const maxLength =
Expand Down Expand Up @@ -130,7 +130,7 @@ export class TestCollection {
}

#mkDisabledTest(test: Test): TestDisabled {
return _.extend(test.clone(), { disabled: true });
return _.extend(test.clone(), { disabled: true }) as TestDisabled;
}

disableTest(fullTitle: string, browserId?: string): this {
Expand Down
2 changes: 1 addition & 1 deletion src/test-reader/controllers/skip-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class SkipController {
#addTrap(match: (browserId: string) => boolean, reason: string, { silent }: SkipOpts = {}): void {
this.#eventBus.emit(ReadEvents.NEW_BUILD_INSTRUCTION, ({ treeBuilder }: { treeBuilder: TreeBuilder }) => {
treeBuilder.addTrap(obj => {
if (!match(obj.browserId)) {
if (obj.browserId && !match(obj.browserId)) {
return;
}

Expand Down
104 changes: 0 additions & 104 deletions src/test-reader/test-object/configurable-test-object.js

This file was deleted.

107 changes: 107 additions & 0 deletions src/test-reader/test-object/configurable-test-object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import _ from "lodash";
import { TestObject } from "./test-object";
import type { ConfigurableTestObjectData, TestObjectData } from "./types";

type ConfigurableTestObjectOpts = Pick<ConfigurableTestObjectData, "file" | "id"> & TestObjectData;

type SkipData = {
reason: string;
};

export class ConfigurableTestObject extends TestObject {
#data: ConfigurableTestObjectData;

constructor({ title, file, id }: ConfigurableTestObjectOpts) {
super({ title });

this.#data = { id, file } as ConfigurableTestObjectData;
}

assign(src: this): this {
this.#data = { ...src.#data };

return super.assign(src);
}

skip({ reason }: SkipData): void {
this.pending = true;
this.skipReason = reason;
}

disable(): void {
this.disabled = true;
this.silentSkip = true;
}

get id(): ConfigurableTestObjectData["id"] {
return this.#data.id;
}

get file(): ConfigurableTestObjectData["file"] {
return this.#data.file;
}

set pending(val: ConfigurableTestObjectData["pending"]) {
this.#data.pending = val;
}

get pending(): ConfigurableTestObjectData["pending"] {
return this.#getInheritedProperty<ConfigurableTestObjectData["pending"]>("pending", false);
}

set skipReason(reason: ConfigurableTestObjectData["skipReason"]) {
this.#data.skipReason = reason;
}

get skipReason(): ConfigurableTestObjectData["skipReason"] {
return this.#getInheritedProperty<ConfigurableTestObjectData["skipReason"]>("skipReason", "");
}

set disabled(val: ConfigurableTestObjectData["disabled"]) {
this.#data.disabled = val;
}

get disabled(): ConfigurableTestObjectData["disabled"] {
return this.#getInheritedProperty<ConfigurableTestObjectData["disabled"]>("disabled", false);
}

set silentSkip(val: ConfigurableTestObjectData["silentSkip"]) {
this.#data.silentSkip = val;
}

get silentSkip(): ConfigurableTestObjectData["silentSkip"] {
return this.#getInheritedProperty<ConfigurableTestObjectData["silentSkip"]>("silentSkip", false);
}

set timeout(timeout: ConfigurableTestObjectData["timeout"]) {
this.#data.timeout = timeout;
}

get timeout(): ConfigurableTestObjectData["timeout"] {
return this.#getInheritedProperty<ConfigurableTestObjectData["timeout"]>("timeout", 0);
}

set browserId(id: string) {
this.#data.browserId = id;
}

get browserId(): ConfigurableTestObjectData["browserId"] {
return this.#getInheritedProperty<ConfigurableTestObjectData["browserId"]>("browserId", undefined);
}

set browserVersion(version: string) {
this.#data.browserVersion = version;
}

get browserVersion(): ConfigurableTestObjectData["browserVersion"] {
return this.#getInheritedProperty<ConfigurableTestObjectData["browserVersion"]>("browserVersion", undefined);
}

get hasBrowserVersionOverwritten(): boolean {
return "browserVersion" in this.#data;
}

#getInheritedProperty<T>(name: keyof ConfigurableTestObjectData, defaultValue: T): T {
return name in this.#data ? (this.#data[name] as T) : (_.get(this.parent, name, defaultValue) as T);
}
}
32 changes: 0 additions & 32 deletions src/test-reader/test-object/hook.js

This file was deleted.

Loading

0 comments on commit eecbe23

Please sign in to comment.