Skip to content

Commit

Permalink
fix: minor import and types fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Sep 2, 2024
1 parent 9f7174c commit 41520fb
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 43 deletions.
11 changes: 2 additions & 9 deletions src/base-testplane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,15 @@ import Errors from "./errors";
import { tryToRegisterTsNode } from "./utils/typescript";
import { ConfigInput } from "./config/types";

type ConstructorWithOptionalConfig<T> = new (config?: string | ConfigInput) => T;
type ConstructorWithStringParam<T> = new (config: string) => T;

export abstract class BaseTestplane extends AsyncEmitter {
protected _interceptors: Interceptor[] = [];
protected _config: Config;

static create<T extends BaseTestplane>(this: ConstructorWithOptionalConfig<T>, config?: string | ConfigInput): T;

static create<T extends BaseTestplane>(this: ConstructorWithStringParam<T>, config: string): T;

static create<T extends BaseTestplane>(
this: ConstructorWithOptionalConfig<T> | ConstructorWithStringParam<T>,
this: new (config?: string | ConfigInput) => T,
config?: string | ConfigInput,
): T {
return new this(config as string);
return new this(config);
}

protected constructor(config?: string | ConfigInput) {
Expand Down
6 changes: 3 additions & 3 deletions src/browser-pool/basic-pool.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import debug from "debug";
import _ from "lodash";

import { NewBrowser } from "../browser/new-browser";
import { CancelledError } from "./cancelled-error";
import { AsyncEmitter, MasterEvents } from "../events";
import { Pool } from "./types";
import debug from "debug";
import { BrowserOpts, Pool } from "./types";
import { Config } from "../config";
import { Browser } from "../browser/browser";
import { BrowserOpts } from "./limited-pool";

export class BasicPool implements Pool {
private _config: Config;
Expand Down
7 changes: 4 additions & 3 deletions src/browser-pool/caching-pool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LimitedUseSet } from "./limited-use-set";
import debug from "debug";

import { LimitedUseSet } from "./limited-use-set";
import { buildCompositeBrowserId } from "./utils";
import { BasicPool } from "./basic-pool";
import { Config } from "../config";
Expand Down Expand Up @@ -34,7 +35,7 @@ export class CachingPool implements Pool {
return this._caches[compositeId];
}

getBrowser(id: string, opts: { version?: string } = {}): Promise<NewBrowser> {
async getBrowser(id: string, opts: { version?: string } = {}): Promise<NewBrowser> {
const { version } = opts;
const cache = this._getCacheFor(id, version);
const browser = cache.pop();
Expand Down Expand Up @@ -81,7 +82,7 @@ export class CachingPool implements Pool {
* not be cached
* @returns {Promise<undefined>}
*/
freeBrowser(browser: NewBrowser, options: FreeBrowserOpts = {}): Promise<void> {
async freeBrowser(browser: NewBrowser, options: FreeBrowserOpts = {}): Promise<void> {
const shouldFreeForNextRequest = (): boolean => {
const { compositeIdForNextRequest } = options;

Expand Down
25 changes: 10 additions & 15 deletions src/browser-pool/limited-pool.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
import debug from "debug";
import _ from "lodash";
import yallist from "yallist";
import { Pool } from "./types";

import { BrowserOpts, Pool } from "./types";
import { CancelledError } from "./cancelled-error";
import debug from "debug";
import { buildCompositeBrowserId } from "./utils";
import { Browser } from "../browser/browser";

export type LimitedPoolOpts = {
export interface LimitedPoolOpts {
limit: number;
isSpecificBrowserLimiter?: boolean;
};

export type BrowserOpts = {
force?: boolean;
version?: string;
highPriority?: boolean;
};
}

export type QueueItem = {
interface QueueItem {
id: string;
opts: {
force?: boolean;
version?: string;
};
resolve: (value: unknown) => void;
reject: (value: unknown) => void;
};
}

export class LimitedPool implements Pool {
private _limit: number;
Expand Down Expand Up @@ -68,7 +63,7 @@ export class LimitedPool implements Pool {
}
}

freeBrowser(browser: Browser, opts: BrowserOpts = {}): Promise<void> {
async freeBrowser(browser: Browser, opts: BrowserOpts = {}): Promise<void> {
--this._requests;

const nextRequest = this._lookAtNextRequest();
Expand Down Expand Up @@ -97,7 +92,7 @@ export class LimitedPool implements Pool {
this.underlyingPool.cancel();
}

private _getBrowser(id: string, opts: BrowserOpts = {}): Promise<Browser> {
private async _getBrowser(id: string, opts: BrowserOpts = {}): Promise<Browser> {
if (this._launched < this._limit) {
this.log("can launch one more");
this._launched++;
Expand All @@ -113,7 +108,7 @@ export class LimitedPool implements Pool {
});
}

private _newBrowser(id: string, opts: object): Promise<Browser> {
private async _newBrowser(id: string, opts: object): Promise<Browser> {
this.log(`launching new browser ${id} with opts:${JSON.stringify(opts)}`);

return this.underlyingPool.getBrowser(id, opts).catch(e => {
Expand Down
4 changes: 2 additions & 2 deletions src/browser-pool/limited-use-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import debug from "debug";
* attempt to put an object there causes the object to be finalized.
*/

export type LimitedUseSetOpts<T> = {
export interface LimitedUseSetOpts<T> {
useLimit: number;
finalize: (value: T) => Promise<void>;
formatItem: (value: T) => string;
};
}

export class LimitedUseSet<T extends object = object> {
private _useCounts: WeakMap<T, number>;
Expand Down
3 changes: 2 additions & 1 deletion src/browser-pool/per-browser-limited-pool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import debug from "debug";
import { zipObject, forEach } from "lodash";

import { Pool } from "./types";
import debug from "debug";
import { Config } from "../config";
import { Browser } from "../browser/browser";
import { LimitedPool } from "./limited-pool";
Expand Down
6 changes: 6 additions & 0 deletions src/browser-pool/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ export interface Pool<T extends Browser = Browser> {
freeBrowser(browser: T, opts?: object): Promise<void>;
cancel(): void;
}

export interface BrowserOpts {
force?: boolean;
version?: string;
highPriority?: boolean;
}
6 changes: 4 additions & 2 deletions src/browser/browser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import crypto from "crypto";
import { RequestOptions } from "https";

import { RemoteCapability } from "@wdio/types/build/Capabilities";
import _ from "lodash";

import { SAVE_HISTORY_MODE } from "../constants/config";
import { X_REQUEST_ID_DELIMITER } from "../constants/browser";
import history from "./history";
Expand All @@ -10,8 +14,6 @@ import { Config } from "../config";
import { AsyncEmitter } from "../events";
import { BrowserConfig } from "../config/browser-config";
import Callstack from "./history/callstack";
import { RemoteCapability } from "@wdio/types/build/Capabilities";
import { RequestOptions } from "https";

const CUSTOM_SESSION_OPTS = [
"outputDir",
Expand Down
2 changes: 1 addition & 1 deletion src/browser/existing-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Promise = require("bluebird");
const _ = require("lodash");
const webdriverio = require("webdriverio");
const { sessionEnvironmentDetector } = require("@wdio/utils-cjs");
const Browser = require("./browser").Browser;
const { Browser } = require("./browser");
const commandsList = require("./commands");
const Camera = require("./camera");
const clientBridge = require("./client-bridge");
Expand Down
2 changes: 2 additions & 0 deletions src/browser/new-browser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { URLSearchParams } from "url";

import URI from "urijs";
import { isBoolean, assign, isEmpty } from "lodash";
import { remote, RemoteOptions } from "webdriverio";

import { Browser, BrowserOpts } from "./browser";
import signalHandler from "../signal-handler";
import { runGroup } from "./history";
Expand Down
4 changes: 2 additions & 2 deletions src/test-reader/sets-builder/test-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class TestSet {
this.#set = _.clone(set);
}

expandFiles(expandOpts: globExtra.ExpandOpts, globOpts: globExtra.GlobOpts = {}): Promise<TestSetData> {
async expandFiles(expandOpts: globExtra.ExpandOpts, globOpts: globExtra.GlobOpts = {}): Promise<TestSetData> {
const { files, ignoreFiles = [] } = this.#set;
globOpts = _.clone(globOpts);
globOpts.ignore = ([] as string[])
Expand All @@ -34,7 +34,7 @@ export class TestSet {
.then(expandedFiles => (this.#set = _.extend(this.#set, { files: expandedFiles })));
}

transformDirsToMasks(): Promise<string[]> {
async transformDirsToMasks(): Promise<string[]> {
return Promise.all(
this.#set.files.map(file => {
if (globExtra.isMask(file)) {
Expand Down
7 changes: 6 additions & 1 deletion src/worker/runner/browser-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export class BrowserAgent {
this._pool = pool;
}

getBrowser({ sessionId, sessionCaps, sessionOpts, state }: BrowserAgentBrowserOpts): Promise<ExistingBrowser> {
async getBrowser({
sessionId,
sessionCaps,
sessionOpts,
state,
}: BrowserAgentBrowserOpts): Promise<ExistingBrowser> {
return this._pool.getBrowser({
browserId: this.browserId,
browserVersion: this.browserVersion,
Expand Down
2 changes: 0 additions & 2 deletions src/worker/testplane-facade.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

import { Testplane, WorkerRunTestOpts, WorkerRunTestResult } from "./testplane";
import RuntimeConfig from "../config/runtime-config";
import debug from "debug";
Expand Down
5 changes: 3 additions & 2 deletions src/worker/testplane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { WorkerEvents } from "../events";
import Runner from "./runner";
import { BaseTestplane } from "../base-testplane";
import { RefImageInfo, WdioBrowser, WorkerEventHandler } from "../types";
import { ConfigInput } from "../config/types";

export interface WorkerRunTestOpts {
browserId: string;
Expand Down Expand Up @@ -40,8 +41,8 @@ export interface Testplane {
export class Testplane extends BaseTestplane {
protected runner: Runner;

constructor(configPath: string) {
super(configPath);
constructor(config?: string | ConfigInput) {
super(config);

this.runner = Runner.create(this._config);

Expand Down

0 comments on commit 41520fb

Please sign in to comment.