Skip to content

Commit

Permalink
chore: update webdriverio version (#989)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kabir-Ivan authored Aug 12, 2024
1 parent 9e5959e commit fdd4670
Show file tree
Hide file tree
Showing 8 changed files with 2,202 additions and 3,502 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ build
*.swo
*.swp
*.iml
*.tgz
.fuse*
.project
node_modules
Expand Down
5,629 changes: 2,146 additions & 3,483 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@
"@gemini-testing/commander": "2.15.3",
"@jspm/core": "2.0.1",
"@types/mocha": "10.0.1",
"@wdio/globals": "8.21.0",
"@wdio/protocols": "8.22.0",
"@wdio/types": "8.21.0",
"@wdio/utils": "8.35.0",
"@wdio/globals": "8.39.0",
"@wdio/protocols": "8.38.0",
"@wdio/types": "8.39.0",
"@wdio/utils": "8.39.0",
"@wdio/utils-cjs": "npm:@wdio/utils@7.26.0",
"bluebird": "3.5.1",
"chalk": "2.4.2",
"clear-require": "1.0.1",
"debug": "2.6.9",
"devtools": "8.21.0",
"devtools": "8.39.0",
"error-stack-parser": "2.1.4",
"escape-string-regexp": "1.0.5",
"expect-webdriverio": "3.5.3",
"expect-webdriverio": "3.6.0",
"fastq": "1.13.0",
"fs-extra": "5.0.0",
"gemini-configparser": "1.4.1",
Expand All @@ -93,7 +93,7 @@
"urijs": "1.19.11",
"url-join": "4.0.1",
"vite": "5.1.6",
"webdriverio": "8.21.0",
"webdriverio": "8.39.0",
"worker-farm": "1.7.0",
"yallist": "3.1.1"
},
Expand Down Expand Up @@ -154,8 +154,8 @@
"uglifyify": "3.0.4"
},
"peerDependencies": {
"ts-node": ">=10.5.0",
"@swc/core": ">=1.3.96"
"@swc/core": ">=1.3.96",
"ts-node": ">=10.5.0"
},
"peerDependenciesMeta": {
"ts-node": {
Expand Down
28 changes: 28 additions & 0 deletions src/browser/existing-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,40 @@ module.exports = class ExistingBrowser extends Browser {
_addCommands() {
this._addMetaAccessCommands(this._session);
this._decorateUrlMethod(this._session);
// The reason for doing this is that in webdriverio 8.26.2 there was a breaking change that made ElementsList an async iterator
// https://github.com/webdriverio/webdriverio/pull/11874
this._overrideGetElementsList(this._session);

commandsList.forEach(command => require(`./commands/${command}`).default(this));

super._addCommands();
}

_overrideGetElementsList(session) {
session.overwriteCommand("$$", async (origCommand, selector) => {
const arr = [];
const res = await origCommand(selector);
for await (const el of res) arr.push(el);
arr.parent = res.parent;
arr.foundWith = res.foundWith;
arr.selector = res.selector;
return arr;
});
session.overwriteCommand(
"$$",
async (origCommand, selector) => {
const arr = [];
const res = await origCommand(selector);
for await (const el of res) arr.push(el);
arr.parent = res.parent;
arr.foundWith = res.foundWith;
arr.selector = res.selector;
return arr;
},
true,
);
}

_addMetaAccessCommands(session) {
session.addCommand("setMeta", (key, value) => (this._meta[key] = value));
session.addCommand("getMeta", key => (key ? this._meta[key] : this._meta));
Expand Down
15 changes: 12 additions & 3 deletions src/browser/stacktrace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,25 @@ const overwriteAddCommand = (session: WebdriverIO.Browser, stackFrames: ShallowS
const overwriteOverwriteCommand = (session: WebdriverIO.Browser, stackFrames: ShallowStackFrames): void =>
session.overwriteCommand(
"overwriteCommand",
function (this, origCommand, name, wrapper: AnyFunc, elementScope): unknown {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function (this, origCommand: any, name, wrapper: AnyFunc, elementScope): unknown {
function decoratedWrapper(this: unknown, origFn: unknown, ...args: unknown[]): unknown {
return runWithStacktraceHooks({
stackFrames,
fn: () => wrapper.call(this, origFn, ...args),
stackFilterFunc: decoratedWrapper,
});
}

return origCommand.call(this, name, decoratedWrapper, elementScope);
return origCommand.call(
this,
name,
decoratedWrapper as WebdriverIO.OverwriteCommandFn<
WebdriverIO.Browser | WebdriverIO.Element,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(...args: any) => any
>,
elementScope,
);
},
);

Expand Down
9 changes: 4 additions & 5 deletions src/worker/browser-env/runner/test-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import type { Browser } from "../../../../browser/types";
import type { WorkerViteSocket } from "./types";
import type { BrowserViteEvents } from "../../../../runner/browser-env/vite/types";
import type { AsyncExpectationResult } from "../../../../runner/browser-env/vite/browser-modules/types";

type ExpectWdioMatchers = ExpectWebdriverIO.Matchers<AsyncExpectationResult, unknown>;
type ExpectWdioMatchers = ExpectWebdriverIO.Matchers<Promise<void>, unknown>;
type ExpectWdioMatcher = (actual: unknown, ...expected: unknown[]) => AsyncExpectationResult;

const prepareData = <T>(data: T): T => {
Expand Down Expand Up @@ -255,11 +254,11 @@ export class TestRunner extends NodejsEnvTestRunner {
const { publicAPI: session } = browser;

return async (payload, cb): Promise<void> => {
if (!global.expect) {
if (typeof expect === "undefined") {
return cb([{ pass: false, message: "Couldn't find expect module" }]);
}

const matcher = expectMatchers[payload.name as keyof ExpectWdioMatchers] as ExpectWdioMatcher;
const matcher = expectMatchers[payload.name as keyof ExpectWdioMatchers] as unknown as ExpectWdioMatcher;

if (!matcher) {
return cb([{ pass: false, message: `Couldn't find expect matcher with name "${payload.name}"` }]);
Expand Down Expand Up @@ -316,7 +315,7 @@ function transformExpectArg(arg: any): unknown {
arg.$$typeof as keyof typeof SUPPORTED_ASYMMETRIC_MATCHER
] as keyof AsymmetricMatchers;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const matcher: any = arg.inverse ? (global.expect.not as any)[matcherKey] : (global.expect as any)[matcherKey];
const matcher: any = arg.inverse ? (expect as any)[matcherKey] : (expect as any)[matcherKey];

if (!matcher) {
throw new Error(`Matcher "${matcherKey}" is not supported by expect-webdriverio`);
Expand Down
2 changes: 1 addition & 1 deletion src/worker/testplane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Testplane extends BaseTestplane {
async init(): Promise<void> {
await this._init();

if (!global.expect) {
if (typeof expect === "undefined") {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { setOptions } = require("expect-webdriverio");
setOptions(this._config.system.expectOpts);
Expand Down
2 changes: 1 addition & 1 deletion typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ declare namespace globalThis {

// remove after updating expect-webdriverio@4 (should migrate to esm first)
declare module "expect-webdriverio/lib/matchers" {
const matchers: ExpectWebdriverIO.Matchers<Promise<{ pass: boolean; message(): string }>, unknown>;
const matchers: ExpectWebdriverIO.Matchers<Promise<void>, unknown>;
export default matchers;
}

0 comments on commit fdd4670

Please sign in to comment.