@wdio/utils
Advanced tools
Comparing version 8.19.0 to 8.20.0
@@ -0,12 +1,11 @@ | ||
import webdriverMonad from './monad.js'; | ||
import initialisePlugin from './initialisePlugin.js'; | ||
import { startWebDriver } from './startWebDriver.js'; | ||
import { initialiseWorkerService, initialiseLauncherService } from './initialiseServices.js'; | ||
import webdriverMonad from './monad.js'; | ||
import { commandCallStructure, isValidParameter, getArgumentType, safeImport, isFunctionAsync, transformCommandLogResult, canAccess, sleep, isAppiumCapability } from './utils.js'; | ||
import { commandCallStructure, isValidParameter, getArgumentType, safeImport, isFunctionAsync, transformCommandLogResult, sleep, isAppiumCapability } from './utils.js'; | ||
import { wrapCommand, executeHooksWithArgs, executeAsync } from './shim.js'; | ||
import { testFnWrapper, wrapGlobalTestMethod } from './test-framework/index.js'; | ||
import { isW3C, capabilitiesEnvironmentDetector, sessionEnvironmentDetector, devtoolsEnvironmentDetector } from './envDetector.js'; | ||
import { startWebDriver } from './driver/index.js'; | ||
import { setupDriver, setupBrowser } from './driver/manager.js'; | ||
import { UNICODE_CHARACTERS, HOOK_DEFINITION } from './constants.js'; | ||
export { initialisePlugin, initialiseLauncherService, initialiseWorkerService, isFunctionAsync, transformCommandLogResult, webdriverMonad, commandCallStructure, isValidParameter, getArgumentType, safeImport, canAccess, sleep, isAppiumCapability, startWebDriver, setupBrowser, setupDriver, | ||
export { startWebDriver, initialisePlugin, initialiseLauncherService, initialiseWorkerService, isFunctionAsync, transformCommandLogResult, webdriverMonad, commandCallStructure, isValidParameter, getArgumentType, safeImport, sleep, isAppiumCapability, | ||
/** | ||
@@ -13,0 +12,0 @@ * runner shim |
/* istanbul ignore file */ | ||
import webdriverMonad from './monad.js'; | ||
import initialisePlugin from './initialisePlugin.js'; | ||
import { startWebDriver } from './startWebDriver.js'; | ||
import { initialiseWorkerService, initialiseLauncherService } from './initialiseServices.js'; | ||
import webdriverMonad from './monad.js'; | ||
import { commandCallStructure, isValidParameter, getArgumentType, safeImport, isFunctionAsync, transformCommandLogResult, canAccess, sleep, isAppiumCapability } from './utils.js'; | ||
import { commandCallStructure, isValidParameter, getArgumentType, safeImport, isFunctionAsync, transformCommandLogResult, sleep, isAppiumCapability } from './utils.js'; | ||
import { wrapCommand, executeHooksWithArgs, executeAsync } from './shim.js'; | ||
import { testFnWrapper, wrapGlobalTestMethod } from './test-framework/index.js'; | ||
import { isW3C, capabilitiesEnvironmentDetector, sessionEnvironmentDetector, devtoolsEnvironmentDetector } from './envDetector.js'; | ||
import { startWebDriver } from './driver/index.js'; | ||
import { setupDriver, setupBrowser } from './driver/manager.js'; | ||
import { UNICODE_CHARACTERS, HOOK_DEFINITION } from './constants.js'; | ||
export { initialisePlugin, initialiseLauncherService, initialiseWorkerService, isFunctionAsync, transformCommandLogResult, webdriverMonad, commandCallStructure, isValidParameter, getArgumentType, safeImport, canAccess, sleep, isAppiumCapability, startWebDriver, setupBrowser, setupDriver, | ||
export { startWebDriver, initialisePlugin, initialiseLauncherService, initialiseWorkerService, isFunctionAsync, transformCommandLogResult, webdriverMonad, commandCallStructure, isValidParameter, getArgumentType, safeImport, sleep, isAppiumCapability, | ||
/** | ||
@@ -14,0 +13,0 @@ * runner shim |
@@ -1,3 +0,2 @@ | ||
import path from 'node:path'; | ||
import { safeImport } from './utils.js'; | ||
import { safeImport, isAbsolute } from './utils.js'; | ||
/** | ||
@@ -13,3 +12,3 @@ * initialise WebdriverIO compliant plugins like reporter or services in the following way: | ||
*/ | ||
if (name[0] === '@' || path.isAbsolute(name)) { | ||
if (name[0] === '@' || isAbsolute(name)) { | ||
const service = await safeImport(name); | ||
@@ -16,0 +15,0 @@ if (service) { |
@@ -1,17 +0,3 @@ | ||
interface Retries { | ||
limit: number; | ||
attempts: number; | ||
} | ||
declare global { | ||
var expectAsync: any; | ||
} | ||
declare global { | ||
namespace NodeJS { | ||
interface Global { | ||
expect: any; | ||
expectAsync: any; | ||
} | ||
} | ||
} | ||
declare const executeHooksWithArgs: <T>(this: any, hookName: string, hooks?: Function | Function[], args?: any[]) => Promise<(Error | T)[]>; | ||
import type { Frameworks } from '@wdio/types'; | ||
export declare function executeHooksWithArgs<T>(this: any, hookName: string, hooks?: Function | Function[], args?: any[]): Promise<(T | Error)[]>; | ||
/** | ||
@@ -22,3 +8,3 @@ * wrap command to enable before and after command to be executed | ||
*/ | ||
declare const wrapCommand: <T>(commandName: string, fn: Function) => (...args: any) => Promise<T>; | ||
export declare function wrapCommand<T>(commandName: string, fn: Function): (...args: any) => Promise<T>; | ||
/** | ||
@@ -33,4 +19,3 @@ * execute test or hook asynchronously | ||
*/ | ||
declare function executeAsync(this: any, fn: Function, retries: Retries, args?: any[], timeout?: number): Promise<unknown>; | ||
export { executeHooksWithArgs, wrapCommand, executeAsync, }; | ||
export declare function executeAsync(this: any, fn: Function, retries: Frameworks.TestRetries, args?: any[], timeout?: number): Promise<unknown>; | ||
//# sourceMappingURL=shim.d.ts.map |
@@ -15,3 +15,3 @@ import logger from '@wdio/logger'; | ||
const PROMISE_METHODS = ['then', 'catch', 'finally']; | ||
const executeHooksWithArgs = async function executeHooksWithArgsShim(hookName, hooks = [], args = []) { | ||
export async function executeHooksWithArgs(hookName, hooks = [], args = []) { | ||
/** | ||
@@ -65,3 +65,3 @@ * make sure hooks are an array of functions | ||
return result; | ||
}; | ||
} | ||
/** | ||
@@ -72,3 +72,3 @@ * wrap command to enable before and after command to be executed | ||
*/ | ||
const wrapCommand = function wrapCommand(commandName, fn) { | ||
export function wrapCommand(commandName, fn) { | ||
async function wrapCommandFn(...args) { | ||
@@ -238,3 +238,3 @@ const beforeHookArgs = [commandName, args]; | ||
}; | ||
}; | ||
} | ||
/** | ||
@@ -249,3 +249,3 @@ * execute test or hook asynchronously | ||
*/ | ||
async function executeAsync(fn, retries, args = [], timeout = 20000) { | ||
export async function executeAsync(fn, retries, args = [], timeout = 20000) { | ||
this.wdioRetries = retries.attempts; | ||
@@ -286,2 +286,1 @@ try { | ||
} | ||
export { executeHooksWithArgs, wrapCommand, executeAsync, }; |
@@ -1,2 +0,3 @@ | ||
import type { Services } from '@wdio/types'; | ||
import type { Options, Services } from '@wdio/types'; | ||
export declare function isAbsolute(p: string): boolean; | ||
/** | ||
@@ -66,8 +67,2 @@ * overwrite native element commands with user defined | ||
/** | ||
* Helper utility to check file access | ||
* @param {string} file file to check access for | ||
* @return true if file can be accessed | ||
*/ | ||
export declare const canAccess: (file?: string) => boolean; | ||
/** | ||
* sleep | ||
@@ -84,2 +79,15 @@ * @param {number=0} ms number in ms to sleep | ||
export declare function isAppiumCapability(caps: WebdriverIO.Capabilities): boolean; | ||
/** | ||
* helper method to determine if we need to setup a browser driver | ||
* which is: | ||
* - whenever the user has set connection options that differ | ||
* from the default, or a port is set | ||
* - whenever the user defines `user` and `key` which later will | ||
* update the connection options | ||
*/ | ||
export declare function definesRemoteDriver(options: Pick<Options.WebDriver, 'user' | 'key' | 'protocol' | 'hostname' | 'port' | 'path'>): boolean; | ||
export declare function isChrome(browserName?: string): boolean; | ||
export declare function isSafari(browserName?: string): boolean; | ||
export declare function isFirefox(browserName?: string): boolean; | ||
export declare function isEdge(browserName?: string): boolean; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -1,8 +0,15 @@ | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import { pathToFileURL } from 'node:url'; | ||
import { resolve } from 'import-meta-resolve'; | ||
import { SUPPORTED_BROWSERNAMES, DEFAULT_PROTOCOL, DEFAULT_HOSTNAME, DEFAULT_PATH } from './constants.js'; | ||
const SCREENSHOT_REPLACEMENT = '"<Screenshot[base64]>"'; | ||
const SCRIPT_PLACEHOLDER = '"<Script[base64]>"'; | ||
const REGEX_SCRIPT_NAME = /return \((async )?function (\w+)/; | ||
const SLASH = '/'; | ||
function assertPath(path) { | ||
if (typeof path !== 'string') { | ||
throw new TypeError('Path must be a string. Received ' + JSON.stringify(path)); | ||
} | ||
} | ||
export function isAbsolute(p) { | ||
assertPath(p); | ||
return p.length > 0 && p.charCodeAt(0) === SLASH.codePointAt(0); | ||
} | ||
/** | ||
@@ -169,14 +176,20 @@ * overwrite native element commands with user defined | ||
* | ||
* Note that import-meta-resolve will resolve to CJS no ESM export is found | ||
* Note that import-meta-resolve will resolve to CJS no ESM export is found. | ||
* Only in Node.js environments | ||
*/ | ||
const localNodeModules = path.join(process.cwd(), 'node_modules'); | ||
try { | ||
importPath = await resolve(name, import.meta.url); | ||
} | ||
catch (err) { | ||
if (!globalThis.window) { | ||
const { resolve } = await import('import-meta-resolve'); | ||
try { | ||
importPath = await resolve(name, pathToFileURL(localNodeModules).toString()); | ||
importPath = await resolve(name, import.meta.url); | ||
} | ||
catch (err) { | ||
return null; | ||
const { join } = await import('node:path'); | ||
const { pathToFileURL } = await import('node:url'); | ||
const localNodeModules = join(process.cwd(), 'node_modules'); | ||
try { | ||
importPath = await resolve(name, pathToFileURL(localNodeModules).toString()); | ||
} | ||
catch (err) { | ||
return null; | ||
} | ||
} | ||
@@ -249,19 +262,2 @@ } | ||
/** | ||
* Helper utility to check file access | ||
* @param {string} file file to check access for | ||
* @return true if file can be accessed | ||
*/ | ||
export const canAccess = (file) => { | ||
if (!file) { | ||
return false; | ||
} | ||
try { | ||
fs.accessSync(file); | ||
return true; | ||
} | ||
catch (err) { | ||
return false; | ||
} | ||
}; | ||
/** | ||
* sleep | ||
@@ -282,1 +278,28 @@ * @param {number=0} ms number in ms to sleep | ||
} | ||
/** | ||
* helper method to determine if we need to setup a browser driver | ||
* which is: | ||
* - whenever the user has set connection options that differ | ||
* from the default, or a port is set | ||
* - whenever the user defines `user` and `key` which later will | ||
* update the connection options | ||
*/ | ||
export function definesRemoteDriver(options) { | ||
return Boolean((options.protocol && options.protocol !== DEFAULT_PROTOCOL) || | ||
(options.hostname && options.hostname !== DEFAULT_HOSTNAME) || | ||
Boolean(options.port) || | ||
(options.path && options.path !== DEFAULT_PATH) || | ||
Boolean(options.user && options.key)); | ||
} | ||
export function isChrome(browserName) { | ||
return Boolean(browserName && SUPPORTED_BROWSERNAMES.chrome.includes(browserName.toLowerCase())); | ||
} | ||
export function isSafari(browserName) { | ||
return Boolean(browserName && SUPPORTED_BROWSERNAMES.safari.includes(browserName.toLowerCase())); | ||
} | ||
export function isFirefox(browserName) { | ||
return Boolean(browserName && SUPPORTED_BROWSERNAMES.firefox.includes(browserName.toLowerCase())); | ||
} | ||
export function isEdge(browserName) { | ||
return Boolean(browserName && SUPPORTED_BROWSERNAMES.edge.includes(browserName.toLowerCase())); | ||
} |
{ | ||
"name": "@wdio/utils", | ||
"version": "8.19.0", | ||
"version": "8.20.0", | ||
"description": "A WDIO helper utility to provide several utility functions used across the project.", | ||
@@ -9,7 +9,14 @@ "author": "Christian Bromann <mail@bromann.dev>", | ||
"type": "module", | ||
"types": "./build/index.d.ts", | ||
"exports": { | ||
".": "./build/index.js", | ||
".": { | ||
"import": "./build/index.js", | ||
"types": "./build/index.d.ts" | ||
}, | ||
"./node": { | ||
"import": "./build/node/index.js", | ||
"types": "./build/node/index.d.ts" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"types": "./build/index.d.ts", | ||
"typeScriptVersion": "3.8.3", | ||
@@ -36,3 +43,3 @@ "engines": { | ||
"@wdio/logger": "8.16.17", | ||
"@wdio/types": "8.19.0", | ||
"@wdio/types": "8.20.0", | ||
"decamelize": "^6.0.0", | ||
@@ -53,3 +60,3 @@ "deepmerge-ts": "^5.1.0", | ||
}, | ||
"gitHead": "5179b3b3d0bced033e719890baf4517137ac1576" | ||
"gitHead": "6aa9e33233a6abc832bb16d2e24aaaa382e206b6" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
155173
60
3204
+ Added@wdio/types@8.20.0(transitive)
- Removed@wdio/types@8.19.0(transitive)
Updated@wdio/types@8.20.0